home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / MISC / SPLITTER / OPL / SPLITTER.OPL
Encoding:
Text File  |  1995-02-19  |  2.4 KB  |  123 lines

  1. rem splits a plain text file into smaller files
  2. rem GNU Copyleft to:
  3. rem Roger Burton-West <rburtonw@nyx.cs.du.edu>
  4. rem 19 February, 1995
  5.  
  6. PROC splitter:
  7.     local index&(1000),a$(130),size&
  8.     global hi%,aa$(130),ab$(4),m%
  9.     local seek&,parts%,fs&,os&
  10.     local dat$(255),da%,r%,sp&,lp&,para%
  11.     local p%(6)
  12.     lock on
  13.     font 10,0
  14.     da%=addr(dat$)+1
  15.     a$="\wrd\*.wrd"
  16.     size&=27000
  17.     para%=1
  18.     dINIT "File splitter"
  19.     dFILE a$,"Source file",0
  20.     dLONG size&,"Part size / bytes",1024,1000000
  21.     dCHOICE para%,"Split at","Line,Paragraph"
  22.     if dialog=0
  23.         return
  24.     endif
  25.     ie%:(ioopen(hi%,a$,$600))
  26.     ie%:(IOSEEK(hi%,2,fs&))
  27.     if fs&<=size&
  28.         ie%:(ioclose(hi%))
  29.         sal:("File is smaller than split size","")
  30.         return
  31.     endif
  32.     os&=0
  33.     seek&=size&-255
  34.     parts%=1
  35.     do
  36.         do
  37.             if os&>=seek&
  38.                 sal:("Can't find EOL in part "+gen$(parts%,3),"")
  39.                 return
  40.             endif
  41.             ie%:(ioseek(hi%,1,seek&))
  42.             r%=ie%:(ioread(hi%,da%,255))
  43.             pokeb da%-1,r%
  44.             do
  45.                 r%=r%-1
  46.             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
  47.             if r%>1
  48.                 break
  49.             endif
  50.             seek&=seek&-250
  51.         until 0
  52.         os&=seek&
  53.         index&(parts%)=seek&+r%+1
  54.         seek&=index&(parts%)+size&-255
  55.         parts%=parts%+1
  56.         if parts%>999
  57.             sal:("Too many parts","")
  58.             return
  59.         endif
  60.     until seek&+255>fs&
  61.     index&(parts%)=fs&
  62.     m%=len(gen$(parts%,3))
  63.     a$=parse$(a$,"",p%())
  64.     if p%(5)-p%(4)<9-m%
  65.         aa$=left$(a$,p%(5)-1)
  66.     else
  67.         aa$=left$(a$,p%(4)+7-m%)
  68.     endif
  69.     ab$=mid$(a$,p%(5),4)
  70.     print "Writing",parts%,"parts:"
  71.     rem parts% = the # of parts, and
  72.     rem index%() is the ENDPOINT of the part
  73.     r%=1
  74.     do
  75.         if r%=1
  76.             sp&=0
  77.         else
  78.             sp&=index&(r%-1)
  79.         endif
  80.         lp&=index&(r%)
  81.         print "Part",r%
  82.         writeout:(r%,sp&,lp&)
  83.         r%=r%+1
  84.     until r%>parts%
  85.     ie%:(ioclose(hi%))
  86. ENDP
  87.  
  88. PROC writeout:(n%,start&,end&)
  89.     local k$(130),ho%,s&,std&
  90.     local buf&(4096),ba%,r%
  91.     ba%=addr(buf&())
  92.     s&=start&
  93.     k$=aa$+right$("00"+gen$(n%,m%),m%)+ab$
  94.     ie%:(ioopen(ho%,k$,$102))
  95.     do
  96.         std&=end&-s&
  97.         ie%:(ioseek(hi%,1,s&))
  98.         r%=ie%:(ioread(hi%,ba%,min(std&,16384)))
  99.         ie%:(iowrite(ho%,ba%,r%))
  100.         s&=s&+r%
  101.     until std&<16384
  102.     ioclose(ho%)
  103. ENDP
  104.  
  105. PROC ie%:(k%)
  106.     if k%<0
  107.         sal:("Error "+gen$(k%,4),err$(k%))
  108.         stop
  109.     else
  110.         return k%
  111.     endif
  112. ENDP
  113.  
  114. PROC sal:(l1$,l2$)
  115.     dINIT
  116.     dTEXT "",l1$,2
  117.     if l2$<>""
  118.         dTEXT "",l2$,2
  119.     endif
  120.     dBUTTONS "Abandon",-27
  121.     dialog
  122. ENDP
  123.