home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 142_01 / find.asm < prev    next >
Encoding:
Assembly Source File  |  1985-11-15  |  19.5 KB  |  1,199 lines

  1.  
  2.     TITLE    'FIND+ 2.0'
  3. ;
  4. ;            FYNDE.ASM   Copyright (C) 1982
  5. ;            Universidad Autonoma de Puebla
  6. ;
  7. ;    The original of FIND wasn't copyright and neither is
  8. ;    my work on it here. Bill Bolton
  9. ;
  10. ;    -----------------------------------------------------
  11. ;
  12. ;    Reassembly of FIND.COM, which was originally extracted
  13. ;    from the CBBS(R) package available from Ward Christensen
  14. ;    and Randy Suess. However, considerable rearrangement has
  15. ;    taken place, most notably the following:
  16. ;
  17. ;    *    <no file name> results in a screen of information
  18. ;    *    the search pattern may be a regular expression
  19. ;    *    label+line number as an alternative to line number
  20. ;    *    instance count reported, both per file and globally
  21. ;    *    files listed in a table in the data section at the end
  22. ;         are automatically excluded
  23. ;    *    squeezed files do not deter the search
  24. ;
  25. ;    To achieve compatibility with MicroShell the vertical bar
  26. ;    may be replaced by exclamation point; all syntactic elements
  27. ;    are defined by EQU's and may be redefined. LABEL|PATTERN
  28. ;    is checked for balanced parentheses and non-null arguments
  29. ;    to forestall the most common failure modes. Had MicroShell
  30. ;    not been available, an option to direct the output to some
  31. ;    disk file would probably have been included.
  32. ;
  33. ;
  34. ;VERSION LIST, in reverse order for easy on line scanning
  35. ;
  36. ;23/Oct/84 Added exclusion table code to check for file types
  37. ;       not to serach. Fixed bug when searching large files,
  38. ;       often started on non-zero exetent, which mightly
  39. ;       confused the file unsqueezing mechanism. Now once a
  40. ;       suitable file is found to search the extent is forced
  41. ;       to zero to start. Added conditional code for RCPM
  42. ;       use to test for SYS and F2 attributes along the lines
  43. ;       of FIND+. Lifted usage message from FIND+, added version
  44. ;       number to signon message. Version 2.0
  45. ;       Bill Bolton, Software Tools RCPM, Brisbane, Australia
  46. ;
  47. ;04/Jul/84 No false matches with nul lines. Harold V. Mcintosh
  48. ;
  49. ;01/Jul/84 Scan squeezed files. Harold V. McIntosh
  50. ;
  51. ;20/Dec/82 Originally written. Harold V. McIntosh
  52. ;
  53. ;    ----------------------------------------------------------
  54.  
  55.  
  56. TRUE    equ    0FFH
  57. FALSE    equ    0
  58. ;
  59. VERS    equ    20        ;version number
  60. ;
  61. HT    equ    09H        ;horizontal tab
  62. LF    equ    0AH        ;line feed
  63. CR    equ    0DH        ;carriage return
  64. KZ    equ    1AH        ;^Z
  65. MASK    equ    7FH        ;ASCII mask
  66.  
  67. ;    Delimiters for the command line
  68.  
  69. LSQ    equ    '['        ;begin alternative list
  70. RSQ    equ    ']'        ;end alternative list
  71. LBR    equ    '{'        ;begin iterated expression
  72. RBR    equ    '}'        ;end iterated expression
  73. ORR    equ    '|'        ;separate alternatives
  74.  
  75. ;    Representatives of characters or classes.
  76.  
  77. TAB    equ    '_'        ;substitute for tab
  78. QUE    equ    '?'        ;represent any byte
  79. ALF    equ    '@'        ;represent any alphanumeric
  80.  
  81. ;    CP/M and other locations and parameters
  82.  
  83. cfcb    equ    005CH        ;CP/M's file control block
  84. cblk    equ    007CH        ;CP/M's block counter
  85. csiz    equ    0080H        ;CP/M's record size
  86. cbuf    equ    0080H        ;CP/M's record buffer
  87. ksiz    equ    255        ;sector capacity of IN buffer
  88. isiz    equ    ksiz*128    ;buffer 2 file extents in memory
  89. hsiz    equ    256        ;max characters in Huffman code
  90. ;
  91. RCPM    equ    FALSE        ;true for RCPM use
  92. ;
  93. ;    ------------
  94.     org    100H
  95. ;    ------------
  96.  
  97. X0100:
  98.     lxi    sp,stak
  99.     lda    cfcb+1        ;file name
  100.     cpi    ' '
  101.     jnz    X0143
  102.     lxi    h,usage
  103. ferm:
  104.     call    mssg        ;message to console
  105.     jmp    0000
  106.  
  107. X0143:
  108.     lxi    h,signon
  109.     call    mssg        ;message to console
  110.     mvi    c,12
  111.     lxi    d,cfcb        ;CP/M's file control block
  112.     lxi    h,file
  113.     call    miuc        ;block move
  114.     xra    a
  115.     sta    enth
  116.     lxi    h,cbuf        ;CP/M's record buffer
  117.     mov    e,m
  118.     mov    c,e
  119.     mov    d,a
  120.     xchg
  121.     inx    d
  122.     dad    d
  123.     mov    m,a
  124.     xchg
  125. X0152:
  126.     inx    h
  127.     dcr    c
  128.     mov    a,m
  129.     ora    a
  130.     jz    X029C
  131.     cpi    ' '
  132.     jnz    X0152
  133.     inx    h
  134.     call    bala        ;check balance of [], {}.
  135.     call    nula        ;check for null alternatives
  136.     lxi    d,patt        ;command line pattern
  137.     call    muve
  138.     mvi    c,4
  139.     lxi    d,lzer
  140.     lxi    h,dtot
  141.     call    miuc        ;block move
  142.     lxi    h,0000
  143.     shld    lapo
  144.     lxi    h,patt        ;command line pattern
  145.     shld    papo
  146.     call    next
  147.     ora    a
  148.     jz    scan
  149.     shld    papo
  150.     lxi    h,patt
  151.     shld    lapo
  152.  
  153. ;    Scan the directory for file names.
  154.  
  155. scan:
  156.     mvi    c,26        ;(1A) set DMA address
  157.     lxi    d,cbuf        ;CP/M's record buffer
  158.     call    0005        ; - B D O S -
  159.     mvi    c,17        ;(11) search once
  160.     lxi    d,file
  161.     call    0005        ; - B D O S -
  162.     lxi    h,enth
  163.     inr    m
  164.     mov    c,m
  165. fnth:
  166.     inr    a
  167.     jz    done        ;we're all done
  168.     dcr    c
  169.     jz    this
  170.     push    b
  171.     mvi    c,18        ;(12) search again
  172.     lxi    d,file
  173.     call    0005        ; - B D O S -
  174.     pop    b
  175.     jmp    fnth
  176.  
  177. ;    We're all done.
  178.  
  179. done:
  180.     lxi    h,dtot
  181.     jmp    ferm        ;final (error) message
  182.  
  183. ;    A prospective file has been located
  184.  
  185. this:
  186.     dcr    a
  187.     ani    03
  188.     add    a
  189.     add    a
  190.     add    a
  191.     add    a
  192.     add    a
  193.     adi    81H
  194.     mov    e,a
  195.     mvi    d,00
  196.     mvi    c,11
  197.     lxi    h,cfcb+1    ;CP/M's file control block
  198.     call    miuc        ;block move
  199.     lxi    h,cfcb+12
  200.     xra    a
  201.     mov    m,a        ;make sure we start on extent 0
  202.  
  203.     if    rcpm        ;your favourite catalogue file type
  204.  
  205.     lda    cfcb+9
  206.     ani    mask
  207.     cpi    'A'        ;file type of ALL/AQL always OK
  208.     jnz    tagtest        ; on Software Tools RCPM
  209.     lda    cfcb+10
  210.     ani    mask
  211.     cpi    'L'
  212.     cnz    Qcheck        ;maybe squeezed
  213.     jnz    tagtest
  214.     lda    cfcb+11
  215.     ani    mask
  216.     cpi    'L'
  217.     jz    ok    
  218. tagtest:
  219.     lda    cfcb+2
  220.     ani    80h        ;TAG2 attribute set?
  221.     jnz    scan        ;yes
  222.     lda    cfcb+10        ;no
  223.     ani    80h        ;SYS attribute set?
  224.     jnz    scan        ;yes
  225.  
  226.     endif    ;rcpm
  227.  
  228.     call    ignore        ;disregard files in table
  229.     jz    scan
  230.  
  231. ;    Open the file, check for squeezing.
  232.  
  233. ok:
  234.     mvi    c,15        ;(0F) open file
  235.     lxi    d,cfcb        ;CP/M's FCB
  236.     call    0005        ; - B I O S -
  237.     inr    a
  238.     jz    0000        ;quit [without message]
  239.     xra    a
  240.     sta    cblk        ;block pointer
  241.     sta    dens        ;z/nz=un/squeezed
  242.     sta    mult        ;repeat factor
  243.     lxi    h,0000
  244.     shld    ictr        ;input counter
  245.  
  246.     lxi    h,cfcb+10    ;CP/M's file control block
  247.     mov    a,m
  248.     cpi    'Q'
  249.     jnz    nsqz
  250.     call    gbyt        ;fetch one byte
  251.     cpi    076H
  252.     jnz    nsqz
  253.     call    gbyt        ;fetch one byte
  254.     cpi    0FFH
  255.     jnz    nsqz
  256.     lxi    h,dens        ;z/nz=un/squeezed
  257.     mvi    m,0FFH
  258.     call    rwor        ;fetch word
  259.  
  260. ;    unsqueezed file name
  261.  
  262.     lxi    b,200CH        ;twelve spaces
  263.     lxi    h,uzfn        ;unsqueezed file's name
  264.     call    fiuc        ;block fill
  265.  
  266.     mvi    b,8
  267.     lxi    d,uzfn        ;unsqueezed file's name
  268. luup:
  269.     call    gbyt        ;fetch one byte
  270.     ora    a
  271.     jz    ldic
  272.     cpi    '.'
  273.     jz    luuw
  274.     stax    d
  275.     inx    d
  276.     dcr    b
  277.     jnz    luup
  278. luuz:
  279.     call    gbyt
  280.     ora    a
  281.     jz    ldic
  282.     cpi    '.'
  283.     jnz    luuz
  284. luuw:
  285.     mvi    b,3
  286.     lxi    d,uzfn+8
  287.     stax    d
  288.     inx    d
  289. luur:
  290.     call    gbyt
  291.     ora    a
  292.     jz    ldic
  293.     stax    d
  294.     inx    d
  295.     dcr    b
  296.     jnz    luur
  297. luus:
  298.     call    gbyt
  299.     ora    a
  300.     jnz    luus
  301.  
  302. ;    load code directory
  303.  
  304. ldic:
  305.     call    rwor        ;fetch word
  306.     lxi    b,hsiz
  307.     mov    a,c
  308.     sub    l
  309.     mov    a,b
  310.     sbb    h
  311.     jnc    ldii
  312.     lxi    h,M8        ;'code table won't fit'
  313.     call    mssg
  314.     jmp    scan
  315.  
  316. ldii:
  317.     dad    h
  318.     dad    h
  319.     mov    c,l
  320.     mov    b,h
  321.     lxi    d,code        ;code table
  322. ldij:
  323.     call    gbyt        ;fetch one byte
  324.     stax    d
  325.     inx    d
  326.     dcx    b
  327.     mov    a,c
  328.     ora    b
  329.     jnz    ldij
  330.  
  331.     lxi    h,roco        ;rotation count
  332.     mvi    m,1
  333.  
  334. nsqz:
  335.     mvi    c,4
  336.     lxi    d,lzer
  337.     lxi    h,lnum        ;'line number'
  338.     call    miuc        ;block move
  339.  
  340.     mvi    c,4
  341.     lxi    d,lzer
  342.     lxi    h,ftot        ;'file total'
  343.     call    miuc        ;block move
  344.  
  345.     mvi    c,8
  346.     lxi    d,cfcb+1    ;file name
  347.     lxi    h,fnam        ;'file name'
  348.     call    miuc        ;block move
  349.  
  350.     mvi    c,3
  351.     lxi    d,0065H        ;extension
  352.     lxi    h,fext        ;'file extension'
  353.     call    miuc        ;block move
  354.  
  355.     lxi    h,fhed
  356.     call    mssg        ;message to console
  357.     lda    dens
  358.     ora    a
  359.     jz    sixs
  360.     lxi    h,hesq        ;'[original]'
  361.     call    mssg
  362.  
  363. sixs:
  364. ;    lxi    b,2006H        ;six spaces
  365. ;    lxi    h,llbl
  366. ;    call    fiuc        ;block fill
  367.  
  368. X01C8:
  369.     lxi    h,lnum+3    ;increment l.c.
  370.     call    inco        ;increment line counter
  371.     lxi    h,lbuf        ;line buffer
  372.     mvi    b,0FFH
  373. X01E0:
  374.     inr    b
  375.     jm    X01FD
  376.     push    b
  377.     push    h
  378.     call    inch        ;char from big bffr to line bffr
  379.     pop    h
  380.     pop    b
  381.     mov    m,a
  382.     inx    h
  383.     cpi    KZ
  384.     jnz    X01E8
  385.     lxi    h,ftot
  386.     call    mssg        ;message to console
  387.     jmp    scan
  388. X01E8:
  389.     cpi    LF
  390.     jnz    X01E0
  391.     jmp    X0202
  392.  
  393. X01FD:
  394.     mvi    m,CR
  395.     inx    h
  396.     mvi    m,LF
  397.     inx    h
  398.  
  399. ;    Check console for termination request. If one
  400. ;    is present, clear it out before leaving.
  401.  
  402. X0202:
  403.     mvi    m,00        ;guarantee right hand fence
  404.     mvi    c,11        ;(0B) console status
  405.     call    0005        ; - B I O S -
  406.     ora    a
  407.     jz    culi
  408.     mvi    c,1        ;(01) read console
  409.     call    0005        ; - B D O S -
  410.     cpi    03H        ;^C
  411.     jnz    skpf
  412.     lxi    h,M4        ;"search terminated"
  413.     jmp    ferm        ;final (error) message
  414.  
  415. skpf:
  416.     lxi    h,M5        ;"remainder of file skipped"
  417.     call    mssg        ;message to console
  418.     jmp    scan
  419.  
  420. ;    Scan the current line.
  421. ;    First see if it is labelled.
  422.  
  423. culi:
  424.     lhld    lapo
  425.     mov    a,h
  426.     ora    l
  427.     jz    X0217        ;no label requested
  428.     xchg
  429.     lxi    h,lbuf
  430.     call    chek
  431.     jnz    X0217        ;label not found
  432.     push    h
  433.     lxi    b,2006H        ;six spaces
  434.     lxi    h,llbl
  435.     call    fiuc        ;block fill
  436.     pop    h
  437.     lxi    d,llbl+5
  438.     mvi    c,6
  439. didl:
  440.     dcx    h
  441.     mov    a,m
  442.     cpi    HT        ;ignore tabs in text
  443.     jz    didl
  444.     cpi    ' '        ;quit at head of line
  445.     jc    dido
  446.     stax    d
  447.     dcx    d
  448.     dcr    c
  449.     jnz    didl
  450. dido:
  451.     mvi    c,4
  452.     lxi    d,lzer
  453.     lxi    h,lnum
  454.     call    miuc        ;block move
  455.  
  456. ;    Now look for the pattern
  457.  
  458. X0217:
  459.     lxi    h,lbuf        ;line buffer
  460. X021A:
  461.     xchg
  462.     lhld    papo        ;pattern pointer
  463.     xchg
  464.     push    h
  465.     call    chek
  466.     pop    h
  467.     jz    X0263
  468.     mov    a,m
  469.     cpi    CR
  470.     jz    X01C8        ;increment l.c. at X026A
  471.     inx    h
  472.     jmp    X021A
  473.  
  474. ;    Pattern matches, so type label & line containing it
  475.  
  476. X0263:
  477. ;    lxi    h,llbl        ;line label
  478. ;    call    mssg        ;message to console
  479.     lxi    h,lbuf        ;line buffer
  480.     call    mssg        ;message to console
  481.     lxi    h,ftot+3
  482.     call    inco
  483.     lxi    h,dtot+3
  484.     call    inco
  485.     jmp    X01C8        ;increment l.c. at X026A
  486.  
  487. ;    Increment ASCII counter at (HL-3).
  488.  
  489. inco:
  490.     mov    a,m
  491.     ori    30H
  492.     inr    a
  493.     mov    m,a
  494.     cpi    ':'
  495.     rnz
  496.     mvi    m,'0'
  497.     dcx    h
  498.     jmp    inco
  499.  
  500. ;    Memory to console
  501.  
  502. mssg:
  503.     mov    e,m
  504.     inx    h
  505.     push    h
  506.     mvi    c,2        ;(02) write console
  507.     call    0005        ; - B I O S -
  508.     pop    h
  509.     mov    a,m
  510.     ora    a
  511.     jnz    mssg        ;message to console
  512.     ret
  513.  
  514. X029C:
  515.     lxi    h,M3        ;"bad pattern"
  516.     call    ferm        ;final (error) message
  517.  
  518. ;    decode next character
  519.  
  520. dnch:
  521.     lxi    h,code        ;code table
  522. dncr:
  523.     call    rbit
  524.     jnc    dncs
  525.     inx    h
  526.     inx    h
  527. dncs:
  528.     mov    e,m
  529.     inx    h
  530.     mov    d,m
  531.     mov    a,d
  532.     cpi    0FEH
  533.     jz    dnct
  534.     ora    a
  535.     jp    dncu
  536.     mov    a,e
  537.     cma
  538.     stc
  539.     cmc
  540.     ret
  541.  
  542. dnct:
  543.     stc
  544.     ret
  545.  
  546. ;    Calculate <code>+4*<offset>.
  547.  
  548. dncu:
  549.     lxi    h,code        ;code table
  550.     dad    d
  551.     dad    d
  552.     dad    d
  553.     dad    d
  554.     jmp    dncr
  555.  
  556. ;    read one bit at a time
  557.  
  558. rbit:
  559.     push    h
  560.     lxi    h,roco        ;rotation count
  561.     dcr    m
  562.     jnz    rbiu
  563.     mvi    m,8
  564.     call    gbyt        ;fetch one byte
  565.     sta    roby        ;rotating byte
  566. rbiu:
  567.     lda    roby        ;rotating byte
  568.     rar
  569.     sta    roby        ;rotating byte
  570.     pop    h
  571.     ret
  572.  
  573. ;    read one word
  574.  
  575. rwor:
  576.     call    gbyt        ;fetch one byte
  577.     push    psw
  578.     call    gbyt        ;fetch one byte
  579.     pop    h
  580.     mov    l,h
  581.     mov    h,a
  582.     ret
  583.  
  584. ;    Fetch the next byte. The input buffer will be refreshed if it
  585. ;    is necessary. For normal files, one byte will be extracted from
  586. ;    the input buffer; for squeezed files, one byte will be decoded
  587. ;    from the incoming bit stream and subtracted from the checksum.
  588.  
  589. inch:
  590.     lda    dens        ;z/nz = un/squeezed
  591.     ora    a
  592.     jz    gbyt        ;fetch one byte
  593.     lda    mult        ;repeat factor
  594.     ora    a
  595.     jz    gusq
  596.     dcr    a
  597.     sta    mult        ;repeat factor
  598.     lda    lach        ;last character read
  599.     ret
  600.  
  601. gusq:
  602.     call    dnch
  603.     jnc    guss
  604.     mvi    a,1AH
  605.     ret
  606.  
  607. guss:
  608.     cpi    090H
  609.     jz    gusu
  610.     sta    lach        ;last character read
  611.     ret
  612.  
  613. gusu:
  614.     call    dnch
  615.     ora    a
  616.     jnz    gusv
  617.     mvi    a,090H
  618.     ret
  619.  
  620. gusv:
  621.     dcr    a
  622.     dcr    a
  623.     sta    mult        ;repeat factor
  624.     lda    lach        ;last character read
  625.     ret
  626.  
  627. ;    unsqueezed (normal) text
  628.  
  629. gbyt:
  630.     lhld    ictr        ;input counter
  631.     mov    a,h
  632.     ora    l
  633.     cz    indi        ;disk to IN area
  634.     lhld    ictr        ;input counter
  635.     dcx    h
  636.     shld    ictr        ;input counter
  637.     lhld    iptr        ;input pointer
  638.     mov    a,m
  639.     inx    h
  640.     shld    iptr        ;input pointer
  641.     ret
  642.  
  643. indi:
  644.     mvi    b,ksiz
  645.     lxi    h,isiz
  646.     shld    ictr        ;input counter
  647.     lxi    h,ibuf        ;input buffer
  648.     shld    iptr        ;input pointer
  649. indd:
  650.     mvi    m,KZ
  651.     push    h
  652.     push    b
  653.     xchg
  654.     mvi    c,26        ;(1A) set DMA address
  655.     call    0005        ; - B D O S -
  656.     lxi    d,cfcb        ;CP/M's file control block
  657.     mvi    c,20        ;(14) read one record
  658.     call    0005        ; - B D O S -
  659.     pop    b
  660.     pop    h
  661.     ora    a
  662.     rnz
  663.     dcr    b
  664.     rz
  665.     lxi    d,csiz        ;CP/M's record size
  666.     dad    d
  667.     jmp    indd
  668.  
  669. ;    Disregard certain files
  670.  
  671. ignore:
  672.     mvi    c,(table$end - table$start)/3
  673.     lxi    h,table$start-3
  674.     shld    store
  675. loop:
  676.     lhld    store        ;get pointer
  677.     lxi    d,3        ;bump to next entry
  678.     dad    d
  679.     shld    store
  680.     lxi    d,cfcb+9    ;point to start of file type
  681.     call    match        ;matched?
  682.     rz            ;yes
  683.     dcr    c        ;no, finished count?
  684.     jnz    loop        ;no
  685.     mvi    a,1        ;yes
  686.     ora    a        ;return non-zero
  687.     ret
  688. ;
  689. match:
  690.     ldax    d
  691.     ani    mask
  692.     cmp    m        ;first character match?
  693.     rnz            ;no
  694.     inx    h
  695.     inx    d
  696.     ldax    d
  697.     ani    mask
  698.     cmp    m        ;second character match?
  699.     cnz    Qcheck        ;squeezed version of file type?
  700.     rnz            ;no
  701.     inx    h
  702.     inx    d
  703.     ldax    d
  704.     ani    mask
  705.     cmp    m        ;third character match?
  706.     ret
  707. ;    
  708. Qcheck
  709.     cpi    'Q'
  710.     ret
  711. ;
  712. ;    Advance to next alternative
  713.  
  714. nexx:
  715.     mov    e,m
  716.     inx    h
  717.     mov    d,m
  718.     xchg
  719. next:
  720.     mov    a,m
  721.     ora    a
  722.     rz
  723.     inx    h
  724.     call    enda
  725.     rz
  726.     call    begb
  727.     jz    nexx
  728.     jmp    next
  729.  
  730. ;    Block fill with C B's starting at (HL).
  731.  
  732. fiuc:
  733.     mov    m,b
  734.     inx    h
  735.     dcr    c
  736.     jnz    fiuc        ;block fill
  737.     ret
  738.  
  739. ;    Block move of C bytes from (DE) to (HL).
  740.  
  741. miuc:
  742.     ldax    d
  743.     mov    m,a
  744.     inx    d
  745.     inx    h
  746.     dcr    c
  747.     jnz    miuc        ;block move
  748.     ret
  749.  
  750. ;    Move and semi-compile the command line.
  751.  
  752. muve:
  753.     mov    a,m
  754.     cpi    TAB
  755.     jnz    munt
  756.     mvi    a,HT
  757. munt:
  758.     stax    d
  759.     inx    h
  760.     inx    d
  761.     cpi    RBR
  762.     jz    murb
  763.     cpi    RSQ
  764.     jz    murb
  765.     cpi    LBR
  766.     jz    mulb
  767.     cpi    LSQ
  768.     jz    mulb
  769. must:
  770.     dcr    c
  771.     jnz    muve
  772.     ret
  773.  
  774. murb:
  775.     xthl
  776.     mov    m,e
  777.     inx    h
  778.     mov    m,d
  779.     pop    h
  780.     jmp    must
  781.  
  782. mulb:
  783.     push    d
  784.     inx    d
  785.     inx    d
  786.     jmp    must
  787.  
  788. ;    Check balance of []'s and {}'s.
  789.  
  790. bala:
  791.     push    h
  792.     push    b
  793.     lxi    b,0101H
  794. balb:
  795.     mov    a,m
  796.     inx    h
  797.     cpi    LSQ
  798.     jnz    balc
  799.     inr    b
  800.     jmp    balb
  801. balc:
  802.     cpi    RSQ
  803.     jnz    bald
  804.     dcr    b
  805.     jz    balx
  806.     jmp    balb
  807. bald:
  808.     cpi    LBR
  809.     jnz    bale
  810.     inr    c
  811.     jmp    balb
  812. bale:
  813.     cpi    RBR
  814.     jnz    balf
  815.     dcr    c
  816.     jz    balx
  817.     jmp    balb
  818. balf:
  819.     ora    a
  820.     jnz    balb
  821.     mov    a,c
  822.     cpi    01
  823.     jnz    balx
  824.     mov    a,b
  825.     cpi    01
  826.     pop    b
  827.     pop    h
  828.     rz
  829. balx:
  830.     lxi    h,M3        ;"bad pattern"
  831.     jmp    ferm        ;final (error) message
  832.  
  833. ;    Check for termination of alternative.
  834.  
  835. enda:
  836.     cpi    ORR
  837.     rz
  838. endb:
  839.     cpi    RSQ
  840.     rz
  841.     cpi    RBR
  842.     rz
  843.     ora    a
  844.     ret
  845.  
  846. ;    Check for beginning of alternative.
  847.  
  848. bega:
  849.     cpi    ORR
  850.     rz
  851. begb:
  852.     cpi    LSQ
  853.     rz
  854.     cpi    LBR
  855.     ret
  856.  
  857. ;    Check for null alternative.
  858.  
  859. nula:
  860.     push    h
  861.     call    nulb
  862.     pop    h
  863.     ret
  864. nulb:
  865.     mov    a,m
  866.     inx    h
  867.     ora    a
  868.     rz
  869.     call    bega
  870.     jnz    nulb
  871.     mov    a,m
  872.     call    enda
  873.     jnz    nulb
  874.     jmp    balx
  875.  
  876. ;    Check for given expression.
  877.  
  878. chek:
  879.     ldax    d
  880.     inx    d
  881.     call    enda
  882.     rz
  883.     mov    b,a
  884.     mov    a,m
  885.     cpi    CR
  886.     jz    chno
  887.     mov    a,b
  888.     cpi    LBR
  889.     jz    chlb
  890.     cpi    LSQ
  891.     jz    chsq
  892.     mov    c,m
  893.     inx    h
  894.     cpi    QUE
  895.     jz    chek
  896.     cpi    ALF
  897.     jz    chal
  898.     cmp    c
  899.     jz    chek
  900.     mov    b,a
  901.     mov    a,c
  902.     cpi    'a'
  903.     jc    chno
  904.     cpi    '{'
  905.     jnc    chno
  906.     ani    05FH
  907.     cmp    b
  908.     jz    chek
  909. chno:
  910.     ori    0FFH
  911.     ret
  912.  
  913. ;    Check alphanumeric.
  914.  
  915. chal:
  916.     mov    a,c
  917.     cpi    '0'
  918.     jc    chno
  919.     cpi    ':'
  920.     jc    chek
  921.     cpi    'A'
  922.     jc    chno
  923.     cpi    '['
  924.     jc    chek
  925.     cpi    'a'
  926.     jc    chno
  927.     cpi    '{'
  928.     jc    chek
  929.     jmp    chno
  930.  
  931. ;    Check list of alternatives.
  932.  
  933. chsq:
  934.     mov    c,l
  935.     mov    b,h
  936.     lhld    sqxx
  937.     push    h
  938.     lhld    sqaa
  939.     push    h
  940.     lhld    sqzz
  941.     push    h
  942.     mov    l,c
  943.     mov    h,b
  944.     shld    sqxx
  945.     xchg
  946.     mov    e,m
  947.     inx    h
  948.     mov    d,m
  949.     inx    h
  950.     shld    sqaa
  951.     xchg
  952.     shld    sqzz
  953. chaa:
  954.     lhld    sqxx
  955.     call    chek
  956.     jz    chff
  957. chbb:
  958.     lhld    sqaa        ;fail so find next alternative
  959. chcc:
  960.     call    next
  961.     cpi    RSQ
  962.     jz    chdd        ;no more alternatives, so fail
  963.     cpi    ORR
  964.     jnz    chcc
  965.     shld    sqaa
  966.     xchg
  967.     jmp    chaa        ;try next alternative
  968. chdd:
  969.     lhld    sqxx
  970.     ori    0FFH
  971. chee:
  972.     mov    c,l
  973.     mov    b,h
  974.     pop    h
  975.     shld    sqzz
  976.     pop    h
  977.     shld    sqaa
  978.     pop    h
  979.     shld    sqxx
  980.     mov    l,c
  981.     mov    h,b
  982.     ret
  983. chff:
  984.     xchg            ;good alternative, try rest
  985.     lhld    sqzz
  986.     xchg
  987.     call    chek
  988.     jz    chee
  989.     jmp    chbb
  990.  
  991. ;    Check iterative pattern.
  992.  
  993. chlb:
  994.     mov    c,l
  995.     mov    b,h
  996.     lhld    text
  997.     push    h
  998.     lhld    texx
  999.     push    h
  1000.     lhld    rest
  1001.     push    h
  1002.     lhld    repeat
  1003.     push    h
  1004.     lhld    repp
  1005.     push    h
  1006.     mov    l,c
  1007.     mov    h,b
  1008.     shld    text
  1009.     shld    texx
  1010.     xchg
  1011.     mov    e,m
  1012.     inx    h
  1013.     mov    d,m
  1014.     inx    h
  1015.     shld    repeat
  1016.     shld    repp
  1017.     xchg
  1018.     shld    rest
  1019. chlc:
  1020.     lhld    rest
  1021.     xchg
  1022.     lhld    text
  1023.     call    chek        ;check rest
  1024.     jz    chzz
  1025. chii:
  1026.     lhld    repeat        ;rest failed
  1027.     xchg
  1028.     lhld    text        ;keep same text
  1029.     call    chek        ;try out the rer
  1030.     jnz    choo
  1031.     shld    text        ;repeater worked, record progress
  1032.     lhld    repp        ;start alternatives over again
  1033.     shld    repeat
  1034.     jmp    chlc
  1035. choo:
  1036.     lhld    repeat        ;rer failed, try next
  1037. chxx:
  1038.     call    next
  1039.     cpi    RBR
  1040.     jz    chyy        ;this was the last, quit
  1041.     cpi    ORR
  1042.     jnz    chxx
  1043.     shld    repeat
  1044.     jmp    chii
  1045. chyy:
  1046.     lhld    texx
  1047.     ori    00        ;emphasize the RBR
  1048. chzz:
  1049.     mov    c,l
  1050.     mov    b,h
  1051.     pop    h
  1052.     shld    repp
  1053.     pop    h
  1054.     shld    repeat
  1055.     pop    h
  1056.     shld    rest
  1057.     pop    h
  1058.     shld    texx
  1059.     pop    h
  1060.     shld    text
  1061.     mov    l,c
  1062.     mov    h,b
  1063.     ret
  1064.  
  1065. ;    Data area
  1066.  
  1067.     if    rcpm
  1068.  
  1069. usage    db    CR,LF,CR,LF
  1070.     db    'Usage:',CR,LF
  1071.     db    HT,'FIND filename.typ string[|string]'
  1072.     db    CR,LF,CR,LF
  1073.     db    'Where:',CR,LF
  1074.     db    HT,'filename.typ =',HT,'any CATALOG name, (* and ? allowed).'
  1075.     db    CR,LF
  1076.     db    HT,HT,HT,'CATALOG names are...'
  1077.     db    CR,LF,LF
  1078.     db    HT,HT,HT,'SIGM-1.AQL to SIGM-4.AQL, CPMCAT.AQL'
  1079.     db    CR,LF
  1080.     db    HT,HT,HT,'CUGCAT.AQL, MISC.AQL, PCBLUE.AQL'
  1081.     db    CR,LF
  1082.     db    CR,LF
  1083.     db    HT,'string',HT,'     =',HT,'any string of characters'
  1084.     db    CR,LF
  1085.     db    HT,HT,HT,'(* and ? not allowed).'
  1086.     db    CR,LF,LF
  1087.     db    HT,'|',HT,'     =',HT,'optional OR connector for multiple strings'
  1088.     db    CR,LF
  1089.     db    HT,HT,HT,'i.e. FIND MISC.AQL DOC|TXT'
  1090.     db    CR,LF,CR,LF
  1091.     db    'Type HELP THIS-SYS for a full description of FIND'
  1092.     db    CR,LF,0
  1093.     endif    ;rcpm
  1094.  
  1095.     if    not rcpm
  1096.  
  1097. usage    db    'The command line',CR,LF
  1098.     db    '     FYNDE D:FILE.EXT EXPRESSION',CR,LF
  1099.     db    'will search through all instances of FILE.EXT',CR,LF
  1100.     db    '(which may be an ambiguous reference) on disk D',CR,LF
  1101.     db    'to find lines containing EXPRESSION. Such lines',CR,LF
  1102.     db    'will be presented on the console preceded by a',CR,LF
  1103.     db    'line number, and classified by file. EXPRESSION',CR,LF
  1104.     db    'may have the form LABEL!PATTERN or simply the',CR,LF
  1105.     db    'form PATTERN. Both may contain:',CR,LF
  1106.     db    '     [p1!p2!...!pn]  alternative strings',CR,LF
  1107.     db    '     {p1!p2!...!pn}  repeated alternatives',CR,LF
  1108.     db    '     ? any single character',CR,LF
  1109.     db    '     @ for any alphanumeric: a-z, A-Z, 0-9',CR,LF
  1110.     db    '     _ in place of horizontal tab',CR,LF
  1111.     db    'When a label is present, lines will be numbered',CR,LF
  1112.     db    'relative to the label.  Example: X{?}:![call!ret]',CR,LF
  1113.     db    'will list calls and returns relative to labels',CR,LF
  1114.     db    'like X0100: or X33:. LABEL begins in column 1,',CR,LF
  1115.     db    'PATTERN can begin in any column. Squeezed files',CR,LF
  1116.     db    'will be searched as well as unsqueezed ones. Use',CR,LF
  1117.     db    '^C to quit, any other key skips rest of file.',CR,LF
  1118.     db    00
  1119.  
  1120.     endif    ;not rcpm
  1121.  
  1122. signon    db    CR,LF
  1123.     db    'FIND+ Version '
  1124.     db    VERS/10 + '0','.',VERS MOD 10 + '0'
  1125.     db    CR,LF,0
  1126.  
  1127. M3    db    '-- Bad Pattern --',00
  1128.  
  1129. M4    db    CR,LF,'-- Search Terminated --',00
  1130.  
  1131. M5    db    ' -- Remainder of File Skipped --',CR,LF,00
  1132.  
  1133. M8    db    ' -- Code Table Won''t Fit --',CR,LF,00
  1134.  
  1135. enth    ds    1
  1136. file    db    'DFilenameEXT',00
  1137.     ds    19
  1138.  
  1139. sqxx    ds    2
  1140. sqaa    ds    2
  1141. sqzz    ds    2
  1142. text    ds    2
  1143. texx    ds    2
  1144. rest    ds    2
  1145. repeat    ds    2
  1146. repp    ds    2
  1147.  
  1148.     ds    100        ;stack area
  1149. stak    ds    2        ;initialize stack pointer
  1150. lapo    ds    2        ;label pointer
  1151. papo    ds    2        ;pattern pointer
  1152. store    ds    2        ;name pointer
  1153. hesq    db    '[original]  '
  1154. uzfn    db    'original.xxx'    ;unsqueezed file's name
  1155.     db    CR,LF,00
  1156. fhed    db    CR,LF
  1157.     db    '----> File  '
  1158. fnam    db    'xxxxxxxx.'    ;filename
  1159. fext    db    'xxx',CR,LF,00    ;file extension
  1160. llbl    db    '      +'
  1161. lnum    db    '         ',00
  1162. lzer    db    '   0'
  1163. ftot    db    CR,LF
  1164.     db    '      matching lines found in this file.',CR,LF,00
  1165. dtot    db    '      matching lines in all the files searched.',CR,LF,00
  1166. ;
  1167. ;    Table of file types to exclude for searchhing
  1168. ;
  1169. table$start
  1170.     db    'COM'        ;CP/M command file
  1171.     db    'OBJ'        ;CP/M command file
  1172.     db    'LBR'        ;LU/LAR library file
  1173.     db    'CMD'        ;CP/M-86 command file
  1174.     db    'REL'        ;Relocatable file
  1175.     db    'C0M'        ;MSDOS command file
  1176.     db    'EXE'        ;MSDOS command file
  1177.     db    'OVR'        ;Overlay file
  1178.     db    'OVL'        ;Overlay file
  1179.     db    'CRL'        ;BDS C relocatable file
  1180.     db    'IRL'        ;Libarary file
  1181. table$end    
  1182. ;
  1183.     db    00        ;fence for line buffer
  1184. lbuf    ds    85H        ;line buffer
  1185. dens    ds    1        ;z/nz = un/squeezed
  1186. roby    ds    1        ;rotating byte
  1187. roco    ds    1        ;rotation count
  1188. mult    ds    1        ;r factor
  1189. lach    ds    1        ;last character read
  1190. ictr    ds    2        ;input counter
  1191. iptr    ds    2        ;input pointer
  1192. ibuf    ds    isiz        ;input buffer
  1193. patt    ds    256        ;command line pattern
  1194. code    ds    4*csiz        ;Huffman code table
  1195. fini    ds    0
  1196.  
  1197.     end
  1198.  
  1199.