home *** CD-ROM | disk | FTP | other *** search
- rem splits a plain text file into smaller files
- rem GNU Copyleft to:
- rem Roger Burton-West <rburtonw@nyx.cs.du.edu>
- rem 19 February, 1995
-
- PROC splitter:
- local index&(1000),a$(130),size&
- global hi%,aa$(130),ab$(4),m%
- local seek&,parts%,fs&,os&
- local dat$(255),da%,r%,sp&,lp&,para%
- local p%(6)
- lock on
- font 10,0
- da%=addr(dat$)+1
- a$="\wrd\*.wrd"
- size&=27000
- para%=1
- dINIT "File splitter"
- dFILE a$,"Source file",0
- dLONG size&,"Part size / bytes",1024,1000000
- dCHOICE para%,"Split at","Line,Paragraph"
- if dialog=0
- return
- endif
- ie%:(ioopen(hi%,a$,$600))
- ie%:(IOSEEK(hi%,2,fs&))
- if fs&<=size&
- ie%:(ioclose(hi%))
- sal:("File is smaller than split size","")
- return
- endif
- os&=0
- seek&=size&-255
- parts%=1
- do
- do
- if os&>=seek&
- sal:("Can't find EOL in part "+gen$(parts%,3),"")
- return
- endif
- ie%:(ioseek(hi%,1,seek&))
- r%=ie%:(ioread(hi%,da%,255))
- pokeb da%-1,r%
- do
- r%=r%-1
- until (para%=1 and mid$(dat$,r%,2)=chr$(13)+chr$(10)) or (para%=2 and mid$(dat$,r%,4)=chr$(13)+chr$(10)+chr$(13)+chr$(10)) or r%=1
- if r%>1
- break
- endif
- seek&=seek&-250
- until 0
- os&=seek&
- index&(parts%)=seek&+r%+1
- seek&=index&(parts%)+size&-255
- parts%=parts%+1
- if parts%>999
- sal:("Too many parts","")
- return
- endif
- until seek&+255>fs&
- index&(parts%)=fs&
- m%=len(gen$(parts%,3))
- a$=parse$(a$,"",p%())
- if p%(5)-p%(4)<9-m%
- aa$=left$(a$,p%(5)-1)
- else
- aa$=left$(a$,p%(4)+7-m%)
- endif
- ab$=mid$(a$,p%(5),4)
- print "Writing",parts%,"parts:"
- rem parts% = the # of parts, and
- rem index%() is the ENDPOINT of the part
- r%=1
- do
- if r%=1
- sp&=0
- else
- sp&=index&(r%-1)
- endif
- lp&=index&(r%)
- print "Part",r%
- writeout:(r%,sp&,lp&)
- r%=r%+1
- until r%>parts%
- ie%:(ioclose(hi%))
- ENDP
-
- PROC writeout:(n%,start&,end&)
- local k$(130),ho%,s&,std&
- local buf&(4096),ba%,r%
- ba%=addr(buf&())
- s&=start&
- k$=aa$+right$("00"+gen$(n%,m%),m%)+ab$
- ie%:(ioopen(ho%,k$,$102))
- do
- std&=end&-s&
- ie%:(ioseek(hi%,1,s&))
- r%=ie%:(ioread(hi%,ba%,min(std&,16384)))
- ie%:(iowrite(ho%,ba%,r%))
- s&=s&+r%
- until std&<16384
- ioclose(ho%)
- ENDP
-
- PROC ie%:(k%)
- if k%<0
- sal:("Error "+gen$(k%,4),err$(k%))
- stop
- else
- return k%
- endif
- ENDP
-
- PROC sal:(l1$,l2$)
- dINIT
- dTEXT "",l1$,2
- if l2$<>""
- dTEXT "",l2$,2
- endif
- dBUTTONS "Abandon",-27
- dialog
- ENDP
-