diff options
author | Tobias Klauser <klto@zhaw.ch> | 2009-04-21 12:49:28 +0200 |
---|---|---|
committer | Tobias Klauser <klto@zhaw.ch> | 2009-04-21 12:49:28 +0200 |
commit | 6ec838a7232b7adf051935b93cbe132ba7616b25 (patch) | |
tree | 8df383b8efb84d06fc54d1bf34307af38bce6e66 |
Initial commit
-rwxr-xr-x | mkheader.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/mkheader.py b/mkheader.py new file mode 100755 index 0000000..b28e1de --- /dev/null +++ b/mkheader.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import os +import sys +import re + +def usage(): + print """usage: %s header...""" % (os.path.basename(sys.argv[0])) + +def main(): + if len(sys.argv) < 2: + usage() + sys.exit() + + overwrite = False + first = 1 + if len(sys.argv) >= 2 and sys.argv[1] == '-f': + overwrite = True + first = 2 + + p = re.compile('[a-zA-Z0-9._-]+\.h') + for f in sys.argv[first:]: + if not p.match(f): + print "Invalid header filename '%s'. Header not created" % f + continue + + if not overwrite and os.path.exists(f): + print "Header file '%s' already exists. Use -f to override." % f + continue + + print "Creating %s..." % f + q = re.compile('[.-]') + define = q.sub('_', f.upper()) + f = open(f, 'w') + f.write('#ifndef _%s_\n' % define) + f.write('#define _%s_\n\n' % define) + f.write('/* TODO: Your code here */\n\n') + f.write('#endif /* _%s_ */' % define) + f.close() + + print "Finished" + +if __name__ == '__main__': + main() |