Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Scientists are people who build the Brooklyn Bridge and then buy it. -- William Buckley


devel / comp.lang.fortran / Re: Globmatch module from FLIBS

SubjectAuthor
* Globmatch module from FLIBSPrestonMag
`* Re: Globmatch module from FLIBSgah4
 `* Re: Globmatch module from FLIBSJohn
  `* Re: Globmatch module from FLIBSJohn
   `* Re: Globmatch module from FLIBSPrestonMag
    `- Re: Globmatch module from FLIBSJohn

1
Globmatch module from FLIBS

<af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2698&group=comp.lang.fortran#2698

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:2548:b0:6b6:113d:34fd with SMTP id s8-20020a05620a254800b006b6113d34fdmr136095qko.132.1660774250355;
Wed, 17 Aug 2022 15:10:50 -0700 (PDT)
X-Received: by 2002:a81:1d09:0:b0:31d:a40:8332 with SMTP id
d9-20020a811d09000000b0031d0a408332mr260392ywd.138.1660774250108; Wed, 17 Aug
2022 15:10:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Wed, 17 Aug 2022 15:10:49 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=86.23.219.49; posting-account=nxI9QQoAAAAghgXsH3J6SCzhIkUuJyQQ
NNTP-Posting-Host: 86.23.219.49
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>
Subject: Globmatch module from FLIBS
From: prestonmag@gmail.com (PrestonMag)
Injection-Date: Wed, 17 Aug 2022 22:10:50 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5528
 by: PrestonMag - Wed, 17 Aug 2022 22:10 UTC

I have an old version of the source code for FLIBS. I have been using the globmatching module from the strings group. Tracking down an error it seems to me that the string_match function always returns false if the last character in the pattern is a "?" wildcard. Is this a known fault and does anyone know a solution please?

My test version allows a user defined 5 character pattern to be checked against the 5 character string "ALERT"

A pattern of "ALER?" returns false when it should return true.

I am using Gfortran version 11.2 running under Code::blocks.

My test code is
program TestGlobMatch

implicit none

character*5 String/'ALERT'/
character*5 pattern/'ALER?'/
character*1 c1
logical mymatch, string_match

print *, "Hello TestGlobMatch World!"
write(*,fmt="(a)") ' '
write(*.fmt="(A,$)") 'Enter 5 charactacter pattern: '
read(*,fmt="(a)") pattern

write(*,fmt="(5A)") "String = <",string,">, Pattern = <",pattern,">"
! write(*,fmt="(3A)") "Pattern = <",pattern,">"

mymatch = string_match(String,pattern)
write(*,fmt="(A,L,A)") "Match returned as <",mymatch,">"

write(*,fmt="(A,$)") "Hit enter "
read(*,fmt="(A)") c1

end program
recursive function string_match( string, pattern ) result(match)
implicit none

character(len=1), parameter :: backslash = '\'
character(len=1), parameter :: star = '*'
character(len=1), parameter :: question = '?'
character(len=*), intent(in) :: string
character(len=*), intent(in) :: pattern
logical :: match

character(len=len(pattern)) :: literal
integer :: ptrim
integer :: p
integer :: k
integer :: ll
integer :: method
integer :: start
integer :: strim

match = .false.
method = 0
ptrim = len_trim( pattern )
strim = len_trim( string )
p = 1
ll = 0
start = 1

!
! Split off a piece of the pattern
!
do while ( p <= ptrim )
select case ( pattern(p:p) )
case( star )
if ( ll .ne. 0 ) exit
method = 1
case( question )
if ( ll .ne. 0 ) exit
method = 2
start = start + 1
case( backslash )
p = p + 1
ll = ll + 1
literal(ll:ll) = pattern(p:p)
case default
ll = ll + 1
literal(ll:ll) = pattern(p:p)
end select

p = p + 1
enddo

!
! Now look for the literal string (if any!)
!
if ( method == 0 ) then
!
! We are at the end of the pattern, and of the string?
!
if ( strim == 0 .and. ptrim == 0 ) then
match = .true.
else
!
! The string matches a literal part?
!
if ( ll > 0 ) then
if ( string(start:min(strim,start+ll-1)) == literal(1:ll) ) then
start = start + ll
match = string_match( string(start:), pattern(p:) )
endif
endif
endif
endif

if ( method == 1 ) then
!
! Scan the whole of the remaining string ...
!
if ( ll == 0 ) then
match = .true.
else
do while ( start <= strim )
k = index( string(start:), literal(1:ll) )
if ( k > 0 ) then
start = start + k + ll - 1
match = string_match( string(start:), pattern(p:) )
if ( match ) then
exit
endif
endif

start = start + 1
enddo
endif
endif

if ( method == 2 .and. ll > 0 ) then
!
! Scan the whole of the remaining string ...
!
if ( string(start:min(strim,start+ll-1)) == literal(1:ll) ) then
match = string_match( string(start+ll:), pattern(p:) )
endif
endif
return
end function string_match

Re: Globmatch module from FLIBS

<bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2699&group=comp.lang.fortran#2699

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:20ed:b0:476:dde3:ed29 with SMTP id 13-20020a05621420ed00b00476dde3ed29mr440480qvk.102.1660776756241;
Wed, 17 Aug 2022 15:52:36 -0700 (PDT)
X-Received: by 2002:a81:bb41:0:b0:328:fd1b:5713 with SMTP id
a1-20020a81bb41000000b00328fd1b5713mr379542ywl.238.1660776756052; Wed, 17 Aug
2022 15:52:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Wed, 17 Aug 2022 15:52:35 -0700 (PDT)
In-Reply-To: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:193c:7fe3:f557:7af4;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:193c:7fe3:f557:7af4
References: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com>
Subject: Re: Globmatch module from FLIBS
From: gah4@u.washington.edu (gah4)
Injection-Date: Wed, 17 Aug 2022 22:52:36 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1527
 by: gah4 - Wed, 17 Aug 2022 22:52 UTC

(snip)

> if ( method == 2 .and. ll > 0 ) then
> !
> ! Scan the whole of the remaining string ...
> !
> if ( string(start:min(strim,start+ll-1)) == literal(1:ll) ) then
> match = string_match( string(start+ll:), pattern(p:) )
> endif
> endif
> return
> end function string_match

If method==2 and ll==0 then you should return .true.

Re: Globmatch module from FLIBS

<17327aab-54aa-4f4d-90dd-345cb40b4f72n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2700&group=comp.lang.fortran#2700

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:6905:0:b0:6bb:5827:e658 with SMTP id e5-20020a376905000000b006bb5827e658mr497719qkc.735.1660784021142;
Wed, 17 Aug 2022 17:53:41 -0700 (PDT)
X-Received: by 2002:a25:41d8:0:b0:692:93c:f950 with SMTP id
o207-20020a2541d8000000b00692093cf950mr791047yba.313.1660784019936; Wed, 17
Aug 2022 17:53:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Wed, 17 Aug 2022 17:53:39 -0700 (PDT)
In-Reply-To: <bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:3127:4a75:68fb:8ffa;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:3127:4a75:68fb:8ffa
References: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com> <bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <17327aab-54aa-4f4d-90dd-345cb40b4f72n@googlegroups.com>
Subject: Re: Globmatch module from FLIBS
From: urbanjost@comcast.net (John)
Injection-Date: Thu, 18 Aug 2022 00:53:41 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1464
 by: John - Thu, 18 Aug 2022 00:53 UTC

The glob() procedure in

https://github.com/urbanjost/M_strings

is similar and there is a relatively extensive test program included. It is PD and I think (not sure) the FLIB procedure might be GPL licensed, if that makes a difference.

Re: Globmatch module from FLIBS

<ac207e79-4260-482f-91e2-9d332fdcb8d8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2701&group=comp.lang.fortran#2701

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:e6c:b0:476:a4bd:2b95 with SMTP id jz12-20020a0562140e6c00b00476a4bd2b95mr538806qvb.25.1660786241192;
Wed, 17 Aug 2022 18:30:41 -0700 (PDT)
X-Received: by 2002:a81:8a87:0:b0:333:a706:2734 with SMTP id
a129-20020a818a87000000b00333a7062734mr745472ywg.431.1660786241016; Wed, 17
Aug 2022 18:30:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Wed, 17 Aug 2022 18:30:40 -0700 (PDT)
In-Reply-To: <17327aab-54aa-4f4d-90dd-345cb40b4f72n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:3127:4a75:68fb:8ffa;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:3127:4a75:68fb:8ffa
References: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>
<bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com> <17327aab-54aa-4f4d-90dd-345cb40b4f72n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ac207e79-4260-482f-91e2-9d332fdcb8d8n@googlegroups.com>
Subject: Re: Globmatch module from FLIBS
From: urbanjost@comcast.net (John)
Injection-Date: Thu, 18 Aug 2022 01:30:41 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1333
 by: John - Thu, 18 Aug 2022 01:30 UTC

https://fortranwiki.org/fortran/show/match_wild

Re: Globmatch module from FLIBS

<17942267-71f0-4f77-9728-380589a84ea2n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2703&group=comp.lang.fortran#2703

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ae9:ed89:0:b0:6bb:9968:de30 with SMTP id c131-20020ae9ed89000000b006bb9968de30mr1463878qkg.774.1660817676265;
Thu, 18 Aug 2022 03:14:36 -0700 (PDT)
X-Received: by 2002:a25:f8a:0:b0:672:3e36:ee36 with SMTP id
132-20020a250f8a000000b006723e36ee36mr2002536ybp.523.1660817675880; Thu, 18
Aug 2022 03:14:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 18 Aug 2022 03:14:35 -0700 (PDT)
In-Reply-To: <ac207e79-4260-482f-91e2-9d332fdcb8d8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=86.23.219.49; posting-account=nxI9QQoAAAAghgXsH3J6SCzhIkUuJyQQ
NNTP-Posting-Host: 86.23.219.49
References: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>
<bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com> <17327aab-54aa-4f4d-90dd-345cb40b4f72n@googlegroups.com>
<ac207e79-4260-482f-91e2-9d332fdcb8d8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <17942267-71f0-4f77-9728-380589a84ea2n@googlegroups.com>
Subject: Re: Globmatch module from FLIBS
From: prestonmag@gmail.com (PrestonMag)
Injection-Date: Thu, 18 Aug 2022 10:14:36 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1598
 by: PrestonMag - Thu, 18 Aug 2022 10:14 UTC

On Thursday, 18 August 2022 at 02:30:42 UTC+1, John wrote:
> https://fortranwiki.org/fortran/show/match_wild

Thank-you, everyone. I've tried the match_wild function in my test code and it works perfectly. I'll now incorporate it in my main software but don't expect and problems

Thank-you again

Re: Globmatch module from FLIBS

<4ff03839-d0d8-4dd8-be13-3fcd64c3dc15n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2708&group=comp.lang.fortran#2708

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:290d:b0:6b5:cecc:1cab with SMTP id m13-20020a05620a290d00b006b5cecc1cabmr7202667qkp.465.1660980510340;
Sat, 20 Aug 2022 00:28:30 -0700 (PDT)
X-Received: by 2002:a25:6405:0:b0:695:626f:2f54 with SMTP id
y5-20020a256405000000b00695626f2f54mr4359663ybb.532.1660980509964; Sat, 20
Aug 2022 00:28:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sat, 20 Aug 2022 00:28:29 -0700 (PDT)
In-Reply-To: <17942267-71f0-4f77-9728-380589a84ea2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:84a8:921e:59b0:bdd9;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:84a8:921e:59b0:bdd9
References: <af743c13-b74c-443e-ab21-9c04e1565eaen@googlegroups.com>
<bec14ef4-0e47-4900-89b0-d2b22bc9ed7fn@googlegroups.com> <17327aab-54aa-4f4d-90dd-345cb40b4f72n@googlegroups.com>
<ac207e79-4260-482f-91e2-9d332fdcb8d8n@googlegroups.com> <17942267-71f0-4f77-9728-380589a84ea2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4ff03839-d0d8-4dd8-be13-3fcd64c3dc15n@googlegroups.com>
Subject: Re: Globmatch module from FLIBS
From: urbanjost@comcast.net (John)
Injection-Date: Sat, 20 Aug 2022 07:28:30 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 5503
 by: John - Sat, 20 Aug 2022 07:28 UTC

Since I mentioned the other routines, I wanted to post the results of some
tests of the listed procedures.

There is a test program of the three
procedures that shows that if a NULL character is assumed otherwise not
used in the string and pattern and is appended that the glob() procedure
passes all tests, and the string_match() routine passes all tests except
for an issue with patterns composed completely of wildcard characters,
but that the match_wild procedure (surprisingly, as it has been available
from the Fortran Wiki for a long time as well as other sites) seems to
fail on a number of cases.

The string_match() procedure was altered to prevent undersubscripting
and oversubscripting but was not changed otherwise, although the fix
described above may reduce the failures when the null is not added. Have
not had time to try it yet.

At some point I want to add [a-b] character ranges and escaping if it does not have it
to one
of these (probably glob()) and/or make an interface to the C procedure
fnmatch() if it is available on most platforms, so I wanted to look at
the currently available routines anyway; but since you mentioned you
used match_wild() I wanted to mention the preliminary results showed
some failures and that if appending a null is acceptable string_match()
works pretty well after all almost as-is except for the outlier with the
'*?' pattern so far.

The test program and procedures will be in

wget http://www.urbanjost.altervista.org/REMOVE/match.tgz

for at least a few months with the test program and module (set up for
fpm(1) but pretty easy to just compile) for anyone interested. It seemed
a bit long to post. I do not see anything I did obviously wrong when
using string_match().

I got the same results with ifort, gfortran, and nvfortran compilers
tested so far.

Note also that there is a BRE (Basic Regular Expression) routine
in the GPF package at https://github.com/urbanjost.

The significant output from the test is summarized below:

> >>>>>>>>>>>>>> METHOD 1: glob with //char(0)
> Passed
> >>>>>>>>>>>>>> METHOD 2: string_match with //char(0)
> Failed match on ab vs. *?
> Failed match on abc vs. *?
> Failed
> >>>>>>>>>>>>>> METHOD 3: match_wild with //char(0)
> Failed match on abcccd vs. *ccd
> Failed match on mississippi vs. *sip*
> Failed match on mississipissippi vs. *issip*ss*
> Failed match on mississippi vs. mi*sip*
> Failed match on ababac vs. *abac*
> Failed match on mississipPI vs. *issip*PI
> Failed match on bababa vs. b*ba
> Failed match on aaabbaabbaab vs. *aabbaa*a*
> Failed
> >>>>>>>>>>>>>> METHOD 4: glob
> Failed match on baaaaa vs. b*a
> Failed match on vs.
> Failed
> >>>>>>>>>>>>>> METHOD 5: string_match
> Failed match on ab vs. *?
> Failed match on abc vs. *?
> Failed match on a vs. *?
> Failed match on ab vs. ?*?
> Failed match on abc vs. ?**?*?
> Failed match on abcd vs. ?b*??
> Failed match on abcd vs. ?**?c?
> Failed match on abcde vs. ?*b*?*d*?
> Failed match on bLah vs. bLa?
> Failed match on bababa vs. b*ba
> Failed
> >>>>>>>>>>>>>> METHOD 6: match_wild
> Failed match on a*abab vs. a*b
> Failed match on abcccd vs. *ccd
> Failed match on mississippi vs. *sip*
> Failed match on mississipissippi vs. *issip*ss*
> Failed match on mississippi vs. mi*sip*
> Failed match on ababac vs. *abac*
> Failed match on mississipPI vs. *issip*PI
> Failed match on ab vs. *?*?*
> Failed match on abc vs. ?**?*?
> Failed match on abcde vs. ?*b*?*d*?
> Failed match on abcde vs. *e *
> Failed match on baaaaa vs. b*a
> Failed match on bababa vs. b*ba
> Failed match on b vs.
> Failed match on aaabbaabbaab vs. *aabbaa*a*
> Failed match on abc vs. ********a********b********c********
> Failed

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor