10
20 ON ERROR REPORT:PROCClose_All:PRINT LEFT$(" at line"+STR$ERL,ERR<128 AND ERR<>17):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: TxSplit <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 IF bsz%<258:PRINT"Buffer size too small":END
140 DIM buffer% bsz%:digits%=0:IFsize%>bsz%:size%=bsz%*(size%DIVbsz%)
150 IFRIGHT$(out$,1)="#":REPEAT:digits%=digits%+1:out$=LEFT$(out$,LENout$-1):UNTILRIGHT$(out$,1)<>"#"
160 :
170 count%=1:in%=OPENIN(in$):REPEAT
180 IFdigits%=0:outfile$=out$+STR$count% ELSE outfile$=out$+FNd0(count%,digits%)
190 PROCcopy:UNTILEOF#in%:CLOSE#in%:in%=0
200 END
210 :
220 DEFPROCcopy
230 PRINToutfile$;SPC4;:out%=OPENOUT(outfile$)
240 ptr%=PTR#in%:ext%=EXT#in%:len%=ext%-ptr%:stop%=FALSE:IFlen%>size%:len%=size%:stop%=TRUE
250 REPEAT
260 PRINT FNpc(ptr%,ext%);
270 num%=len%:last%=stop%:IF num%>bsz%:num%=bsz%:last%=FALSE
280 PROCgbpb(3,in%,buffer%,num%,ptr%)
290 IF last%:p%=buffer%+num%-256:n%=256:REPEATA%=?p%:p%=p%+1:n%=n%-1:UNTIL A%=13 OR A%=10 OR n%<1:num%=num%-n%:PTR#in%=PTR#in%-n%
300 PROCgbpb(1,out%,buffer%,num%,PTR#out%)
310 len%=len%-num%:ptr%=ptr%+num%
320 PRINT CHR$8;CHR$8;CHR$8;SPC3;
330 UNTIL len%<1 OR last%:CLOSE#out%:out%=0
340 X%!2=ld%:X%!6=ex%:X%!14=at%:A%=FNfile(outfile$,1)
350 count%=count%+1:PRINT
360 ENDPROC
370 :
380 DEFPROCClose_All
390 in%=in%:IFin%:A%=in%:in%=0:CLOSE#A%
400 out%=out%:IFout%:A%=out%:out%=0:CLOSE#A%
410 ENDPROC
420 DEFFNd0(A%,N%)=RIGHT$("000000000"+STR$A%,N%)
430 DEFFNpc(A%,B%)=CHR$8+CHR$8+CHR$8+FNd0((100*A%)DIVB%,2)+"%"
440 DEFFNfile(A$,A%):$name%=A$:?X%=name%:X%?1=name%DIV256:=(USR&FFDD)AND&FF
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%=32:IFPAGE>&FFFF:DIMX%LOCAL256:SYS"GetModuleFileName",0,X%,255:run$=$$X%:=@cmd$
520 IFos%=32:A$=$&100
530 IFLENA$=0:IFHIMEM>&FFFF:run$=$&8100:SYS16TOA$,,A%:SYS72,"",A%:A$=MID$(A$,1+INSTR(A$+" "," ",1+INSTR(A$," "))):IFLENA$=0:A$=run$
540 IFLENA$=0:IF?(TOP-3):A$=$&600 ELSE IFLENA$=0:A$=$(PAGE-&300)
550 FORY%=-1TO0:A$=" "+A$:REPEATA$=MID$(A$,2):UNTILASCA$<>32
560 IFY%:IFASCA$=34:A%=INSTR(A$,"""",2)+1 ELSE IFY%:A%=INSTR(A$+" "," ")
570 IFY%:run$=LEFT$(A$,A%-1):IFrun$<>"":A$=MID$(A$,A%+1)
580 NEXT:=A$
590 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$
600 IFl$="":A%=INSTR(A$+" "," "):l$=LEFT$(A$,A%-1):A$=FNs(MID$(A$,A%+1)):=l$
610 IFn%=0:IFl$<>"":A%=INSTR(A$,l$):IFA%:A$=FNs(LEFT$(A$,A%-1)+MID$(A$,INSTR(A$," ",A%)+1))+" ":=TRUE
620 IFn%=0:IFl$<>"":=FALSE
630 A%=INSTR(LEFT$(" ",ASCl$=32)+A$,l$):IFA%=0:=""
640 A$=LEFT$(A$,A%-1)+FNs(MID$(A$,INSTR(A$," ",A%)+1))
650 IFASCl$=32:l$=MID$(A$,A%):A$=LEFT$(A$,A%-1):=MID$(l$,1-(ASCl$=34),LENl$+2*(ASCl$=34))
660 IFASCMID$(A$,A%,1)<>34:l$=MID$(A$,A%,INSTR(A$+" "," ",A%)-A%):A$=LEFT$(A$,A%-1)+MID$(A$,A%+LENl$+1):=l$
670 l$=MID$(A$,A%+1,INSTR(A$+""" ",""" ",A%+1)-A%-1):A$=LEFT$(A$,A%-1)+MID$(A$,A%+LENl$+3):=l$
680 DEFFNs(A$):IFLEFT$(A$,1)=" ":REPEATA$=MID$(A$,2):UNTILLEFT$(A$,1)<>" "
690 IFRIGHT$(A$,1)=" ":REPEATA$=LEFT$(A$,LENA$-1):UNTILRIGHT$(A$,1)<>" "
700 =A$