10
20 ON ERROR REPORT:PROCClose_All:PRINT:END
30 A$=FNOS_GetEnv:DIM ctrl% 31,name% 127:X%=ctrl%:Y%=X%DIV256
40 in$=FNcl("",0):out$=FNcl("",0):size$=FNcl("",0)
50 IFin$="-?":PRINT"Syntax: FSplit <infile> <outprefix> <size>K":END
60 IFin$="" :INPUTLINE "Input file: "in$
70 IFout$="" :INPUTLINE "Output prefix: "out$
80 IFsize$="":INPUTLINE "Size to split by (K): "size$
90 size%=1024*VALsize$:IFsize%=0:size%=1024*1024
100 IF FNfile(in$,5)<>1:PRINT"File '"in$"' not found":END
110 :
120 ld%=X%!2:ex%=X%!6:at%=X%!14:bsz%=(HIMEM-LOMEM-2500)AND-1024
130 DIM buffer% bsz%:digits%=0:IFsize%>bsz%:size%=bsz%*(size%DIVbsz%)
140 IF RIGHT$(out$,1)="#":REPEAT:digits%=digits%+1:out$=LEFT$(out$,LENout$-1):UNTILRIGHT$(out$,1)<>"#"
150 :
160 count%=1:in%=OPENIN(in$):REPEAT
170 IFdigits%=0:outfile$=out$+STR$count% ELSE outfile$=out$+FNd0(count%,digits%)
180 PROCcopy:UNTILEOF#in%:CLOSE#in%:in%=0
190 END
200 :
210 DEFPROCcopy
220 PRINToutfile$;SPC4;:out%=OPENOUT(outfile$)
230 ptr%=PTR#in%:ext%=EXT#in%:len%=ext%-ptr%:IFlen%>size%:len%=size%
240 REPEAT
250 PRINT FNpc(ptr%,ext%);
260 num%=len%:IFnum%>bsz%:num%=bsz%
270 PROCgbpb(3,in%,buffer%,num%,ptr%)
280 PROCgbpb(1,out%,buffer%,num%,PTR#out%)
290 len%=len%-num%:ptr%=ptr%+num%
300 PRINT CHR$8;CHR$8;CHR$8;SPC3;
310 UNTIL len%<1:CLOSE#out%:out%=0
320 X%!2=ld%:X%!6=ex%:X%!14=at%:A%=FNfile(outfile$,1)
330 count%=count%+1:PRINT
340 ENDPROC
350 :
360 DEFPROCClose_All
370 in%=in%:IFin%:A%=in%:in%=0:CLOSE#A%
380 out%=out%:IFout%:A%=out%:out%=0:CLOSE#A%
390 ENDPROC
400 DEFFNd0(A%,N%)=RIGHT$("000000000"+STR$A%,N%)
410 DEFFNpc(A%,B%)=CHR$8+CHR$8+CHR$8+FNd0((100*A%)DIVB%,2)+"%"
420 DEFFNfile(A$,A%):$name%=A$:?X%=name%:X%?1=name%DIV256:=(USR&FFDD)AND&FF
430 DEFPROCgbpb(A%,chn%,addr%,num%,ptr%)
440 ?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:IFPAGE<&FFFFF:CALL&FFD1:ENDPROC
450 IFA%=1ORA%=3:PTR#?X%=X%!9
460 REPEAT:IFA%=1ORA%=2:BPUT#?X%,?X%!1 ELSE IFA%=3ORA%=4:?X%!1=BGET#?X%
470 X%!1=X%!1+1:X%!5=X%!5-1:UNTIL(EOF#?X% AND A%>2)OR X%!5<1:ENDPROC
480 DEFFNOS_GetEnv:LOCALA$,A%,X%,Y%:X%=1:os%=((USR&FFF4)AND&FF00)DIV256
490 IFos%=32:IFPAGE>&FFFF:DIMX%LOCAL256:SYS"GetModuleFileName",0,X%,255:run$=$$X%:=@cmd$
500 IFos%=32:A$=$&100
510 IFLENA$=0:IFHIMEM>&FFFF:run$=$&8100:SYS16TOA$,,A%:SYS72,"",A%:A$=MID$(A$,1+INSTR(A$+" "," ",1+INSTR(A$," "))):IFLENA$=0:A$=run$
520 IFLENA$=0:IF?(TOP-3):A$=$&600 ELSE IFLENA$=0:A$=$(PAGE-&300)
530 FORY%=-1TO0:A$=" "+A$:REPEATA$=MID$(A$,2):UNTILASCA$<>32
540 IFY%:IFASCA$=34:A%=INSTR(A$,"""",2)+1 ELSE IFY%:A%=INSTR(A$+" "," ")
550 IFY%:run$=LEFT$(A$,A%-1):IFrun$<>"":A$=MID$(A$,A%+1)
560 NEXT:=A$
570 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$
580 IFl$="":A%=INSTR(A$+" "," "):l$=LEFT$(A$,A%-1):A$=FNs(MID$(A$,A%+1)):=l$
590 IFn%=0:IFl$<>"":A%=INSTR(A$,l$):IFA%:A$=FNs(LEFT$(A$,A%-1)+MID$(A$,INSTR(A$," ",A%)+1))+" ":=TRUE
600 IFn%=0:IFl$<>"":=FALSE
610 A%=INSTR(LEFT$(" ",ASCl$=32)+A$,l$):IFA%=0:=""
620 A$=LEFT$(A$,A%-1)+FNs(MID$(A$,INSTR(A$," ",A%)+1))
630 IFASCl$=32:l$=MID$(A$,A%):A$=LEFT$(A$,A%-1):=MID$(l$,1-(ASCl$=34),LENl$+2*(ASCl$=34))
640 IFASCMID$(A$,A%,1)<>34:l$=MID$(A$,A%,INSTR(A$+" "," ",A%)-A%):A$=LEFT$(A$,A%-1)+MID$(A$,A%+LENl$+1):=l$
650 l$=MID$(A$,A%+1,INSTR(A$+""" ",""" ",A%+1)-A%-1):A$=LEFT$(A$,A%-1)+MID$(A$,A%+LENl$+3):=l$
660 DEFFNs(A$):IFLEFT$(A$,1)=" ":REPEATA$=MID$(A$,2):UNTILLEFT$(A$,1)<>" "
670 IFRIGHT$(A$,1)=" ":REPEATA$=LEFT$(A$,LENA$-1):UNTILRIGHT$(A$,1)<>" "
680 =A$