home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / asm / wasm / filt1.asm < prev    next >
Assembly Source File  |  1988-03-06  |  15KB  |  554 lines

  1. ;************************************************
  2. ; Text FILTer
  3. ;
  4. ; Filter routines for FILT.ASM.
  5.  
  6. ;================================================
  7. ; Convert the letter in AL to lower case.
  8.  
  9. Lo_Case PROC    NEAR
  10.         cmp     al, 'A'
  11.         jb      locas1
  12.         cmp     al, 'Z'
  13.         ja      locas1
  14.         add     al, 'a'-'A'
  15. locas1  ret
  16.         ENDP                    ;Lo_Case
  17.  
  18. ;================================================
  19. ; Convert the letter in AL to upper case.
  20.  
  21. Up_Case PROC    NEAR
  22.         cmp     al, 'a'
  23.         jb      upcas1
  24.         cmp     al, 'z'
  25.         ja      upcas1
  26.         sub     al, 'a'-'A'
  27. upcas1  ret
  28.         ENDP                    ;Up_Case
  29.  
  30. ;================================================
  31. ; Store some spaces.
  32. ;
  33. ; In: DX= number of spaces; DI= location.
  34.  
  35. Spaces  PROC  NEAR
  36.         push    ax
  37.         push    cx
  38.         mov     cx, dx          ;load count
  39.         mov     al, ' '         ;space
  40.         rep
  41.         stosb                   ;store bytes
  42.         pop     cx
  43.         pop     ax
  44.         ret
  45.         ENDP                    ;Spaces
  46.  
  47. ;================================================
  48. ; Tab routines.
  49.  
  50. ;------------------------------------------------
  51. ; Clear all tab stops.
  52.  
  53. Tab_Clear PROC  NEAR
  54.         push    ax
  55.         push    cx
  56.         push    di
  57.         sub     al, al          ;zero
  58.         mov     cx, MAXLIN      ;number of entries
  59.         lea     di, TabTbl      ;table location
  60.         rep
  61.         stosb                   ;fill table
  62.         pop     di
  63.         pop     cx
  64.         pop     ax
  65.         ret
  66.         ENDP                    ;Tab_Clear
  67.  
  68. ;------------------------------------------------
  69. ; Set tab stops a every 8 locations.
  70.  
  71. Tab_Reset PROC  NEAR
  72.         call    Tab_Clear       ;clear all tab stops first
  73.  
  74.         push    cx
  75.         push    di
  76.         sub     cx, cx          ;initial column count
  77.         lea     di, TabTbl      ;table location
  78.  
  79. tabres1 cmp     di, TabEnd      ;check if at end
  80.         je      tabres3
  81.         cmp     cx, 8           ;check if at tab stop
  82.         je      tabres2
  83.         inc     cx
  84.         inc     di
  85.         jmps    tabres1
  86.  
  87. tabres2 mov     BYTE [di], 1
  88.         sub     cx, cx
  89.         jmps    tabres1
  90.  
  91. tabres3 pop     di
  92.         pop     cx
  93.         ret
  94.         ENDP                    ;Tab_Reset
  95.  
  96. ;------------------------------------------------
  97. ; Set a tab stop.
  98. ;
  99. ; In: BX= column number.
  100.  
  101. Tab_Set PROC    NEAR
  102.         push    bx
  103.         lea     bx, [TabTbl + bx]       ;get address
  104.         cmp     bx, TabEnd              ;check if past end
  105.         jae     tabset1
  106.         mov     BYTE [bx], 1            ;set to non-zero
  107. tabset1 pop     bx
  108.         ret
  109.         ENDP                            ;Tab_Set
  110.  
  111. ;------------------------------------------------
  112. ; Return the number of spaces to the next tab
  113. ; stop.
  114. ;
  115. ; In: CX= present column number.
  116. ;
  117. ; Out: DX= spaces to next stop; CY= set if at tab
  118. ; tab stop.
  119.  
  120. Tab_Next PROC   NEAR
  121.         push    bx
  122.         push    si
  123.         mov     bx, cx                  ;tab column
  124.         add     bx, TabOff              ;add special offset
  125.         lea     bx, [TabTbl + bx]       ;get starting address
  126.         sub     dx, dx
  127.         cmp     bx, TabEnd              ;check if at or past end
  128.         jae     tabnex3                 ;jump if so
  129.  
  130.         mov     si, bx          ;save starting location
  131.         inc     bx              ;start at next column
  132.         inc     dx              ;set count
  133.  
  134. ;--- loop until tab stop is found or end of table
  135.  
  136. tabnex1 cmp     bx, TabEnd      ;check if end
  137.         jae     tabnex2
  138.         cmp     BYTE [bx], 0    ;check if tab
  139.         jne     tabnex2
  140.         inc     bx              ;next column
  141.         inc     dx              ;increment count
  142.         jmps    tabnex1         ;loop back
  143.  
  144. ;--- found tab stop
  145.  
  146. tabnex2 cmp     BYTE [si], 0    ;check if started at tab stop
  147.         jne     tabnex3
  148.         pop     si
  149.         pop     bx
  150.         clc
  151.         ret
  152.  
  153. ;--- initial tab stop
  154.  
  155. tabnex3 pop     si
  156.         pop     bx
  157.         stc
  158.         ret
  159.         ENDP                    ;Tab_Next
  160.  
  161. ;------------------------------------------------
  162. ; Store a tab character if stored characters.
  163.  
  164. Store_Tab PROC  NEAR
  165.         cmp     SpcCnt, 0       ;check if any spaces to compress
  166.         je      stotab1         ;jump if not
  167.         push    ax
  168.         mov     al, TAB         ;load tab
  169.         stosb                   ;store
  170.         inc     cx              ;increment byte count
  171.         dec     TabOff          ;adjust column
  172.         mov     SpcCnt, 0       ;reset space count
  173.         pop     ax
  174. stotab1 ret
  175.         ENDP                    ;Store_Tab
  176.  
  177. ;------------------------------------------------
  178. ; Store the stored spaces.
  179.  
  180. Store_Spc PROC  NEAR
  181.         push    dx
  182.         mov     dx, SpcCnt      ;get number of stored spaces
  183.         or      dx, dx          ;check if any
  184.         jz      stospc1
  185.         call    Spaces          ;store spaces
  186.         add     cx, dx          ;byte count
  187.         sub     TabOff, dx      ;adjust column offset
  188.         mov     SpcCnt, 0       ;reset space count
  189. stospc1 pop     dx
  190.         ret
  191.         ENDP                    ;Store_Spc
  192.  
  193. ;================================================
  194. ; Process a byte.
  195. ;
  196. ; In: AL= character; DI= buffer location; CX=
  197. ; bytes in buffer.
  198. ;
  199. ; Out: CX and DI= updated.
  200.  
  201. Proc_Byte PROC   NEAR
  202.  
  203. ;--- read byte
  204.  
  205.         push    cx
  206.         push    di
  207.         lea     bx, InpBlk      ;input control block
  208.         mov     cx, 1           ;bytes to read
  209.         lea     di, InpBuf      ;input buffer
  210.         call    File_Read       ;read byte
  211.         pop     di
  212.         pop     cx
  213.         jc      probyt5         ;jump if error or EOF
  214.  
  215. ;--- check type of character
  216.  
  217.         mov     al, InpBuf      ;load byte
  218.  
  219. probyt1 cmp     al, 32
  220.         jb      probyt2
  221.         cmp     al, 127
  222.         ja      probyt3
  223.  
  224. ;--- normal byte, 31 < AL < 128
  225.  
  226.         call    Byte_Norm
  227.         ret
  228.  
  229. ;--- low byte, AL < 32
  230.  
  231. probyt2 call    Byte_Low
  232.         ret
  233.  
  234. ;--- high byte, AL > 127
  235.  
  236. probyt3 test    Options, STR_BIT ;check if strip high bit
  237.         jnz     probyt4
  238.         call    Byte_High
  239.         ret
  240.  
  241. probyt4 and     al, 7fh         ;clear bit
  242.         jmps    probyt1         ;loop back
  243.  
  244. ;--- error reading
  245.  
  246. probyt5 cmp     ax, 0           ;check if EOF
  247.         jne     probyt7
  248.         or      InpSta, INP_EOF ;set end of file flag
  249.         or      cx, cx          ;check if any bytes
  250.         jz      probyt6
  251.         or      InpSta, INP_EOL ;set end of line also
  252. probyt6 ret
  253.         ret
  254.  
  255. probyt7 or      InpSta, INP_ERR ;set error flag
  256.         ret
  257.         ENDP                    ;Proc_Byte
  258.  
  259. ;------------------------------------------------
  260. ; Process low byte.
  261.  
  262. Byte_Low PROC   NEAR
  263.  
  264. ;--- end of line
  265.  
  266.         cmp     al, EOL         ;check if end of line
  267.         jne     bytlo1
  268.         or      InpSta, INP_EOL
  269.         ret
  270.  
  271. ;--- replace tabs with spaces
  272.  
  273. bytlo1  test    Options, REP_TAB ;test if replace tabs
  274.         jz      bytlo3
  275.         cmp     al, TAB         ;check if tab
  276.         jne     bytlo3
  277.         call    Tab_Next        ;get spaces needed
  278.         call    Spaces          ;store spaces
  279.         add     cx, dx          ;byte count
  280.         ret
  281.  
  282. ;--- carriage return
  283.  
  284. bytlo3  test    Options, SAV_CR  ;check if saving CR's
  285.         jnz     bytlo4
  286.         cmp     al, CR          ;check if carriage return
  287.         jne     bytlo4
  288.         ret
  289.  
  290. ;--- end of file
  291.  
  292. bytlo4  test    Options, SKP_EOF ;check if ignore EOF
  293.         jnz     bytlo6
  294.         cmp     al, EOF         ;check if end of page
  295.         jne     bytlo6
  296.         or      InpSta, INP_EOF ;set flag
  297.         or      cx, cx          ;check if any bytes
  298.         jz      bytlo5
  299.         or      InpSta, INP_EOL ;set end of line also
  300. bytlo5  ret
  301.  
  302. ;--- remove low bytes
  303.  
  304. bytlo6  test    Options, STR_LOB ;test if remove low bytes
  305.         jz      bytlo7
  306.         ret
  307.  
  308. ;--- write byte
  309.  
  310. bytlo7  stosb
  311.         inc     cx
  312.         ret
  313.         ENDP                    ;Byte_Low
  314.  
  315. ;------------------------------------------------
  316. ; Process normal byte.
  317.  
  318. Byte_Norm PROC  NEAR
  319.  
  320. ;--- end of line
  321.  
  322.         cmp     al, EOL         ;check if end of line
  323.         jne     bytnor1
  324.         or      InpSta, INP_EOL
  325.         ret
  326.  
  327. ;--- replace spaces with tabs
  328.  
  329. bytnor1 test    Options, REP_SPC ;test if replace spaces
  330.         jz      bytnor4
  331.  
  332. ;------ write tab stop
  333.  
  334.         call    Tab_Next        ;get next tab stop
  335.         jnc     bytnor2         ;jump if not at stop
  336.         call    Store_Tab       ;store a tab
  337.  
  338. ;------ space
  339.  
  340. bytnor2 cmp     al, ' '         ;check if really space
  341.         jne     bytnor3         ;jump if not
  342.         inc     SpcCnt          ;increment space count
  343.         inc     TabOff          ;increment column
  344.         ret
  345.  
  346. ;------ non-space
  347.  
  348. bytnor3 call    Store_Spc       ;store any spaces
  349.  
  350. ;--- convert to lower case
  351.  
  352. bytnor4 test    Options, MAK_LWR ;test if make lower case
  353.         jz      bytnor5
  354.         call    Lo_Case
  355.         stosb
  356.         inc     cx
  357.         ret
  358.  
  359. ;--- convert to upper case
  360.  
  361. bytnor5 test    Options, MAK_UPR ;test if make upper case
  362.         jz      bytnor6
  363.         call    Up_Case
  364.         stosb
  365.         inc     cx
  366.         ret
  367.  
  368. ;--- capitalize
  369.  
  370. bytnor6 test    Options, MAK_CAP ;test if capitalize
  371.         jz      bytnor8
  372.         test    InpSta, LAS_LET ;check if last was letter
  373.         jz      bytnor7
  374.         call    Lo_Case
  375.         stosb
  376.         inc     cx
  377.         ret
  378.  
  379. bytnor7 call    Up_Case
  380.         stosb
  381.         inc     cx
  382.         ret
  383.  
  384. ;--- write byte
  385.  
  386. bytnor8 stosb
  387.         inc     cx
  388.         ret
  389.         ENDP            ;Byte_Norm
  390.  
  391. ;------------------------------------------------
  392. ; Process high byte.
  393.  
  394. Byte_High PROC    NEAR
  395.  
  396. ;--- end of line
  397.  
  398.         cmp     al, EOL         ;check if end of line
  399.         jne     bythi1
  400.         or      InpSta, INP_EOL
  401.         ret
  402.  
  403. ;--- remove high bytes
  404.  
  405. bythi1  test    Options, STR_HIB ;test if remove high bytes
  406.         jz      bythi2
  407.         ret
  408.  
  409. ;--- write byte
  410.  
  411. bythi2  stosb
  412.         inc     cx
  413.         ret
  414.         ENDP                    ;Byte_High
  415.  
  416. ;================================================
  417. ; Process a line.
  418.  
  419. Proc_Line PROC  NEAR
  420.         sub     cx, cx                  ;clear bytes in buffer
  421.         lea     di, LinBuf              ;buffer location
  422.         mov     SpcCnt, 0               ;initial space count
  423.         mov     TabOff, 0               ;column offset
  424.         and     InpSta, NOT (LAS_LET OR INP_EOL)
  425.  
  426. ;--- loop for each byte in line
  427.  
  428. prolin1 call    Proc_Byte                       ;process byte
  429.  
  430.         test    InpSta, INP_EOL OR INP_EOF OR INP_ERR
  431.         jnz     prolin2
  432.  
  433.         test    Options, MAK_CAP                ;test if capitalize
  434.         jz      prolin1
  435.         or      cx, cx                          ;check if any input
  436.         jz      prolin1
  437.         and     InpSta, NOT LAS_LET             ;clear letter bit
  438.         mov     al, [di-1]                      ;get last character
  439.         call    Lo_Case                         ;make lower case
  440.         cmp     al, 'a'                         ;check if below a
  441.         jb      prolin1
  442.         cmp     al, 'z'                         ;check if above z
  443.         ja      prolin1
  444.         or      InpSta, LAS_LET                 ;set letter bit
  445.         jmps    prolin1
  446.  
  447. ;--- end of line
  448.  
  449. prolin2 test    InpSta, INP_EOL ;check if any line returned
  450.         jnz     prolin3
  451.         ret
  452.  
  453. ;--- extra trailing spaces
  454.  
  455. prolin3 lea     si, LinBuf      ;start of line data
  456.  
  457.         call    Tab_Next        ;get next tab stop
  458.         jnc     prolin4         ;jump if not at stop
  459.         call    Store_Tab       ;store a tab
  460.         jmps    prolin5
  461.  
  462. prolin4 call    Store_Spc       ;store any spaces
  463.  
  464. ;--- left margin
  465.  
  466. prolin5 mov     ax, LeftMar     ;get left margin
  467.         add     cx, ax          ;add to byte count
  468.         sub     si, ax          ;add margin
  469.  
  470. ;--- delete left margin characters
  471.  
  472.         mov     ax, LeftDel     ;margin remove
  473.         add     si, ax          ;skip beginning characters
  474.         sub     cx, ax          ;reduce count
  475.         jnc     prolin6         ;jump if okay (CX >= AX)
  476.         sub     cx, cx          ;set cx to zero
  477.  
  478. ;--- truncate line
  479.  
  480. prolin6 mov     ax, Trunc       ;truncate length
  481.         or      ax, ax          ;check if set
  482.         jz      prolin7
  483.         cmp     cx, ax
  484.         jbe     prolin7
  485.         mov     di, si          ;start of buffer
  486.         add     di, ax          ;line length
  487.         mov     cx, ax          ;byte count
  488.  
  489. ;--- remove trailing spaces
  490.  
  491. prolin7 test    Options, REM_SPC        ;check if remove
  492.         jz      prolin10
  493.  
  494. prolin8 or      cx, cx                  ;see if no bytes left
  495.         jz      prolin10
  496.         cmp     BYTE [di-1], ' '        ;check if space
  497.         je      prolin9
  498.         test    Options, REP_SPC        ;check if also delete tabs
  499.         jz      prolin10
  500.         cmp     BYTE [di-1], TAB        ;check if tab
  501.         jne     prolin10
  502.  
  503. prolin9 dec     di                      ;reduce pointer
  504.         dec     cx                      ;reduce count
  505.         jmps    prolin8
  506.  
  507. ;--- append CR+LF
  508.  
  509. prolin10 mov     al, CR
  510.         stosb                   ;store CR
  511.         inc     cx
  512.         mov     al, LF
  513.         stosb                   ;store LF
  514.         inc     cx              ;increment
  515.  
  516. ;--- write line
  517.  
  518.         lea     bx, OutBlk      ;output control block
  519.         call    File_Write      ;write to file
  520.         jnc     prolin11
  521.         or      InpSta, OUT_ERR ;set error flag
  522.  
  523. prolin11 ret
  524.         ENDP                    ;Proc_Line
  525.  
  526. ;================================================
  527. ; Process a document.
  528.  
  529. Proc_Doc  PROC  NEAR
  530.  
  531. ;--- process every line
  532.  
  533. propag1 call    Proc_Line
  534.         test    InpSta, INP_EOF OR INP_ERR OR OUT_ERR
  535.         jz      propag1
  536.  
  537. ;--- write EOF
  538.  
  539.         test    Options, SUP_EOF ;check if suppressed
  540.         jnz     propag2
  541.         test    InpSta, INP_ERR ;
  542.         jnz     propag2         ;-- check for errors
  543.         test    InpSta, OUT_ERR ;
  544.         jnz     propag2
  545.  
  546.         mov     cx, 1           ;bytes to write
  547.         lea     si, LinBuf      ;put it in line buffer
  548.         mov     BYTE [si], EOF  ;EOF character
  549.         lea     bx, OutBlk      ;output control block
  550.         call    File_Write      ;write to file
  551.  
  552. propag2 ret
  553.         ENDP                    ;Proc_Page
  554.