home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / A86V402.ZIP / LINES.8 < prev    next >
Text File  |  1994-12-20  |  3KB  |  70 lines

  1. ;---------------
  2. ;  LINES      library module, NOT a standalone program
  3. ;---------------
  4.  
  5. ; This module handles line-oriented standard input.  The main module must leave
  6. ; us with a DATA segment having enough room for 04080 hex bytes; it must call
  7. ; PROCESS_INPUT when it is ready for standard input; it must supply a routine
  8. ; PROCESS_LINE that we call; and it must jump to GOOD_EXIT when it is done.
  9.  
  10. ; We call PROCESS_LINE with SI pointing to CX bytes, constituting the line.
  11. ; The terminating linefeed is counted in the CX bytes.    In addition, DI is
  12. ; left pointing beyond the linefeed.  The main program may clobber any
  13. ; registers.  During the execution of PROCESS_INPUT, we preserve all registers
  14. ; except AL,CX,SI,DI, and the arithmetic flags.
  15.  
  16. ; This module assumes DS=ES=SS at all times.
  17.  
  18. DATA SEGMENT
  19.  
  20. IBUFF:
  21.     DB 04000 DUP (?)
  22. THISLINE:
  23.     DB 128 DUP (?)
  24. DATA ENDS
  25.  
  26.  
  27. ; FETCH_INPUT gets more bytes from the physical standard input, and resets
  28. ;   SI and CX to the pointer and count of those bytes.    Return Z if there were
  29. ;   no more bytes.
  30.  
  31. FETCH_INPUT:
  32.   PUSH AX,BX,DX  ; preserve registers across call
  33.   MOV BX,0     ; zero is the open-file number of standard input
  34.   MOV DX,IBUFF     ; point CX to our input buffer
  35.   MOV CX,04000     ; input limit is the size of our buffer
  36.   MOV AH,03F     ; MSDOS function number for READ
  37.   CALL MSDOS     ; read bytes from standard input
  38.   XCHG CX,AX     ; swap actual count into CX
  39.   MOV SI,DX     ; point SI to the buffer pointer
  40.   POP DX,BX,AX     ; restore clobbered registers
  41.   TEST CX,CX     ; set Z flag if there were no bytes read
  42.   RET
  43.  
  44.  
  45. ; PROCESS_INPUT buffers up standard input, one line at a time, into our buffer
  46. ;   THISLINE, then processes the line.    We return when standard input is
  47. ;   exhausted.
  48.  
  49. PROCESS_INPUT:
  50.   CALL FETCH_INPUT    ; get our first buffer-full of input
  51.   JCXZ RET          ; return if there is no more input
  52.   MOV DI,THISLINE     ; we output a line at a time to our buffer
  53. L1:              ; loop here for each byte copied to our line-buffer
  54.   LODSB           ; fetch the byte
  55.   STOSB           ; store the byte in our buffer
  56.   CMP AL,0A          ; is the byte the line-terminating linefeed?
  57.   JNE >L4          ; jump if not to gather another byte
  58.   PUSH CX,SI          ; preserve input buffer count and pointer
  59.   MOV SI,THISLINE     ; point to the start of this word
  60.   MOV CX,DI          ; point CX beyond the word
  61.   SUB CX,SI          ; calculate the length of the word
  62.   CALL PROCESS_LINE   ; process the input line
  63.   MOV DI,THISLINE     ; restore the gathering-output to the start of the line
  64.   POP SI,CX           ; restore the input buffer's pointer and remaining count
  65. L4:              ; jump here to process the next line
  66.   LOOP L1          ; count down the input buffer bytes
  67.   CALL FETCH_INPUT    ; if buffer was empty then refill it
  68.   JNZ L1          ; loop if there were more bytes
  69.   RET              ; no more bytes-- time to return
  70.