2018-05-01 21:30:36 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# MiRCARTCanonicalise.py -- canonicalise mIRC art {from,to} file (for munki)
|
|
|
|
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2018-11-26 09:35:48 +00:00
|
|
|
# This project is licensed under the terms of the MIT licence.
|
2018-05-01 21:30:36 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
from MiRCARTCanvasImportStore import MiRCARTCanvasImportStore
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def canonicalise(inPathName):
|
|
|
|
canvasStore = MiRCARTCanvasImportStore(inPathName)
|
|
|
|
inMap = canvasStore.outMap.copy(); del canvasStore;
|
|
|
|
with open(inPathName, "w+") as outFile:
|
|
|
|
for inCurRow in range(len(inMap)):
|
2018-06-17 07:45:00 +00:00
|
|
|
lastAttribs = MiRCARTCanvasImportStore._CellState.CS_NONE
|
|
|
|
lastColours = None
|
2018-05-01 21:30:36 +00:00
|
|
|
for inCurCol in range(len(inMap[inCurRow])):
|
|
|
|
inCurCell = inMap[inCurRow][inCurCol]
|
|
|
|
if lastAttribs != inCurCell[2]:
|
|
|
|
if inCurCell[2] & MiRCARTCanvasImportStore._CellState.CS_BOLD:
|
|
|
|
print("\u0002", end="", file=outFile)
|
|
|
|
if inCurCell[2] & MiRCARTCanvasImportStore._CellState.CS_UNDERLINE:
|
|
|
|
print("\u001f", end="", file=outFile)
|
|
|
|
lastAttribs = inCurCell[2]
|
|
|
|
if lastColours == None or lastColours != inCurCell[:2]:
|
|
|
|
print("\u0003{:02d},{:02d}{}".format(*inCurCell[:2], inCurCell[3]), end="", file=outFile)
|
|
|
|
lastColours = inCurCell[:2]
|
|
|
|
else:
|
|
|
|
print(inCurCell[3], end="", file=outFile)
|
|
|
|
print("\n", end="", file=outFile)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Entry point
|
|
|
|
def main(*argv):
|
|
|
|
canonicalise(argv[1])
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if (len(sys.argv) - 1) != 1:
|
|
|
|
print("usage: {} <MiRCART input file pathname>".format(sys.argv[0]), file=sys.stderr)
|
|
|
|
else:
|
|
|
|
main(*sys.argv)
|
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|