Pattern matching logic extended by Ken Pettit
This commit is contained in:
parent
fe5670a067
commit
33a3bb0e37
@ -6197,4 +6197,6 @@
|
|||||||
defintion header files (2013-12-10).
|
defintion header files (2013-12-10).
|
||||||
* arch/arm/src/a1x/a1x_pio.c and .h: Support for PIO configuration
|
* arch/arm/src/a1x/a1x_pio.c and .h: Support for PIO configuration
|
||||||
(2013-12-11).
|
(2013-12-11).
|
||||||
|
* libc/misc/lib_match.c: Pattern matching logic extended to handle
|
||||||
|
matches to sets of characters and ranges of character values. From
|
||||||
|
Ken Pettit (2013-12-12).
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
* Copyright © 1995, 2000 by Jef Poskanzer <jef@mail.acme.com>.
|
* Copyright © 1995, 2000 by Jef Poskanzer <jef@mail.acme.com>.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
* With extensions by Ken Pettit.
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@ -57,6 +59,8 @@
|
|||||||
static int match_one(const char *pattern, int patlen, const char *string)
|
static int match_one(const char *pattern, int patlen, const char *string)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
char first;
|
||||||
|
char last;
|
||||||
int pl;
|
int pl;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -67,6 +71,63 @@ static int match_one(const char *pattern, int patlen, const char *string)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Match single character from a set: "[a-zA-Z]" for instance */
|
||||||
|
|
||||||
|
if (*p == '[' && *string != '\0')
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
while (*p != ']' && *p != '\0')
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
|
||||||
|
if (*string == *p)
|
||||||
|
{
|
||||||
|
/* Match found. Advance to the ']' */
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (*p != ']' && *p != '\0')
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare to test for range */
|
||||||
|
|
||||||
|
if (*p != '\0')
|
||||||
|
{
|
||||||
|
first = *p++;
|
||||||
|
if (*p == '-')
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
last = *p++;
|
||||||
|
if (*string >= first && *string <= *p)
|
||||||
|
{
|
||||||
|
/* Match found. Advance to the ']' */
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (*p != ']' && *p != '\0')
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We reuse 'i' above to indicate match found */
|
||||||
|
|
||||||
|
if (i)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (*p == '*')
|
if (*p == '*')
|
||||||
{
|
{
|
||||||
p++;
|
p++;
|
||||||
@ -92,6 +153,7 @@ static int match_one(const char *pattern, int patlen, const char *string)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +167,7 @@ static int match_one(const char *pattern, int patlen, const char *string)
|
|||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +179,10 @@ static int match_one(const char *pattern, int patlen, const char *string)
|
|||||||
* Name: match
|
* Name: match
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Simple shell-style filename pattern matcher written by Jef Poskanzer
|
* Simple shell-style filename pattern matcher originally written by
|
||||||
* This pattern matcher only handles '?', '*' and '**', and multiple
|
* Jef Poskanzer and extended by Ken Pettit. This pattern matcher handles
|
||||||
* patterns separated by '|'.
|
* '?', '*', '**', sets like [a-zA-z], and multiple patterns separated
|
||||||
|
* by '|'.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Returns 1 (match) or 0 (no-match).
|
* Returns 1 (match) or 0 (no-match).
|
||||||
@ -145,4 +209,3 @@ int match(const char *pattern, const char *string)
|
|||||||
pattern = or + 1;
|
pattern = or + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user