10
20
30 :
40 A$=@cmd$:in%=0:out%=0
50 ON ERROR REPORT:PROCClose_All:PRINT:QUIT
60 SYS"GetStdHandle",-10 TO @hfile%(1):*INPUT 13
70 SYS"GetStdHandle",-11 TO @hfile%(2):*OUTPUT 14
80 SYS"SetConsoleMode",@hfile%(1),0
90 IF A$="" OR A$="-?":PRINT "Syntax: GSenc <infile> (<outfile>)":QUIT
100 A%=INSTR(A$+" "," "):in$=LEFT$(A$,A%-1):REPEAT:A%=A%+1:UNTILMID$(A$,A%,1)<>" ":A$=MID$(A$,A%)
110 A%=INSTR(A$+" "," "):out$=LEFT$(A$,A%-1)
120 in%=OPENIN(in$):IF in%=0:PRINT "File '"+in$+"' not found":QUIT
130 IF out$<>"":out%=OPENOUT(out$):IF out%=0:PRINT"Can't open '"out$"'":PROCClose_All:QUIT
140 IF EXT#in%=0:PROCCloseAll:QUIT
150 :
160 max%=64
170 REPEAT
180 A$=""
190 REPEAT:A$=A$+FNgs(BGET#in%)
200 UNTIL LENA$>=max% OR EOF#in%
210 IF A$<>"" THEN
220 IF out%:BPUT#out%,A$ ELSE PRINT A$
230 ENDIF
240 UNTIL EOF#in%
250 PROCClose_All
260 QUIT
270 :
280 DEFPROCClose_All
290 out%=out%:IFout%:A%=out%:out%=0:CLOSE#A%
300 in%=in%:IFin%:A%=in%:in%=0:CLOSE#A%
310 ENDPROC
320 :
330 DEFFNgs(A%):IFA%>127:="|!"+FNgs(A%AND127)
340 IFA%<32ORA%=127:="|"+CHR$(A%EOR64)ELSE=LEFT$("|",A%=34ORA%=124)+CHR$A%