home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc2 / filters.lzh / LOWER.ASM < prev    next >
Assembly Source File  |  1985-05-11  |  3KB  |  116 lines

  1.     Name lower
  2.     Title    Uppercase to Lowercase filter.
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that translates all uppercase
  7.     characters to lowercase.  It will optionally accept a
  8.     filename to read input from.  All output goes to the
  9.     standard output device unless redirected.
  10.  
  11.     Examples:
  12.         Upper abc.txt        read input from abc.txt,
  13.                 output goes to screen.
  14.         Upper abc.txt >abcnew.txt
  15.                 read input from abc.txt,
  16.                 output goes to abcnew.txt.
  17.         Upper <abc.txt >abcnew.txt
  18.                 same as previous example
  19.         Upper abc.txt | find "ABC"
  20.                 translates abc.txt to lowercase
  21.                 and then searches the result
  22.                 for the string "ABC".
  23.                 Output goes to screen.
  24.         find "abc" abc.txt | lower | sort
  25.                               Search abc.txt for all lines that
  26.                 contain "abc".  Translate all lines
  27.                 selected and sort them, sending output
  28.                 to the screen.
  29. /
  30. ;===================================================================
  31. code    segment    public
  32. ;===================================================================
  33. ;
  34. ;    command line is at 80h of psp - first byte is length
  35. ;
  36.     org    80h
  37. parmsize    db    ?
  38. parm        db    7fh dup (?)
  39. ;
  40. ; .com starts at 100h - but must jump around any data area
  41. ;
  42.     org    100h            ; com file starts here
  43.     assume    cs:code,ds:code,es:code
  44. lower:
  45.     jmp    clear
  46. ;===================================================================
  47. ;
  48. ; data area for .com programs
  49. ;
  50. handle    dw    0h            ; assume standard input
  51. bufsiz    equ    255
  52. buffer    db    bufsiz dup (?)
  53. ;
  54. ;===================================================================
  55. clear:
  56. ;
  57. ; start of actual code is here (clear)
  58. ;
  59. ;
  60. ; now figure out which file to read from - parm line or standard input
  61. ;
  62.     cmp    parmsize,0h    ; if zero, no parm
  63.     jz    again        ; assume standard input
  64. ;
  65. ; parm length is not zero - assume the parm is a file name.  If not
  66. ; found, quit.
  67. ;
  68.     mov    al,parmsize    ; get size of parm
  69.     xor    ah,ah        ; zero out top part of accum.
  70.     mov    si,ax        ; use length as a pointer into the dta
  71.     mov    [si]+parm,0h    ; to tack on a zero byte (asciiz).
  72. ;
  73. ; now try to open the file
  74. ;
  75.     lea    dx,parm+1    ; address of 'filename'
  76.     mov    al,0h        ; open for read only
  77.     mov    ah,3dh        ; dos open function
  78.     int    21h        ; invoke function
  79.     jc    oops        ; open error - quit
  80.     mov    handle,ax    ; save file handle
  81. again:
  82.     mov    bx,handle    ; read from standard input or file
  83.     mov    cx,bufsiz    ; # of characters to read
  84.     lea    dx,buffer    ; seg:off address of buffer area
  85.     mov    ah,3fh        ; dos read function
  86.     int    21h        ; invoke function
  87.     jc    oops        ; error!
  88.     cmp    ax,0h        ; if zero, end of file
  89.     jz    oops
  90. ;
  91.     push    ax        ; save copy of ax
  92.     mov    cx,ax        ; cx (and ax) contain # characters read
  93.     lea    si,buffer    ; offset of buffer
  94.     mov    di,si        ; di gets it too
  95. loop1:
  96.     lodsb            ; get a character from buffer
  97.     cmp    al,'A'        ; if not between 'A' and 'Z', skip
  98.     jl    ok
  99.     cmp    al,'Z'
  100.     jg    ok
  101.     add    al,20h        ; else switch to lowercase
  102. ok:
  103.     stosb            ; put back into buffer
  104.     loop    loop1        ; and repeat for entire buffer
  105. ;
  106.     pop    cx        ; restore character count
  107.     mov    bx,1h        ; standard output device
  108.     mov    ah,40h        ; dos write function
  109.     int    21h        ; invoke dos function
  110.  
  111.     jmp    again        ; repeat until end of file or error
  112. oops:
  113.     int    20h        ; return to dos
  114. code    ends
  115.     end    lower
  116.