From 6ec838a7232b7adf051935b93cbe132ba7616b25 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Apr 2009 12:49:28 +0200 Subject: Initial commit --- mkheader.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 mkheader.py 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() -- cgit v1.2.3-54-g00ecf