10
20
30 :
40 A$=@cmd$:in%=0:out%=0:WIDTH 0
50 ON ERROR REPORT:PROCClose_All:PRINT " at line ";ERL: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: GSdec <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 REPEAT
170 A$=GET$#in%
180 IF A$<>"" THEN
190 A$=FNGS_Decode(""""+A$+"""",0)
200 IF out%:BPUT#out%,A$; ELSE PRINT A$;
210 ENDIF
220 UNTIL EOF#in%
230 PROCClose_All
240 QUIT
250 :
260 DEFPROCClose_All
270 out%=out%:IFout%:A%=out%:out%=0:CLOSE#A%
280 in%=in%:IFin%:A%=in%:in%=0:CLOSE#A%
290 ENDPROC
300 :
310 DEFFNGS_Decode(inp$,flg%)
320 LOCAL out$,byte%,set%
330 IF LEFT$(inp$,1)=" ":REPEAT:inp$=MID$(inp$,2):UNTIL LEFT$(inp$,1)<>" "
340 IF LEFT$(inp$,1)="""":IF RIGHT$(inp$,1)="""":inp$=MID$(inp$,2,LENinp$-2)
350 IF inp$="":=""
360 REPEAT
370 byte%=-1:set%=0
380 IF LEFT$(inp$,2)="|!":set%=128:inp$=MID$(inp$,3)
390 IF LEFT$(inp$,1)="|":byte%=ASCMID$(inp$,2,1)AND31
400 IF LEFT$(inp$,2)="||":byte%=ASC"|"
410 IF LEFT$(inp$,2)="|?":byte%=127
420 IF LEFT$(inp$,2)="|""":byte%=34
430 IF LEFT$(inp$,2)="""""":byte%=34
440 IF byte%<0:byte%=ASC(inp$):inp$=MID$(inp$,2) ELSE inp$=MID$(inp$,3)
450 out$=out$+CHR$(set%+byte%)
460 UNTIL inp$=""
470 =out$