249249 "zip" ,
250250]
251251
252-
253252# this must match the equivalent function in qstr.c
254253def compute_hash (qstr , bytes_hash ):
255254 hash = 5381
@@ -351,13 +350,12 @@ def parse_input_headers(infiles):
351350 return qcfgs , qstrs , i18ns
352351
353352
354- def escape_bytes (qstr ):
353+ def escape_bytes (qstr , qbytes ):
355354 if all (32 <= ord (c ) <= 126 and c != "\\ " and c != '"' for c in qstr ):
356355 # qstr is all printable ASCII so render it as-is (for easier debugging)
357356 return qstr
358357 else :
359358 # qstr contains non-printable codes so render entire thing as hex pairs
360- qbytes = bytes_cons (qstr , "utf8" )
361359 return "" .join (("\\ x%02x" % b ) for b in qbytes )
362360
363361
@@ -368,7 +366,7 @@ def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
368366 if qlen >= (1 << (8 * cfg_bytes_len )):
369367 print ("qstr is too long:" , qstr )
370368 assert False
371- qdata = escape_bytes (qstr )
369+ qdata = escape_bytes (qstr , qbytes )
372370 return '%d, %d, "%s"' % (qhash , qlen , qdata )
373371
374372
@@ -402,18 +400,10 @@ def print_qstr_data(qcfgs, qstrs, i18ns):
402400 print ("// {} bytes worth of qstr" .format (total_qstr_size ))
403401
404402
405- def print_qstr_enums (qstrs ):
406- # print out the starter of the generated C header file
407- print ("// This file was automatically generated by makeqstrdata.py" )
408- print ("" )
409-
410- # add NULL qstr with no hash or data
411- print ("QENUM(MP_QSTRnull)" )
412-
413- # go through each qstr and print it out
414- for order , ident , qstr in sorted (qstrs .values (), key = lambda x : x [0 ]):
415- print ("QENUM(MP_QSTR_%s)" % (ident ,))
416403
404+ def do_work (infiles ):
405+ qcfgs , qstrs , i18ns = parse_input_headers (infiles )
406+ print_qstr_data (qcfgs , qstrs , i18ns )
417407
418408if __name__ == "__main__" :
419409 import argparse
@@ -424,19 +414,7 @@ def print_qstr_enums(qstrs):
424414 parser .add_argument (
425415 "infiles" , metavar = "N" , type = str , nargs = "+" , help = "an integer for the accumulator"
426416 )
427- parser .add_argument (
428- "--output_type" ,
429- default = "enums" ,
430- type = str ,
431- help = "output definitions" ,
432- choices = ("enums" , "data" ),
433- )
434417
435418 args = parser .parse_args ()
436419
437- qcfgs , qstrs , i18ns = parse_input_headers (args .infiles )
438- if args .output_type == "data" :
439- i18ns = sorted (i18ns )
440- print_qstr_data (qcfgs , qstrs , i18ns )
441- else :
442- print_qstr_enums (qstrs )
420+ do_work (args .infiles )
0 commit comments