home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol165 / fynde.asn < prev    next >
Encoding:
Text File  |  1984-07-09  |  11.2 KB  |  673 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. ;        label+line number as an alternative to line number.
  11. ;        instance count reported, both per file and globally
  12. ;    To achieve compatibility with MicroShell the vertical bar
  13. ;    was replaced by exclamation point; all syntactic elements
  14. ;    are defined by equ's and may be redefined. LABEL!PATTERN
  15. ;    is checked for balanced parentheses and non-null arguments
  16. ;    to forestall the most common failure modes. Had MicroShell
  17. ;    not been available, an option to direct the output to some
  18. ;    disk file would probably have been included. This is the
  19. ;    Intel 8086 version, transformed with TRANS86 and revised.
  20. ;
  21. ;            FYNDE.ASN   Copyright (C) 1982
  22. ;            Universidad Autonoma de Puebla
  23. ;
  24. ;    [Harold V. McIntosh, 20 December 1982]
  25. ;    ----------------------------------------------------------
  26.  
  27. HT    equ    09H        ;horizontal tab
  28. LF    equ    0AH        ;line feed
  29. CR    equ    0DH        ;carriage return
  30.  
  31. ;    Delimiters for the command line
  32.  
  33. LSQ    equ    '['        ;begin alternative list
  34. RSQ    equ    ']'        ;end alternative list
  35. LBR    equ    '{'        ;begin iterated expression
  36. RBR    equ    '}'        ;end iterated expression
  37. ORR    equ    '!'        ;separate alternatives
  38.  
  39. ;    Representatives of characters or classes.
  40.  
  41. TAB    equ    '_'        ;substitute for tab
  42. QUE    equ    '?'        ;represent any byte
  43. ALF    equ    '@'        ;represent any alphanumeric
  44.  
  45. bdos    equ    224        ;CP/M interrupt to BDOS
  46.  
  47. ksiz    equ    40        ;records in IN buffer
  48. isiz    equ    ksiz*128    ;bytes in IN buffer
  49.  
  50.     org    100H
  51.  
  52. X0100:    ld    al,005DH    ;file name
  53.     cmp    al,#' '
  54.     jnz    X0143
  55.     ld    bx,#M1
  56.     call    mssg
  57. exit:    ld    dl,#00
  58.     ld    cl,#00
  59.     int    bdos
  60.  
  61. X0143:    ld    bx,#M2
  62.     call    mssg
  63.     ld    ah,#12
  64.     ld    dx,#005CH
  65.     ld    bx,#file
  66.     call    miuc
  67.     stob    #00,enth
  68.     ld    bx,#0080H    ;CP/M's sector buffer
  69.     ld    dl,[bx]
  70.     mov    cl,dl
  71.     ld    dh,#00
  72.     xchg    bx,dx
  73.     inc    dx
  74.     add    bx,dx
  75.     stob    #00,[bx]
  76.     xchg    bx,dx
  77. X0152:    inc    bx
  78.     dec    cl
  79.     cmpb    [bx],#00
  80.     jnz    :G2
  81.     jmp    X029C
  82. :G2    cmpb    [bx],#' '
  83.     jnz    X0152
  84.     inc    bx
  85.     call    bala        ;check balance of [], {}.
  86.     call    nula        ;check for null alternatives
  87.     ld    dx,#patt    ;command line pattern
  88.     call    muve
  89.     ld    ah,#4
  90.     ld    dx,#lzer
  91.     ld    bx,#dtot
  92.     call    miuc
  93.     sto    #0000,lapo
  94.     ld    bx,#patt    ;command line pattern
  95.     sto    bx,papo
  96.     call    next
  97.     or    al,al
  98.     jz    scan
  99.     sto    bx,papo
  100.     sto    #patt,lapo
  101.  
  102. ;    Scan the directory for file names.
  103.  
  104. scan:    ld    cl,#26        ;(1A) set DMA address
  105.     ld    dx,#0080H    ;CPM's sector buffer
  106.     int    bdos        ; - B D O S -
  107.     ld    cl,#17        ;(11) search once
  108.     ld    dx,#file
  109.     int    bdos        ; - B D O S -
  110.     incb    enth
  111.     ld    cl,enth
  112. fnth:    inc    al
  113.     jz    done        ;we're all done
  114.     dec    cl
  115.     jz    this
  116.     push    cx
  117.     ld    cl,#18        ;(12) search again
  118.     ld    dx,#file
  119.     int    bdos        ; - B D O S -
  120.     pop    cx
  121.     jmp    fnth
  122.  
  123. ;    We're all done so output summary, then exit.
  124.  
  125. done:    ld    bx,#dtot
  126.     call    mssg
  127.     jmp    exit
  128.  
  129. ;    A prospective file has been located
  130.  
  131. this:    dec    al
  132.     and    al,#03
  133.     add    al,al
  134.     add    al,al
  135.     add    al,al
  136.     add    al,al
  137.     add    al,al
  138.     add    al,#81H
  139.     mov    dl,al
  140.     ld    dh,#00
  141.     ld    ah,#12
  142.     ld    bx,#005DH
  143.     call    miuc
  144.     ld    cl,#15        ;(0F) open file
  145.     ld    dx,#005CH    ;CP/M's FCB
  146.     int    bdos        ; - B D O S -
  147.     inc    al
  148.     jnz    :G6
  149.     jmp    exit        ;quit [without message]
  150. :G6    sto    #00,007CH    ;block pointer
  151.  
  152.     ld    ah,#4
  153.     ld    dx,#lzer
  154.     ld    bx,#ftot
  155.     call    miuc
  156.     ld    ah,#4
  157.     ld    dx,#lzer
  158.     ld    bx,#lnum    ;'line number'
  159.     call    miuc
  160.     ld    ah,#8
  161.     ld    dx,#005DH    ;file name
  162.     ld    bx,#fnam    ;'file name'
  163.     call    miuc
  164.     ld    ah,#3
  165.     ld    dx,#0065H    ;extension
  166.     ld    bx,#fext    ;'file extension'
  167.     call    miuc
  168.     ld    bx,#fhed
  169.     call    mssg        ;message to console
  170.     ld    ax,#0620H    ;six spaces
  171.     ld    bx,#llbl
  172.     call    fiuc
  173.  
  174. X01C2:    sto    #0000,ictr
  175. X01C8:    ld    bx,#lnum+3    ;increment l.c.
  176.     call    inco
  177.     ld    bx,#lbuf    ;line buffer
  178.     ld    ch,#0FFH    ;limit on line length
  179. X01E0:    inc    ch
  180.     js    X01FD
  181.     push    cx
  182.     push    bx
  183.     call    inch        ;char from big bffr to line bffr
  184.     pop    bx
  185.     pop    cx
  186.     sto    al,[bx]
  187.     inc    bx
  188.     cmp    al,#1AH
  189.     jnz    X01E8
  190.     ld    bx,#ftot
  191.     call    mssg
  192.     jmp    scan
  193. X01E8:    cmp    al,#LF
  194.     jnz    X01E0
  195.     jmp    X0202
  196.  
  197. X01FD:    stob    #CR,[bx]
  198.     inc    bx
  199.     stob    #LF,[bx]
  200.     inc    bx
  201.  
  202. ;    Check console for termination request, which may
  203. ;    be generated by pressing any key. Clear out the
  204. ;    requesting character before leaving.
  205.  
  206. X0202:    stob    #00,[bx]    ;guarantee right hand fence
  207.     ld    cl,#11        ;(0B) console status
  208.     int    bdos        ; - B D O S -
  209.     or    al,al
  210.     jz    culi        ;scan the current line
  211.     ld    cl,#1        ;(01) read console
  212.     int    bdos        ; - B D O S -
  213.     ld    bx,#M4        ;"search terminated"
  214.     call    mssg
  215.     jmp    exit
  216.  
  217. ;    Scan the current line.
  218. ;    First, see if it is labelled.
  219.  
  220. culi:    ld    dx,lapo
  221.     or    dx,dx
  222.     jz    X0217        ;no label requested
  223.     ld    bx,#lbuf
  224.     call    chek
  225.     jnz    X0217        ;label not found
  226.     push    bx
  227.     ld    ax,#0620H
  228.     ld    bx,#llbl
  229.     call    fiuc
  230.     pop    bx
  231.     ld    dx,#llbl+5
  232.     ld    ah,#6
  233. didl:    dec    bx
  234.     ld    al,[bx]
  235.     cmp    al,#HT        ;ignore tabs in text
  236.     jz    didl
  237.     cmp    al,#' '        ;quit at head of line
  238.     jc    dido
  239.     xchg    bx,dx
  240.     sto    al,[bx]
  241.     xchg    bx,dx
  242.     dec    dx
  243.     dec    ah
  244.     jnz    didl
  245. dido:    ld    ah,#4
  246.     ld    dx,#lzer
  247.     ld    bx,#lnum
  248.     call    miuc
  249.  
  250. ;    Now look for the pattern
  251.  
  252. X0217:    ld    bx,#lbuf    ;line buffer
  253. X021A:    ld    dx,papo        ;pattern pointer
  254.     push    bx
  255.     call    chek
  256.     pop    bx
  257.     jz    X0263
  258.     inc    bx
  259.     cmpb    [bx],#CR
  260.     jnz    X021A
  261.     jmp    X01C8        ;increment l.c. at X026A
  262.  
  263. ;    This line contains the pattern.
  264.  
  265. X0263:    ld    bx,#llbl    ;line label
  266.     call    mssg        ;mssg to console
  267.     ld    bx,#lbuf    ;line buffer
  268.     call    mssg        ;mssg to console
  269.     ld    bx,#ftot+3
  270.     call    inco
  271.     ld    bx,#dtot+3
  272.     call    inco
  273.     jmp    X01C8        ;increment l.c. at X026A
  274.  
  275. ;    Increment an ASCII counter
  276.  
  277. inco:    orb    [bx],#30H
  278.     incb    [bx]
  279.     cmpb    [bx],#':'
  280.     jnz    incr
  281.     stob    #'0',[bx]
  282.     dec    bx
  283.     jmp    inco
  284. incr:    ret
  285.  
  286. ;    Memory to console
  287.  
  288. mssg:    ld    dl,[bx]
  289.     inc    bx
  290.     push    bx
  291.     ld    cl,#2        ;(02) write console
  292.     int    bdos        ; - B D O S -
  293.     pop    bx
  294.     cmpb    [bx],#00
  295.     jnz    mssg
  296.     ret
  297.  
  298. X029C:    ld    bx,#M3        ;"bad pattern"
  299.     call    mssg
  300.     jmp    exit
  301.  
  302. ;    Move a character from the big buffer to the line
  303. ;    buffer, replenishing the big buffer when it is
  304. ;    exhausted.
  305.  
  306. inch:    cmp    ictr,#0000
  307.     jnz    incc
  308.     call    indi
  309. incc:    dec    ictr
  310.     ld    bx,iptr
  311.     ld    al,[bx]
  312.     cmp    al,#1AH
  313.     jz    inrr
  314.     inc    iptr
  315. inrr:    ret
  316.  
  317. indi:    ld    al,#ksiz
  318.     sto    #isiz,ictr
  319.     sto    #ibuf,iptr
  320.     ld    dx,iptr
  321. indd:    push    dx
  322.     push    ax
  323.     ld    cl,#26        ;(1A) set DMA address
  324.     int    bdos        ; -B D O S -
  325.     ld    dx,#005CH    ;CP/M's FCB
  326.     ld    cl,#20        ;(14) read one record
  327.     int    bdos        ; - B D O S -
  328.     or    al,al
  329.     jnz    inee
  330.     pop    ax
  331.     pop    dx
  332.     dec    al
  333.     jz    inss
  334.     add    dx,#0080H
  335.     jmp    indd
  336.  
  337. inee:    pop    ax
  338.     pop    dx
  339.     sto    #1AH,[bx]
  340. inss:    ret
  341.  
  342. ;    Advance to next alternative
  343.  
  344. nexr:    ret
  345. nexx:    ld    bx,[bx]
  346. next:    ld    al,[bx]
  347.     or    al,al
  348.     jz    nexr
  349.     inc    bx
  350.     call    enda
  351.     jz    nexr
  352.     call    begb
  353.     jz    nexx
  354.     jmp    next
  355.  
  356. fiuc:    sto    al,[bx]
  357.     inc    bx
  358.     dec    ah
  359.     jnz    fiuc
  360.     ret
  361.  
  362. miuc:    xchg    bx,dx
  363.     ld    al,[bx]
  364.     xchg    bx,dx
  365.     sto    al,[bx]
  366.     inc    dx
  367.     inc    bx
  368.     dec    ah
  369.     jnz    miuc
  370.     ret
  371.  
  372. ;    Move and semi-compile the command line.
  373.  
  374. muve:    ld    al,[bx]
  375.     cmp    al,#TAB
  376.     jnz    munt
  377.     ld    al,#HT
  378. munt:    xchg    bx,dx
  379.     sto    al,[bx]
  380.     xchg    bx,dx
  381.     inc    bx
  382.     inc    dx
  383.     cmp    al,#RBR
  384.     jz    murb
  385.     cmp    al,#RSQ
  386.     jz    murb
  387.     cmp    al,#LBR
  388.     jz    mulb
  389.     cmp    al,#LSQ
  390.     jz    mulb
  391. must:    dec    cl
  392.     jnz    muve
  393.     ret
  394.  
  395. murb:    mov    ax,bx
  396.     pop    bx
  397.     sto    dx,[bx]
  398.     mov    bx,ax
  399.     jmp    must
  400.  
  401. mulb:    push    dx
  402.     inc    dx
  403.     inc    dx
  404.     jmp    must
  405.  
  406. ;    Check balance of []'s and {}'s.
  407.  
  408. bala:    push    bx
  409.     push    cx
  410.     ld    cx,#0101H
  411. balb:    ld    al,[bx]
  412.     inc    bx
  413.     cmp    al,#LSQ
  414.     jnz    balc
  415.     inc    ch
  416.     jmp    balb
  417. balc:    cmp    al,#RSQ
  418.     jnz    bald
  419.     dec    ch
  420.     jz    balx
  421.     jmp    balb
  422. bald:    cmp    al,#LBR
  423.     jnz    bale
  424.     inc    cl
  425.     jmp    balb
  426. bale:    cmp    al,#RBR
  427.     jnz    balf
  428.     dec    cl
  429.     jz    balx
  430.     jmp    balb
  431. balf:    or    al,al
  432.     jnz    balb
  433.     mov    al,cl
  434.     cmp    al,#01
  435.     jnz    balx
  436.     mov    al,ch
  437.     cmp    al,#01
  438.     pop    cx
  439.     pop    bx
  440.     jz    balr
  441. balx:    ld    bx,#M3        ;"bad pattern"
  442.     call    mssg
  443.     jmp    exit        ;PDL unbalanced but doesn't matter
  444. balr:    ret
  445.  
  446. ;    Check for termination of alternative.
  447.  
  448. enda:    cmp    al,#ORR
  449.     jz    endr
  450.     cmp    al,#RSQ
  451.     jz    endr
  452.     cmp    al,#RBR
  453.     jz    endr
  454.     or    al,al
  455. endr:    ret
  456.  
  457. ;    Check for beginning of alternative.
  458.  
  459. bega:    cmp    al,#ORR
  460.     jz    begr
  461. begb:    cmp    al,#LSQ
  462.     jz    begr
  463.     cmp    al,#LBR
  464. begr:    ret
  465.  
  466. ;    Check for null alternative.
  467.  
  468. nula:    push    bx
  469.     call    nulb
  470.     pop    bx
  471. nulr:    ret
  472. nulb:    ld    al,[bx]
  473.     inc    bx
  474.     or    al,al
  475.     jz    nulr
  476.     call    bega
  477.     jnz    nulb
  478.     ld    al,[bx]
  479.     call    enda
  480.     jnz    nulb
  481.     jmp    balx
  482.  
  483. ;    Check for given expression.
  484.  
  485. chek:    ld    ah,[bx]
  486.     xchg    bx,dx
  487.     ld    al,[bx]
  488.     xchg    bx,dx
  489.     inc    dx
  490.     call    enda
  491.     jz    chre
  492.     cmp    ah,#CR
  493.     jz    chno
  494.     cmp    al,#LBR
  495.     jnz    :G41
  496.     jmp    chlb
  497. :G41    cmp    al,#LSQ
  498.     jnz    :G42
  499.     jmp    chsq
  500. :G42    inc    bx
  501.     cmp    al,#QUE
  502.     jz    chek
  503.     cmp    al,#ALF
  504.     jz    chal
  505.     cmp    al,ah
  506.     jz    chek
  507.     cmp    ah,#'a'
  508.     jc    chno
  509.     cmp    ah,#'{'
  510.     jnc    chno
  511.     and    ah,#05FH
  512.     cmp    al,ah
  513.     jz    chek
  514. chno:    or    al,#0FFH
  515. chre:    ret
  516.  
  517. ;    Check alphanumeric.
  518.  
  519. chal:    cmp    ah,#'0'
  520.     jc    chno
  521.     cmp    ah,#':'
  522.     jc    chek
  523.     cmp    ah,#'A'
  524.     jc    chno
  525.     cmp    ah,#'['
  526.     jc    chek
  527.     cmp    ah,#'a'
  528.     jc    chno
  529.     cmp    ah,#'{'
  530.     jc    chek
  531.     jmp    chno
  532.  
  533. ;    Check list of alternatives.
  534.  
  535. chsq:    push    sqxx
  536.     push    sqaa
  537.     push    sqzz
  538.     sto    bx,sqxx
  539.     xchg    bx,dx
  540.     ld    dx,[bx]
  541.     inc    bx
  542.     inc    bx
  543.     sto    bx,sqaa
  544.     xchg    bx,dx
  545.     sto    bx,sqzz
  546. chaa:    ld    bx,sqxx
  547.     call    chek
  548.     jz    chff
  549. chbb:    ld    bx,sqaa        ;fail so find next alternative
  550. chcc:    call    next
  551.     cmp    al,#RSQ
  552.     jz    chdd        ;no more alternatives, so fail
  553.     cmp    al,#ORR
  554.     jnz    chcc
  555.     sto    bx,sqaa
  556.     xchg    bx,dx
  557.     jmp    chaa        ;try next alternative
  558. chdd:    ld    bx,sqxx
  559.     or    al,#0FFH
  560. chee:    pop    sqzz
  561.     pop    sqaa
  562.     pop    sqxx
  563.     ret
  564. chff:    ld    dx,sqzz        ;good alternative, try rest
  565.     call    chek
  566.     jz    chee
  567.     jmp    chbb
  568.  
  569. ;    Check iterative pattern.
  570.  
  571. chlb:    push    text
  572.     push    texx
  573.     push    rest
  574.     push    rept
  575.     push    repp
  576.     sto    bx,text
  577.     sto    bx,texx
  578.     xchg    bx,dx
  579.     ld    dx,[bx]
  580.     inc    bx
  581.     inc    bx
  582.     sto    bx,rept
  583.     sto    bx,repp
  584.     sto    dx,rest
  585. chlc:    ld    dx,rest
  586.     ld    bx,text
  587.     call    chek        ;check rest
  588.     jz    chzz
  589. chii:    ld    dx,rept        ;rest failed
  590.     ld    bx,text        ;keep same text
  591.     call    chek        ;try out the repeater
  592.     jnz    choo
  593.     sto    bx,text        ;repeater worked, record progress
  594.     ld    bx,repp        ;start alternatives over again
  595.     sto    bx,rept
  596.     jmp    chlc
  597. choo:    ld    bx,rept        ;repeater failed, try next
  598. chxx:    call    next
  599.     cmp    al,#RBR
  600.     jz    chyy        ;this was the last, quit
  601.     cmp    al,#ORR
  602.     jnz    chxx
  603.     sto    bx,rept
  604.     jmp    chii
  605. chyy:    ld    bx,texx
  606.     or    al,#00        ;emphasize the RBR
  607. chzz:    pop    repp
  608.     pop    rept
  609.     pop    rest
  610.     pop    texx
  611.     pop    text
  612.     ret
  613.  
  614. M1:    db    'The command line',CR,LF
  615.     db    '     FYNDE D:FILE.EXT EXPRESSION',CR,LF
  616.     db    'will search through all instances of FILE.EXT',CR,LF
  617.     db    '(which may be an ambiguous reference) on disk D',CR,LF
  618.     db    'to find lines containing EXPRESSION. Such lines',CR,LF
  619.     db    'will be presented on the console preceded by a',CR,LF
  620.     db    'line number, and classified by file. EXPRESSION',CR,LF
  621.     db    'may have the form LABEL!PATTERN or simply the',CR,LF
  622.     db    'form PATTERN. Both may contain:',CR,LF
  623.     db    '     [p1!p2!...!pn]  alternative strings',CR,LF
  624.     db    '     {p1!p2!...!pn}  repeated alternatives',CR,LF
  625.     db    '     ? any single character',CR,LF
  626.     db    '     @ for any alphanumeric: a-z, A-Z, 0-9',CR,LF
  627.     db    '     _ in place of horizontal tab',CR,LF
  628.     db    'When a label is present, lines will be numbered',CR,LF
  629.     db    'relative to the label.  Example: X{?}:![call!ret]',CR,LF
  630.     db    'will list calls and returns relative to labels',CR,LF
  631.     db    'like X0100: or X33:. LABEL begins in column 1,',CR,LF
  632.     db    'PATTERN can begin in any column.',CR,LF,00
  633.  
  634. M2:    db    'FYNDE.CMD 12/20/82 ICUAP',CR,LF,00
  635.  
  636. M3:    db    '-- Bad Pattern --',00
  637.  
  638. M4:    db    CR,LF,'-- Search Terminated --',00
  639.  
  640. enth:    ds    1
  641. file:    db    'DFilenameEXT',00
  642.     ds    19
  643.  
  644. sqxx:    ds    2
  645. sqaa:    ds    2
  646. sqzz:    ds    2
  647. text:    ds    2
  648. texx:    ds    2
  649. rest:    ds    2
  650. rept:    ds    2
  651. repp:    ds    2
  652.  
  653. patt:    ds    256        ;command line pattern
  654. X0492:    ds    2        ;end of stack
  655. lapo:    ds    2        ;label pointer
  656. papo:    ds    2        ;pattern pointer
  657. fhed:    db    '~~~~~~> File '
  658. fnam:    db    'xxxxxxxx.'    ;filename
  659. fext:    db    'xxx',CR,LF,00    ;file extension
  660. llbl:    db    '      +'
  661. lnum:    db    '         ',00
  662. lzer:    db    '   0'
  663. ftot:    db    '      lines found',CR,LF,00
  664. dtot:    db    '      instances throughout the disk',CR,LF,00
  665.     db    00        ;fence for line buffer
  666. lbuf:    ds    85H        ;line buffer
  667. ictr:    ds    2
  668. iptr:    ds    2
  669. ibuf:    ds    isiz
  670. fini:    ds    0
  671.  
  672.     END
  673.