home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / oproclin.asm < prev    next >
Assembly Source File  |  1988-08-28  |  5KB  |  194 lines

  1.  
  2. ;    FILENAME: OPROCLIN.ASM
  3. ;    Copyright (c) 1988 by Borland International, Inc.
  4. ;
  5. ;    Description: This module implements the routine ProcLine. ProcLine
  6. ;    processes a line.
  7. ;    This module uses MASM mode syntax and standard segment directives. 
  8. ;    ASSEMBLY INSTRUCTIONS: To assemble this module use the following 
  9. ;    TASM command line. 
  10. ;        TASM oproclin
  11.  
  12. include globals.inc
  13.  
  14. _TEXT   segment
  15.  
  16.     ProcLine proc
  17.  
  18.     ;    This procedure processes a normal byte character 
  19.     ;    (31 < ASCII value < 128) in al.
  20.     ;
  21.     ;    Input 
  22.     ;       cx - number of bytes in buffer
  23.     ;       LinBuf - starting location of the line buffer
  24.     ;       SpcCnt - space count (for compressing spaces)
  25.     ;       TabOff - tab offset (decrements the tab column number)
  26.     ;       LAS_LET - designates the last character was a letter
  27.     ;       INP_EOL - designates an end-of-line condition
  28.     ;       INP_EOF - designates an end-of-file condition
  29.     ;       INP_ERR - designates an input error condition
  30.     ;       Options - the options being used
  31.     ;       MAK_CAP - designates character is to be capitalized
  32.     ;       LeftMar - left margin
  33.     ;       LeftDel - left characters to delete
  34.     ;       Trunc - truncate line length (truncate if non-zero)
  35.     ;       REM_SPC - delete trailing spaces
  36.     ;       REP_SPC - replace spaces with tabs
  37.     ;       TAB - ASCII 09
  38.     ;       CR - ASCII 13
  39.     ;       LF - ASCII 10
  40.     ;       OutBlk - output control block
  41.     ;       OUT_ERR - output error
  42.     ;    Output 
  43.     ;       InpSta - input status updated
  44.     ;       di - line buffer location updated
  45.     ;       cx - byte count updated
  46.     ;       si - start of line data
  47.     ;    Registers modified 
  48.     ;       ax, cx, di, si
  49.  
  50.     ; Process a line.
  51.  
  52.     sub     cx, cx                  ;clear bytes in buffer
  53.     lea     di, LinBuf              ;buffer location
  54.     mov     SpcCnt, 0               ;initial space count
  55.     mov     TabOff, 0               ;column offset
  56.  
  57.     push    ax
  58.     or      ax, LAS_LET
  59.     or      ax, INP_EOL
  60.     not     ax
  61.     and     InpSta, ax
  62.     pop     ax
  63.  
  64.     ;--- loop for each byte in line
  65.  
  66. prolin1:
  67.     call    ProcByte                       ;process byte
  68.  
  69.     push    ax
  70.     sub     ax, ax
  71.     or      ax, INP_EOL
  72.     or      ax, INP_EOF
  73.     or      ax, INP_ERR
  74.     test    InpSta, ax
  75.     pop     ax
  76.  
  77.     jnz     prolin2
  78.  
  79.     test    Options, MAK_CAP                ;test if capitalize
  80.     jz      prolin1
  81.     or      cx, cx                          ;check if any input
  82.     jz      prolin1
  83.  
  84.     push    ax
  85.     sub     ax, ax
  86.     mov     ax, LAS_LET
  87.     not     ax
  88.     and     InpSta, ax                      ;clear letter bit
  89.     pop     ax
  90.  
  91.     mov     al, [di-1]                      ;get last character
  92.     call    LoCase                          ;make lower case
  93.     cmp     al, 'a'                         ;check if below a
  94.     jb      prolin1
  95.     cmp     al, 'z'                         ;check if above z
  96.     ja      prolin1
  97.     or      InpSta, LAS_LET                 ;set letter bit
  98.     jmp     prolin1
  99.  
  100.     ;--- end of line
  101.  
  102. prolin2:
  103.     test    InpSta, INP_EOL ;check if any line returned
  104.     jnz     prolin3
  105.     ret
  106.  
  107.     ;--- extra trailing spaces
  108.  
  109. prolin3:
  110.     lea     si, LinBuf      ;start of line data
  111.  
  112.     call    TabNext         ;get next tab stop
  113.     jnc     prolin4         ;jump if not at stop
  114.     call    StoreTab        ;store a tab
  115.     jmp     SHORT prolin5
  116.  
  117. prolin4:
  118.     call    StoreSpc       ;store any spaces
  119.  
  120.     ;--- left margin
  121.  
  122. prolin5:
  123.     mov     ax, LeftMar     ;get left margin
  124.     add     cx, ax          ;add to byte count
  125.     sub     si, ax          ;add margin
  126.  
  127.     ;--- delete left margin characters
  128.  
  129.     mov     ax, LeftDel     ;margin remove
  130.     add     si, ax          ;skip beginning characters
  131.     sub     cx, ax          ;reduce count
  132.     jnc     prolin6         ;jump if okay (CX >= AX)
  133.     sub     cx, cx          ;set cx to zero
  134.  
  135.     ;--- truncate line
  136.  
  137. prolin6:
  138.     mov     ax, Trunc       ;truncate length
  139.     or      ax, ax          ;check if set
  140.     jz      prolin7
  141.     cmp     cx, ax
  142.     jbe     prolin7
  143.     mov     di, si          ;start of buffer
  144.     add     di, ax          ;line length
  145.     mov     cx, ax          ;byte count
  146.  
  147.     ;--- remove trailing spaces
  148.  
  149. prolin7:
  150.     test    Options, REM_SPC        ;check if remove
  151.     jz      prolin10
  152.  
  153. prolin8:
  154.     or      cx, cx                  ;see if no bytes left
  155.     jz      prolin10
  156.     cmp     BYTE PTR [di-1], ' '    ;check if space
  157.     je      prolin9
  158.     test    Options, REP_SPC        ;check if also delete tabs
  159.     jz      prolin10
  160.     cmp     BYTE PTR [di-1], TAB    ;check if tab
  161.     jne     prolin10
  162.  
  163. prolin9:
  164.     dec     di                      ;reduce pointer
  165.     dec     cx                      ;reduce count
  166.     jmp     prolin8
  167.  
  168.     ;--- append CR+LF
  169.  
  170. prolin10:
  171.     mov     al, CR
  172.     stosb                   ;store CR
  173.     inc     cx
  174.     mov     al, LF
  175.     stosb                   ;store LF
  176.     inc     cx              ;increment
  177.  
  178.     ;--- write line
  179.  
  180.     lea     bx, OutBlk      ;output control block
  181.     call    FileWrite       ;write to file
  182.     jnc     prolin11
  183.     or      InpSta, OUT_ERR ;set error flag
  184.  
  185. prolin11:
  186.     ret
  187.     ProcLine endp
  188.  
  189. _TEXT    ends
  190.  
  191. end
  192.