home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Du Jour
/
SoftwareDuJour.iso
/
BUSINESS
/
DBASE
/
DBAPG.ARC
/
FIX.A86
< prev
next >
Wrap
Text File
|
1984-08-12
|
6KB
|
272 lines
; Subroutine.: FIX.A86
; Author.....: Bob Doolittle
; Date.......: 08/12/84
; Notice.....: Copyright 1984, Ashton-Tate, All Rights Reserved.
; Notes......: CP/M 86 version.
;
M EQU Byte Ptr 0[BX]
;
ORG 100H
;
;BDOS equates
;
BDOS EQU 224 ;BDOS entry point
TBUF EQU 80H ;Default buffer
FCB EQU 5CH ;Default FCB
CFS EQU 35 ;Compute file size
CONIN EQU 1 ;Console in
CONOUT EQU 2 ;Console out
PSTR EQU 9 ;Print string
STRIN EQU 10 ;Console string input
OPEN EQU 15 ;Open file
CLOSE EQU 16 ;Close file
READ EQU 20 ;Read sequential
WRITE EQU 21 ;Write sequential
MAKE EQU 22 ;Make file
DELETE EQU 19 ;Delete file
READR EQU 33 ;Read random
;
;ASCII equates
;
CR EQU 13
LF EQU 10
;
START: MOV Byte Ptr FLG,0 ;Initialize CRLF flag to destroy CRLF
MOV AL,Byte Ptr .FCB+1
CMP AL,20H ;Was input file on command line
JNZ ST2 ;Yes
MOV DX,(Offset MES1) ;No, print message and abort
MOV CL,PSTR
INT BDOS
JMP EXIT
;
ST2: MOV DX,(Offset MES4) ;Print CRLF message
MOV CL,PSTR
INT BDOS
MOV CL,CONIN ;Get response
INT BDOS
AND AL,5FH ;Make upper case
CMP AL,'Y'
JNZ ST7
MOV AL,1
MOV Byte Ptr FLG,AL
ST7: MOV CL,PSTR ;Ask for # of bytes
MOV DX,(Offset MES6)
INT BDOS
MOV DX,(Offset CBUF) ;Get response
MOV CL,STRIN
INT BDOS
MOV BX,(Offset CBUF)+2
CALL CONV ;Convert to binary in HL
CALL DIV ;Divide by 128
MOV Word Ptr QUO,BX ;Save quotient and remainder
CALL CRLF
CALL CLEAR ;Clear FCB+32-35, FCB+15 and FCB+12
MOV BX,FCB
MOV DX,(Offset FCB1)
MOV CL,9
MOVE: MOV AL,M ;Move file name and drive from FCB to FCB1
MOV SI,DX
MOV [SI],AL
INC BX
INC DX
DEC CL
JNZ MOVE
MOV DX,FCB
MOV CL,OPEN ;Open file
INT BDOS
INC AL ;Was open successful?
JNZ ST3 ;Yes
MOV DX,(Offset MES2) ;No, print message and abort
MOV CL,PSTR
INT BDOS
JMP EXIT
ST3: MOV DX,(Offset MES5) ;Working message
MOV CL,PSTR
INT BDOS
MOV DX,FCB
MOV CL,CFS ;Compute file size
INT BDOS
MOV BX,Word Ptr .FCB+33 ;Get last record+1
MOV Word Ptr REC,BX ;Save locally
DEC BX ;Last record number
MOV Word Ptr .FCB+33,BX ;Store it back
MOV CL,READR
MOV DX,FCB
INT BDOS ;Read last record
MOV BX,TBUF-1
MOV CL,0 ;Initialize counter
LOP: INC BX ;Scan to 1st EOF mark and keep count
INC CL
CMP M,1AH ;Is it EOF?
JNZ LOP ;No, keep looping
PUSH CX ;Save count to EOF in last record
CALL CLEAR ;Clear again
MOV DX,(Offset FCB1)
MOV CL,DELETE ;Delete any possible previous out file
INT BDOS
MOV DX,FCB
MOV CL,OPEN ;Re-open the input file
INT BDOS
MOV DX,(Offset FCB1)
MOV CL,MAKE ;Make output file
INT BDOS
;
FIRS: MOV DX,FCB ;Scan off quotient # of records
MOV CL,READ
INT BDOS
OR AL,AL ;Read OK ?
JZ FST1 ;Yes
MOV DX,(Offset MES3) ;No
MOV CL,PSTR
INT BDOS
POP CX ;Balance stack
JMP EXIT
;
FST1: MOV BX,Word Ptr REC ;Bump record count down
DEC BX
MOV Word Ptr REC,BX
MOV BX,Word Ptr QUO ;Get DIV result
OR BH,BH ;Have we read sector with remainder ?
JZ FST2 ;Yes
DEC BH ;No
MOV Word Ptr QUO,BX ;Dec and store sector counter
MOV DX,(Offset FCB1) ;Write sector
MOV CL,WRITE
INT BDOS
JMPS FIRS ;Loop for more
FST2: ADD BL,80H ;BL now has filter start address
FST3: CALL FILTER
INC BX
OR BH,BH
JZ FST3 ;Filter to end of sector
MOV DX,(Offset FCB1)
MOV CL,WRITE ;Write to output file
INT BDOS
LOOP: MOV DX,FCB
MOV CL,READ ;Read a record to default buffer
INT BDOS
OR AL,AL ;Was read successful?
JZ LO4 ;Yes
ERR: MOV DX,(Offset MES3)
MOV CL,PSTR ;No, print message and abort
INT BDOS
POP CX ;Balance stack
JMPS EXIT
;
LO4: DEC Word Ptr REC ;Decrement record count
JNZ GOAH ;If not at last record
POP CX ;Yes, get back count
MOV BX,TBUF
;
LO1: DEC CL ;Are we at EOF
JZ LO2 ;Yes
CALL FILTER
INC BX
JMPS LO1 ;Loop
;
LO2: MOV DX,(Offset FCB1)
MOV CL,WRITE ;Write last record
INT BDOS
MOV DX,(Offset FCB1)
MOV CL,CLOSE ;Close output file
INT BDOS
EXIT: MOV CL,0 ;Finished
MOV DL,0
INT BDOS
;
GOAH: MOV BX,TBUF
MOV CX,80H ;Initialize record count
GO1: CALL FILTER ;Scan the record
INC BX
LOOP GO1 ;Loop to end of record
MOV DX,(Offset FCB1)
MOV CL,WRITE ;Write record to output file
INT BDOS
JMPS LOOP ;Loop to read next record
;
FILTER: AND M,7FH ;Strip bit 7
CMP M,20H ;Is it < space
JNAE L_1
RET ;No
L_1: TEST Byte Ptr FLG,0FFH ;Are we killing CRLF ?
JZ FIL1 ;Yes
MOV AL,M
CMP AL,CR
JNZ L_2
RET ;Don't change
L_2: CMP AL,LF
JNZ FIL1
RET ;Don't change
FIL1: MOV M,20H ;Replace anything < space by space
RET
;
CONV: MOV DX,0 ;Convert # pointed to by HL to binary in HL
XCHG BX,DX ;Conversion stops when # < '0' is found
MOV SI,DX ;Binary returned in BX
MOV AH,0
CONV1: MOV AL,[SI]
SUB AL,'0'
JNS L_4
RET
L_4: CMP AL,10
CMC
JNB L_5
RET
L_5: INC SI
SHL BX,1
MOV CX,BX
SHL BX,1
SHL BX,1
ADD BX,CX
ADD BX,AX
JMPS CONV1
;
DIV: MOV AX,BX ;Divide BX by 128
MOV CL,128
DIV CL
MOV BH,AL ;Quotient in BH, remainder in BL
MOV BL,AH
RET
;
CLEAR: XOR AL,AL ;Zero key fields in FCB
MOV BX,FCB+32
MOV M,AL
INC BX
MOV M,AL
INC BX
MOV M,AL
INC BX
MOV M,AL
MOV Byte Ptr .FCB+15,AL
MOV Byte Ptr .FCB+12,AL
RET
;
CRLF: MOV DL,CR
MOV CL,CONOUT
INT BDOS
MOV DL,LF
MOV CL,CONOUT
INT BDOS
RET
L_6 EQU $
DSEG
ORG Offset L_6
MES1 DB CR,LF,' USAGE: FIX [d:]<filename.typ>'
DB CR,LF,'where d is an optional drive designator'
DB CR,LF,'and filename.typ is the file name and type'
DB CR,LF,'of the file to be processed. The output'
DB CR,LF,'file will be named filename.FIX.$'
MES2 DB CR,LF,'Cannot find file on specified drive.$'
MES3 DB CR,LF,'Read past EOF.$'
MES4 DB CR,LF,'Do you want to preserve CRLF''s (Y or N) ? $'
MES5 DB CR,LF,'Working...$'
MES6 DB CR,LF,'What is the size of the header (in bytes)? $'
CBUF DB 10,0
DB 0,0,0,0,0,0,0,0,0,0,0,0
REC RS 2 ;Storage for record count
QUO RS 2 ;Storage for quotient and remainder
FLG DB 0 ;CRLF flag
FCB1 DB 0,' FIX'
DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0