match Interface

public interface match

Contents


Module Procedures

private function match_(lin, pat)

NAME

match(3f) - [M_MATCH] find match to a basic regular expression anywhere on input string
(LICENSE:PD)

SYNOPSIS

integer function match(line, pattern)

 character(len=*),intent(in) :: line
 integer,intent(in)          :: pattern(MAXPAT)

DESCRIPTION

Given a BRE(Basic Regular Expression) converted to a pattern return whether an input string matches it.

OPTIONS

LIN  string to search for a match to the pattern
PAT  pattern generated from a BRE using getpat(3f) or makpat(3f).

EXAMPLE

Sample program:

 program demo_match
 use :: M_match, only : getpat, match
 use :: M_match, only : MAXPAT, MAXARG, MAXLINE, YES, ERR
 implicit none
 ! find _ find patterns in text
 integer                      :: pat(MAXPAT)
 character(len=MAXARG-1)      :: argument
 integer                      :: stat
 integer                      :: ios
 integer                      :: len_arg
 character(len=MAXLINE-2)     :: line
 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
       if(ios.ne.0)exit
       if(match(trim(line), pat) .eq. YES) then
          write(*,'(*(a))')trim(line)
       endif
    enddo INFINITE
 endif
 end program demo_match

AUTHOR

John S. Urban

REFERENCE

“Software Tools” by Kernighan and Plauger , 1976

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
integer(kind=chr) :: lin(maxline)
integer(kind=chr) :: pat(maxpat)

Return Value integer(kind=def)

private function match__(lin_str, pat)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: lin_str
integer(kind=chr) :: pat(maxpat)

Return Value integer(kind=def)