2019-11-24 20:51:36 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Data is from https://www.iana.org/assignments/character-sets/character-sets.xml
|
|
|
|
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
mibmap = OrderedDict()
|
|
|
|
|
2019-11-27 07:31:56 +00:00
|
|
|
def fixalias(alias):
|
|
|
|
# if alias contains space remove everything after it, spaces are not
|
|
|
|
# allowed in encoding names, example of such case is Amiga-1251 alias
|
|
|
|
alias = alias.replace('\n', ' ')
|
|
|
|
return alias.split(' ')[0]
|
|
|
|
|
2019-11-24 20:51:36 +00:00
|
|
|
tree = ET.parse('character-sets.xml')
|
2019-11-27 07:31:56 +00:00
|
|
|
registry = tree.find('{http://www.iana.org/assignments}registry')
|
2021-11-20 17:09:41 +02:00
|
|
|
for record in registry:
|
2019-11-24 20:51:36 +00:00
|
|
|
recordnames = []
|
|
|
|
recordvalue = None
|
|
|
|
|
2021-11-20 17:09:41 +02:00
|
|
|
for recordchild in record:
|
2019-11-24 20:51:36 +00:00
|
|
|
if recordchild.tag == '{http://www.iana.org/assignments}name':
|
|
|
|
recordnames.append(recordchild.text)
|
|
|
|
elif recordchild.tag == '{http://www.iana.org/assignments}value':
|
|
|
|
recordvalue = recordchild.text
|
|
|
|
elif recordchild.tag == '{http://www.iana.org/assignments}alias':
|
2019-11-27 07:31:56 +00:00
|
|
|
alias = recordchild.text
|
|
|
|
if alias in recordnames:
|
|
|
|
# alias to self, e.g. US-ASCII
|
|
|
|
continue
|
|
|
|
recordnames.append(fixalias(alias))
|
2019-11-24 20:51:36 +00:00
|
|
|
|
|
|
|
mibmap[recordvalue] = recordnames
|
|
|
|
|
|
|
|
print('''static const struct MIBTblData {
|
2019-11-27 07:31:56 +00:00
|
|
|
const qint16 mib;
|
2019-11-24 20:51:36 +00:00
|
|
|
const char* name;
|
|
|
|
} MIBTbl[] = {''')
|
|
|
|
|
|
|
|
for mib in mibmap:
|
|
|
|
for name in mibmap[mib]:
|
|
|
|
print(' { %s, "%s\\0" },' % (mib, name))
|
|
|
|
|
|
|
|
print('''};
|
|
|
|
static const qint16 MIBTblSize = sizeof(MIBTbl) / sizeof(MIBTblData);\n''')
|