[UP]


Manual Reference Pages  - amatch (3)

NAME

amatch - look for pattern matching regular expression; returns its location (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
See Also
Diagnostics
Author
Reference
License

SYNOPSIS

loc = amatch(line, from, pat, tagbeg, tagend)

    character(len=*),intent(in) :: line
    integer,intent(in)          :: from
    character                   :: pat(MAXPAT)
    integer                     :: tagbeg(10), tagend(10)
    integer                     :: loc

DESCRIPTION

AMATCH scans LINE starting at location FROM, looking for a pattern which matches the regular expression coded in PAT. If the pattern is found, its starting location in LINE is returned. If the pattern is not found, AMATCH returns 0.

The regular expression in PAT must have been previously encoded by GETPAT(3f) or MAKPAT(3f). (For a complete description of regular expressions, see the manpage for M_BRE.)

AMATCH(3f) is a special-purpose version of MATCH(3f), which should be used in most cases.

OPTIONS

LINE input line to scan
FROM beginning location to start scan from
PAT coded regular expression encoded by GETPAT(3f) or MAKPAT(3f)
TAGBEG,TAGEND
  element "i + 1" returns start or end, respectively, of "i"th tagged subpattern

RETURNS

LOC returns location match was found or zero (0) if no match remains

EXAMPLE

Sample program:

    program demo_amatch
    use :: M_BRE, only : getpat, amatch
    use :: M_BRE, only : MAXPAT, MAXARG, MAXLINE, MAXTAGS, YES, ERR
    implicit none
    ! find _ find patterns in text
    integer                      :: pat(MAXPAT)
    character(len=MAXARG-1)      :: argument
    integer                      :: stat
    integer                      :: ios
    integer                      :: len_arg
    integer                      :: loc
    integer                      :: ii
    character(len=MAXLINE-2)     :: line
    integer                      :: tagbeg(MAXTAGS),tagend(MAXTAGS)
    call get_command_argument(1, argument,status=stat,length=len_arg)
    if(stat.ne.0.or.argument.eq.’’)then
       write(*,*)"usage: find pattern."
    elseif(getpat(argument(:len_arg), pat) .eq. ERR) then
       write(*,*)"illegal pattern."
    else
       INFINITE: do
          read(*,’(a)’,iostat=ios)line
          tagbeg=-9999;tagend=-9999
          if(ios.ne.0)exit
          loc = amatch(trim(line), 1, pat, tagbeg, tagend) ! returns location/0
          if(loc.gt.0)then ! matched; if no match, loc is returned as 0
             write(*,’(*(a))’)trim(line)
             ! (element "i + 1" returns start or end, respectively, of "i"th tagged subpattern)
             write(*,’(*(i0,1x,i0,1x,i0,/))’)(ii,tagbeg(ii),tagend(ii),ii=1,size(tagbeg))
          endif
       enddo INFINITE
    endif
    end program demo_amatch

SEE ALSO

match, getpat, makpat

DIAGNOSTICS

None

AUTHOR

John S. Urban

REFERENCE

"Software Tools" by Kernighan and Plauger , 1976

LICENSE

Public Domain


amatch (3) March 11, 2021
Generated by manServer 1.08 from a89f9574-a456-45d3-a391-1b8d02db215a using man macros.