From cd382ae40663ca89aef49bc946de58dc8a6766c1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Dec 2009 19:47:13 +0100 Subject: mkheader.py: Accept path to header as an argument The full path will be used as a base for the guard name unless you pass the -p option, which causes mkheader.py to just use the basename. --- mkheader.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mkheader.py b/mkheader.py index d35a600..0b5f927 100755 --- a/mkheader.py +++ b/mkheader.py @@ -20,12 +20,13 @@ def usage(): -e launch editor after creating files. Uses editor from $EDITOR envvar. -f overwrite existing files + -p do not include full path in header guard name, just the basename -s print generated to stdout instead of writing it to file -h show this help and exit""" % (os.path.basename(sys.argv[0])) def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "efsh") + opts, args = getopt.getopt(sys.argv[1:], "efpsh") except getopt.GetoptError, err: print str(err) usage() @@ -37,12 +38,15 @@ def main(): overwrite = False launch_editor = False + include_path = True to_stdout = False for o, a in opts: if o == "-e": launch_editor = True elif o == "-f": overwrite = True + elif o == "-p": + include_path = False elif o == "-s": to_stdout = True elif o == "-h": @@ -55,18 +59,18 @@ def main(): print "Options -e and -s cannot be used together" sys.exit(2) - p = re.compile('[a-zA-Z0-9._-]+\.h') for f in args: - if not p.match(f): - print "Invalid header filename '%s'. Header not created" % f - continue + if include_path: + s = f + else: + s = os.path.basename(f) if not to_stdout and not overwrite and os.path.exists(f): print "Header file '%s' already exists. Use -f to override." % f continue - q = re.compile('[.-]') - define = q.sub('_', f.upper()) + q = re.compile('[^a-zA-Z0-9_]') + define = q.sub('_', s.upper()) if to_stdout: fd = sys.stdout else: -- cgit v1.2.3-54-g00ecf