xref: /netbsd-src/external/gpl3/gcc.old/dist/contrib/header-tools/replace-header (revision 36ac495d2b3ea2b9d96377b2143ebfedac224b92)
1#! /usr/bin/python2
2import os.path
3import sys
4import shlex
5import re
6
7from headerutils import *
8
9
10files = list()
11replace = list()
12find = ""
13usage = False
14
15for 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
28if find == "":
29  usage = True
30
31if usage:
32  print "replace-header -fheader -rheader [-rheader] file1 [filen.]"
33  sys.exit(0)
34
35string = ""
36for x in replace:
37  string = string + " '"+x+"'"
38print "Replacing '"+find+"'  with"+string
39
40for 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
54