1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #! /usr/bin/env python2.7
- # -*- coding: utf-8 -*-
- #
- # Alexander Shiryaev, 2020.01
- #
- # Documents.ExportDocument
- #
- # ASCII only
- import sys, re
- def Int (x):
- assert x >= 0
- assert x < 0x100000000
- return chr(x % 0x100) + chr((x >> 8) % 0x100) + chr((x >> 16) % 0x100) + chr((x >> 24) % 0x100)
- hdr0 = "CDOo" + Int(0) + \
- "\x82\xf1" + "Documents.StdDocumentDesc" + \
- "\x00\xf1" + "Documents.DocumentDesc" + \
- "\x00\xf1" + "Containers.ViewDesc" + \
- "\x00\xf1" + "Views.ViewDesc" + \
- "\x00\xf0" + "Stores.StoreDesc" + \
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00"
- hdr1 = "\x00\x00\x00\x83\xf1" + "Documents.ModelDesc" + \
- "\x00\xf1" + "Containers.ModelDesc" + \
- "\x00\xf1" + "Models.ModelDesc" + \
- "\x00\xf1" + "Stores.ElemDesc" + \
- "\x00\xf2\x04\x00\x00\x00\x00\x00\x00\x00"
- hdr2 = "\x09\x00\x00\x00"
- hdr3 = "\x00\x00\x00\x00\x00\x82\xf1" + "TextViews.StdViewDesc" + \
- "\x00\xf1" + "TextViews.ViewDesc" + \
- "\x00\xf2\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00"
- hdr4 = "\x00\x00\x00\x83\xf1" + "TextModels.StdModelDesc" + \
- "\x00\xf1" + "TextModels.ModelDesc" + \
- "\x00\xf2\x06\x00\x00\x00\x00\x00\x00\x00"
- hdr5 = "\x0f\x00\x00\x00"
- hdr6 = "\x00\x00\x00\x00\x00\x00\x51\x00\x00\x00\x00\x82\xf1" + "TextModels.AttributesDesc" + \
- "\x00\xf2\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x2a\x00\x18\xf0\x01\x00\x00\x00\x00\x00\x90\x01\x00\x00\x00\x00"
- hdr7 = "\xff"
- trl = "\x82\xf1" + "TextControllers.StdCtrlDesc" + \
- "\x00\xf1" + "TextControllers.ControllerDesc" + \
- "\x00\xf1" + "Containers.ControllerDesc" + \
- "\x00\xf1" + "Controllers.ControllerDesc" + \
- "\x00\xf2\x04\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x82\xf1" + "TextRulers.StdRulerDesc" + \
- "\x00\xf1" + "TextRulers.RulerDesc" + \
- "\x00\xf2\x03\x00\x00\x00\x00\x00\x00\x00\xab\x00\x00\x00\x07\x00\x00\x00\xa3\x00\x00\x00\x00\x00\x00\x83\xf1" + "TextRulers.StdStyleDesc" + \
- "\x00\xf1" + "TextRulers.StyleDesc" + \
- "\x00\xf2\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x5a\x00\x00\x00\x00\x00\x00\x00\x82\xf1" + "TextRulers.AttributesDesc" + \
- "\x00\xf2\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x20\xa3\x5a\x00\x00\x00\x00\x00\xbb\xf2\x01\x00\x2c\x68\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x82\xf2\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x2a\x00\x18\xf0\x01\x00\x00\x00\x00\x00\x90\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\xf8\x00\x00\x0c\xf8\x00\x00\x2c\x9b\x5b\x00\x0b\xf8\x00\x40\x82\xf1" + "Documents.ControllerDesc" + \
- "\x00\xf2\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x40\x5b\x73\x00\x00\x99\xa2\x00\x80\xfc\x0a\x00\x80\xfc\x0a\x00\xc0\x5e\x68\x00\x80\x9c\x97\x00\x00"
- def splitToLines (text):
- lines = []
- [ [ lines.append(l1) for l1 in re.split( '[\r\n]', l ) ] for l in text.split('\r\n') ]
- return lines
- def txt2odc (text):
- # text = text.replace('\n', chr(0x0d))
- text = chr(0x0d).join(splitToLines(text))
- l = len(text)
- return hdr0 + Int(l + 873) + hdr1 + Int(l + 695) + hdr2 + Int(l + 687) + hdr3 + Int(l + 601) + hdr4 + Int(l + 99) + hdr5 + Int(l + 91) + hdr6 + Int(l) + hdr7 + text + trl
- def main ():
- if len(sys.argv) == 3:
- fh = open(sys.argv[1], 'rb')
- text = fh.read()
- fh.close()
- fh = open(sys.argv[2], 'wb')
- fh.write(txt2odc(text))
- fh.close()
- else:
- print("usage: %s file.txt file.odc" % (sys.argv[0],))
- if __name__ == '__main__':
- main()
|