·汇编源码--BRK
·汇编源码--CLOCK
·汇编源码--BURNOUT
·汇编源码--DOSSYM
·汇编源码--circle
·汇编源码--DEV
·汇编源码--getspace
·汇编源码--CLEAR
·汇编源码--col
·汇编源码--gameport
namecleanf
page55,132
title'CLEANF - Filter text file'
;
; CLEANF - a DOS 2.0 filter for wordprocessing document files.
;
; CLEAN.ASM Originally written by Ray Duncan
; Converted to DOS 2.0 filter CLEANF.ASM by Bob Taylor.
;
; This program reads text from the standard input device and writes
; filtered and transformed text to the standard output device.
;
;1. High bit of all characters is stripped off.
; 2. Tabs are expanded.
; 3. Removes all control codes except for line
; feeds, carriage returns, and form feeds.
; 4. Appends an end-of-file mark to the text, if
; none was present in the input stream.
;
; Can be used to make a WordStar file acceptable for
; other screen or line editors, and vice versa.
;
;
crequ0dh; ASCII carriage return
lfequ0ah; ASCII line feed
ffequ0ch; ASCII form feed
eofequ01ah; End-of-file marker
tabequ09h; ASCII tab code
commandequ80h; buffer for command tail
; DOS 2.0 Pre-Defined Handles
stdinequ0000; standard input file
stdoutequ0001; standard output file
stderrequ0002; standard error file
stdauxequ0003; standard auxilliary file
stdprnequ0004; standard printer file
csegsegment para public 'CODE'
assumecs:cseg,ds:cseg
org100H; start .COM at 100H
cleanprocfar; entry point from PC-DOS.
pushds; push a long return back
xorax,ax; to DOS onto the stack.
pushax
clean3:callget_char; get a character from input.
andal,7fh; turn off the high bit.
cmpal,20h; is it a control char?
jaeclean4; no. write it to output.
cmpal,eof; is it end of file?
jeclean6; yes, go write EOF mark and exit.
cmpal,tab; is it a tab?
jeclean5; yes, go expand it to spaces.
cmpal,cr; is it a carriage return?
jeclean35; yes, go process it.
cmpal,lf; is it a line feed?
jeclean35; yes, go process it.
cmpal,ff; is it a form feed?
jneclean3; no. discard it.
clean35:
movcolumn,0; if it's a legit ctrl char,
jmpclean45; we should be back at column 0.
clean4:inccolumn; if it's a non-ctrl char,
clean45:; col = col + 1.
callput_char; write the char to output.
jncclean3; if OK, go back for another char.
movbx,stderr; not OK. Set up to show error.
movdx,offset err_msg
movcx,err_msg_len; error = Disk full.
movah,40h; write the error message
int21h; to the standard error device. (CON:)
ret; back to DOS.
clean5:movax,column; tab code detected, must expand
cwd; expand tabs to spaces.
movcx,8; divide the current column counter
idivcx; by eight...
subcx,dx; eight minus the remainder is the
addcolumn,cx; number of spaces to send out to
clean55:; move to the next tab position.
pushcx
moval,20h
callput_char; send an ASCII blank
popcx
loopclean55
jmpclean3
clean6:callput_char; write out the EOF mark,
ret; and return to DOS.
cleanendp
get_char proc near
movbx,stdin; get chars from std. input
movcx,1; # of chars to get = 1
movdx,offset input_buffer; location = input_buffer
movah,3fh
int21h; do the function call
orax,ax; test # of chars returned
jzget_char1; if none, return EOF
moval,input_buffer; else, return the char in AL
ret
get_char1:
moval,eof; no chars read, return
ret; an End-of-File (EOF) mark.
get_char endp
put_char proc near
movoutput_buffer,al; put char to write in buffer.
movbx,stdout; write to std. output
movcx,1; # of chars = 1
movdx,offset output_buffer; location = output_buffer
movah,40h
int21h; do the function call
cmpax,1; check to see it was really done.
jneput_char1
clc; really done. return carry = 0
ret; as success signal.
put_char1:
stc; not really done. return carry = 1
ret; as error signal (device is full).
put_char endp
input_bufferdb0
output_bufferdb0
columndw0
err_msgdbcr,lf
db'clean: Disk is full.'
dbcr,lf
err_msg_lenequ(this byte)-(offset err_msg)
csegends
endclean
进入讨论组讨论。