replace-header 910 B

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