; EBCD2ASC
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program transforms input into output by mapping
; the characters from EBCDC to ASCII encoding.
#!proteus -z
; Print program instructions, when no parameter is specified
IF LT(ARGC, 6)
CONSOLELN "Syntax: proteus " ARGV(2) " <input.ebc> <output.asc>"
CONSOLELN ""
CONSOLELN "Purpose: transform file \"input.ebc\" into \"output.asc\","
CONSOLELN "mapping from EBCDC to ASCII encoding."
ABORT 0
FI
; Open source file, warn user if something goes wrong
H = FOPEN(ARGV(5), 4)
IF EQ(H, -1)
CONSOLELN "File \"" ARGV(5) "\" not found!"
ABORT 1
FI
; Open destination file, wanr user if something goes wrong
D = FOPEN(ARGV(6), 26)
IF EQ(D, -1)
CONSOLELN "Could not create/write to \"" ARGV(6) "\"!"
ABORT 2
FI
BA = MAPNEW("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E" \
"\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D" \
"\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C" \
"\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B" \
"\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A" \
"\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59" \
"\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68" \
"\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77" \
"\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86" \
"\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95" \
"\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3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x73\x74\x75" \
"\x76\x77\x78\x79\x7A\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB" \
"\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\x7B\x41\x42" \
"\x43\x44\x45\x46\x47\x48\x49\xE8\xE9\xEA\xEB\xEC\xED\x7D\x4A" \
"\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\xEE\xEF\xF0\xF1\xF2\xF3\x5C" \
"\x9F\x53\x54\x55\x56\x57\x58\x59\x5A\xF4\xF5\xF6\xF7\xF8\xF9" \
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\xFA\xFB\xFC\xFD\xFE" \
"\xFF")
REPEAT
B = FREAD(H, 1024)
Y = STRLEN(B)
FWRITE(D, MAP(BA, B))
UNTIL FEOF(H)
FCLOSE(H)
FCLOSE(D)
ABORT 0