home *** CD-ROM | disk | FTP | other *** search
- PAGE 57,132
- TITLE PIPE -- File Pipeline routine.
- NAME PIPE
- ;
- ; Usage examples:
- ; PIPE <INPUT.FIL >OUTPUT.FIL
- ; SORT <DATA.FIL | PIPE >DATA.FIL
- ;
- ; This is a pipeline routine which merely copies the input file
- ; to the output file, using a 8192 byte buffer.
- ;
- ; Program by Harry M. Murphy, 28 January 1988.
- ;
- BEL EQU 07H ;Bell (beep) code.
- BUFLEN EQU 2000H ;Buffer length for I/O.
- CR EQU 0DH ;Carriage Return code.
- DOS EQU 21H ;DOS interrupt.
- LF EQU 0AH ;Line Feed code.
- STDIN EQU 0 ;Standard input file handle.
- STDOUT EQU 1 ;Standard output file handle.
- ;
- PIPE SEGMENT 'CODE'
- ORG 100H ;This is a "COM" routine.
- ASSUME CS:PIPE,DS:PIPE
- ;
- START: JMP SHORT READ
- ;
- NBYTES DW ?
- RDMSG DB CR,LF,'PIPE: Read error!',CR,LF,BEL,0
- WRMSG DB CR,LF,'PIPE: Write error!',CR,LF,BEL,0
- WFMSG DB CR,LF,'PIPE: Disk full error!',CR,LF,BEL,0
- ;
- EVEN
- READ: MOV AH,3FH ;Read up to BUFLEN bytes
- MOV BX,STDIN ; into the buffer from the
- MOV CX,BUFLEN ; standard
- MOV DX,OFFSET BUFFER ; input
- INT DOS ; unit.
- MOV SI,OFFSET RDMSG ;Point to read-error message
- JC ABORT ; and abort if carry is set.
- ;
- MOV NBYTES,AX ;No read error. Save number of bytes
- OR AX,AX ; read in NBYTES and, if it's zero,
- JZ EXIT ; we have read it all, so exit.
- ;
- WRITE: MOV AH,40H ;Write NBYTES
- MOV BX,STDOUT ; from the buffer to the
- MOV CX,NBYTES ; standard
- MOV DX,OFFSET BUFFER ; output
- INT DOS ; unit.
- MOV SI,OFFSET WRMSG ;Point to write-error message
- JC ABORT ; and abort if carry is set.
- ;
- CMP AX,NBYTES ;If we wrote all the bytes,
- JE READ ; loop for the next buffer.
- ;
- MOV SI,OFFSET WFMSG ;Otherwise, point to "full" message
- JMP SHORT ABORT ; and abort.
- ;
- EXIT: MOV AX,4C00H ;Exit with
- INT DOS ; ERRORLEVEL = 0.
- ;
- ABORT: MOV AH,0EH ;Prepare for BIOS output text in
- XOR BX,BX ; teletype mode interrupt and
- CLD ; clear the direction flag.
- ;
- ABRT1: LODSB ;Get next byte of the message,
- OR AL,AL ; test for zero and
- JZ ABRT2 ; skip out on zero.
- ;
- INT 10H ;Else, display the byte and
- JMP ABRT1 ; loop for next byte.
- ;
- ABRT2: MOV AX,4C07H ;Exit with
- INT DOS ; ERRORLEVEL = 7.
- ;
- EVEN
- BUFFER LABEL BYTE
- PIPE ENDS
- END START