home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol5n13.zip / DSTRIP.ASM < prev    next >
Assembly Source File  |  1987-12-13  |  5KB  |  121 lines

  1. ;-----------------------------------------------------------------------------
  2. ;DSTRIP - Dos Filter to remove leading and trailing blanks, blank lines and
  3. ;         comment lines, from Dbase command files, and to capitalize text
  4. ;         not in quotation marks.
  5. ;-----------------------------------------------------------------------------
  6. COMSEG    SEGMENT    PARA PUBLIC 'CODE'
  7.     ASSUME    CS:COMSEG,DS:COMSEG,ES:COMSEG,SS:COMSEG
  8.     ORG     100H
  9.  
  10. START    PROC    FAR
  11.     CLD
  12.     MOV    BL,00000001B    ;the bits in the BL register will hold the 
  13.                 ;following information when set to 1:
  14.                 ;0-bit  only tabs and blanks encountered
  15.                 ;       in current line
  16.                     ;1-bit a '*' encountered as first char of line
  17.                 ;4-bit    char inside 'single' quotes
  18.                 ;5-bit    char inside "double" quotes
  19.                 ;6-bit    last char was LF
  20.                 ;7-bit  last char in *-line was a ';'
  21.     XOR    DX,DX        ;DX will count blanks/tabs after a char
  22. LOAD:    PUSH     BX        ;save registers and 
  23.     PUSH    DX
  24.     MOV    DX,OFFSET DATA    ;read into memory
  25.     MOV    CX,64000    ;64K bytes
  26.     XOR    BX,BX        ;from standard input
  27.     MOV     AH,3FH        ;with DOS function call
  28.     INT    21H
  29.     POP    DX        ;restore registers
  30.     POP    BX
  31.     OR    AX,AX        ;AX has number of bytes read - test for 0
  32.     JNZ    LOAD0
  33.     JMP    DONE
  34. LOAD0:    MOV    CX,AX        ;move count into CX
  35.     MOV    SI,OFFSET DATA    ;and position index registers for
  36.     MOV    DI,OFFSET DATA    ;a string move
  37. SCAN0:    LODSB            ;fetch a byte into AL
  38.     CMP    AL,26        ;end of file?
  39.     JZ    STORE        ;if so, store and get out
  40.     TEST    BL,01000000B    ;LF on previous fetch?
  41.     JZ    NEXT        ;if not, skip
  42.     OR    BL,1        ;set beginning of line bit
  43.     AND    BL,10111111B    ;and reset the LF bit
  44.     TEST    BL,10000000B    ;a ';' at end of line?
  45.     JNZ    NEXT0        ;if yes, skip
  46.     AND    BL,11111101B    ;otherwise reset '*'-bit
  47. NEXT0:    AND    BL,01111111B    ;reset ';'-bit
  48. NEXT:    CMP    AL,59        ;a ';'?
  49.     JNZ    NEXT1        ;if not, skip
  50.     OR    BL,10000000B    ;set ';'-bit
  51.     JMP    SHORT NEXT5    ;and do loop routine
  52. NEXT1:    CMP    AL,32        ;blank?
  53.     JZ    COUNT        ;if yes, check whether to count it
  54.     CMP    AL,09        ;tab?
  55.     JNZ    NEXT2        ;if not, skip count
  56. COUNT:    TEST    BL,11B        ;are we at beginning of line or in a '*' line?
  57.     JNZ    LOOP        ;if yes, loop and omit
  58.     INC    DX        ;otherwise count the blank/tab
  59.     JMP    SHORT STORE    ;and store it
  60. NEXT2:    CMP    AL,13        ;CR?
  61.     JZ    OUT        ;if yes go to end of line routine
  62. NEXT3:    CMP    AL,10        ;LF?
  63.     JNZ    NEXT4        ;if not, go on checking
  64.     OR    BL,01000000B    ;set end of line bit
  65.     JMP    SHORT OUT    ;and go to end of line routine
  66. NEXT4:    TEST    BL,1        ;have we seen any non blank/tab char before?
  67.     JZ    NEXT6        ;if yes, ignore the next step
  68.     CMP    AL,42        ;a '*'?
  69.     JNZ    NEXT5        ;if not' skip
  70.     OR    BL,10B        ;otherwise set the '*'-bit
  71. NEXT5:    AND    BL,11111110B    ;and in either case we have non blank/tab char
  72. NEXT6:    XOR    DX,DX        ;set blank/tab count to 0
  73. OUT:    TEST    BL,11B        ;are we at beginning of line or in a '*'-line?
  74.     JNZ    LOOP        ;if so, ignore (includes CR/LF of blank lines)
  75.     SUB    DI,DX        ;DX is non-zero only if we encountered a CR
  76.     XOR    DX,DX        ;reset DX to 0
  77.     AND    BL,01111111B    ;reset ';'-bit
  78. CAPS0:    JMP     SHORT CAPS    ;capitalize
  79. STORE:    STOSB            ;store char
  80. LOOP:    CMP    AL,26        ;test for end of file
  81.     LOOPNZ    SCAN0        ;and loop for next fetch
  82.     PUSH    AX        ;save registers
  83.     PUSH    BX
  84.     PUSH    DX
  85.     MOV    DX,OFFSET DATA    ;compute the numbers of bytes stored
  86.     MOV    CX,DI
  87.     SUB    CX,DX        ;in CX, and 
  88.     MOV    BX,01        ;write to standard output
  89.     MOV    AH,40H        ;with DOS function call
  90.     INT    21H
  91.     POP    DX
  92.     POP    BX
  93.     POP    AX
  94.     CMP    AL,26        ;end of file?
  95.     JZ    DONE
  96.     JMP    LOAD        ;if not, read another 64K bytes
  97. DONE:    INT    20H        ;end program
  98. ;
  99. CAPS:    CMP    AL,39        ;single quote?
  100.     JNZ    QUOT        ;if not check double quote
  101.     TEST    BL,100000B    ;is double quote bit set?
  102.     JNZ    STORE        ;if yes, ignore
  103.     XOR    BL,010000B    ;(re-)set single quote bit
  104.     JMP    SHORT STORE
  105. QUOT:    CMP    AL,34        ;double quote?
  106.     JNZ    CAPS01        ;if not, skip
  107.     XOR    BL,00100000B    ;(re-)set double-quote bit
  108.     JMP    SHORT STORE
  109. CAPS01:    TEST    BL,00110000B    ;any quote-bits set?
  110.     JNZ    STORE        ;if so, don't capitalize
  111. CAPS1:    CMP    AL,97        ;below 'a'?
  112.     JB    STORE        ;if so, leave it alone
  113. CAPS2:    CMP    AL,122        ;above 'z'?
  114.     JA    STORE        ;if so, don't change
  115. CAPS3:    AND    AL,5FH        ;otherwise capitalize
  116. OUT2:    JMP    SHORT STORE
  117. START    ENDP
  118. DATA:
  119. COMSEG    ENDS
  120.     END    START
  121.