Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. # This file can be used as a template for search-and-replace operations across a bunch of files.
  2. # It's fairly slow, but it's still a lot faster than doing it by hand.
  3. # You can use foreach.exe or batch commands to run the script on a bunch of files at once.
  4. # It's a good idea to test your regular expressions beforehand though. To do this, just set g_bTest to 1.
  5. import sys
  6. import re
  7. g_bTest = 0
  8. # Read the file in.
  9. f = open( sys.argv[1], "rt" )
  10. lines = f.readlines()
  11. f.close()
  12. # First entry is the regular expression to look for.
  13. # Second entry is the text to replace it with.
  14. myREList = [
  15. [re.compile( r"m_vecRenderOrigin" ), r"GetAbsOrigin()"],
  16. [re.compile( r"m_vecRenderAngles" ), r"GetAbsAngles()"],
  17. [re.compile( r"GetAbsOrigin\(\)\s*\=\s*(?P<setTo>.+);" ), r"SetAbsOrigin( \g<setTo> );" ],
  18. [re.compile( r"GetAbsAngles\(\)\s*\=\s*(?P<setTo>.+);" ), r"SetAbsAngles( \g<setTo> );" ],
  19. [re.compile( r"SetAbsOrigin\( GetAbsOrigin\(\) \);" ), r"" ],
  20. [re.compile( r"SetAbsAngles\( GetAbsAngles\(\) \);" ), r"" ],
  21. [re.compile( r"GetAbsOrigin\(\)\.Init\(\)" ), r"SetAbsOrigin( Vector( 0, 0, 0 ) )"],
  22. [re.compile( r"GetAbsAngles\(\)\.Init\(\)" ), r"SetAbsAngles( Vector( 0, 0, 0 ) )"],
  23. ]
  24. # Now replace occurrences of it.
  25. i = 1
  26. if g_bTest:
  27. # If g_bTest is set, just print out the matches.
  28. for x in lines:
  29. startX = x
  30. for curRE in myREList:
  31. x = curRE[0].sub( curRE[1], x )
  32. if x != startX:
  33. print "%d: %s" % ( i, x )
  34. i += 1
  35. else:
  36. f = open( sys.argv[1], "wt" )
  37. for x in lines:
  38. for curRE in myREList:
  39. x = curRE[0].sub( curRE[1], x )
  40. f.write( x )
  41. f.close()
  42. print sys.argv[1]