Skip to content

Instantly share code, notes, and snippets.

@FabianInostroza
Created December 15, 2016 21:25
Show Gist options
  • Save FabianInostroza/9aaf0942c405579cdb3029f199df0a3d to your computer and use it in GitHub Desktop.
Save FabianInostroza/9aaf0942c405579cdb3029f199df0a3d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
with open("microchip_pic18mcu.dcm", "r") as fi, open("microchip_pic18mcu2.dcm", "w") as fo:
nextpart = ''
copypart = False
for line in fi.readlines():
fields = line.split(' ')
if fields[0] == '$CMP' and fields[1].startswith('PIC18(L)'):
part = fields[1].strip().split('(L)')
fo.write('$CMP PIC18' +part[1] + '\n')
nextpart = '$CMP PIC18L' + part[1] + '\n'
copypart = True
elif fields[0] == 'D':
if fields[1].startswith('PIC18(L)'):
#print line.strip()
fo.write('D PIC18' + fields[1][8:] + ' '.join(fields[2:]))
if copypart:
nextpart += 'D PIC18L' + fields[1][8:] + ' '.join(fields[2:])
else:
fo.write(line)
if copypart:
nextpart += line
else:
if copypart:
nextpart += line
fo.write(line)
if line.startswith('$ENDCMP') and copypart:
fo.write('#\n' + nextpart)
nextpart = ''
copypart = False
#!/usr/bin/env python
with open("microchip_pic18mcu.lib", "r") as fi, open("microchip_pic18mcu2.lib", "w") as fo:
aliases = ''
for line in fi.readlines():
fields = line.split(' ')
if fields[0] == 'DEF' and fields[1].startswith('PIC18(L)'):
fo.write('DEF PIC18' + fields[1][8:] + ' ' + ' '.join(fields[2:]))
aliases += ' PIC18L'+fields[1][8:]
elif fields[0] == 'F1' and fields[1].startswith('"PIC18(L)'):
fo.write('F1 "PIC18' + fields[1][9:] + ' ' + ' '.join(fields[2:]))
elif fields[0] == 'ALIAS' and fields[1].startswith('PIC18'):
#print line.strip()
for alias in fields[1:]:
alias = alias.strip()
if alias.startswith('PIC18(L)'):
part = alias.split('(L)')
aliases += ' PIC18L'+part[1] + ' PIC18'+part[1]
else:
aliases += ' ' + alias
fo.write('ALIAS' + aliases + '\n')
aliases = ''
else:
fo.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment