aboutsummaryrefslogtreecommitdiff
path: root/py/makeqstrdata.py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-10 03:38:42 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-10 03:38:42 +0300
commitacb133d1b1a68847bd85c545312c3e221a6f7c0b (patch)
tree429feb6ce2189c080e0497d0ba292a1b4e96aded /py/makeqstrdata.py
parent881d9af05e7a707bbf17f2661ceab774eef6a9bb (diff)
makeqstrdata.py: Add support for conditionally defined qstrs.
Syntax is usual C #if*/#endif, but each qstr must be wrapped individually.
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r--py/makeqstrdata.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index 741336571..e60f00044 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -29,6 +29,7 @@ def do_work(infiles):
for infile in infiles:
with open(infile, 'rt') as f:
line_number = 0
+ conditional = None
for line in f:
line_number += 1
line = line.strip()
@@ -37,6 +38,18 @@ def do_work(infiles):
if len(line) == 0 or line.startswith('//'):
continue
+ if line[0] == '#':
+ if conditional == "<endif>":
+ assert line == "#endif"
+ conditional = None
+ else:
+ assert conditional is None
+ conditional = line
+ continue
+
+ if conditional == "<endif>":
+ assert False, "#endif expected before '%s'" % line
+
# verify line is of the correct form
match = re.match(r'Q\((.+)\)$', line)
if not match:
@@ -52,15 +65,21 @@ def do_work(infiles):
continue
# add the qstr to the list, with order number to retain original order in file
- qstrs[ident] = (len(qstrs), ident, qstr)
+ qstrs[ident] = (len(qstrs), ident, qstr, conditional)
+ if conditional is not None:
+ conditional = "<endif>"
# process the qstrs, printing out the generated C header file
print('// This file was automatically generated by makeqstrdata.py')
print('')
- for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
+ for order, ident, qstr, conditional in sorted(qstrs.values(), key=lambda x: x[0]):
qhash = compute_hash(qstr)
qlen = len(qstr)
+ if conditional:
+ print(conditional)
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))
+ if conditional:
+ print('#endif')
return True