home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol165 / stute.asn < prev    next >
Encoding:
Text File  |  1984-07-08  |  16.0 KB  |  843 lines

  1.  
  2.  
  3. ;    ----------------------------------------------------------
  4. ;    Reassembly of FIND.COM, which was originally extracted
  5. ;    from the CBBS(R) package available from Ward Christensen
  6. ;    and Randy Suess. However, considerable rearrangement has
  7. ;    taken place, most notably the following:
  8. ;     -  <no file name> results in a screen of information
  9. ;     -  the search pattern may be a regular expression
  10. ;     -  instance count reported, both per file and globally
  11. ;    To achieve compatibility with MicroShell the vertical bar
  12. ;    was replaced by exclamation point; all syntactic elements
  13. ;    are defined by equ's and may be redefined. PATTERN!SKELETON
  14. ;    is checked for balanced parentheses and non-null arguments
  15. ;    to forestall the most common failure modes. Had MicroShell
  16. ;    not been available, an option to direct the output to some
  17. ;    disk file would probably have been included. STUTE.ASN was
  18. ;    derived from STUTE.ASM by applying Sorcim's TRANS86, then
  19. ;    cleaning up the resulting code by hand. The code can be
  20. ;    assembled by Sorcim's ACT86, which uses a different style
  21. ;    than the Intel assembler. STUTE differs from FIND in that
  22. ;    the patterns found are replaced by a constant rather than
  23. ;    just being locatse, and that a new disk file is created
  24. ;    to hold the modified text. The extension of each original
  25. ;    file is changed to .BAK.
  26. ;
  27. ;            STUTE.ASN   Copyright (C) 1983
  28. ;            Universidad Autonoma de Puebla
  29. ;
  30. ;    [Harold V. McIntosh, 16 November 1983]
  31. ;    ----------------------------------------------------------
  32.  
  33. HT    equ    09H        ;horizontal tab
  34. LF    equ    0AH        ;line feed
  35. CR    equ    0DH        ;carriage return
  36. KZ    equ    1AH        ;^Z
  37.  
  38. ;    Delimiters for the command line
  39.  
  40. LSQ    equ    '['        ;begin alternative list
  41. RSQ    equ    ']'        ;end alternative list
  42. LBR    equ    '{'        ;begin iterated expression
  43. RBR    equ    '}'        ;end iterated expression
  44. ORR    equ    '!'        ;separate alternatives
  45.  
  46. ;    Representatives of characters or classes.
  47.  
  48. TAB    equ    '_'        ;substitute for tab
  49. QUE    equ    '?'        ;represent any byte
  50. ALF    equ    '@'        ;represent any alphanumeric
  51.  
  52. ;    CPM locations and parameters
  53.  
  54. BDOS:    equ    224        ;CP/M interrupt to BDOS
  55.  
  56. TFCB    equ    005CH        ;CP/M's file control block
  57. CBLK    equ    007CH        ;CP/M's block counter
  58. TSIZ    equ    0080H        ;CP/M's record size
  59. TBUF    equ    0080H        ;CP/M's record buffer
  60. KSIZ    equ    26        ;sector capacity of IN buffer
  61. ISIZ    equ    KSIZ*128
  62. OSIZ    equ    128
  63.  
  64. ;    -------------
  65.     org    0100H
  66. ;    -------------
  67.  
  68. BEGN:    cmpb    TFCB+1,#' '    ;file name
  69.     jnz    X0143
  70.     ld    bx,#TUTO    ;tutorial message
  71.     jmp    GBYE
  72.  
  73. X0143:    ld    bx,#LOGO    ;identification line
  74.     call    MSSG
  75.  
  76.     ld    ah,#12
  77.     ld    dx,#TFCB    ;CP/M's FCB
  78.     ld    bx,#FILE    ;generic filename
  79.     call    MIUC
  80.  
  81.     ld    al,FILE        ;generic filename
  82.     sto    al,KFIL        ;backup file (.BAK)
  83.     sto    al,IFIL        ;input file  (.EXT)
  84.     sto    al,OFIL        ;output file (.$$$)
  85.     sto    al,UFIL        ;active output (.$$$)
  86.     stob    #0,ENTH
  87.  
  88.     ld    bx,#TBUF    ;CP/M's record buffer
  89.     ld    dl,[bx]
  90.     mov    cl,dl
  91.     ld    dh,#0
  92.     xchg    bx,dx
  93.     inc    dx
  94.     add    bx,dx
  95.     stob    #0,[bx]        ;mark end of console line
  96.     xchg    bx,dx        ;take up beginning of line
  97. X0152:    inc    bx
  98.     dec    cl
  99.     cmpb    [bx],#0
  100.     jnz    GPAT
  101.     jmp    BADP        ;message: 'Bad Pattern'
  102. GPAT:    cmpb    [bx],#' '
  103.     jnz    X0152        ;pass over file name
  104.     inc    bx
  105.     call    BALA        ;check balance of [], {}.
  106.     call    NULA        ;check for null alternatives
  107.     ld    dx,#PATT    ;command line pattern
  108.     call    MUVE
  109.     xchg    bx,dx
  110.     dec    bx
  111.     sto    bx,SKND        ;skeleton end
  112.  
  113.     ld    ah,#4
  114.     ld    dx,#LZER    ;counter initializer
  115.     ld    bx,#DTOT    ;'Disk Total'
  116.     call    MIUC
  117.  
  118.     ld    bx,#PATT    ;command line pattern
  119.     sto    bx,PAPO        ;pattern pointer
  120.     call    NEXT
  121.     sto    bx,SKPO        ;skeleton pointer
  122.  
  123. ;    Scan the directory for file names. A list is made of files
  124. ;    which will be scanned, both because of a quirk in CP/M's
  125. ;    "search again" and to avoid a future encounter with a file
  126. ;    which has already been processed and given the old name.
  127. ;    Likewise, .BAK and .$$$ files are excluded from analysis.
  128.  
  129. PREP:    sto    #1,DCTR        ;directory counter
  130.     sto    #DIRY,DPTR    ;#directory extract,directory pointer
  131.  
  132.     ld    cl,#26        ;(1A) set DMA address
  133.     ld    dx,#TBUF    ;CP/M's record buffer
  134.     int    BDOS        ; - B D O S -
  135.  
  136.     ld    cl,#17        ;(11) search once
  137.     ld    dx,#FILE    ;generic filename
  138.     int    BDOS        ; - B D O S -
  139.  
  140. ;    Find the Nth file which fits the file description.
  141.  
  142. FNTH:    cmp    al,#0FFH    ;FF=search failed
  143.     jz    SCAN        ;all relevant files located
  144.     and    al,#03        ;isolate quad
  145.     ld    ah,#32
  146.     mulb    ah
  147.     ld    bx,#0081H
  148.     add    bx,ax
  149.     cmpb    [bx+8],#'B'
  150.     jnz    NBAK
  151.     cmpb    [bx+9],#'A'
  152.     jnz    NBAK
  153.     cmpb    [bx+10],#'K'
  154.     jz    OMIT
  155. NBAK:    cmpb    [bx+8],#'$'
  156.     jnz    NDOL
  157.     cmpb    [bx+9],#'$'
  158.     jnz    NDOL
  159.     cmpb    [bx+10],#'$'
  160.     jz    OMIT
  161. NDOL:    ld    ah,#12
  162.     mov    dx,bx
  163.     ld    bx,DPTR        ;directory pointer
  164.     call    MIUC
  165.     sto    bx,DPTR        ;directory pointer
  166.     incb    DCTR        ;directory counter
  167.  
  168. OMIT:    ld    cl,#18        ;(12) search again
  169.     ld    dx,#FILE    ;generic filename
  170.     int    BDOS        ; - B D O S -
  171.  
  172.     jmp    FNTH
  173.  
  174. ;    We're all done.
  175.  
  176. DONE:    ld    bx,#DTOT    ;'Disk Total'
  177. GBYE:    call    MSSG
  178. EXIT:    ld    dl,#00
  179.     ld    cl,#00
  180.     int    BDOS
  181.  
  182. ;    Now we are ready to scan the prospective files.
  183.  
  184. SCAN:    sto    #DIRY,DPTR
  185. SCAM:    decb    DCTR
  186.     jz    DONE
  187.     push    DPTR
  188.     add    DPTR,#12
  189.  
  190.     ld    ah,#8
  191.     pop    dx
  192.     push    dx
  193.     ld    bx,#KFIL+1    ;backup file (.BAK)
  194.     call    MIUC
  195.  
  196.     ld    ah,#11
  197.     pop    dx
  198.     push    dx
  199.     ld    bx,#IFIL+1    ;input file  (.EXT)
  200.     call    MIUC
  201.  
  202.     ld    ah,#8
  203.     pop    dx
  204.     push    dx
  205.     ld    bx,#OFIL+1    ;output file (.$$$)
  206.     call    MIUC
  207.  
  208.     ld    ah,#8
  209.     pop    dx
  210.     push    dx
  211.     ld    bx,#UFIL+1    ;active output (.$$$)
  212.     call    MIUC
  213.  
  214.     ld    ah,#12
  215.     pop    dx
  216.     ld    bx,#TFCB+1    ;CP/M's file control block
  217.     call    MIUC
  218.  
  219.     ld    cl,#19        ;(13) delete file
  220.     ld    dx,#KFIL    ;backup file (.BAK)
  221.     int    BDOS        ; - B D O S -
  222.  
  223.     ld    cl,#19        ;(13) delete file
  224.     ld    dx,#OFIL    ;output file (.$$$)
  225.     int    BDOS        ; - B D O S -
  226.  
  227.     ld    cl,#22        ;(16) create file
  228.     ld    dx,#UFIL    ;active output (.$$$)
  229.     int    BDOS        ; - B D O S -
  230.     stob    #0,UREC
  231.  
  232.     ld    cl,#15        ;(0F) open file
  233.     ld    dx,#TFCB    ;CP/M's FCB
  234.     int    BDOS        ; - B D O S -
  235.     inc    al
  236.     jnz    STAY
  237.     jmp    EXIT        ;quit [without message]
  238. STAY:    stob    #0,CBLK        ;block pointer
  239.  
  240.     ld    ah,#4
  241.     ld    dx,#LZER    ;counter initializer
  242.     ld    bx,#LNUM    ;'line number'
  243.     call    MIUC
  244.  
  245.     ld    ah,#4
  246.     ld    dx,#LZER    ;counter initializer
  247.     ld    bx,#FTOT    ;'file total'
  248.     call    MIUC
  249.  
  250.     ld    ah,#8
  251.     ld    dx,#TFCB+1    ;file name
  252.     ld    bx,#FNAM    ;'file name'
  253.     call    MIUC
  254.  
  255.     ld    ah,#3
  256.     ld    dx,#0065H    ;extension
  257.     ld    bx,#FEXT    ;'file extension'
  258.     call    MIUC
  259.  
  260.     ld    bx,#FHED    ;"File" header
  261.     call    MSSG        ;message to console
  262.  
  263. X01C2:    sto    #0000,ICTR    ;input file counter
  264.     sto    #TSIZ,OCTR
  265.     sto    #UBUF,OPTR
  266. LOOP:    ld    bx,#LNUM+3    ;increment l.c.
  267.     call    INCO        ;increment line counter
  268.     ld    bx,#LBUF    ;line buffer
  269.     ld    ch,#0FFH
  270. MORL:    inc    ch
  271.     js    CRLF        ;force a line after 80H columns
  272.     push    cx
  273.     push    bx
  274.     call    INCH        ;char from big bffr to line bffr
  275.     pop    bx
  276.     pop    cx
  277.     sto    al,[bx]
  278.     inc    bx
  279.     cmp    al,#KZ
  280.     jnz    X01E8
  281.     ld    bx,#FTOT
  282.     call    MSSG
  283.  
  284. ;    Close out last, incomplete record.
  285.  
  286. LARE:    cmp    OCTR,#0000
  287.     jz    CLOF
  288.     ld    al,#KZ
  289.     call    OUCH
  290.     jmp    LARE
  291.  
  292. CLOF:    ld    cl,#21        ;(15) write one record
  293.     ld    dx,#UFIL    ;active output (.$$$)
  294.     int    BDOS        ; - B D O S -
  295.  
  296.     ld    cl,#16        ;(10) close file
  297.     ld    dx,#UFIL    ;active output (.$$$)
  298.     int    BDOS        ; - B D O S -
  299.  
  300.     ld    cl,#23        ;(17) rename file
  301.     ld    dx,#IFIL    ;input file  (.EXT)
  302.     int    BDOS        ; - B D O S -
  303.  
  304.     ld    cl,#23        ;(17) rename file
  305.     ld    dx,#OFIL    ;output file (.$$$)
  306.     int    BDOS        ; - B D O S -
  307.  
  308.     jmp    SCAM
  309.  
  310. X01E8:    cmp    al,#LF
  311.     jnz    MORL        ;line not finished
  312.     jmp    IRRQ
  313.  
  314. CRLF:    stob    #CR,[bx]
  315.     inc    bx
  316.     stob    #LF,[bx]
  317.     inc    bx
  318.  
  319. ;    Check console for termination request. If one
  320. ;    is present, clear it out before leaving.
  321.  
  322. IRRQ:    stob    #00,[bx]    ;guarantee right hand fence
  323.     ld    cl,#11        ;(0B) console status
  324.     int    BDOS        ; - B D O S -
  325.     or    al,al
  326.     jz    CULI
  327.     ld    cl,#1        ;(01) read console
  328.     int    BDOS        ; - B D O S -
  329.     ld    bx,#M4        ;"search terminated"
  330.     jmp    GBYE
  331.  
  332. ;    Scan the current line.
  333.  
  334. CULI:    ld    bx,#LBUF    ;line buffer
  335.     sto    bx,ALFA        ;begin good segment
  336.     sto    bx,BETA        ;end good segment
  337. NEXB:    ld    dx,PAPO        ;pattern pointer
  338.     ld    bx,BETA        ;end good segment
  339.     cmpb    [bx],#CR
  340.     jz    NULI
  341.     call    CHEK
  342.     jnz    FAIL
  343.     push    dx
  344.     push    bx
  345.     ld    bx,#LNUM    ;'line number'
  346.     call    MSSG
  347.     ld    bx,#LBUF
  348.     call    MSSG
  349.     ld    bx,#FTOT+3
  350.     call    INCO
  351.     ld    bx,#DTOT+3    ;'Disk Total'
  352.     call    INCO
  353.     ld    dx,BETA        ;end good segment
  354.     ld    bx,ALFA        ;begin good segment
  355.     call    OULI
  356.     ld    dx,SKND        ;skeleton end
  357.     ld    bx,SKPO        ;skeleton pointer
  358.     call    OULI
  359.     pop    bx
  360.     sto    bx,ALFA        ;begin good segment
  361.     dec    bx
  362.     sto    bx,BETA        ;end good segment
  363.     pop    dx
  364. FAIL:    inc    BETA        ;end good segment
  365.     jmp    NEXB        ;move scan up one byte
  366.  
  367. NULI:    ld    dx,BETA        ;end good segment
  368.     inc    dx
  369.     inc    dx
  370.     ld    bx,ALFA        ;begin good segment
  371.     call    OULI
  372.     jmp    LOOP        ;go for another line
  373.  
  374. ;    Increment ASCII counter at (HL-3).
  375.  
  376. INCC:    stob    #'0',[bx]
  377.     dec    bx
  378.     orb    [bx],#30H
  379. INCO:    incb    [bx]
  380.     cmpb    [bx],#':'
  381.     jz    INCC
  382.     ret
  383.  
  384. ;    Memory to console
  385.  
  386. MSSG:    ld    dl,[bx]
  387.     inc    bx
  388.     push    bx
  389.     ld    cl,#2        ;(02) write console
  390.     int    BDOS        ; - B D O S -
  391.     pop    bx
  392.     cmpb    [bx],#0
  393.     jnz    MSSG
  394.     ret
  395.  
  396. ;    Read a character from the input buffer; if and when
  397. ;    the buffer is empty, more sectors are brought in from
  398. ;    the disk until an end-of-file is reached.
  399.  
  400. INCH:    cmp    ICTR,#0000    ;input file counter
  401.     jnz    INCI
  402.     call    INDI        ;disk to IN area
  403. INCI:    dec    ICTR        ;input file counter
  404.     ld    bx,IPTR        ;input file pointer
  405.     ld    al,[bx]
  406.     cmp    al,#KZ
  407.     jz    INCR
  408.     inc    IPTR        ;input file pointer
  409. INCR:    ret
  410.  
  411. ;    Bring in reinforcements from the disk.
  412.  
  413. INDI:    ld    ch,#KSIZ
  414.     sto    #ISIZ,ICTR    ;input file counter
  415.     ld    bx,#IBUF    ;input file buffer
  416.     sto    bx,IPTR        ;input file pointer
  417. INDD:    stob    #KZ,[bx]
  418.     push    bx
  419.     push    cx
  420.  
  421.     xchg    bx,dx
  422.     ld    cl,#26        ;(1A) set DMA address
  423.     int    BDOS        ; - B D O S -
  424.  
  425.     ld    dx,#TFCB    ;CP/M's file control block
  426.     ld    cl,#20        ;(14) read one record
  427.     int    BDOS        ; - B D O S -
  428.  
  429.     pop    cx
  430.     pop    bx
  431.     or    al,al
  432.     jnz    INDR
  433.     dec    ch
  434.     jz    INDR
  435.     add    bx,#TSIZ    ;CP/M's record size
  436.     jmp    INDD
  437. INDR:    ret
  438.  
  439. ;    Send a "line" [(HL) to (DE)] to out file
  440.  
  441. OULJ:    ld    al,[bx]
  442.     call    OUCH
  443.     inc    bx
  444. OULI:    cmp    bx,dx
  445.     jnz    OULJ
  446.     ret
  447.  
  448. ;    Send one character to the output file, conserve BC, HL
  449.  
  450. OUCH:    push    dx
  451.     push    bx
  452.     push    ax
  453.     cmp    OCTR,#0000
  454.     jnz    OUCI
  455.     call    OUDI        ;OUT area to disk
  456. OUCI:    dec    OCTR
  457.     pop    ax
  458.     ld    bx,OPTR
  459.     sto    al,[bx]
  460.     inc    OPTR
  461.     pop    bx
  462.     pop    dx
  463.     ret
  464.  
  465. ;    Flush the buffer when it is full, make ready for next.
  466.  
  467. OUDI:    sto    #OSIZ,OCTR
  468.     sto    #UBUF,OPTR
  469.  
  470.     ld    cl,#26        ;(1A) set DMA address
  471.     ld    dx,#UBUF
  472.     int    BDOS        ; - B D O S -
  473.  
  474.     ld    cl,#21        ;(15) write one record
  475.     ld    dx,#UFIL    ;active output (.$$$)
  476.     int    BDOS        ; - B D O S -
  477.  
  478.     cmp    al,#0
  479.     jz    OUDR
  480.     ld    bx,#M5
  481.     jmp    GBYE
  482. OUDR:    ret
  483.  
  484. ;    Advance to next alternative
  485.  
  486. NEXX:    ld    bx,[bx]
  487. NEXT:    ld    al,[bx]
  488.     or    al,al
  489.     jz    NEXR
  490.     inc    bx
  491.     call    ENDA
  492.     jz    NEXR
  493.     call    BEGB
  494.     jz    NEXX
  495.     jmp    NEXT
  496. NEXR:    ret
  497.  
  498. ;    Move by Increment Until Count.
  499.  
  500. MIUC:    xchg    bx,dx
  501.     ld    al,[bx]
  502.     xchg    bx,dx
  503.     sto    al,[bx]
  504.     inc    dx
  505.     inc    bx
  506.     dec    ah
  507.     jnz    MIUC
  508.     ret
  509.  
  510. ;    Move and semi-compile the command line.
  511.  
  512. MUVE:    ld    al,[bx]
  513.     cmp    al,#TAB
  514.     jnz    MUNT
  515.     ld    al,#HT
  516. MUNT:    xchg    bx,dx
  517.     sto    al,[bx]
  518.     xchg    bx,dx
  519.     inc    bx
  520.     inc    dx
  521.     cmp    al,#RBR
  522.     jz    MURB
  523.     cmp    al,#RSQ
  524.     jz    MURB
  525.     cmp    al,#LBR
  526.     jz    MULB
  527.     cmp    al,#LSQ
  528.     jz    MULB
  529. MUST:    dec    cl
  530.     jnz    MUVE
  531.     ret
  532.  
  533. MURB:    mov    ax,bx
  534.     pop    bx
  535.     sto    dx,[bx]
  536.     mov    bx,ax
  537.     jmp    MUST
  538.  
  539. MULB:    push    dx
  540.     inc    dx
  541.     inc    dx
  542.     jmp    MUST
  543.  
  544. ;    Check balance of []'s and {}'s.
  545.  
  546. BALA:    push    bx
  547.     push    cx
  548.     ld    cx,#0101H
  549. BALB:    ld    al,[bx]
  550.     inc    bx
  551.     cmp    al,#LSQ
  552.     jnz    BALC
  553.     inc    ch
  554.     jmp    BALB
  555. BALC:    cmp    al,#RSQ
  556.     jnz    BALD
  557.     dec    ch
  558.     jz    BADP
  559.     jmp    BALB
  560. BALD:    cmp    al,#LBR
  561.     jnz    BALE
  562.     inc    cl
  563.     jmp    BALB
  564. BALE:    cmp    al,#RBR
  565.     jnz    BALF
  566.     dec    cl
  567.     jz    BADP
  568.     jmp    BALB
  569. BALF:    or    al,al
  570.     jnz    BALB
  571.     cmp    cl,#01
  572.     jnz    BADP
  573.     cmp    ch,#01
  574.     pop    cx
  575.     pop    bx
  576.     jnz    BADP
  577.     ret
  578.  
  579. BADP:    ld    bx,#M3        ;"bad pattern"
  580.     jmp    GBYE
  581.  
  582.  
  583. ;    Check for termination of alternative.
  584.  
  585. ENDA:    cmp    al,#ORR
  586.     jz    ENDC
  587.     cmp    al,#RSQ
  588.     jz    ENDC
  589.     cmp    al,#RBR
  590.     jz    ENDC
  591.     or    al,al
  592. ENDC:    ret
  593.  
  594. ;    Check for beginning of alternative.
  595.  
  596. BEGA:    cmp    al,#ORR
  597.     jz    BEGC
  598. BEGB:    cmp    al,#LSQ
  599.     jz    BEGC
  600.     cmp    al,#LBR
  601. BEGC:    ret
  602.  
  603. ;    Check for null alternative.
  604.  
  605. NULA:    push    bx
  606.     call    NULC
  607.     pop    bx
  608. NULB:    ret
  609. NULC:    ld    al,[bx]
  610.     inc    bx
  611.     or    al,al
  612.     jz    NULB
  613.     call    BEGA
  614.     jnz    NULC
  615.     ld    al,[bx]
  616.     call    ENDA
  617.     jnz    NULC
  618.     jmp    BADP
  619.  
  620. ;    Check for given expression.
  621.  
  622. CHEK:    ld    ah,[bx]
  623.     xchg    bx,dx
  624.     ld    al,[bx]
  625.     xchg    bx,dx
  626.     inc    dx
  627.     call    ENDA
  628.     jz    CHNR
  629.     cmp    ah,#CR
  630.     jz    CHNO
  631.     cmp    al,#LBR
  632.     jnz    CHEL
  633.     jmp    CHLB
  634. CHEL:    cmp    al,#LSQ
  635.     jz    CHSQ
  636.     ld    cl,[bx]
  637.     inc    bx
  638.     cmp    al,#QUE
  639.     jz    CHEK
  640.     cmp    al,#ALF
  641.     jz    CHAL
  642.     cmp    al,ah
  643.     jz    CHEK
  644.     cmp    ah,#'a'
  645.     jc    CHNO
  646.     cmp    ah,#'{'
  647.     jnc    CHNO
  648.     and    ah,#05FH
  649.     cmp    al,ah
  650.     jz    CHEK
  651. CHNO:    or    al,#0FFH
  652. CHNR:    ret
  653.  
  654. ;    Check alphanumeric.
  655.  
  656. CHAL:    mov    al,cl
  657.     cmp    al,#'0'
  658.     jc    CHNO
  659.     cmp    al,#':'
  660.     jc    CHEK
  661.     cmp    al,#'A'
  662.     jc    CHNO
  663.     cmp    al,#'['
  664.     jc    CHEK
  665.     cmp    al,#'a'
  666.     jc    CHNO
  667.     cmp    al,#'{'
  668.     jc    CHEK
  669.     jmp    CHNO
  670.  
  671. ;    Check list of alternatives.
  672.  
  673. CHSQ:    push    SQXX
  674.     push    SQAA
  675.     push    SQZZ
  676.     sto    bx,SQXX
  677.     xchg    bx,dx
  678.     ld    dx,[bx]
  679.     inc    bx
  680.     inc    bx
  681.     sto    bx,SQAA
  682.     sto    dx,SQZZ
  683. CHAA:    ld    bx,SQXX
  684.     call    CHEK
  685.     jz    CHFF
  686. CHBB:    ld    bx,SQAA        ;fail so find next alternative
  687. CHCC:    call    NEXT
  688.     cmp    al,#RSQ
  689.     jz    CHDD        ;no more alternatives, so fail
  690.     cmp    al,#ORR
  691.     jnz    CHCC
  692.     sto    bx,SQAA
  693.     xchg    bx,dx
  694.     jmp    CHAA        ;try next alternative
  695. CHDD:    ld    bx,SQXX
  696.     or    al,#0FFH
  697. CHEE:    pop    SQZZ
  698.     pop    SQAA
  699.     pop    SQXX
  700.     ret
  701. CHFF:    ld    dx,SQZZ        ;good alternative, try rest
  702.     call    CHEK
  703.     jz    CHEE
  704.     jmp    CHBB
  705.  
  706. ;    Check iterative pattern.
  707.  
  708. CHLB:    push    TEXT
  709.     push    TEXX
  710.     push    REST
  711.     push    REPT
  712.     push    REPP
  713.     sto    bx,TEXT
  714.     sto    bx,TEXX
  715.     xchg    bx,dx
  716.     ld    dx,[bx]
  717.     inc    bx
  718.     inc    bx
  719.     sto    bx,REPT
  720.     sto    bx,REPP
  721.     sto    dx,REST
  722. CHLC:    ld    dx,REST
  723.     ld    bx,TEXT
  724.     call    CHEK        ;check rest
  725.     jz    CHZZ
  726. CHII:    ld    dx,REPT        ;rest failed
  727.     ld    bx,TEXT        ;keep same text
  728.     call    CHEK        ;try out the repeater
  729.     jnz    CHOO
  730.     sto    bx,TEXT        ;repeater worked, record progress
  731.     ld    bx,REPP        ;start alternatives over again
  732.     sto    bx,REPT
  733.     jmp    CHLC
  734. CHOO:    ld    bx,REPT        ;repeater failed, try next
  735. CHXX:    call    NEXT
  736.     cmp    al,#RBR
  737.     jz    CHYY        ;this was the last, quit
  738.     cmp    al,#ORR
  739.     jnz    CHXX
  740.     sto    bx,REPT
  741.     jmp    CHII
  742. CHYY:    ld    bx,TEXX
  743.     or    al,#00        ;emphasize the RBR
  744. CHZZ:    pop    REPP
  745.     pop    REPT
  746.     pop    REST
  747.     pop    TEXX
  748.     pop    TEXT
  749.     ret
  750.  
  751. TUTO:    db    'The command line',CR,LF
  752.     db    '     STUTE D:FILE.EXT PATTERN!SKELETON',CR,LF
  753.     db    'will search through all instances of FILE.EXT',CR,LF
  754.     db    '(which may be an ambiguous reference) on disk D',CR,LF
  755.     db    'to find lines containing PATTERN. Such lines will',CR,LF
  756.     db    'be shown on the console preceded by a line number,',CR,LF
  757.     db    'classified by file. Whenever the regular expression',CR,LF
  758.     db    'PATTERN is found, it will be replaced by the constant',CR,LF
  759.     db    'SKELETON. The PATTERN may contain:',CR,LF
  760.     db    '     [p1!p2!...!pn]  alternative strings',CR,LF
  761.     db    '     {p1!p2!...!pn}  repeated alternatives',CR,LF
  762.     db    '     ? any single character',CR,LF
  763.     db    '     @ for any alphanumeric: a-z, A-Z, 0-9',CR,LF
  764.     db    '     _ in place of horizontal tab',CR,LF
  765.     db    'A general PATTERN must be used with extreme caution',CR,LF
  766.     db    'because the same constant will replace it, whatever',CR,LF
  767.     db    'its form. The PATTERN may not involve more than one',CR,LF
  768.     db    'single line, but more than one instance of the PATTERN',CR,LF
  769.     db    'may occupy the same line.',CR,LF
  770.     db    00
  771.  
  772. LOGO:    db    'STUTE.CMD 16/NOV/83 ICUAP',CR,LF,00
  773.  
  774. M3:    db    '-- Bad Pattern --',00
  775.  
  776. M4:    db    CR,LF,'-- Substitution Terminated --',00
  777.  
  778. M5:    db    CR,LF,'-- Disk or Directory Full --',00
  779.  
  780. ;    The following file control segments are arranged in just
  781. ;    the form shown so that they will be properly paired for
  782. ;    the renaming which has to be done after closing each file.
  783.  
  784. ENTH:    ds    1
  785. FILE:    db    'DFilenameEXT',00,00,00,00    ;generic filename
  786.     ds    16
  787. OFIL:    db    'DFilename$$$',00,00,00,00    ;output file (.$$$)
  788. IFIL:    db    'DFilenameEXT',00,00,00,00    ;input file  (.EXT)
  789. KFIL:    db    'DFilenameBAK',00,00,00,00    ;backup file (.BAK)
  790. UFIL:    db    'Dfilename$$$',00,00,00,00    ;active output (.$$$)
  791.     ds    16
  792. UREC:    ds    1
  793. UBUF:    ds    80H
  794. OPTR:    ds    2
  795. OCTR:    ds    2
  796.  
  797. ;    All the relevant files are located and noted before any
  798. ;    substitutions are made, to avoid a newly created file
  799. ;    being placed in the dictionary, being encountered again
  800. ;    later on and then being processed a second time. The worst
  801. ;    case would be to have to use all 64 files (minus one, for
  802. ;    elbow room) in the directory, but that's not likely.
  803.  
  804. DCTR:    ds    1        ;directory counter
  805. DPTR:    ds    2        ;directory pointer
  806. DIRY:    ds    1024        ;directory of file names, if needed
  807.  
  808. ;    Temporary storage for the regular expression parser.
  809.  
  810. SQXX:    ds    2
  811. SQAA:    ds    2
  812. SQZZ:    ds    2
  813. TEXT:    ds    2
  814. TEXX:    ds    2
  815. REST:    ds    2
  816. REPT:    ds    2
  817. REPP:    ds    2
  818.  
  819. ;    Scan pointers, buffers, headings and labels.
  820.  
  821. ALFA:    ds    2        ;begin good segment
  822. BETA:    ds    2        ;end good segment
  823.  
  824. PATT:    ds    256        ;command line pattern
  825. PAPO:    ds    2        ;pattern pointer
  826. SKPO:    ds    2        ;skeleton pointer
  827. SKND:    ds    2        ;skeleton end
  828. FHED:    db    '----> File '    ;"File" header
  829. FNAM:    db    'xxxxxxxx.'    ;filename
  830. FEXT:    db    'xxx',CR,LF,00    ;file extension
  831. LNUM:    db    '   0     ',00    ;'line number'
  832. LZER:    db    '   0'        ;counter initializer
  833. FTOT:    db    '   0  substitutions made',CR,LF,00
  834. DTOT:    db    '   0  instances in the entire disk',CR,LF,00
  835.     db    00        ;fence for line buffer
  836. LBUF:    ds    85H        ;line buffer
  837. ICTR:    ds    2        ;input file counter
  838. IPTR:    ds    2        ;input file pointer
  839. IBUF:    ds    ISIZ        ;input file buffer
  840. FINI:    ds    0
  841.  
  842.     end
  843.