PR tree-optimization/82929
[official-gcc.git] / contrib / header-tools / replace-header
blobce20096a453d755c705dfe97088e02db14c4ee89
1 #! /usr/bin/python2
2 import os.path
3 import sys
4 import shlex
5 import re
7 from headerutils import *
10 files = list()
11 replace = list()
12 find = ""
13 usage = False
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)
28 if find == "":
29   usage = True
31 if usage:
32   print "replace-header -fheader -rheader [-rheader] file1 [filen.]"
33   sys.exit(0)
35 string = ""
36 for x in replace:
37   string = string + " '"+x+"'"
38 print "Replacing '"+find+"'  with"+string
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