diff options
Diffstat (limited to 'internalize_scripts.py')
-rwxr-xr-x | internalize_scripts.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/internalize_scripts.py b/internalize_scripts.py index b0b06fdf..314fb6c0 100755 --- a/internalize_scripts.py +++ b/internalize_scripts.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -import string, sys, os.path +import string, sys, os.path, getopt escapes = {} escapes['\a'] = r'\a' @@ -64,7 +64,34 @@ class cfunc: TYPES = ['function', 'completion'] type_to_funcs = dict((t, []) for t in TYPES) -for file in sys.argv[1:]: + +def usage(script_name): + print("Usage: {0} [--output output_directory] files...".format(script_name)) + print("""Command options are: + --output directory\t\tThe directory to output the files + -h, --help\t\t\tShow this help message + """) + +script_name = sys.argv[0] +try: + opts, file_paths = getopt.gnu_getopt(sys.argv[1:], 'h', ['output=', 'help']) +except getopt.GetoptError as err: + print(err.msg) # will print something like "option -a not recognized" + usage(script_name) + sys.exit(2) + +output_directory = './' +for opt, value in opts: + if opt in ('--output',): + output_directory = value + elif opt in ('-h', '--help'): + usage(script_name) + sys.exit(0) + else: + assert False, "unhandled option" + + +for file in file_paths: fd = open(file, 'r') newlines = [] for line in fd: @@ -89,7 +116,7 @@ for funcs in type_to_funcs.values(): funcs.sort(key=cfunc.cfunc_name) # Output our header -fd = open('builtin_scripts.h', 'w') +fd = open(os.path.join(output_directory, 'builtin_scripts.h'), 'w') fd.write('/* This file is generated by internalize_scripts.py */\n\n') fd.write("""struct builtin_script_t { const wchar_t *name; @@ -106,7 +133,7 @@ for type in TYPES: fd.close() # Output the function definitions -fd = open('builtin_scripts.cpp', 'w') +fd = open(os.path.join(output_directory, 'builtin_scripts.cpp'), 'w') fd.write('/* This file is generated by internalize_scripts.py */\n\n') fd.write('#include "builtin_scripts.h"\n\n') for type in TYPES: |