home *** CD-ROM | disk | FTP | other *** search
-
- ;
- ; MSFILE.ASM
- ; MS 4.0
- ; Copyright (c) 1985, 87 by Borland International, Inc.
- ;
- ; Fast Routines for file operations in Editor Toolbox
- ;
-
- DATA SEGMENT BYTE PUBLIC
-
- DATA ENDS
-
- CODE SEGMENT BYTE PUBLIC
-
- ASSUME CS:CODE,DS:DATA
-
- PUBLIC EdFastExpand, EdStripHighBit
-
- ;****************************************************** EdFastExpand
-
- ;procedure EdFastExpand(var b, t; var tlen : word;
- ; blen, tabsize, maxlinelength : word);
-
- ;expand tabs in buffer b
- ;output in textline t and length in tlen
-
- ;equates for parameters
- b EQU DWORD PTR [BP+012H]
- t EQU DWORD PTR [BP+0EH]
- tlen EQU DWORD PTR [BP+0AH]
- blen EQU WORD PTR [BP+08]
- tabsize EQU WORD PTR [BP+06]
- maxlen EQU WORD PTR [BP+04]
-
- EdFastExpand PROC NEAR
-
- PUSH BP ;Save BP
- MOV BP,SP ;Set up stack frame
- PUSH DS ;Save DS
-
- XOR DX,DX ;DX will have output length
- MOV CX,blen ;Get length of input
-
- ;does line have any tabs at all?
- LES DI,b ;Point ES:DI to input
- MOV BX,CX ;Save buffer length
- CLD ;Forward direction
- MOV AX,0909H ;Look for Tab
- REPNE SCASB ;Scan
- JNE Done ;No tabs, get out quick
-
- ;initialize for tab expansion
- LDS SI,b ;Point DS:SI to input buffer
- LES DI,t ;Point ES:DI to output buffer
- INC DI ;Skip over junk byte
- MOV CX,BX ;Input length back into CX
-
- ;loop expanding input
- NextC: LODSB ;Next input into AL
- CMP AL,AH ;Is it a tab?
- JE CompT ;Yes? compute the tab stop
- STOSB ;No? put non-tab in output
- INC DX ;Increment output length
- CMP DX,maxlen ;Check for max line length
- JAE Done ;Get out if line full
- LOOP NextC ;Get next character
- JMP SHORT Done ;Get out at end of loop
-
- ;expand a given tab to next tab stop
- CompT: MOV BX,CX ;Save input position
- MOV AX,DX ;Output position into AX
- PUSH DX ;Save output length
- XOR DX,DX ;DX:AX has output position as dword
- DIV tabsize ;Output pos / tabsize
- INC AX ;Round up to next tab position
- MUL tabsize ;Next tab pos in AX
- POP DX ;Get output length back
- CMP AX,maxlen ;Will line fit?
- JAE Done ;Line too long, quit
-
- ;insert blanks for current tab
- SUB AX,DX ;AX has count of blanks
- ADD DX,AX ;New output line count in DX
- MOV CX,AX ;Loop counter for blanks
- MOV AX,0920H ;Blank in AL, Tab in AH
- REP STOSB ;Store blanks
- MOV CX,BX ;Input position restored
- LOOP NextC ;Get next character
-
- ;recuperate and return
- Done: POP DS ;Restore DS
- LES DI,tlen ;Point to output length parameter
- MOV ES:[DI],DX ;Store output length
-
- MOV SP,BP ;Restore SP
- POP BP ;Restore BP
- RET 18 ;Remove parameters and return
-
- EdFastExpand ENDP
-
- ;****************************************************** EdStripHighBit
-
- ;procedure EdStripHighBit(var B; Len : Word);
-
- ;Given a buffer B of length Len, reset high bit of all characters
-
- ;equates for parameters:
- SHLen EQU WORD PTR [BP+4]
- SHBuffer EQU DWORD PTR [BP+6]
-
- ;constants
- HighBitMask EQU 01111111b
-
- EdStripHighBit PROC NEAR
-
- PUSH BP ;Save BP
- MOV BP,SP ;Set up stack frame
- MOV BX,DS ;Save DS in BX
-
- LDS SI,SHBuffer ;DS:SI points to buffer
- INC SI ;skip junk byte
- MOV CX,SHLen ;get length of buffer
- MOV AL,HighBitMask ;AL = Mask to strip high order bits
-
- SHNext: AND [SI],AL ;clear high bit
- INC SI ;next character
- LOOP SHNext ;repeat while CX <> 0
-
- MOV DS,BX ;Restore DS from BX
- MOV SP,BP ;Restore SP
- POP BP ;Restore BP
- RET 6 ;Remove parameters and return
-
- EdStripHighBit ENDP
-
-
- CODE ENDS
-
- END