Category : C Source Code
Archive   : FILTERS.ZIP
Filename : SNGLSPC.ASM

 
Output of file : SNGLSPC.ASM contained in archive : FILTERS.ZIP
Name Snglspc
Title Convert doublespace to singlespace (remove blank lines.)
page ,132
comment /

This program is a filter that delete blank lines from a file.

Examples:
Snglspc abc.txt read input from abc.txt,
Snglspc abc.txt >abcnew.txt
Snglspc abcnew.txt
Snglspc abc.txt | find "ABC"
find "abc" abc.txt | Snglspc | sort
/
;===================================================================
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
snglspc:
jmp clear
;===================================================================
;
; data area for .com programs
;
cr equ 0dh
lf equ 0ah
eof equ 1ah
;
handle dw 0h ; assume standard input
bufsiz equ 255
bufferin db bufsiz dup (?)
bufferout db bufsiz dup (?)
flag db 0h
outcount dw 0h ; output char count
;
;===================================================================
clear:
;
; start of actual code is here (clear)
;
;
; 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
;
lea dx,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
lea dx,bufferin ; seg:off address of buffer area
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 (and ax) contain # characters read
mov outcount,0h ; init output character counter
lea si,bufferin ; offset of buffer
lea di,bufferout ; address of output area
loop1:
lodsb ; get a character. If cr or lf,
cmp al,cr ; increment flag.
jne next
add flag,1h
jmp next3
next:
cmp al,lf
jne next2
add flag,1h
jmp next3
next2:
mov flag,0h ; not cr/lf, reset flag
next3:
cmp flag,02h ; if flag is greater than 2, skip
jg skip ; the characters.
inc outcount ; increment count of characters output
stosb
skip:
loop loop1 ; and repeat for entire buffer
;
mov cx,outcount ; restore character count
mov bx,1h ; standard output device
lea dx,bufferout ; output buffer
mov ah,40h ; dos write function
int 21h ; invoke dos function

jmp again ; repeat until end of file or error
oops:
int 20h ; return to dos
code ends
end snglspc


  3 Responses to “Category : C Source Code
Archive   : FILTERS.ZIP
Filename : SNGLSPC.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/