Skip to content

Instantly share code, notes, and snippets.

@ameerkat
Created July 10, 2011 02:27
Show Gist options
  • Save ameerkat/1074174 to your computer and use it in GitHub Desktop.
Save ameerkat/1074174 to your computer and use it in GitHub Desktop.
Templatized header generator for a cpp project
from sys import argv
import re
def header_def_name(camelcase):
word = ""
for ch in camelcase:
if ch.isupper() and len(word) > 0:
word += "_"
word += ch
return word.upper()
if __name__ == "__main__":
if(len(argv) <= 1):
print "error: must have at least one argument"
exit()
f = open(argv[1])
if argv[1] == "generic_header.tpl":
# create header name for generic tpl if not provided
if(len(argv) <= 3):
argv.append(header_def_name(argv[2]))
infile = f.read()
print infile.format(*argv[2:]),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment