diff --git a/util/wren_to_c_string.py b/util/wren_to_c_string.py index 8129882f..6dc237d2 100755 --- a/util/wren_to_c_string.py +++ b/util/wren_to_c_string.py @@ -21,34 +21,39 @@ def wren_to_c_string(input_path, wren_source_lines, module): wren_source = "" + # cut off blank lines at the bottom + while (wren_source_lines[-1].strip()==""): + wren_source_lines.pop() for line in wren_source_lines: line = line.replace('"', "\\\"") - line = line.replace("\n", "\\n\"") - if wren_source: wren_source += "\n" - wren_source += '"' + line + line = line.replace("\n", "\\n") + wren_source += '"' + line + '"\n' + + wren_source = wren_source.strip() return PREAMBLE.format(input_path, module, wren_source) +def process_file(path): + infile = os.path.basename(path) + outfile = infile + ".inc" + print("{} => {}").format(path.replace("src/",""), outfile) -def main(): - parser = argparse.ArgumentParser( - description="Convert a Wren library to a C string literal.") - parser.add_argument("output", help="The output file to write") - parser.add_argument("input", help="The source .wren file") - - args = parser.parse_args() - - with open(args.input, "r") as f: + with open(path, "r") as f: wren_source_lines = f.readlines() - module = os.path.splitext(os.path.basename(args.input))[0] + module = os.path.splitext(infile)[0] module = module.replace("opt_", "") module = module.replace("wren_", "") - c_source = wren_to_c_string(args.input, wren_source_lines, module) + c_source = wren_to_c_string(infile, wren_source_lines, module) - with open(args.output, "w") as f: + with open(outfile, "w") as f: f.write(c_source) +def main(): + files = glob.glob("src/module/*.wren") + for file in files: + process_file(file) + main()