home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / ace_basic / ace / utils / removeline.b < prev    next >
Text File  |  1977-12-31  |  4KB  |  151 lines

  1. /*  ACE version of the RemoveLine utility. 
  2.     It will 'shave' off all lines that are put in by the acpp (tested) or
  3.     dcpp (untested) preprocessors.
  4.     It uses a somewhat modified version of Roland Acton's buffered _Read
  5.     routine as used in the ACE Basic Indenter.
  6.     Also the ParseCommandLine SUB from the same program is used.
  7.     Uses two 8K buffers for reading and writing the preprocessed source. */
  8.     
  9.    
  10.  
  11. LIBRARY "exec.library"
  12.  
  13. DECLARE FUNCTION CopyMem() LIBRARY "exec.library"
  14. DECLARE SUB SHORTINT ParseCommandLine
  15.  
  16. DECLARE FUNCTION AllocMem& library exec
  17. DECLARE FUNCTION FreeMem& library exec
  18. DECLARE FUNCTION _Open& library dos
  19. DECLARE FUNCTION _Close& library dos
  20. DECLARE FUNCTION _Read& library dos
  21. DECLARE FUNCTION _Write& library dos
  22. LONGINT srcfilehandle,destfilehandle
  23.  
  24. SUB SHORTINT ParseCommandLine
  25.   shared srcfilehandle,destfilehandle
  26.  
  27.   if argcount<>2 then
  28.     print "Command line error."
  29.     print "Usage: ";ARG$(0);" <source-file> <destination-file>"
  30.     ParseCommandLine=0%
  31.   else
  32.         srcfilehandle=_Open(arg$(1),1005&) 
  33. /*        srcfilehandle=_Open("t:removeline.beta",1005&) */
  34.         if srcfilehandle>0& then
  35.           destfilehandle=_Open(arg$(2),1006&) 
  36. /*          destfilehandle=_Open("t:removeline.b",1006&) */
  37.           if destfilehandle>0& then
  38.             ParseCommandLine=1%
  39.           else
  40.             _Close(srcfilehandle)
  41.             print "Couldn't open file ";arg$(2)
  42.             ParseCommandLine=0%
  43.           end if
  44.         else
  45.           print "Couldn't open file ";arg$(1)
  46.           ParseCommandLine=0%
  47.         end if
  48.     end if
  49. END SUB
  50.  
  51. SUB RetFail
  52.     PRINT "Out of memory!"
  53.     STOP
  54. END SUB
  55.  
  56. SUB RemoveLine
  57.     SHARED srcfilehandle,destfilehandle
  58.  
  59.     ADDRESS BufferStart
  60.     ADDRESS FileLineAddress
  61.     ADDRESS LastLetterAddress
  62.  
  63.     LONGINT ReadBuffer
  64.     LONGINT WriteBuffer
  65.     LONGINT ReadBufferStart
  66.     LONGINT WriteBufferStart
  67.     LONGINT ReadBufferPos
  68.     LONGINT WriteBufferPos
  69.     LONGINT BufferCount
  70.  
  71.     SHORTINT Letter
  72.  
  73.     ReadBuffer=8192&
  74.     WriteBuffer=8192&
  75.     ReadBufferPos=0&
  76.     WriteBufferPos=0&
  77.  
  78.     ReadBufferStart=AllocMem(ReadBuffer,0&)
  79.     IF (ReadBufferStart=0) THEN
  80.         _Close(srcfilehandle)
  81.         _Close(destfilehandle)
  82.         RetFail
  83.     END IF
  84.     WriteBufferStart=AllocMem(WriteBuffer,0&)
  85.     IF (WriteBufferStart=0) THEN
  86.         _Close(srcfilehandle)
  87.         _Close(destfilehandle)
  88.         RetFail
  89.     END IF
  90.  
  91.     BufferCount=_Read(srcfilehandle,ReadBufferStart,ReadBuffer)
  92.  
  93.     IF BufferCount THEN
  94.         IF PEEK(ReadBufferStart)=35% THEN
  95.             REPEAT
  96.                 ++ReadBufferPos
  97.                 IF ReadBufferPos=BufferCount THEN
  98.                     BufferCount=_Read(srcfilehandle,ReadBufferStart,ReadBuffer)
  99.                     ReadBufferPos=0&
  100.                 END IF
  101.             UNTIL (PEEK(ReadBufferStart+ReadBufferPos)=10%) OR (BufferCount=0&)
  102.         END IF
  103.         IF BufferCount THEN
  104.             REPEAT
  105.                 REPEAT
  106.                     Letter=PEEK(ReadBufferStart+ReadBufferPos)
  107.                     POKE WriteBufferStart+WriteBufferPos,Letter
  108.                     ++ReadBufferPos
  109.                     ++WriteBufferPos
  110.                     IF ReadBufferPos=BufferCount THEN
  111.                         BufferCount=_Read(srcfilehandle,ReadBufferStart,ReadBuffer)
  112.                         ReadBufferPos=0&
  113.                     END IF
  114.                     IF WriteBufferPos=WriteBuffer THEN
  115.                         _Write(destfilehandle,WriteBufferStart,WriteBuffer)
  116.                         WriteBufferPos=0&
  117.                     END IF
  118.                 UNTIL Letter=10%
  119.                 IF PEEK(ReadBufferStart+ReadBufferPos)=35% THEN
  120.                     REPEAT
  121.                         ++ReadBufferPos
  122.                         IF ReadBufferPos=BufferCount THEN
  123.                             BufferCount=_Read(srcfilehandle,ReadBufferStart,ReadBuffer)
  124.                             ReadBufferPos=0&
  125.                         END IF
  126.                     UNTIL (PEEK(ReadBufferStart+ReadBufferPos)=10%) OR (BufferCount=0&)
  127.                 END IF
  128.             UNTIL BufferCount=0&
  129.             IF WriteBufferPos THEN
  130.                 _Write(destfilehandle,WriteBufferStart,WriteBufferPos)
  131.             END IF
  132.         END IF
  133.     END IF    
  134.  
  135.     FreeMem(ReadBufferStart,ReadBuffer)
  136.     FreeMem(WriteBufferStart,WriteBuffer)
  137.     _Close(srcfilehandle)
  138.     _Close(destfilehandle)
  139. END SUB
  140.  
  141. SHORTINT ParseSuccess
  142.  
  143. ParseSuccess=ParseCommandLine()
  144. IF ParseSuccess THEN
  145.     PRINT "Removing obsolete lines."
  146. /*    t!=TIMER */
  147.     RemoveLine()
  148. /*    PRINT TIMER-t! */
  149. END IF
  150. END
  151.