44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
import sys
|
|
from os import path
|
|
|
|
from csv_input import read_input
|
|
from generate import renderer
|
|
|
|
from byte_position import parse
|
|
|
|
type_dict = {
|
|
1: 'uint8_t',
|
|
2: 'uint16_t',
|
|
4: 'uint16_le_be',
|
|
8: 'uint32_le_be',
|
|
}
|
|
|
|
def _camelcase(name):
|
|
want_upper = True
|
|
for c in name:
|
|
if c == '_':
|
|
want_upper = True
|
|
else:
|
|
yield c.upper() if want_upper else c
|
|
want_upper = False
|
|
|
|
def camelcase(name):
|
|
return "".join(_camelcase(name))
|
|
|
|
def render_fields(input_name, fields):
|
|
yield "package filesystem.iso9660;"
|
|
yield f"class {camelcase(input_name)} {{"
|
|
for field in fields:
|
|
yield f"public static final int {field.name.upper()} = {field.start - 1};"
|
|
yield "}"
|
|
|
|
if __name__ == "__main__":
|
|
input_file = sys.argv[1]
|
|
input_name0, _ = path.splitext(input_file)
|
|
_, input_name = path.split(input_name0)
|
|
rows = read_input(input_file)
|
|
fields = list(parse(rows))
|
|
render, out = renderer()
|
|
render(render_fields(input_name, fields))
|
|
sys.stdout.write(out.getvalue())
|