mirror of https://github.com/nirenjan/libx52.git
69 lines
2.4 KiB
Python
Executable File
69 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Generate the module name to map for use by the daemon"""
|
|
|
|
import os.path
|
|
import sys
|
|
|
|
import module_defs
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) != 3:
|
|
print("Usage: {sys.argv[0]} <output-header> <output-source>", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
with open(sys.argv[1], 'w', encoding='utf-8') as out_fd:
|
|
# Generate the header
|
|
print("// Autogenerated module/loglevel header - DO NOT EDIT\n",
|
|
file=out_fd)
|
|
|
|
include_guard = os.path.basename(sys.argv[1]).replace('-', '_').replace('.', '_').upper()
|
|
print(f"#ifndef {include_guard}", file=out_fd)
|
|
print(f"#define {include_guard}\n", file=out_fd)
|
|
|
|
for mod in module_defs.Module:
|
|
print(f"#define X52D_MOD_{mod.name} {mod.value}", file=out_fd)
|
|
|
|
print(f"#define X52D_MOD_GLOBAL 0xFF", file=out_fd)
|
|
print(f"#define X52D_MOD_MAX {len(module_defs.Module)}\n", file=out_fd)
|
|
|
|
print(f"int lookup_module_by_name(const char *name);", file=out_fd)
|
|
print(f"const char * lookup_module_by_id(int id);", file=out_fd)
|
|
print(f"int lookup_level_by_name(const char *name);", file=out_fd)
|
|
print(f"const char * lookup_level_by_id(int id);", file=out_fd)
|
|
|
|
print(f"\n#endif // !defined {include_guard}", file=out_fd)
|
|
|
|
with open(sys.argv[2], 'w', encoding='utf-8') as out_fd:
|
|
print("// Autogenerated module/loglevel tables - DO NOT EDIT\n",
|
|
file=out_fd)
|
|
|
|
print('#include <stddef.h>', file=out_fd)
|
|
print('#include <limits.h>\n', file=out_fd)
|
|
|
|
print(f'#include "{os.path.basename(sys.argv[1])}"', file=out_fd)
|
|
print('#include "name-id-map.h"\n', file=out_fd)
|
|
|
|
print('const struct name_id_map module_map[] = {', file=out_fd)
|
|
for mod in module_defs.Module:
|
|
print(f' {{ "{mod.name.lower()}", {mod.value} }},', file=out_fd)
|
|
|
|
print(' { NULL, INT_MAX }', file=out_fd)
|
|
print('};\n', file=out_fd)
|
|
|
|
print('const struct name_id_map loglevel_map[] = {', file=out_fd)
|
|
for level in module_defs.LogLevel:
|
|
if level == module_defs.LogLevel.NOTSET:
|
|
level_name = 'default'
|
|
else:
|
|
level_name = level.name.lower()
|
|
|
|
print(f' {{ "{level_name}", {level.value} }},', file=out_fd)
|
|
|
|
print(' { NULL, INT_MAX }', file=out_fd)
|
|
|
|
print('};\n', file=out_fd)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|