import re SCR_CMD_PAT = re.compile(r"^[ \t]*script_cmd_table_entry\s+(SCR_OP_\w+).*?ScrCmd_.*") def main(): output = [ "//", "// DO NOT MODIFY THIS FILE! It is auto-generated by tools/misc/make_scr_cmd_constants.py", "//", "#ifndef GUARD_SCR_CMD_CONSTANTS_H", "#define GUARD_SCR_CMD_CONSTANTS_H\n", "enum ScrOp", "{" ] with open("data/script_cmd_table.inc", "r") as f: ctr = 0 for line in f.readlines(): if match := re.search(SCR_CMD_PAT, line): new_line = " " + match.group(1) + f" = 0x{ctr:X}," output.append(new_line) ctr += 1 output.append("};") output.append("\n#endif // GUARD_SCR_CMD_CONSTANTS_H\n") with open("include/constants/script_commands.h", "w+") as f: f.write('\n'.join(output)) if __name__ == "__main__": main()