;lcs -          converts entire text to lower case;
;               excluding what may be in quotes!
;
;written by:    jalal raissi
;
;edit history:
;               1.0 01-jun-85 created. /jer
;               UCS was GLOBALed with lcs and UPPER with lower via UCS.M68!
;format:
;               .lcs filename
;               .lcs test.bas
;
       vmajor=1
       vminor=1

       search  sys
       search  syssym

       .ofini
       .ofdef  in,d.ddb                ;input file
       .ofdef  out,d.ddb               ;output file
       .ofdef  key,512.                ;encryption key
       .ofsiz  memsiz

       qt=d4

start:  phdr    -1,0,ph$ree!ph$reu      ;program header
       getimp  memsiz,a5               ;allocate impure area

help:   byp                             ;bypass leading white space
       lin                             ;end of line?
       jne     getin                   ; no
       crlf                            ;newline
       typecr  <function: converts text to lower case.>
       typecr  <usage:    .lcs filename>
       typecr  <example:  .lcs test.bas>
       crlf                            ;newline
       exit                            ;exit

getin:  mov     a2,a3                   ;save line index
       fspec   in(a5),bas              ;process filespec
       init    in(a5)                  ;load driver, allocate buffer

getout: mov     a3,a2                   ;restore line index
       fspec   out(a5),bas             ;process filespec
       init    out(a5)                 ;load driver, allocate buffer
       movw    #[$$$],out+d.ext(a5)    ;set output extension to .$$$

opnin:  openi   in(a5)                  ;open input file

opnout: lookup  out(a5)                 ;check for existence of output file
       bne     10$                     ;not found
       dskdel  out(a5)                 ;delete output file
10$:    openo   out(a5)                 ;open output file

getbyt: ctrlc   endfil                  ;branch on ^c
       filinb  in(a5)                  ;read byte
       tst     in+d.siz(a5)            ;test for end-of-file
       beq     endfil                  ;branch on end-of-file
       cmpb    d1,#42                  ;is it a "
       bne     skpqt
       tstb    qt
       beq     set
       clr     qt
       br      skpqt
set:
       movb    #1,qt
skpqt:
       cmpb    d1,#12                  ;is it a lf
       bne     skplf
       clr     qt
skplf:
       tstb    qt
       bne     tty
       lcs     d1                      ;convert character to lcs
tty:    tty

putbyt: filotb  out(a5)                 ;output lcsed byte
       br      getbyt                  ;loop till end of file

endfil: close   in(a5)
       close   out(a5)
       ctrlc   abort

delin:  dskdel  in(a5)

renout: mov     in+d.fil(a5),out+d.ddb(a5)
       movw    in+d.ext(a5),out+d.ddb+4(a5)
       dskren  out(a5)
       exit

abort:  dskdel  out(a5)
       exit

       end