mirror of
https://github.com/forth-ev/VolksForth.git
synced 2024-11-19 17:31:23 +00:00
16857ea57a
Zero bytes in text files can't be handled by at least some editors.
29 lines
738 B
Python
Executable File
29 lines
738 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import sys
|
|
|
|
def readToString(inFile):
|
|
blockNo = 0
|
|
result = []
|
|
while(True):
|
|
block = inFile.read(1024)
|
|
if len(block) == 0:
|
|
break
|
|
result.append("\n\\ *** Block No. %d, Hexblock %x\n"
|
|
% (blockNo, blockNo));
|
|
offset = 0
|
|
while(offset < len(block)):
|
|
# sys.stderr.write("block %d offset %d\n" % (blockNo, offset))
|
|
line = block[offset:offset+64].decode(encoding="cp437")
|
|
result.append(line.rstrip().replace('\0', '^@'))
|
|
offset += 64
|
|
blockNo += 1
|
|
return result
|
|
|
|
inFileName, outFileName = sys.argv[1], sys.argv[2]
|
|
inFile = open(inFileName, "rb")
|
|
result = readToString(inFile)
|
|
result.append('')
|
|
outFile = open(outFileName, "w")
|
|
outFile.write("\n".join(result))
|