@@ -40,12 +40,25 @@ def compute_hash(qstr):
4040
4141def do_work (infiles ):
4242 # read the qstrs in from the input files
43+ qcfgs = {}
4344 qstrs = {}
4445 for infile in infiles :
4546 with open (infile , 'rt' ) as f :
4647 for line in f :
48+ line = line .strip ()
49+
50+ # is this a config line?
51+ match = re .match (r'^QCFG\((.+), (.+)\)' , line )
52+ if match :
53+ value = match .group (2 )
54+ if value [0 ] == '(' and value [- 1 ] == ')' :
55+ # strip parenthesis from config value
56+ value = value [1 :- 1 ]
57+ qcfgs [match .group (1 )] = value
58+ continue
59+
4760 # is this a QSTR line?
48- match = re .match (r'^Q\((.+ )\)$' , line . strip () )
61+ match = re .match (r'^Q\((.* )\)$' , line )
4962 if not match :
5063 continue
5164
@@ -63,11 +76,13 @@ def do_work(infiles):
6376 # process the qstrs, printing out the generated C header file
6477 print ('// This file was automatically generated by makeqstrdata.py' )
6578 print ('' )
79+ # add NULL qstr with no hash or data
80+ print ('QDEF(MP_QSTR_NULL, (const byte*)"\\ x00\\ x00\\ x00\\ x00" "")' )
6681 for order , ident , qstr in sorted (qstrs .values (), key = lambda x : x [0 ]):
6782 qhash = compute_hash (qstr )
6883 qlen = len (qstr )
6984 qdata = qstr .replace ('"' , '\\ "' )
70- print ('Q( %s, (const byte*)"\\ x%02x\\ x%02x\\ x%02x\\ x%02x" "%s")' % (ident , qhash & 0xff , (qhash >> 8 ) & 0xff , qlen & 0xff , (qlen >> 8 ) & 0xff , qdata ))
85+ print ('QDEF(MP_QSTR_ %s, (const byte*)"\\ x%02x\\ x%02x\\ x%02x\\ x%02x" "%s")' % (ident , qhash & 0xff , (qhash >> 8 ) & 0xff , qlen & 0xff , (qlen >> 8 ) & 0xff , qdata ))
7186
7287 return True
7388
0 commit comments