home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR8
/
PCMCVT.ZIP
/
PCMASM.ZIP
/
AMICONV.INC
next >
Wrap
Text File
|
1993-05-22
|
9KB
|
244 lines
;AMICONV.INC
;Copyright (c) 1993 Jay Munro
;First Published in PC Magazine June 29 1993
;PCMCVT Conversion module for AMIPro 2.x
;Variables used by AMICONV
LastCharacter DW ? ;last character value
CharCounter DW ? ;character counter
AMIProCVT Proc Near
ReadAMIFile:
Call AMIReadIt ;go read the file
Jc AmiErrorLeap ;error, bag out immediately
;---- This section searches for the key word [edoc] which signals the start
; of the text
SearchLoop: ;find the start of the file
Push BX
Invoke SearchString, 1, Addr ReadBuffer, BufferSize, Addr AmiEdoc, 6
Or AX,AX
Jnz AMIFilter ;got a match, start moving.
Mov AX,BufferSize
Pop BX ;BX contains current write count
Sub AX,6 ;back up to besure to get whole match
Js AmiErrorLeap ;oops something went wrong.
Call AdjustFilePtr ;slide file pointer up (6 chars back)
Jc AmiErrorLeap
Jmp ReadAMIFile
AmiErrorLeap:
Jmp AMIExit
;--- This section starts filtering text from control chars
AMIFilter:
Add AX,5 ;start just after [edoc] string (6)
Lea SI,ReadBuffer ;get address of read buffer
Add SI,AX ;add offset of [edoc]
Mov CX,BufferSize
Sub CX,AX
RAMILoop:
LodSb ;grab a character
Cmp AL,'>' ;is it the end of the line?
Jnz @F
Mov AL,-1 ;a bad read, quit now
Call AMIWrite ;flush buffer
Jmp APExitLeap ;yes out now
@@:
;--Check for <> command
Cmp AL,'<' ;start of a command?
Jnz AtLoop ;jump ahead to check more
Dec CX ;count it
Jnz @F ;if CX = 0 then we're out of characters
Call AMIReadIt ;go back for a new read
Jnc @F
APExitLeap:
Jmp AMIExit ;if out of characters then exit
@@:
Cmp Byte Ptr [SI],'<' ;ok, if next one is, then we're not in a command
Jz AA1 ;yes, then use it
Cmp Byte Ptr [SI],';' ;is it a a reverse one?
Jnz ACmdLoop ;no skip ahead
Inc SI ;yes skip semicolon
Dec CX ;count the character
Jnz @F ;still have characters in buffer?
Call AMIReadIt ;no read more
Jnc @F ;read ok, keep going
Jmp AMIExit ;read not good, exit
@@:
LodSb
Jmp AWrite ;skip it if it's a double
AA1:
Inc SI
Jmp AWrite ;skip it if it's a double
ACmdLoop: ;AMI commands within < >
LodSb
Cmp AL,'>' ;did we hit the other end?
Jz ASkip
Loop ACmdLoop
Call AMIReadIt ;go read the file
Jc APExitLeap
Jmp ACmdLoop ;go back for more
ASkip:
Jmp AMIReloop
AtLoop: ;other commands surrounded by @ signs
Cmp AL,'@' ;ok, is it an at sign?
Jnz AMCRLF ;no, keep looking at it
Dec CX ;count the character
Jnz @F ;if still characters left, jump ahead
Call AMIReadIt ;read some more characters
Jc APExitLeap ;no more to read, quit now
@@: ;loop until end of @ stuff
Cmp Byte Ptr [SI],'@' ;check next one
Jnz AA
Inc SI
Jmp AMCRLF
AA:
LodSb
Cmp AL,'@'
Jz AMIReLoop
Loop AA
Call AMIReadIt ;go read the file
Jc APExitLeap
Jmp AA ;go back for more
AMCRLF:
Cmp AL,13 ;a carriage return?
Jz APCheckCRLF
;check line per graf
Cmp AL,9 ;tab character
Jnz @F
Call DoTabs ;expand the tabs
Jmp AMIReLoop ;bag out
@@:
Cmp AL,31 ;ok, skip the rest
Jbe AMIReLoop ;skip it
Or AL,AL ;is it a zero...not cool
Jz AMIReLoop ;yes, skip it
Jmp AWrite ;otherwise write it.
APCheckCRLF: ;check crlf
Cmp Word Ptr CRLF_FLAG,-1
Jz AWrite ;yes, then ignore them.
Call APEatCRLF
Jc APExitLeap
Jmp AMIReLoop
AWrite: ;write what's left
Call AMIWrite ;call our local write module
Jc APExitLeap
AMIReLoop:
Loop AMIReLeap
Call AMIReadIt ;go read the file
Jnc AMIReLeap ;skip ahead
Jmp AMIExit ;jump out if we got an error
AMIReLeap:
Jmp RAMILoop ;go back for more
AMIWrite:
Call WriteIt ;no, then write it
RetN
AMIReadIt:
Call ReadIt ;go read the file
Jnc @F ;out and out error!
Or BX,BX ;do we have anything to write?
Jz A1 ;nothing to write, skip out
Mov AL,-1 ;a bad read, quit now
Call AMIWrite ;flush buffer
A1:
Stc
@@:
RetN
AdjustFilePtr: ;sets file pointer to another position
Add Word Ptr FilePointer,AX
Adc Word Ptr FilePointer[2],0 ;add buffer to file pointer
Push BX
Invoke Seek, SHandle, FilePointer ;move pointer up
Pop BX
RetN
CheckCX:
Jcxz @F
RetN
@@: ;cx = 0, go read more
Call AMIReadIt ;go read the file
RetN
APEatCRLF: ;--- Eats excess CRLF's in .SAM file
Mov LastCRLF,1
Dec CX ;ok, count it
Call CheckCX
NextCRLF:
LodSb
Cmp AL,13
Jnz @F
Inc LastCRLF ;register another one
Loop NextCRLF ;loop back and keep eatin'
Call CheckCX ;ran out of characters
Loop NextCRLF ;got more, loop back
@@:
Cmp AL,10 ;ok, was it a LF?
Jnz APCRWrite ;done deal, check things out
Loop NextCRLF ;loop back and keep eatin'
Call CheckCX ;ran out of characters
Loop NextCRLF ;got more, loop back
Jmp AMIExit
APCRWrite:
Dec Word Ptr LastCRLF
Js APCRExit
Mov LastCharacter,AX
Mov CharCounter,CX
Mov CX,LastCRLF ;get number of CRLF's
Jcxz SkipCRLF ;
SendCRLF:
Mov AL,13 ;cr
Call AMIWrite ;call our local write module
Jc APCRErrExit ;error time!
Mov AL,10 ;lf
Call AMIWrite ;call our local write module
Jc AMIExit ;error time!
Loop SendCRLF ;do more
SkipCRLF: ;retrieve saved registers
Mov AX, LastCharacter ;last character value
Mov CX, CharCounter ;character counter
APCRExit:
Mov LastCRLF,0 ;reset crlf counter
Dec SI ;back up a character
Inc CX ;add that retrieved character
Clc
RetN
APCRErrExit:
Dec SI
Inc CX
Stc
RetN
AMIExit: ;--- Main Exit
Ret
AMIProCVT EndP