[comp.sys.amiga] pattern matching library for 1.4

MROBINSON@wash-vax.bbn.com (04/05/89)

I've seen lots of talk about a library for filename pattern matching
support in 1.4, but none about supporting pattern matching in strings!

I personally would like to see, IN ADDITION to the previously mentioned
filename "parameter expansion" support, a supported call like

find_pattern_in_string(pattern,plen,string,slen,match_start,match_len)
  char *pattern;
  int   plen;
  char *string;
  int   slen;
  int  *match_start, *match_len;

The idea here is, since the AmigaDOS filename pattern matching capabilities
are a powerful syntax for matching patterns in ANY kind of strings, why not
make it easy for people to write editors and the like that will all use the
same pattern matching syntax?

For the above C function (which would return an int, either TRUE or FALSE
based on whether a match to pattern existed in string), please do NOT
assume pattern or string is null-terminated (since then how could one match
a pattern with a \0 in it).  match_start would be an offset from string
for where the match found starts, and match_len is of course the length of
the matching string.

Perhaps having a standard string pattern matching syntax for all applications
would make it clearer to unix (or domain, or VMS) lovers that the syntax
really isn't difficult to use, eh Commodore?

--Max Robinson (no, not the dead one)

I am giving my opinion, I don't know who else agrees with me.

bader+@andrew.cmu.edu (Miles Bader) (04/06/89)

MROBINSON@wash-vax.bbn.com writes:
> I've seen lots of talk about a library for filename pattern matching
> support in 1.4, but none about supporting pattern matching in strings!
> 
> I personally would like to see, IN ADDITION to the previously mentioned
> filename "parameter expansion" support, a supported call like
> 
> find_pattern_in_string(pattern,plen,string,slen,match_start,match_len)
...

If you're going to implement this, split it into separate compile-pattern and
find-match calls, so that repeated invocations are faster...

E.g.:

struct regexp *regexp_Compile(pattern);
char *pattern;

int /* boolean */ regexp_Match(re,str,strlen,matchP,matchlenP)
struct regexp *re;
char *str;
int strlen;
char **matchP;		/* out parameter, or NULL if not needed */
int *matchlenP;		/* out parameter, or NULL if not needed */

-Miles

w-colinp@microsoft.UUCP (Colin Plumb) (04/06/89)

Henry Spencer wrote an excellent regular expression library you may wish
to use.  (It's used in at least one Microsoft product!)  If you're so
keen, how about hacking it into a sharable library and bestowing
regexp.library on the world?
-- 
	-Colin (uunet!microsoft!w-colinp)

"Don't listen to me.  I never do." - The Doctor

MROBINSON@wash-vax.bbn.com (04/06/89)

Newsgroups: comp.sys.amiga

w-colinp@microsoft.uucp writes:
> Henry Spencer wrote an excellent regular expression library you may wish
> to use.  (It's used in at least one Microsoft product!)  If you're so
> keen, how about hacking it into a sharable library and bestowing
> regexp.library on the world?

Kudos to Henry, and do you know where I could find that library?  However,
me getting his library will not solve any problems but mine.  My point was,
since Commodore appears to be making their string pattern matcher available
for filename matching purposes, why don't they make it available for other
purposes as well, and help us users (and you developers) *standardize* the
behavior and syntax of pattern matching on the Amiga?  Then bright people
like Henry won't have to spend their time redoing something already done,
tested, and supported.

--Max Robinson MROBINSON@wash-vax.bbn.com

BBN's corporate opinions are not necessarily reflected in my comments.

Pearl for the day:  Do stalactites grow faster than continents drift?

daveh@cbmvax.UUCP (Dave Haynie) (04/08/89)

in article <1250@microsoft.UUCP>, w-colinp@microsoft.UUCP (Colin Plumb) says:

> Henry Spencer wrote an excellent regular expression library you may wish
> to use.  (It's used in at least one Microsoft product!)  

> 	-Colin (uunet!microsoft!w-colinp)

For DiskSalv V1.40, I wrote two pattern matching routines that, barring any
bugs, handle all AmigaDOS regular expression metacharacters.  It's only about
1.5k of C code, maybe a bit less; not sure that alone would be a reasonable
library, though something similar would certainly be a good thing for two
calls in a new version of an existing library.  For something as generally
useful as the reasonably standard UNIX regular expression matchers, you'd
need a few new functions, like perhaps something that will explicitly anchor
a pattern at the beginning, and another at the end, of a particular string.
When you're matching filenames, you generally are asking the question "does
this entire string match this pattern".  There are other uses, such as the
command "give me the largest string that matches this pattern", etc.

I'll probably post the pattern matching code I did before too long.  If 
anyone has any sort of verification suite for AmigaDOS patterns, I'd be
interested.

-- 
Dave Haynie  "The 32 Bit Guy"     Commodore-Amiga  "The Crew That Never Rests"
   {uunet|pyramid|rutgers}!cbmvax!daveh      PLINK: D-DAVE H     BIX: hazy
              Amiga -- It's not just a job, it's an obsession