

            amatch (2) --- look for pattern match at specific location  05/29/82


            _C_a_l_l_i_n_g _I_n_f_o_r_m_a_t_i_o_n

                 integer function amatch (lin, from, pat, tagbeg, tagend)
                 character lin (ARB), pat (MAXPAT)
                 integer from, tagbeg (9), tagend (9)

                 Library:  vswtlb (standard Subsystem library)


            _F_u_n_c_t_i_o_n

                 'Amatch'  checks the substring of the line 'lin' starting at
                 position 'from' to see if it matches the pattern  in  'pat'.
                 'Pat' must have been created by the utility routine 'makpat'
                 beforehand.  If a match occurs, then the arrays 'tagbeg' and
                 'tagend'  are  used  to  record the beginning and end of any
                 tagged subpatterns  that  appeared  in  'pat'  (i.e.,  'tag-
                 beg(N+1)'  contains  the  index in 'lin' of the start of the
                 Nth tagged subpattern, 'tagend(N+1)' contains the  index  in
                 'lin'  of  the  end of the Nth subpattern, while 'tagbeg(1)'
                 and 'tagend(1)' bracket the  entire  matched  string).   The
                 function  return is the index of the next unexamined charac-
                 ter in 'lin' if a match was found, zero otherwise.


            _I_m_p_l_e_m_e_n_t_a_t_i_o_n

                 'Amatch' steps through successive entries  in  the  pattern,
                 attempting  to match them against the line of text.  Most of
                 the complexity arises in handling closures;  'amatch'  calls
                 'omatch' repeatedly to match the longest possible substring,
                 then backs up as necessary to make the remainder of the pat-
                 tern  match.  This may involve multiple backups, since there
                 may be more than one closure in a pattern.

                 'Omatch' is called to match all single  non-closure  pattern
                 elements.   If  'omatch'  fails,  then  the stack of pending
                 closures is examined.  If empty, 'amatch' returns  zero;  if
                 non-empty, 'amatch' reduces the last closure and attempts to
                 match again.

                 Whenever  a  pattern  tag  (open  brace  or  close brace) is
                 encountered in the pattern,  'amatch'  records  the  current
                 offset  in  the  line  in 'tagbeg' or 'tagend', whichever is
                 appropriate.


            _A_r_g_u_m_e_n_t_s _M_o_d_i_f_i_e_d

                 tagbeg, tagend


            _C_a_l_l_s

                 omatch, patsiz



            amatch (2)                    - 1 -                    amatch (2)




            amatch (2) --- look for pattern match at specific location  05/29/82


            _B_u_g_s

                 Rather slow.


            _S_e_e _A_l_s_o

                 match (2), makpat (2), omatch (2), find (1), ed (1), se (1)


















































            amatch (2)                    - 2 -                    amatch (2)


