diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2009-12-27 19:38:01 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2009-12-27 19:38:01 +0100 |
commit | 09d2f0e836ba322747b9bac1dc33dcb8ef0224ed (patch) | |
tree | 99d0fc35edb0d897509015af4ff109d3c075d508 | |
parent | 7116841eced45ce326882f7519ffd19ee9eca1af (diff) |
mkheader: Convert tabs to spaces
-rwxr-xr-x | mkheader.py | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/mkheader.py b/mkheader.py index 6ed2592..d35a600 100755 --- a/mkheader.py +++ b/mkheader.py @@ -16,7 +16,7 @@ import getopt import re def usage(): - print """usage: %s [OPTION] FILE... + print """usage: %s [OPTION] FILE... -e launch editor after creating files. Uses editor from $EDITOR envvar. -f overwrite existing files @@ -24,77 +24,77 @@ def usage(): -h show this help and exit""" % (os.path.basename(sys.argv[0])) def main(): - try: - opts, args = getopt.getopt(sys.argv[1:], "efsh") - except getopt.GetoptError, err: - print str(err) - usage() - sys.exit(2) + try: + opts, args = getopt.getopt(sys.argv[1:], "efsh") + except getopt.GetoptError, err: + print str(err) + usage() + sys.exit(2) - if len(args) < 1: - usage() - sys.exit(2) + if len(args) < 1: + usage() + sys.exit(2) - overwrite = False - launch_editor = False - to_stdout = False - for o, a in opts: - if o == "-e": - launch_editor = True - elif o == "-f": - overwrite = True - elif o == "-s": - to_stdout = True - elif o == "-h": - usage() - sys.exit() - else: - assert False, "unhandled option" + overwrite = False + launch_editor = False + to_stdout = False + for o, a in opts: + if o == "-e": + launch_editor = True + elif o == "-f": + overwrite = True + elif o == "-s": + to_stdout = True + elif o == "-h": + usage() + sys.exit() + else: + assert False, "unhandled option" - if to_stdout and launch_editor: - print "Options -e and -s cannot be used together" - sys.exit(2) + if to_stdout and launch_editor: + 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 + 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 not to_stdout and not overwrite and os.path.exists(f): - print "Header file '%s' already exists. Use -f to override." % f - continue + 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()) - if to_stdout: - fd = sys.stdout - else: - print "Creating %s..." % f - fd = open(f, 'w') - fd.write('#ifndef _%s_\n' % define) - fd.write('#define _%s_\n\n' % define) - fd.write('/* TODO: Your code here */\n\n') - fd.write('#endif /* _%s_ */' % define) - if not to_stdout: - fd.close() + q = re.compile('[.-]') + define = q.sub('_', f.upper()) + if to_stdout: + fd = sys.stdout + else: + print "Creating %s..." % f + fd = open(f, 'w') + fd.write('#ifndef _%s_\n' % define) + fd.write('#define _%s_\n\n' % define) + fd.write('/* TODO: Your code here */\n\n') + fd.write('#endif /* _%s_ */' % define) + if not to_stdout: + fd.close() - if launch_editor: - editor = os.getenv("EDITOR") - if editor is None: - editor = "vi" + if launch_editor: + editor = os.getenv("EDITOR") + if editor is None: + editor = "vi" - # Fork an editor for each file as not all editors support - # editing multiple files at once (e.g. splitted view in vim) - for f in args: - print "Editing header '%s' with '%s'" % (f, editor) + # Fork an editor for each file as not all editors support + # editing multiple files at once (e.g. splitted view in vim) + for f in args: + print "Editing header '%s' with '%s'" % (f, editor) - pid = os.fork() - if pid == 0: # child process - os.execvp(editor, [editor, f]) - sys.exit(0) - else: # parent process - os.waitpid(pid, 0) + pid = os.fork() + if pid == 0: # child process + os.execvp(editor, [editor, f]) + sys.exit(0) + else: # parent process + os.waitpid(pid, 0) if __name__ == '__main__': - main() + main() |