home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSFILE.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-12-21  |  5.2 KB  |  141 lines

  1.  
  2. ;
  3. ;       MSFILE.ASM
  4. ;       MS 4.0
  5. ;       Copyright (c) 1985, 87 by Borland International, Inc.
  6. ;
  7. ;       Fast Routines for file operations in Editor Toolbox
  8. ;
  9.  
  10. DATA    SEGMENT BYTE PUBLIC
  11.  
  12. DATA    ENDS
  13.  
  14. CODE    SEGMENT BYTE PUBLIC
  15.  
  16.         ASSUME  CS:CODE,DS:DATA
  17.  
  18.         PUBLIC EdFastExpand, EdStripHighBit
  19.  
  20. ;****************************************************** EdFastExpand
  21.  
  22. ;procedure EdFastExpand(var b, t; var tlen : word;
  23. ;                       blen, tabsize, maxlinelength : word);
  24.  
  25. ;expand tabs in buffer b
  26. ;output in textline t and length in tlen
  27.  
  28. ;equates for parameters
  29.         b       EQU    DWORD PTR [BP+012H]
  30.         t       EQU    DWORD PTR [BP+0EH]
  31.         tlen    EQU    DWORD PTR [BP+0AH]
  32.         blen    EQU    WORD PTR [BP+08]
  33.         tabsize EQU    WORD PTR [BP+06]
  34.         maxlen  EQU    WORD PTR [BP+04]
  35.  
  36. EdFastExpand PROC NEAR
  37.  
  38.         PUSH    BP                      ;Save BP
  39.         MOV     BP,SP                   ;Set up stack frame
  40.         PUSH    DS                      ;Save DS
  41.  
  42.         XOR     DX,DX                   ;DX will have output length
  43.         MOV     CX,blen                 ;Get length of input
  44.  
  45. ;does line have any tabs at all?
  46.         LES     DI,b                    ;Point ES:DI to input
  47.         MOV     BX,CX                   ;Save buffer length
  48.         CLD                             ;Forward direction
  49.         MOV     AX,0909H                ;Look for Tab
  50.         REPNE SCASB                     ;Scan
  51.         JNE     Done                    ;No tabs, get out quick
  52.  
  53. ;initialize for tab expansion
  54.         LDS     SI,b                    ;Point DS:SI to input buffer
  55.         LES     DI,t                    ;Point ES:DI to output buffer
  56.         INC     DI                      ;Skip over junk byte
  57.         MOV     CX,BX                   ;Input length back into CX
  58.  
  59. ;loop expanding input
  60. NextC:  LODSB                           ;Next input into AL
  61.         CMP     AL,AH                   ;Is it a tab?
  62.         JE      CompT                   ;Yes? compute the tab stop
  63.         STOSB                           ;No? put non-tab in output
  64.         INC     DX                      ;Increment output length
  65.         CMP     DX,maxlen               ;Check for max line length
  66.         JAE     Done                    ;Get out if line full
  67.         LOOP    NextC                   ;Get next character
  68.         JMP SHORT Done                  ;Get out at end of loop
  69.  
  70. ;expand a given tab to next tab stop
  71. CompT:  MOV     BX,CX                   ;Save input position
  72.         MOV     AX,DX                   ;Output position into AX
  73.         PUSH    DX                      ;Save output length
  74.         XOR     DX,DX                   ;DX:AX has output position as dword
  75.         DIV     tabsize                 ;Output pos / tabsize
  76.         INC     AX                      ;Round up to next tab position
  77.         MUL     tabsize                 ;Next tab pos in AX
  78.         POP     DX                      ;Get output length back
  79.         CMP     AX,maxlen               ;Will line fit?
  80.         JAE     Done                    ;Line too long, quit
  81.  
  82. ;insert blanks for current tab
  83.         SUB     AX,DX                   ;AX has count of blanks
  84.         ADD     DX,AX                   ;New output line count in DX
  85.         MOV     CX,AX                   ;Loop counter for blanks
  86.         MOV     AX,0920H                ;Blank in AL, Tab in AH
  87.         REP STOSB                       ;Store blanks
  88.         MOV     CX,BX                   ;Input position restored
  89.         LOOP    NextC                   ;Get next character
  90.  
  91. ;recuperate and return
  92. Done:   POP     DS                      ;Restore DS
  93.         LES     DI,tlen                 ;Point to output length parameter
  94.         MOV     ES:[DI],DX              ;Store output length
  95.  
  96.         MOV     SP,BP                   ;Restore SP
  97.         POP     BP                      ;Restore BP
  98.         RET     18                      ;Remove parameters and return
  99.  
  100. EdFastExpand ENDP
  101.  
  102. ;****************************************************** EdStripHighBit
  103.  
  104. ;procedure EdStripHighBit(var B; Len : Word);
  105.  
  106. ;Given a buffer B of length Len, reset high bit of all characters
  107.  
  108. ;equates for parameters:
  109. SHLen           EQU     WORD PTR [BP+4]
  110. SHBuffer        EQU     DWORD PTR [BP+6]
  111.  
  112. ;constants
  113. HighBitMask     EQU     01111111b
  114.  
  115. EdStripHighBit  PROC NEAR
  116.  
  117.         PUSH    BP                      ;Save BP
  118.         MOV     BP,SP                   ;Set up stack frame
  119.         MOV     BX,DS                   ;Save DS in BX
  120.  
  121.         LDS     SI,SHBuffer             ;DS:SI points to buffer
  122.         INC     SI                      ;skip junk byte
  123.         MOV     CX,SHLen                ;get length of buffer
  124.         MOV     AL,HighBitMask          ;AL = Mask to strip high order bits
  125.  
  126. SHNext: AND     [SI],AL                 ;clear high bit
  127.         INC     SI                      ;next character
  128.         LOOP    SHNext                  ;repeat while CX <> 0
  129.  
  130.         MOV     DS,BX                   ;Restore DS from BX
  131.         MOV     SP,BP                   ;Restore SP
  132.         POP     BP                      ;Restore BP
  133.         RET     6                       ;Remove parameters and return
  134.  
  135. EdStripHighBit  ENDP
  136.  
  137.  
  138. CODE    ENDS
  139.  
  140.         END
  141.