home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
txtutl
/
nocz12.arc
/
NOCZ1.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-10-13
|
5KB
|
193 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
Toad Hall Tweak, Oct 89
- Bumping working buffer to BIG...
- Simplistic PSP command line parsing didn't properly handle
DOS redirection/filter usage. Fixed.
- No reason at all to release memory .. unless maybe for filters??
~
CR equ 0DH
LF equ 0AH
STDOUT equ 1 ;Standard Output
;===================================================================
CSEG segment public para 'CODE'
;===================================================================
;
; command line is at 80h of psp - first byte is length
;
ORG 80h
cmdline label byte ; v1.1
;
; .com starts at 100h - but must jump around any data area
;
ORG 100h ; com file starts here
ASSUME CS:CSEG,DS:CSEG,ES:CSEG
NoCz proc near ;v1.1
mov AH,30h ; get dos version
int 21h
cmp AL,2 ; must be at least 2.0
jb Oops
call Parse_CmdLine ;parse cmdline for target filename v1.1
;(will give help and die if NO
;filename or redirection)
xor bp,bp ;assume StdIn handle v1.1
or dx,dx ;did we get a name? v1.1
jz Save_Handle ;nope, use StdIn
;v1.1 else DX -> filename start
; now try to open the file
mov ax,3D00H ;open file, read only v1.1
int 21h ; invoke function
jc Oops ; open error - quit
mov bp,ax ;keep file handle in BP v1.1
Save_Handle:
mov DX,offset buffer ;DX -> read/write buffer v1.1
;v1.1 We loop here with BIG buffers full of target file text
Again:
mov BX,bp ;handle ; read from standard input or file v1.1
mov CX,BUFSIZ ; # of characters to read v1.1
mov AH,3Fh ; dos read function
int 21h ; invoke function
jc Oops ; error! (error value in AL) v1.1
or ax,ax ; if zero, end of file v1.1
jz Oops ; (errorlevel 0) v1.1
mov CX,AX ; CX contains # characters read
mov SI,dx ;offset buffer ; DS:SI is the "input" pointer v1.1
mov DI,SI ; ES:DI is the "output" pointer
mov ah,26 ;handy Ctrl Z constant v1.1
Loop1:
lodsb ; get a character from buffer
cmp AL,ah ;26 ; if ^Z then skip v1.1
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,dx ;offset buffer ; count
mov BX,STDOUT ; standard output device v1.1
mov AH,40h ; dos write function
int 21h ; invoke dos function
jmp short Again ; repeat until end of file or error
Oops:
mov ah,4CH ;terminate (errorlevel in AL) v1.1
int 21H ; v1.1
NoCz endp ; v1.1
even ; v1.1
buffer LABEL NEAR
BUFSIZ equ NOT ($ - CSEG + 256) ;use full segment v1.1
;minus 256-byte stack
;and program size
;v1.1 Parse commandline for target filename
; Handle redirection spaces
Parse_CmdLine proc near
mov si,offset cmdline ;cmd parm length byte
lodsb ;snarf length byte
;(SI -> 1st char)
xor ah,ah ;clear msb
mov cx,ax ;cmdline length is loop counter
jcxz Help ;no cmdline, give help and die
;v1.1 When redirection happens, DOS leaves spaces instead of simply
; a null line!
; Gotta allow for that by gobbling leading spaces.
; If spaces is all we had .. we have redirection!
xor dx,dx ;clear DX (don't have a name)
mov ah,20H ;handy constant
ParseLup:
lodsb ;snarf cmdline char
cmp al,ah ;space?
jz Relup ;yep, skip it
cmp al,CR ;terminating CR? (no name)
jnz Got_Name ;nope, must be real name
Relup:
loop ParseLup ;do all cmdline chars
;If we fall thru .. there were only spaces (redirection).
ret ;with DX = 0 (no name)
;SI -> target filename's first char (non-space)
Got_Name:
mov dx,si ;DX -> filename's first char +1
dec dx ;back up to real first char
mov ax,CR ;scan for terminating CR
;AH=0
Name_Lup:
cmp [si],al ;terminating CR?
jz AsciiZ_Name ;yep, stuff a 0 there
inc si ;bump filename ptr
loop Name_Lup ;nope, keep going
;If we fell through .. something is SEVERELY wrong with our
;command line count! Shouldn't ever happen.
AsciiZ_Name:
mov [si],ah ;AsciiZ the name
ret
Parse_CmdLine endp
;v1.1 Provide help if no cmd line parms
Help proc near ; v1.1
mov dx,offset help$ ;help msg
mov ah,9 ;display msg
int 21H
mov ax,4C00H ;terminate (errorlevel 0) v1.1
int 21H ; v1.1
help$ db 'NoCZ v1.1 - strips Ctrl Z characters from a file.',CR,LF
db 'Usage: nocz [<] filename.typ [>output]',CR,LF
db 'Input may be a proper path:\filename or redirection.',CR,LF
db 'Output may be redirected as desired (default CON:).'
db CR,LF,'$'
Help endp
CSEG ENDS
END NoCz