aboutsummaryrefslogtreecommitdiff
path: root/scripts/rcc_format.py
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-03-30 14:08:41 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-03-30 14:17:00 +0300
commitf9ea03470e3a0bbe67ccb0a531dcf0e39aec1e90 (patch)
treea2079e6810e083ed437d2c0f1b9b1fe0bba27776 /scripts/rcc_format.py
parentDrop dependency on serge-sans-paille/frozen (diff)
downloadrcc-f9ea03470e3a0bbe67ccb0a531dcf0e39aec1e90.tar.xz
Move scripts/rcc to top level
- add rcc generator for use when importing as subproject
Diffstat (limited to 'scripts/rcc_format.py')
-rw-r--r--scripts/rcc_format.py67
1 files changed, 0 insertions, 67 deletions
diff --git a/scripts/rcc_format.py b/scripts/rcc_format.py
deleted file mode 100644
index 7fcfe34..0000000
--- a/scripts/rcc_format.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from collections import namedtuple
-import xml.etree.ElementTree as xml
-
-resource = namedtuple('resource', 'alias variable path')
-
-def to_variable_name(path):
- name = path.replace('/', '_')
- if name.endswith('.zstd'):
- name = name[:-5]
- name = name.replace('-', '_')
- name = name.replace('.', '_')
- return name
-
-def filelist(file):
- root = xml.parse(file).getroot()
- if root.tag != 'RCC':
- return None
-
- files = []
- for child in root:
- if child.tag == 'qresource':
- prefix = child.attrib['prefix']
- for i in child:
- alias = prefix + '/' + i.attrib['alias']
- variable = to_variable_name(i.text)
- path = i.text
- files.append(resource(alias, variable, path))
-
- return files
-
-def write_header(file, namespace):
- print("// Autogenerated binary file hexdump", file=file)
- print("// This file may get overwritten by the build system\n", file=file)
- print("#include <embed.h>\n", file=file)
- print("namespace {} {{".format(namespace), file=file)
-
-def write_item(file, array_name, array_data):
- line_items = 0
-
- print("constexpr uint8_t {}[] = {{".format(array_name), file=file)
-
- for byte in array_data[0:len(array_data)]:
- line_items+=1
- if line_items == 16:
- print(" 0x{:02X},".format(byte), file=file)
- line_items = 0
- else:
- print(" 0x{:02X},".format(byte), file=file, end='')
-
-
- print("};", file=file)
- print("constexpr size_t {}_len = {};\n".format(array_name, len(array_data)), file=file)
-
-def write_entries(file, resource_list):
- print("constexpr std::array entries {", file=file)
- for f in resource_list:
- print(" \"{}\", ".format(f.alias), file=file)
- print("};\n", file=file)
-
- print("constexpr std::array values {", file=file)
- for f in resource_list:
- print(" std::span( {}, {}_len ),".format(f.variable, f.variable), file=file)
- print("};\n", file=file)
-
-def write_footer(file, namespace):
- print("\n}} // namespace {}".format(namespace), file=file)
-