home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / lang / struct / exampleprograms / uout.struct < prev   
Text File  |  1994-02-12  |  10KB  |  378 lines

  1. ~ Uuencode Out
  2. ~ Version 1.0 by Roland Acton - November 1993
  3. ~ Internet address: xracton@ccvax.fullerton.edu
  4.  
  5. ~ Version 1.1 by Roland Acton - January 1994
  6. ~ Changes: The program now uses register variables and makes proper
  7. ~ procedure and library calls.
  8.  
  9. ~ This program is public domain. You may use any part of it you wish
  10. ~ in a program of your own, provided that you credit me and send me
  11. ~ a copy of the program.
  12.  
  13. define procedure Reiko
  14. define procedure word=GetMemory
  15. define procedure GiveBackMemory
  16. define procedure GetNextLine
  17. define procedure ReadLine
  18. define procedure WriteOutLine
  19. set startup Reiko
  20.  
  21. open library exec
  22. open library dos
  23.  
  24. constant uulinelength=62
  25.  
  26. global srcfilehandle:long,destfilehandle:long,linepointer:long
  27. global inname:long,outname:long,uucodename:long,deletename1:long
  28. global deletename2:long,lastfile:word,bufferstart:long
  29. global buffercount:word,bufferpos:word
  30. global stopwriting:word,disabledelete:word,kludge:long
  31.  
  32. string (returnchar) 10
  33.  
  34.  
  35.  
  36. procedure Reiko
  37. local filenumber:word,temp:word,z:word,copystatus:word,x:byte,y:byte
  38. local temppoint:long,kirishima:long,kloop:word,alldone:word
  39. local allocfailed:word
  40.  
  41. string (info1) "Uuencoded file joiner",10
  42. string (info2) "Version 1.1 by Roland Acton - January 1994",10,10
  43. print info1
  44. print info2
  45. if commandlength>1
  46.   proc call allocfailed=GetMemory
  47.   if allocfailed=0
  48.     lib call destfilehandle=open(outname,1006)
  49.     if destfilehandle=0
  50.       string (tempfileerror) "Couldn't open intermediate file "
  51.       print tempfileerror
  52.       print outname
  53.       print returnchar
  54.     else
  55.       stopwriting=0
  56.       disabledelete=0
  57.       alldone=0
  58.       lastfile=0
  59.       filenumber=1
  60.       repeat
  61.         if lastfile=1
  62.           string (lengtherror1) "Wrong-length line found in file "
  63.           print lengtherror1
  64.           print inname
  65.           print returnchar
  66.           disabledelete=1
  67.         end if
  68.         temp=filenumber/10*10
  69.         byte poke inname+commandlength,temp/10+48
  70.         byte poke inname+commandlength+1,filenumber-temp+48
  71.         lib call srcfilehandle=open(inname,1005)
  72.         if srcfilehandle=0
  73.           exit
  74.         end if
  75.         libcall buffercount=read(srcfilehandle,bufferstart,8192)
  76.         bufferpos=0
  77.         for z=1;5
  78.           proc call GetNextLine
  79.         next
  80.         data register copystatus,filenumber,kloop,x,y,z,temp
  81.         address register kirishima,temppoint,linepointer
  82.         regload
  83.         copystatus=0
  84.         loop ;;
  85.           if copystatus=0
  86.             if filenumber=1
  87.               byte data (begincheck) "begin "
  88.               load address kirishima=begincheck
  89.               long peek temppoint=linepointer
  90.               for temp=0;5
  91.                 byte peek x=kirishima+temp
  92.                 byte peek y=temppoint+temp
  93.                 if y<>x
  94.                   exit
  95.                 end if
  96.               next
  97.               for kloop=22;28;2
  98.                 word peek z=linepointer+kloop
  99.                 if z<>uulinelength
  100.                   exit
  101.                 end if
  102.               next
  103.               if temp=6 & kloop=30
  104.                 copystatus=1
  105.                 proc call WriteOutLine
  106.               end if
  107.             else
  108.               for kloop=20;28;2
  109.                 word peek z=linepointer+kloop
  110.                 if z<>uulinelength
  111.                   exit
  112.                 end if
  113.               next
  114.               if kloop=30
  115.                 byte data (sectionbegincheck) "BEGIN"
  116.                 load address kirishima=sectionbegincheck
  117.                 long peek temppoint=linepointer
  118.                 for temp=0;4
  119.                   byte peek x=kirishima+temp
  120.                   byte peek y=temppoint+temp
  121.                   if y<>x
  122.                     exit
  123.                   end if
  124.                 next
  125.                 if temp<5
  126.                   copystatus=1
  127.                   proc call WriteOutLine
  128.                 end if
  129.               end if
  130.             end if
  131.             for kloop=20;28;2
  132.               word peek z=linepointer+kloop
  133.               if z<>0
  134.                 exit
  135.               end if
  136.             next
  137.             if kloop=30
  138.               string (cannotmatch) ~
  139.               "Insufficient uuencoded lines for positive match",10
  140.               print cannotmatch
  141.               disabledelete=1
  142.               alldone=1
  143.               exit
  144.             end if
  145.           else
  146.             byte data (sectioncheck) "END"
  147.             load address kirishima=sectioncheck
  148.             long peek temppoint=linepointer
  149.             for temp=0;2
  150.               byte peek x=kirishima+temp
  151.               byte peek y=temppoint+temp
  152.               if y<>x
  153.                 exit
  154.               end if
  155.             next
  156.             if temp=3
  157.               exit
  158.             end if
  159.             word peek z=linepointer+20
  160.             if z=uulinelength
  161.               proc call WriteOutLine
  162.             else
  163.               if z<2
  164.                 exit
  165.               end if
  166.               lastfile=1
  167.               proc call WriteOutLine
  168.               byte data (endcheck) "end",10
  169.               load address kirishima=endcheck
  170.               long peek temppoint=linepointer
  171.               for temp=0;3
  172.                 byte peek x=kirishima+temp
  173.                 byte peek y=temppoint+temp
  174.                 if y<>x
  175.                   exit
  176.                 end if
  177.               next
  178.               if temp=4
  179.                 alldone=1
  180.                 exit
  181.               end if
  182.             end if
  183.           end if
  184.           proc call GetNextLine
  185.         end loop
  186.         lib call close(srcfilehandle)
  187.         filenumber=filenumber+1
  188.       until alldone=1
  189.       lib call close(destfilehandle)
  190.       if srcfilehandle=0
  191.         string (error1) "Couldn't open "
  192.         print error1
  193.         print inname
  194.         print returnchar
  195.         lib call execute(deletename1,0,0)
  196.         proc call GiveBackMemory
  197.       else
  198.         lib call execute(uucodename,0,0)
  199.         lib call execute(deletename1,0,0)
  200.         if disabledelete=0
  201.           for z=1;filenumber-1
  202.             temp=z/10*10
  203.             byte poke deletename2+7+commandlength,temp/10+48
  204.             byte poke deletename2+7+commandlength+1,z-temp+48
  205.             lib call execute(deletename2,0,0)
  206.           next
  207.         end if
  208.         proc call GiveBackMemory
  209.       end if
  210.     end if
  211.   end if
  212. else
  213.   string (error2) "Error in command line",10
  214.   string (error3) "Syntax: UOut <file-list-prefix>",10
  215.   print error2
  216.   print error3
  217. end if
  218. end procedure
  219.  
  220.  
  221.  
  222. procedure word=GetMemory
  223. local z:byte,lpcount:word,annoy1:long,annoy2:long
  224. local allocholder:long
  225.  
  226. lib call inname=allocmem(commandlength+3,0)
  227. lib call outname=allocmem(commandlength+3,0)
  228. lib call uucodename=allocmem(commandlength+12,0)
  229. lib call deletename1=allocmem(commandlength+10,0)
  230. lib call deletename2=allocmem(commandlength+10,0)
  231. bytedata (deletedata) "delete "
  232. load address annoy1=deletedata
  233. for lpcount=0;6
  234.   bytepeek z=annoy1+lpcount
  235.   bytepoke deletename1+lpcount,z
  236.   bytepoke deletename2+lpcount,z
  237. next
  238. bytedata (uucodedata) "uudecode "
  239. load address annoy2=uucodedata
  240. for lpcount=0;8
  241.   bytepeek z=annoy2+lpcount
  242.   bytepoke uucodename+lpcount,z
  243. next
  244. bytepoke outname,117
  245. bytepoke outname+1,111
  246. bytepoke outname+2,116
  247. for lpcount=0;commandlength-2
  248.   bytepeek z=commandpointer+lpcount
  249.   bytepoke inname+lpcount,z
  250.   bytepoke outname+3+lpcount,z
  251.   bytepoke deletename2+7+lpcount,z
  252. next
  253. for lpcount=0;commandlength+1
  254.   bytepeek z=outname+lpcount
  255.   bytepoke uucodename+9+lpcount,z
  256.   bytepoke deletename1+7+lpcount,z
  257. next
  258. bytepoke inname+commandlength-1,46
  259. bytepoke deletename2+7+commandlength-1,46
  260. bytepoke inname+commandlength+2,0
  261. bytepoke outname+commandlength+2,0
  262. bytepoke uucodename+9+commandlength+2,0
  263. bytepoke deletename1+7+commandlength+2,0
  264. bytepoke deletename2+7+commandlength+2,0
  265. lib call linepointer=allocmem(30,0)
  266. for lpcount=0;16;4
  267.   lib call allocholder=allocmem(256,0)
  268.   long poke linepointer+lpcount,allocholder
  269. next
  270.  
  271. ~ The memory allocations before this one are really too trivial to
  272. ~ check for failure.
  273.  
  274. lib call bufferstart=allocmem(8192,0)
  275. string (nomemory) "Couldn't allocate 8k for file buffer",10
  276. if bufferstart=0
  277.   print nomemory
  278.   getmemory=1
  279. else
  280.   getmemory=0
  281. end if
  282. end procedure
  283.  
  284.  
  285.  
  286. procedure GiveBackMemory
  287. local lpcount:word,allocholder:long
  288.  
  289. lib call freemem(inname,commandlength+3)
  290. lib call freemem(outname,commandlength+3)
  291. lib call freemem(uucodename,commandlength+12)
  292. lib call freemem(deletename1,commandlength+10)
  293. lib call freemem(deletename2,commandlength+10)
  294. for lpcount=0;16;4
  295.   long peek allocholder=linepointer+lpcount
  296.   lib call freemem(allocholder,256)
  297. next
  298. lib call freemem(linepointer,30)
  299. lib call freemem(bufferstart,8192)
  300. end procedure
  301.  
  302.  
  303.  
  304.  
  305. procedure GetNextLine
  306. local inpointer:long,coppoint:long,coplen:word,counter:word
  307.  
  308. data register counter,coppoint,coplen
  309. address register linepointer
  310. regload
  311. long peek inpointer=linepointer
  312. for counter=0;12;4
  313.   long peek coppoint=linepointer+counter+4
  314.   long poke linepointer+counter,coppoint
  315. next
  316. for counter=20;26;2
  317.   word peek coplen=linepointer+counter+2
  318.   word poke linepointer+counter,coplen
  319. next
  320. long poke linepointer+16,inpointer
  321. proc call ReadLine
  322. end procedure
  323.  
  324.  
  325.  
  326. procedure ReadLine
  327. local linemem:long,length:word,z:byte
  328.  
  329. data register length,z,bufferpos,buffercount
  330. address register linepointer,linemem,bufferstart
  331. regload
  332. long peek linemem=linepointer+16
  333. length=0
  334. if buffercount>0
  335.   repeat
  336.     bytepeek z=bufferstart+bufferpos
  337.     bytepoke linemem+length,z
  338.     bufferpos=bufferpos+1
  339.     length=length+1
  340.     if bufferpos=buffercount
  341.       libcall buffercount=read(srcfilehandle,bufferstart,8192)
  342.       bufferpos=0
  343.     end if
  344.   until z=10 | buffercount=0 | length=256
  345. end if
  346. word poke linepointer+28,length
  347. end procedure
  348.  
  349.  
  350.  
  351. procedure WriteOutLine
  352. local linetowrite:long,length:long
  353.  
  354. data register length
  355. address register linetowrite
  356. regload
  357. long peek linetowrite=linepointer
  358. word peek length=linepointer+20
  359. byte poke linetowrite+length,0
  360.  
  361. ~ The error most likely to occur during writing will be that the
  362. ~ disk is full. DOS will report this to the user via a pop-up
  363. ~ window, so we don't have to. Strictly speaking, the program should
  364. ~ terminate immediately when there's a write error. Doing this,
  365. ~ though, would complicate the program structure. It's much easier
  366. ~ to just not try to write to the disk anymore. This prevents the
  367. ~ "disk full" window from coming up over and over, and allows us to
  368. ~ use our normal termination code.
  369.  
  370. if stopwriting=0
  371.   lib call length=write(destfilehandle,linetowrite,length)
  372.   if length<0
  373.     stopwriting=1
  374.     disabledelete=1
  375.   end if
  376. end if
  377. end procedure
  378.