home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
assemblr
/
asm
/
wasm
/
filt1.asm
< prev
next >
Wrap
Assembly Source File
|
1988-03-06
|
15KB
|
554 lines
;************************************************
; Text FILTer
;
; Filter routines for FILT.ASM.
;================================================
; Convert the letter in AL to lower case.
Lo_Case PROC NEAR
cmp al, 'A'
jb locas1
cmp al, 'Z'
ja locas1
add al, 'a'-'A'
locas1 ret
ENDP ;Lo_Case
;================================================
; Convert the letter in AL to upper case.
Up_Case PROC NEAR
cmp al, 'a'
jb upcas1
cmp al, 'z'
ja upcas1
sub al, 'a'-'A'
upcas1 ret
ENDP ;Up_Case
;================================================
; Store some spaces.
;
; In: DX= number of spaces; DI= location.
Spaces PROC NEAR
push ax
push cx
mov cx, dx ;load count
mov al, ' ' ;space
rep
stosb ;store bytes
pop cx
pop ax
ret
ENDP ;Spaces
;================================================
; Tab routines.
;------------------------------------------------
; Clear all tab stops.
Tab_Clear PROC NEAR
push ax
push cx
push di
sub al, al ;zero
mov cx, MAXLIN ;number of entries
lea di, TabTbl ;table location
rep
stosb ;fill table
pop di
pop cx
pop ax
ret
ENDP ;Tab_Clear
;------------------------------------------------
; Set tab stops a every 8 locations.
Tab_Reset PROC NEAR
call Tab_Clear ;clear all tab stops first
push cx
push di
sub cx, cx ;initial column count
lea di, TabTbl ;table location
tabres1 cmp di, TabEnd ;check if at end
je tabres3
cmp cx, 8 ;check if at tab stop
je tabres2
inc cx
inc di
jmps tabres1
tabres2 mov BYTE [di], 1
sub cx, cx
jmps tabres1
tabres3 pop di
pop cx
ret
ENDP ;Tab_Reset
;------------------------------------------------
; Set a tab stop.
;
; In: BX= column number.
Tab_Set PROC NEAR
push bx
lea bx, [TabTbl + bx] ;get address
cmp bx, TabEnd ;check if past end
jae tabset1
mov BYTE [bx], 1 ;set to non-zero
tabset1 pop bx
ret
ENDP ;Tab_Set
;------------------------------------------------
; Return the number of spaces to the next tab
; stop.
;
; In: CX= present column number.
;
; Out: DX= spaces to next stop; CY= set if at tab
; tab stop.
Tab_Next PROC NEAR
push bx
push si
mov bx, cx ;tab column
add bx, TabOff ;add special offset
lea bx, [TabTbl + bx] ;get starting address
sub dx, dx
cmp bx, TabEnd ;check if at or past end
jae tabnex3 ;jump if so
mov si, bx ;save starting location
inc bx ;start at next column
inc dx ;set count
;--- loop until tab stop is found or end of table
tabnex1 cmp bx, TabEnd ;check if end
jae tabnex2
cmp BYTE [bx], 0 ;check if tab
jne tabnex2
inc bx ;next column
inc dx ;increment count
jmps tabnex1 ;loop back
;--- found tab stop
tabnex2 cmp BYTE [si], 0 ;check if started at tab stop
jne tabnex3
pop si
pop bx
clc
ret
;--- initial tab stop
tabnex3 pop si
pop bx
stc
ret
ENDP ;Tab_Next
;------------------------------------------------
; Store a tab character if stored characters.
Store_Tab PROC NEAR
cmp SpcCnt, 0 ;check if any spaces to compress
je stotab1 ;jump if not
push ax
mov al, TAB ;load tab
stosb ;store
inc cx ;increment byte count
dec TabOff ;adjust column
mov SpcCnt, 0 ;reset space count
pop ax
stotab1 ret
ENDP ;Store_Tab
;------------------------------------------------
; Store the stored spaces.
Store_Spc PROC NEAR
push dx
mov dx, SpcCnt ;get number of stored spaces
or dx, dx ;check if any
jz stospc1
call Spaces ;store spaces
add cx, dx ;byte count
sub TabOff, dx ;adjust column offset
mov SpcCnt, 0 ;reset space count
stospc1 pop dx
ret
ENDP ;Store_Spc
;================================================
; Process a byte.
;
; In: AL= character; DI= buffer location; CX=
; bytes in buffer.
;
; Out: CX and DI= updated.
Proc_Byte PROC NEAR
;--- read byte
push cx
push di
lea bx, InpBlk ;input control block
mov cx, 1 ;bytes to read
lea di, InpBuf ;input buffer
call File_Read ;read byte
pop di
pop cx
jc probyt5 ;jump if error or EOF
;--- check type of character
mov al, InpBuf ;load byte
probyt1 cmp al, 32
jb probyt2
cmp al, 127
ja probyt3
;--- normal byte, 31 < AL < 128
call Byte_Norm
ret
;--- low byte, AL < 32
probyt2 call Byte_Low
ret
;--- high byte, AL > 127
probyt3 test Options, STR_BIT ;check if strip high bit
jnz probyt4
call Byte_High
ret
probyt4 and al, 7fh ;clear bit
jmps probyt1 ;loop back
;--- error reading
probyt5 cmp ax, 0 ;check if EOF
jne probyt7
or InpSta, INP_EOF ;set end of file flag
or cx, cx ;check if any bytes
jz probyt6
or InpSta, INP_EOL ;set end of line also
probyt6 ret
ret
probyt7 or InpSta, INP_ERR ;set error flag
ret
ENDP ;Proc_Byte
;------------------------------------------------
; Process low byte.
Byte_Low PROC NEAR
;--- end of line
cmp al, EOL ;check if end of line
jne bytlo1
or InpSta, INP_EOL
ret
;--- replace tabs with spaces
bytlo1 test Options, REP_TAB ;test if replace tabs
jz bytlo3
cmp al, TAB ;check if tab
jne bytlo3
call Tab_Next ;get spaces needed
call Spaces ;store spaces
add cx, dx ;byte count
ret
;--- carriage return
bytlo3 test Options, SAV_CR ;check if saving CR's
jnz bytlo4
cmp al, CR ;check if carriage return
jne bytlo4
ret
;--- end of file
bytlo4 test Options, SKP_EOF ;check if ignore EOF
jnz bytlo6
cmp al, EOF ;check if end of page
jne bytlo6
or InpSta, INP_EOF ;set flag
or cx, cx ;check if any bytes
jz bytlo5
or InpSta, INP_EOL ;set end of line also
bytlo5 ret
;--- remove low bytes
bytlo6 test Options, STR_LOB ;test if remove low bytes
jz bytlo7
ret
;--- write byte
bytlo7 stosb
inc cx
ret
ENDP ;Byte_Low
;------------------------------------------------
; Process normal byte.
Byte_Norm PROC NEAR
;--- end of line
cmp al, EOL ;check if end of line
jne bytnor1
or InpSta, INP_EOL
ret
;--- replace spaces with tabs
bytnor1 test Options, REP_SPC ;test if replace spaces
jz bytnor4
;------ write tab stop
call Tab_Next ;get next tab stop
jnc bytnor2 ;jump if not at stop
call Store_Tab ;store a tab
;------ space
bytnor2 cmp al, ' ' ;check if really space
jne bytnor3 ;jump if not
inc SpcCnt ;increment space count
inc TabOff ;increment column
ret
;------ non-space
bytnor3 call Store_Spc ;store any spaces
;--- convert to lower case
bytnor4 test Options, MAK_LWR ;test if make lower case
jz bytnor5
call Lo_Case
stosb
inc cx
ret
;--- convert to upper case
bytnor5 test Options, MAK_UPR ;test if make upper case
jz bytnor6
call Up_Case
stosb
inc cx
ret
;--- capitalize
bytnor6 test Options, MAK_CAP ;test if capitalize
jz bytnor8
test InpSta, LAS_LET ;check if last was letter
jz bytnor7
call Lo_Case
stosb
inc cx
ret
bytnor7 call Up_Case
stosb
inc cx
ret
;--- write byte
bytnor8 stosb
inc cx
ret
ENDP ;Byte_Norm
;------------------------------------------------
; Process high byte.
Byte_High PROC NEAR
;--- end of line
cmp al, EOL ;check if end of line
jne bythi1
or InpSta, INP_EOL
ret
;--- remove high bytes
bythi1 test Options, STR_HIB ;test if remove high bytes
jz bythi2
ret
;--- write byte
bythi2 stosb
inc cx
ret
ENDP ;Byte_High
;================================================
; Process a line.
Proc_Line PROC NEAR
sub cx, cx ;clear bytes in buffer
lea di, LinBuf ;buffer location
mov SpcCnt, 0 ;initial space count
mov TabOff, 0 ;column offset
and InpSta, NOT (LAS_LET OR INP_EOL)
;--- loop for each byte in line
prolin1 call Proc_Byte ;process byte
test InpSta, INP_EOL OR INP_EOF OR INP_ERR
jnz prolin2
test Options, MAK_CAP ;test if capitalize
jz prolin1
or cx, cx ;check if any input
jz prolin1
and InpSta, NOT LAS_LET ;clear letter bit
mov al, [di-1] ;get last character
call Lo_Case ;make lower case
cmp al, 'a' ;check if below a
jb prolin1
cmp al, 'z' ;check if above z
ja prolin1
or InpSta, LAS_LET ;set letter bit
jmps prolin1
;--- end of line
prolin2 test InpSta, INP_EOL ;check if any line returned
jnz prolin3
ret
;--- extra trailing spaces
prolin3 lea si, LinBuf ;start of line data
call Tab_Next ;get next tab stop
jnc prolin4 ;jump if not at stop
call Store_Tab ;store a tab
jmps prolin5
prolin4 call Store_Spc ;store any spaces
;--- left margin
prolin5 mov ax, LeftMar ;get left margin
add cx, ax ;add to byte count
sub si, ax ;add margin
;--- delete left margin characters
mov ax, LeftDel ;margin remove
add si, ax ;skip beginning characters
sub cx, ax ;reduce count
jnc prolin6 ;jump if okay (CX >= AX)
sub cx, cx ;set cx to zero
;--- truncate line
prolin6 mov ax, Trunc ;truncate length
or ax, ax ;check if set
jz prolin7
cmp cx, ax
jbe prolin7
mov di, si ;start of buffer
add di, ax ;line length
mov cx, ax ;byte count
;--- remove trailing spaces
prolin7 test Options, REM_SPC ;check if remove
jz prolin10
prolin8 or cx, cx ;see if no bytes left
jz prolin10
cmp BYTE [di-1], ' ' ;check if space
je prolin9
test Options, REP_SPC ;check if also delete tabs
jz prolin10
cmp BYTE [di-1], TAB ;check if tab
jne prolin10
prolin9 dec di ;reduce pointer
dec cx ;reduce count
jmps prolin8
;--- append CR+LF
prolin10 mov al, CR
stosb ;store CR
inc cx
mov al, LF
stosb ;store LF
inc cx ;increment
;--- write line
lea bx, OutBlk ;output control block
call File_Write ;write to file
jnc prolin11
or InpSta, OUT_ERR ;set error flag
prolin11 ret
ENDP ;Proc_Line
;================================================
; Process a document.
Proc_Doc PROC NEAR
;--- process every line
propag1 call Proc_Line
test InpSta, INP_EOF OR INP_ERR OR OUT_ERR
jz propag1
;--- write EOF
test Options, SUP_EOF ;check if suppressed
jnz propag2
test InpSta, INP_ERR ;
jnz propag2 ;-- check for errors
test InpSta, OUT_ERR ;
jnz propag2
mov cx, 1 ;bytes to write
lea si, LinBuf ;put it in line buffer
mov BYTE [si], EOF ;EOF character
lea bx, OutBlk ;output control block
call File_Write ;write to file
propag2 ret
ENDP ;Proc_Page