! pfgrep - Fortran 90 で作られた grep(1) の模倣
!

program pfgrep
    use iso_varying_string
    use regex
    character(len = 80):: pattern, buf
    integer:: ios
    logical:: err
    read(*, "(A)", iostat=ios) pattern
    call nfa_compile(trim(pattern), err)
    if (err) stop "pfgrep: NFA_COMPILE fails"
    call nfa_dump
    call put_line('looking for pattern /' // trim(pattern) // '/')
    do
        read(*, "(A)", iostat=ios) buf
        if (ios /= 0) exit
	if (nfa_accept(automata, trim(buf))) then
            write(*, "(A)") char(27) // "[32m" // buf // char(27) // '[m'
	endif
    enddo
end program
