10
20 ON ERROR REPORT:PROCClose_All:PRINT:PROCexit(ERR):END
30 A$=FNOS_GetEnv:DIM ctrl% 31,name% 127:X%=ctrl%:Y%=X%DIV256
40 in$=FNcl("",0):out$=FNcl("",0)
50 IFin$="-?":PRINT"Syntax: FJoin <infile> <outfile>":END
60 IFin$="" :INPUTLINE "Input prefix: "in$
70 IFout$="":INPUTLINE "Output file: "out$
80 :
90 bsz%=(HIMEM-LOMEM-2500)AND-1024
100 DIM buffer% bsz%-1:digits%=0
110 IF RIGHT$(in$,1)="#":REPEAT:digits%=digits%+1:in$=LEFT$(in$,LENin$-1):UNTILRIGHT$(in$,1)<>"#"
120 :
130 count%=1:out%=0:infile$=""
140 REPEAT
150 last$=infile$
160 IF digits%=0:infile$=in$+STR$ count% ELSE infile$=in$+FNd0(count%,digits%)
170 in%=OPENIN(infile$):found%=in%<>0:IF found%:PROCcopy
180 UNTIL NOT found%:IFout%:CLOSE#out%:out%=0:PRINT
190 A%=FNfile(last$,5):A%=FNfile(out$,1)
200 PROCexit(0):END
210 :
220 DEFPROCcopy
230 PRINTinfile$;SPC4;:IF out%=0:out%=OPENOUT(out$)
240 ptr%=PTR#in%:ext%=EXT#in%:len%=ext%
250 REPEAT
260 PRINT FNpc(ptr%,ext%);
270 num%=len%:IFnum%>bsz%:num%=bsz%
280 PROCgbpb(3,in%,buffer%,num%,ptr%)
290 PROCgbpb(1,out%,buffer%,num%,PTR#out%)
300 len%=len%-num%:ptr%=ptr%+num%
310 PRINT CHR$8;CHR$8;CHR$8;SPC3;
320 UNTIL len%<1
330 CLOSE#in%:in%=0:PRINT CHR$13;
340 count%=count%+1
350 ENDPROC
360 :
370 DEFPROCClose_All
380 out%=out%:IFout%:A%=out%:out%=0:CLOSE#A%
390 in%=in%:IFin%:A%=in%:in%=0:CLOSE#A%
400 ENDPROC
410 DEFFNd0(A%,N%)=RIGHT$("000000000"+STR$A%,N%)
420 DEFFNpc(A%,B%)=CHR$8+CHR$8+CHR$8+FNd0((100*A%)DIVB%,2)+"%"
430 DEFFNfile(A$,A%):$name%=A$:?X%=name%:X%?1=name%DIV256:IFPAGE<&FFFFF:=(USR&FFDD)AND&FF
440 A%=OPENIN(A$):IFA%=0:=0 ELSE CLOSE#A%:=1
450 DEFPROCgbpb(A%,chn%,addr%,num%,ptr%)
460 ?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:IFPAGE<&FFFFF:CALL&FFD1:ENDPROC
470 IFA%=1ORA%=3:PTR#?X%=X%!9
480 REPEAT:IFA%=1ORA%=2:BPUT#?X%,?X%!1 ELSE IFA%=3ORA%=4:?X%!1=BGET#?X%
490 X%!1=X%!1+1:X%!5=X%!5-1:UNTIL(EOF#?X% AND A%>2)OR X%!5<1:ENDPROC
500 DEFFNOS_GetEnv:LOCALA$,A%,X%,Y%:X%=1:os%=((USR&FFF4)AND&FF00)DIV256
510 IFos%>31:IFPAGE>&FFFFF:DIMX%LOCAL256:SYS"GetModuleFileName",0,X%,255:run$=$$X%:=@cmd$
520 A%=&600-&7B00*(PAGE>&8000)-&3F00*(PAGE>&C000):IF!(PAGE-&100)=@%:A%=PAGE-&300
530 IF?(TOP-3)=0:A%=&100:IFHIMEM<&FFFF:A%=PAGE-&300:IF!(HIMEM+512)=@%:A%=HIMEM
540 A$=$A%:IFPAGE=&8F00:run$=A$:SYS16TOA$,,A%:SYS72,"",A%:A$=MID$(A$,1+INSTR(A$+" "," ",1+INSTR(A$," "))):IFLENA$=0:A$=run$
550 FORY%=-1TO0:A$=" "+A$:REPEATA$=MID$(A$,2):UNTILASCA$<>32:IFASCA$=34:A%=INSTR(A$,"""",2)+1 ELSE A%=INSTR(A$+" "," ")
560 IFY%:run$=MID$(A$,1-(ASCA$=34),A%-1+2*(ASCA$=34)):A$=MID$(A$,A%+1)
570 NEXT:=A$
580 DEFPROCos(A$):IFASCA$=42:OSCLIA$:ENDPROC ELSE IFLENA$:CHAINA$
590 DEFPROCexit(A%):OSCLI"FX1,"+STR$(A%AND255):IFPAGE>&FFFFF:QUIT A% ELSE END
600 ENDPROC
610 DEFFNcl(l$,n%):IFl$="":A$=FNs(A$):IFASCA$=34:A%=INSTR(A$+" "" ",""" ",2):l$=MID$(A$,2,A%-2):A$=FNs(MID$(A$,A%+1)):=l$
620 IFl$="":A%=INSTR(A$+" "," "):l$=LEFT$(A$,A%-1):A$=FNs(MID$(A$,A%+1)):=l$
630 IFn%=0:IFl$<>"":A%=INSTR(A$,l$):IFA%:A$=FNs(LEFT$(A$,A%-1)+MID$(A$,INSTR(A$," ",A%)+1))+" ":=TRUE
640 IFn%=0:IFl$<>"":=FALSE
650 A%=INSTR(LEFT$(" ",ASCl$=32)+A$,l$):IFA%=0:=""
660 A$=LEFT$(A$,A%-1)+FNs(MID$(A$,INSTR(A$," ",A%)+1))
670 IFASCl$=32:l$=MID$(A$,A%):A$=LEFT$(A$,A%-1):=MID$(l$,1-(ASCl$=34),LENl$+2*(ASCl$=34))
680 IFASCMID$(A$,A%,1)<>34:l$=MID$(A$,A%,INSTR(A$+" "," ",A%)-A%):A$=LEFT$(A$,A%-1)+MID$(A$,A%+LENl$+1):=l$
690 l$=MID$(A$,A%+1,INSTR(A$+" ",""" ",A%+1)-A%-1):A$=LEFT$(A$,A%-1)+MID$(A$,A%+LENl$+3):=l$
700 DEFFNs(A$):IFLEFT$(A$,1)=" ":REPEATA$=MID$(A$,2):UNTILLEFT$(A$,1)<>" "
710 IFRIGHT$(A$,1)=" ":REPEATA$=LEFT$(A$,LENA$-1):UNTILRIGHT$(A$,1)<>" "
720 =A$