home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / chasm2.zip / LC.ASM < prev    next >
Assembly Source File  |  1986-01-02  |  7KB  |  209 lines

  1. ;===================================================
  2. ; PROGRAM LC    Version 1.0 by Dave Whitman
  3. ;
  4. ; Filter to convert a file to all lower case.
  5. ; Non-alphabetic characters are not affected.
  6. ;
  7. ; Syntax:  LC [?] [/u] [<infile] [>outfile]
  8. ;
  9. ; The ? option prints a help message.
  10. ; /U modifys the conversion to give all caps.
  11. ;
  12. ; Requires DOS 2.0, will abort under earlier versions.
  13. ;====================================================
  14.  
  15. ;============
  16. ; Equates
  17. ;============
  18.  
  19. @read   equ    3FH                ;read file/device
  20. @write  equ    40H                ;write file/device
  21. @dosver equ    30H                ;get dos version
  22. @prnstr equ    09H                ;print string
  23.  
  24. cr      equ    0DH                ;carriage return character
  25. lf      equ    0AH                ;line feed character
  26.  
  27. stdin   equ    0000H              ;standard input
  28. stdout  equ    0001H              ;standard output
  29. u       equ    01H                ;upper case option selected
  30.  
  31. buf_size       equ     512        ;size of input and output buffers
  32.  
  33. param_count    equ     [80H]
  34. param_area     equ     [81H]
  35. mem_avail      equ     [06H]      ;PSP field: memory available in segment
  36.  
  37. up_mask        equ     11011111B  ;mask for lowercase conversion (with AND)
  38. low_mask       equ     00100000B  ;mask for uppercase conversion (with OR)
  39.  
  40. main   proc    far
  41.        call    setup           ;check dos, parse options
  42.        call    process         ;count w, l, c from std i/o
  43.        int     20H             ;and return to dos
  44.        endp
  45.  
  46. ;======================================
  47. ; SUBROUTINE SETUP
  48. ; Checks for proper DOS, parses options
  49. ;======================================
  50. setup  proc    near
  51.  
  52.        mov     ah, @dosver     ;what dos are we under?
  53.        int     21H
  54.        cmp     al, 2           ;2.0 or over?
  55.        jae     a_mem           ;yes, skip
  56.  
  57.        mov     ah, @prnstr     ;no, bitch
  58.        mov     dx, offset(baddos)
  59.        int     21H
  60.        pop     ax              ;reset stack
  61.        int     20H             ;and exit
  62.  
  63. a_mem  mov     ax, mem_avail   ;do we have room for the buffers?
  64.        cmp     ax, buf_size*2
  65.        jae     a_help          ;yes
  66.        mov     ah, @prnstr     ;no, bitch
  67.        mov     dx, offset(nomem)
  68.        int     21H
  69.        pop     ax              ;reset stack
  70.        int     20H             ;and exit
  71.  
  72. a_help xor     ch,ch           ;cx <== param count
  73.        mov     cl, param_count ;  "
  74.        cmp     cl, 00H         ;any params?
  75.        je      aexit           ;return if none
  76.  
  77.        mov     di, offset(param_area)   ;scan for help request
  78.        mov     al, '?'
  79.        repnz                   ;repeat until matched or end
  80.        scasb
  81.        jnz     a_par           ;reached end, no match? skip
  82.        mov     ah, @prnstr     ;found ?, so print help
  83.        mov     dx, offset(help)
  84.        int     21H
  85.        pop     ax              ;pop stack
  86.        int     20H             ;and exit
  87.  
  88. a_par  xor     ch, ch                   ;cx <== param count
  89.        mov     cl, param_count          ;  "
  90.        mov     di, offset(param_area)   ;scan for options
  91. a_loop mov     al, '/'                  ;will be marked with /
  92.        repnz                   ;repeat until matched or end
  93.        scasb
  94.        jnz     aexit           ;reached end, no match? skip
  95.  
  96.        mov     al, [di]        ;get option char (right after '/')
  97.        and     al, up_mask     ;guarantees upper case for compare
  98.  
  99.        cmp     al, 'U'         ;option U specified?
  100.        jne     a_pend          ;nope
  101.        orb     options, u      ;yes, set flag
  102. a_pend jmps    a_loop          ;and loop
  103.  
  104. aexit  ret
  105.  
  106. baddos db      cr lf 'This program requires DOS 2.0!' cr, lf, '$'
  107.  
  108. nomem  db      cr lf 'Insufficient memory, program aborted' cr lf '$'
  109.  
  110.  
  111. help   db      cr lf
  112.        db      'LC version 1.0' cr lf
  113.        db       cr lf
  114.        db      '1/2/86 by D. Whitman' cr lf
  115.        db      cr lf
  116.        db      'Syntax:  LC [?] [/u] [<infile] [>outfile]' cr lf
  117.        db      cr lf
  118.        db      'Reads stdin and writes all lower case to stdout.' cr lf
  119.        db      cr lf
  120.        db      'Options:' cr lf
  121.        db      '    ?  = print this help message' cr lf
  122.        db      '    /u = upper case output' cr lf
  123.        db      cr lf
  124.        db      'This program is in the public domain.' cr lf
  125.        db      cr lf '$'
  126.        endp
  127.  
  128. ;=========================================
  129. ; SUBROUTINE PROCESS
  130. ;
  131. ;   1. load input buffer
  132. ;   2. convert each char, pass to output buffer
  133. ;   3. dump output buffer
  134. ;   4. repeat until EOF
  135. ;==========================================
  136.  
  137. process proc    near
  138.  
  139. bu1    mov     ah, @read       ;read
  140.        mov     bx, stdin       ;from stdin
  141.        mov     cx, buf_size    ;one buffer's worth
  142.        mov     dx, offset(buf_in)
  143.        int     21H
  144.        cmp     ax, 00H         ;test for EOF
  145.        jz      buexit          ;if so, done
  146.  
  147.        push    ax              ;save number of chars read
  148.        mov     cx, ax          ;cx <== number chars read
  149.        mov     si, offset(buf_in)  ;source is input buffer
  150.        mov     di, offset(buf_out) ;destination is output buffer
  151.  
  152. bu2    lodsb                   ;al <== next char from buffer
  153.        cmp al, 'A'             ;test if alphabetic char
  154.        jb  bu4                 ;too low? skip
  155.        cmp al, 'Z'
  156.        jbe bu3                 ;in range? is upper case, so process
  157.        cmp al, 'a'             ;how about a lower case char?
  158.        jb  bu4                 ;nope
  159.        cmp al, 'z'             ;maybe, check upper bound
  160.        ja  bu4                 ;nope  (falls through if lower case)
  161.  
  162. bu3                            ;if here, al guaranteed alphabetic
  163.        testb options, u        ;was option u specified?
  164.        jnz  bu_up              ;yes, jump and set upper case
  165.        or   al, low_mask       ;no, convert to lower case
  166.        jmps bu4                ; and skip u/c conversion
  167. bu_up  and  al, up_mask        ;convert to upper case
  168. bu4    stosb                   ;put in output buffer
  169.        loop bu2                ;loop until input buffer empty
  170.  
  171.                                ;dump output buffer
  172.        mov     ah, @write      ;write
  173.        mov     bx, stdout      ;to stdout
  174.        pop     cx              ;number of chars read
  175.        mov     dx, offset(buf_out)
  176.        int     21H
  177.  
  178.        jmps    bu1              ;and loop until EOF
  179.  
  180. buexit ret
  181.        endp
  182.  
  183. ;=================
  184. ;GLOBAL VARIABLES
  185. ;=================
  186. options  db  00H       ;byte of option flags
  187.  
  188. ;=====================================================
  189. ;BUFFERS
  190. ;
  191. ; No space is actually allocated for the buffers.
  192. ; At run time, the program checks to ensure there
  193. ; is suffcient free memory, then uses the memory
  194. ; immediately after itself for buffers.
  195. ;
  196. ; This stratagy minimizes the size of the object file,
  197. ; and lets the program load quicker.
  198. ;======================================================
  199.  
  200. buf_in                 ;input buffer
  201.  
  202.          org offset($+buf_size)   ;this is a trick to set the address
  203.                                   ;the output buffer.
  204.                                   ;the address of buf_out is set to be
  205.                                   ;the offset of the input buffer, plus
  206.                                   ;the buffer length.
  207.  
  208. buf_out                ;output buffer
  209.