Skip to content

Commit acb133d

Browse files
committed
makeqstrdata.py: Add support for conditionally defined qstrs.
Syntax is usual C #if*/#endif, but each qstr must be wrapped individually.
1 parent 881d9af commit acb133d

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

py/makeqstrdata.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def do_work(infiles):
2929
for infile in infiles:
3030
with open(infile, 'rt') as f:
3131
line_number = 0
32+
conditional = None
3233
for line in f:
3334
line_number += 1
3435
line = line.strip()
@@ -37,6 +38,18 @@ def do_work(infiles):
3738
if len(line) == 0 or line.startswith('//'):
3839
continue
3940

41+
if line[0] == '#':
42+
if conditional == "<endif>":
43+
assert line == "#endif"
44+
conditional = None
45+
else:
46+
assert conditional is None
47+
conditional = line
48+
continue
49+
50+
if conditional == "<endif>":
51+
assert False, "#endif expected before '%s'" % line
52+
4053
# verify line is of the correct form
4154
match = re.match(r'Q\((.+)\)$', line)
4255
if not match:
@@ -52,15 +65,21 @@ def do_work(infiles):
5265
continue
5366

5467
# add the qstr to the list, with order number to retain original order in file
55-
qstrs[ident] = (len(qstrs), ident, qstr)
68+
qstrs[ident] = (len(qstrs), ident, qstr, conditional)
69+
if conditional is not None:
70+
conditional = "<endif>"
5671

5772
# process the qstrs, printing out the generated C header file
5873
print('// This file was automatically generated by makeqstrdata.py')
5974
print('')
60-
for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
75+
for order, ident, qstr, conditional in sorted(qstrs.values(), key=lambda x: x[0]):
6176
qhash = compute_hash(qstr)
6277
qlen = len(qstr)
78+
if conditional:
79+
print(conditional)
6380
print('Q({}, (const byte*)"\\x{:02x}\\x{:02x}\\x{:02x}\\x{:02x}" "{}")'.format(ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qstr))
81+
if conditional:
82+
print('#endif')
6483

6584
return True
6685

0 commit comments

Comments
 (0)