summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2009-12-27 19:47:13 +0100
committerTobias Klauser <tklauser@distanz.ch>2009-12-27 19:47:13 +0100
commitcd382ae40663ca89aef49bc946de58dc8a6766c1 (patch)
tree3d8fc1343125d0ae973c4b9176e46b23c0824fd0
parent09d2f0e836ba322747b9bac1dc33dcb8ef0224ed (diff)
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.
-rwxr-xr-xmkheader.py18
1 files 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: