#!/usr/bin/env python # Convert LCD Assistant file in C format to Spin format # -- Jon McPhalen # -- 08 MAY 2019 def process_file(table): if len(table) > 12: table = table[0:12] # truncate if too long header0 = ' ' + table + (' ' * (14-len(table))) + 'byte ' header1 = (' ' * 16) + 'byte ' try: infile = open(table+'.c', 'r') # open c file for n in range(6): # skip to data infile.readline() except: return -2 # could not open in file try: outfile = open(table+'.spin', 'w') # create spin file outfile.write('dat\n' + '\n') # insert dat section except: infile.close() return -3 # could not open out file outcount = 0 for line in infile: # loop through file if line.find('}') == -1: # if not last line line = line.replace('0x', '$') # C --> Spin notation line = line.replace(',\n', '') # clean end of line if outcount == 0: outfile.write(header0 + line + '\n') else: outfile.write(header1 + line + '\n') outcount += 1 infile.close() outfile.close() print("Processed {} lines.".format(outcount)) return 0 def main(args): if len(args) == 1: print("Table name not specified.") return -1 else: return(process_file(args[1])) if __name__ == '__main__': import sys sys.exit(main(sys.argv))