File: xml2hpp.py

package info (click to toggle)
libretro-nestopia 1.53.0%2B20250119.git5b56b6b-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 13,028 kB
  • sloc: cpp: 108,465; xml: 27,232; python: 1,329; ansic: 772; makefile: 640
file content (31 lines) | stat: -rwxr-xr-x 740 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

# A Python script to convert NstDatabase.xml to a file that can be baked into
# the Nestopia core, so that users won't have to maintain NstDatabase.xml in
# their system directory.
#
# Licensed under the same license as Nestopia UE.

import sys
if len(sys.argv) > 1:
    in_file = sys.argv[1]
else:
    in_file = "../NstDatabase.xml"

if len(sys.argv) > 2:
    out_file = sys.argv[2]
else:
    out_file = "nstdatabase.hpp"

f1 = open(in_file, "r")
f2 = open(out_file, "w")
f2.write("const unsigned char nst_db_xml[] = {\n\t")

while (s := f1.read(1).encode("utf-8")) != b'':
    # Handle multibyte characters
    for i in range(0, len(s)):
        f2.write("0x%x, " % s[i])

f2.write("\n};\n")
f1.close()
f2.close()