| 1 |
#! /usr/bin/python3 |
| 2 |
import os.path |
| 3 |
import sys |
| 4 |
import shlex |
| 5 |
import re |
| 6 |
|
| 7 |
from headerutils import * |
| 8 |
|
| 9 |
|
| 10 |
files = list() |
| 11 |
replace = list() |
| 12 |
find = "" |
| 13 |
usage = False |
| 14 |
|
| 15 |
for x in sys.argv[1:]: |
| 16 |
if x[0:2] == "-h": |
| 17 |
usage = True |
| 18 |
elif x[0:2] == "-f" and find == "": |
| 19 |
find = x[2:] |
| 20 |
elif x[0:2] == "-r": |
| 21 |
replace.append (x[2:]) |
| 22 |
elif x[0:1] == "-": |
| 23 |
print ("Error: unrecognized option " + x) |
| 24 |
usage = True |
| 25 |
else: |
| 26 |
files.append (x) |
| 27 |
|
| 28 |
if find == "": |
| 29 |
usage = True |
| 30 |
|
| 31 |
if usage: |
| 32 |
print ("replace-header -fheader -rheader [-rheader] file1 [filen.]") |
| 33 |
sys.exit(0) |
| 34 |
|
| 35 |
string = "" |
| 36 |
for x in replace: |
| 37 |
string = string + " '"+x+"'" |
| 38 |
print ("Replacing '"+find+"' with"+string) |
| 39 |
|
| 40 |
for x in files: |
| 41 |
src = readwholefile (x) |
| 42 |
src = find_replace_include (find, replace, src) |
| 43 |
if (len(src) > 0): |
| 44 |
print (x + ": Changed") |
| 45 |
out = open(x, "w") |
| 46 |
for line in src: |
| 47 |
out.write (line); |
| 48 |
out.close () |
| 49 |
else: |
| 50 |
print (x) |
| 51 |
|
| 52 |
|
| 53 |
|