home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
txtutl
/
nocz12.arc
/
NOCZ.ASM
next >
Wrap
Assembly Source File
|
1989-10-13
|
3KB
|
120 lines
Name nocz
Title Control Z stripping filter.
page ,132
comment /
This program is a filter that removes all occurrances
of the ASCII character 26 (^Z) from its output stream.
It will optionally accept a filename from which to read
input. All output goes to the standard output device
unless redirected.
Examples:
nocz abc.txt read input from abc.txt,
output goes to screen.
nocz abc.txt >abcnew.txt
read input from abc.txt,
output goes to abcnew.txt.
nocz <abc.txt >abcnew.txt
same as previous example
/
;===================================================================
code segment public
;===================================================================
;
; command line is at 80h of psp - first byte is length
;
ORG 80h
parmsize DB ?
parm DB 7fh DUP (?)
;
; .com starts at 100h - but must jump around any data area
;
ORG 100h ; com file starts here
ASSUME CS:code,DS:code,ES:code
nocz:
jmp clear
;===================================================================
;
; data area for .com programs
;
handle DW 0h ; assume standard input
bufsiz EQU 256
;
;===================================================================
clear:
;
; start of actual code is here (clear)
;
mov AH,30h ; get dos version
int 21h
cmp AL,2 ; must be at least 2.0
jb oops
;
; release uneeded memory
;
mov BX,offset buffer[512] ; 256 byte buffer
mov SP,BX ; + 256 byte local stack
mov CX,4
sar BX,CL
inc BX ; paragraphs needed = end/16 + 1
mov AH,4AH ; SETBLOCK
int 21h
;
; now figure out which file to read from - parm line or standard input
;
cmp parmsize,0h ; if zero, no parm
jz again ; assume standard input
;
; parm length is not zero - assume the parm is a file name. If not
; found, quit.
;
mov AL,parmsize ; get size of parm
xor AH,AH ; zero out top part of accum.
mov SI,AX ; use length as a pointer into the dta
mov [SI]+parm,0h ; to tack on a zero byte (asciiz).
;
; now try to open the file
;
mov DX,offset parm+1 ; address of 'filename'
mov AL,0h ; open for read only
mov AH,3dh ; dos open function
int 21h ; invoke function
jc oops ; open error - quit
mov handle,AX ; save file handle
again:
mov BX,handle ; read from standard input or file
mov CX,bufsiz ; # of characters to read
mov DX,offset buffer
mov AH,3fh ; dos read function
int 21h ; invoke function
jc oops ; error!
cmp AX,0h ; if zero, end of file
jz oops
;
mov CX,AX ; CX contains # characters read
mov SI,offset buffer; DS:SI is the "input" pointer
mov DI,SI ; ES:DI is the "output" pointer
loop1:
lodsb ; get a character from buffer
cmp AL,26 ; if ^Z then skip
je eatit
stosb ; put back into buffer
eatit:
loop loop1 ; and repeat for entire buffer
;
mov CX,DI ; Now calculate the ouput character
sub CX,offset buffer; count
mov BX,1h ; standard output device
mov AH,40h ; dos write function
int 21h ; invoke dos function
jmp short again ; repeat until end of file or error
oops:
int 20h ; return to dos
buffer LABEL NEAR
code ENDS
END nocz