Support glob pattern for epicsEnvShow
Add epicsStrnGlobMatch with tests
This commit is contained in:
@@ -23,6 +23,15 @@
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef vxWorks
|
||||
#include <stdint.h>
|
||||
#else
|
||||
/* VxWorks automaticaly includes stdint.h defining SIZE_MAX in 6.9 but not earlier */
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX (size_t)-1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "epicsAssert.h"
|
||||
#include "epicsStdio.h"
|
||||
#include "cantProceed.h"
|
||||
@@ -259,30 +268,31 @@ size_t epicsStrnLen(const char *s, size_t maxlen)
|
||||
return i;
|
||||
}
|
||||
|
||||
int epicsStrGlobMatch(const char *str, const char *pattern)
|
||||
int epicsStrnGlobMatch(const char *str, size_t len, const char *pattern)
|
||||
{
|
||||
const char *cp = NULL, *mp = NULL;
|
||||
const char *mp = NULL;
|
||||
size_t cp = 0, i = 0;
|
||||
|
||||
while ((*str) && (*pattern != '*')) {
|
||||
if ((*pattern != *str) && (*pattern != '?'))
|
||||
while ((i < len) && (str[i]) && (*pattern != '*')) {
|
||||
if ((*pattern != str[i]) && (*pattern != '?'))
|
||||
return 0;
|
||||
pattern++;
|
||||
str++;
|
||||
i++;
|
||||
}
|
||||
while (*str) {
|
||||
while ((i < len) && str[i]) {
|
||||
if (*pattern == '*') {
|
||||
if (!*++pattern)
|
||||
return 1;
|
||||
mp = pattern;
|
||||
cp = str+1;
|
||||
cp = i+1;
|
||||
}
|
||||
else if ((*pattern == *str) || (*pattern == '?')) {
|
||||
else if ((*pattern == str[i]) || (*pattern == '?')) {
|
||||
pattern++;
|
||||
str++;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
pattern = mp;
|
||||
str = cp++;
|
||||
i = cp++;
|
||||
}
|
||||
}
|
||||
while (*pattern == '*')
|
||||
@@ -290,6 +300,10 @@ int epicsStrGlobMatch(const char *str, const char *pattern)
|
||||
return !*pattern;
|
||||
}
|
||||
|
||||
int epicsStrGlobMatch(const char *str, const char *pattern) {
|
||||
return epicsStrnGlobMatch(str, SIZE_MAX, pattern);
|
||||
}
|
||||
|
||||
char * epicsStrtok_r(char *s, const char *delim, char **lasts)
|
||||
{
|
||||
const char *spanp;
|
||||
|
||||
@@ -36,7 +36,30 @@ LIBCOM_API char * epicsStrnDup(const char *s, size_t len);
|
||||
LIBCOM_API int epicsStrPrintEscaped(FILE *fp, const char *s, size_t n);
|
||||
#define epicsStrSnPrintEscaped epicsStrnEscapedFromRaw
|
||||
LIBCOM_API size_t epicsStrnLen(const char *s, size_t maxlen);
|
||||
|
||||
/** Matches a string against a pattern.
|
||||
*
|
||||
* Checks if str matches the glob style pattern, which may contain ? or * wildcards.
|
||||
* A ? matches any single character.
|
||||
* A * matched any sub-string.
|
||||
*
|
||||
* @returns 1 if str matches the pattern, 0 if not.
|
||||
*
|
||||
* @since EPICS 3.14.7
|
||||
*/
|
||||
LIBCOM_API int epicsStrGlobMatch(const char *str, const char *pattern);
|
||||
|
||||
/** Matches a string against a pattern.
|
||||
*
|
||||
* Like epicsStrGlobMatch but with limited string length.
|
||||
* If the length of str is less than len, the full string is matched.
|
||||
*
|
||||
* @returns 1 if the first len characters of str match the pattern, 0 if not.
|
||||
*
|
||||
* @since UNRELEASED
|
||||
*/
|
||||
LIBCOM_API int epicsStrnGlobMatch(const char *str, size_t len, const char *pattern);
|
||||
|
||||
LIBCOM_API char * epicsStrtok_r(char *s, const char *delim, char **lasts);
|
||||
LIBCOM_API unsigned int epicsStrHash(const char *str, unsigned int seed);
|
||||
LIBCOM_API unsigned int epicsMemHash(const char *str, size_t length,
|
||||
|
||||
Reference in New Issue
Block a user