aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/curl_fnmatch.c
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:56 +0300
commite988f30484abe5fdeedcc7a5d3c226c01a21800c (patch)
tree0a217b173aabb57b7e51f8a169989b1a3e0309fe /contrib/libs/curl/lib/curl_fnmatch.c
parent33ee501c05d3f24036ae89766a858930ae66c548 (diff)
downloadydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/curl_fnmatch.c')
-rw-r--r--contrib/libs/curl/lib/curl_fnmatch.c338
1 files changed, 169 insertions, 169 deletions
diff --git a/contrib/libs/curl/lib/curl_fnmatch.c b/contrib/libs/curl/lib/curl_fnmatch.c
index 4bfa58598e..a6f769b081 100644
--- a/contrib/libs/curl/lib/curl_fnmatch.c
+++ b/contrib/libs/curl/lib/curl_fnmatch.c
@@ -22,16 +22,16 @@
#include "curl_setup.h"
#ifndef CURL_DISABLE_FTP
-#include <curl/curl.h>
-
+#include <curl/curl.h>
+
#include "curl_fnmatch.h"
-#include "curl_memory.h"
+#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
-#ifndef HAVE_FNMATCH
-
+#ifndef HAVE_FNMATCH
+
#define CURLFNM_CHARSET_LEN (sizeof(char) * 256)
#define CURLFNM_CHSET_SIZE (CURLFNM_CHARSET_LEN + 15)
@@ -59,13 +59,13 @@ typedef enum {
CURLFNM_PKW_DDOT
} parsekey_state;
-typedef enum {
- CCLASS_OTHER = 0,
- CCLASS_DIGIT,
- CCLASS_UPPER,
- CCLASS_LOWER
-} char_class;
-
+typedef enum {
+ CCLASS_OTHER = 0,
+ CCLASS_DIGIT,
+ CCLASS_UPPER,
+ CCLASS_LOWER
+} char_class;
+
#define SETCHARSET_OK 1
#define SETCHARSET_FAIL 0
@@ -83,12 +83,12 @@ static int parsekeyword(unsigned char **pattern, unsigned char *charset)
return SETCHARSET_FAIL;
switch(state) {
case CURLFNM_PKW_INIT:
- if(ISLOWER(c))
+ if(ISLOWER(c))
keyword[i] = c;
else if(c == ':')
state = CURLFNM_PKW_DDOT;
else
- return SETCHARSET_FAIL;
+ return SETCHARSET_FAIL;
break;
case CURLFNM_PKW_DDOT:
if(c == ']')
@@ -125,68 +125,68 @@ static int parsekeyword(unsigned char **pattern, unsigned char *charset)
return SETCHARSET_OK;
}
-/* Return the character class. */
-static char_class charclass(unsigned char c)
-{
- if(ISUPPER(c))
- return CCLASS_UPPER;
- if(ISLOWER(c))
- return CCLASS_LOWER;
- if(ISDIGIT(c))
- return CCLASS_DIGIT;
- return CCLASS_OTHER;
-}
-
-/* Include a character or a range in set. */
-static void setcharorrange(unsigned char **pp, unsigned char *charset)
-{
- unsigned char *p = (*pp)++;
- unsigned char c = *p++;
-
- charset[c] = 1;
- if(ISALNUM(c) && *p++ == '-') {
- char_class cc = charclass(c);
- unsigned char endrange = *p++;
-
- if(endrange == '\\')
- endrange = *p++;
- if(endrange >= c && charclass(endrange) == cc) {
- while(c++ != endrange)
- if(charclass(c) == cc) /* Chars in class may be not consecutive. */
- charset[c] = 1;
- *pp = p;
- }
- }
-}
-
+/* Return the character class. */
+static char_class charclass(unsigned char c)
+{
+ if(ISUPPER(c))
+ return CCLASS_UPPER;
+ if(ISLOWER(c))
+ return CCLASS_LOWER;
+ if(ISDIGIT(c))
+ return CCLASS_DIGIT;
+ return CCLASS_OTHER;
+}
+
+/* Include a character or a range in set. */
+static void setcharorrange(unsigned char **pp, unsigned char *charset)
+{
+ unsigned char *p = (*pp)++;
+ unsigned char c = *p++;
+
+ charset[c] = 1;
+ if(ISALNUM(c) && *p++ == '-') {
+ char_class cc = charclass(c);
+ unsigned char endrange = *p++;
+
+ if(endrange == '\\')
+ endrange = *p++;
+ if(endrange >= c && charclass(endrange) == cc) {
+ while(c++ != endrange)
+ if(charclass(c) == cc) /* Chars in class may be not consecutive. */
+ charset[c] = 1;
+ *pp = p;
+ }
+ }
+}
+
/* returns 1 (true) if pattern is OK, 0 if is bad ("p" is pattern pointer) */
static int setcharset(unsigned char **p, unsigned char *charset)
{
setcharset_state state = CURLFNM_SCHS_DEFAULT;
bool something_found = FALSE;
unsigned char c;
-
- memset(charset, 0, CURLFNM_CHSET_SIZE);
+
+ memset(charset, 0, CURLFNM_CHSET_SIZE);
for(;;) {
c = **p;
- if(!c)
- return SETCHARSET_FAIL;
-
+ if(!c)
+ return SETCHARSET_FAIL;
+
switch(state) {
case CURLFNM_SCHS_DEFAULT:
- if(c == ']') {
+ if(c == ']') {
if(something_found)
return SETCHARSET_OK;
- something_found = TRUE;
+ something_found = TRUE;
state = CURLFNM_SCHS_RIGHTBR;
charset[c] = 1;
(*p)++;
}
else if(c == '[') {
- unsigned char *pp = *p + 1;
-
- if(*pp++ == ':' && parsekeyword(&pp, charset))
- *p = pp;
+ unsigned char *pp = *p + 1;
+
+ if(*pp++ == ':' && parsekeyword(&pp, charset))
+ *p = pp;
else {
charset[c] = 1;
(*p)++;
@@ -208,14 +208,14 @@ static int setcharset(unsigned char **p, unsigned char *charset)
}
else if(c == '\\') {
c = *(++(*p));
- if(c)
- setcharorrange(p, charset);
+ if(c)
+ setcharorrange(p, charset);
else
- charset['\\'] = 1;
- something_found = TRUE;
+ charset['\\'] = 1;
+ something_found = TRUE;
}
else {
- setcharorrange(p, charset);
+ setcharorrange(p, charset);
something_found = TRUE;
}
break;
@@ -240,11 +240,11 @@ static int setcharset(unsigned char **p, unsigned char *charset)
goto fail;
break;
case CURLFNM_SCHS_RIGHTBRLEFTBR:
- if(c == ']')
+ if(c == ']')
return SETCHARSET_OK;
- state = CURLFNM_SCHS_DEFAULT;
- charset[c] = 1;
- (*p)++;
+ state = CURLFNM_SCHS_DEFAULT;
+ charset[c] = 1;
+ (*p)++;
break;
}
}
@@ -252,96 +252,96 @@ fail:
return SETCHARSET_FAIL;
}
-static int loop(const unsigned char *pattern, const unsigned char *string,
- int maxstars)
+static int loop(const unsigned char *pattern, const unsigned char *string,
+ int maxstars)
{
unsigned char *p = (unsigned char *)pattern;
unsigned char *s = (unsigned char *)string;
unsigned char charset[CURLFNM_CHSET_SIZE] = { 0 };
for(;;) {
- unsigned char *pp;
-
- switch(*p) {
- case '*':
- if(!maxstars)
- return CURL_FNMATCH_NOMATCH;
- /* Regroup consecutive stars and question marks. This can be done because
- '*?*?*' can be expressed as '??*'. */
- for(;;) {
- if(*++p == '\0')
+ unsigned char *pp;
+
+ switch(*p) {
+ case '*':
+ if(!maxstars)
+ return CURL_FNMATCH_NOMATCH;
+ /* Regroup consecutive stars and question marks. This can be done because
+ '*?*?*' can be expressed as '??*'. */
+ for(;;) {
+ if(*++p == '\0')
return CURL_FNMATCH_MATCH;
- if(*p == '?') {
- if(!*s++)
- return CURL_FNMATCH_NOMATCH;
+ if(*p == '?') {
+ if(!*s++)
+ return CURL_FNMATCH_NOMATCH;
}
- else if(*p != '*')
- break;
+ else if(*p != '*')
+ break;
}
- /* Skip string characters until we find a match with pattern suffix. */
- for(maxstars--; *s; s++) {
- if(loop(p, s, maxstars) == CURL_FNMATCH_MATCH)
+ /* Skip string characters until we find a match with pattern suffix. */
+ for(maxstars--; *s; s++) {
+ if(loop(p, s, maxstars) == CURL_FNMATCH_MATCH)
return CURL_FNMATCH_MATCH;
}
- return CURL_FNMATCH_NOMATCH;
- case '?':
- if(!*s)
- return CURL_FNMATCH_NOMATCH;
- s++;
- p++;
- break;
- case '\0':
- return *s? CURL_FNMATCH_NOMATCH: CURL_FNMATCH_MATCH;
- case '\\':
- if(p[1])
+ return CURL_FNMATCH_NOMATCH;
+ case '?':
+ if(!*s)
+ return CURL_FNMATCH_NOMATCH;
+ s++;
+ p++;
+ break;
+ case '\0':
+ return *s? CURL_FNMATCH_NOMATCH: CURL_FNMATCH_MATCH;
+ case '\\':
+ if(p[1])
p++;
- if(*s++ != *p++)
- return CURL_FNMATCH_NOMATCH;
- break;
- case '[':
- pp = p + 1; /* Copy in case of syntax error in set. */
- if(setcharset(&pp, charset)) {
- int found = FALSE;
- if(!*s)
- return CURL_FNMATCH_NOMATCH;
- if(charset[(unsigned int)*s])
- found = TRUE;
- else if(charset[CURLFNM_ALNUM])
- found = ISALNUM(*s);
- else if(charset[CURLFNM_ALPHA])
- found = ISALPHA(*s);
- else if(charset[CURLFNM_DIGIT])
- found = ISDIGIT(*s);
- else if(charset[CURLFNM_XDIGIT])
- found = ISXDIGIT(*s);
- else if(charset[CURLFNM_PRINT])
- found = ISPRINT(*s);
- else if(charset[CURLFNM_SPACE])
- found = ISSPACE(*s);
- else if(charset[CURLFNM_UPPER])
- found = ISUPPER(*s);
- else if(charset[CURLFNM_LOWER])
- found = ISLOWER(*s);
- else if(charset[CURLFNM_BLANK])
- found = ISBLANK(*s);
- else if(charset[CURLFNM_GRAPH])
- found = ISGRAPH(*s);
+ if(*s++ != *p++)
+ return CURL_FNMATCH_NOMATCH;
+ break;
+ case '[':
+ pp = p + 1; /* Copy in case of syntax error in set. */
+ if(setcharset(&pp, charset)) {
+ int found = FALSE;
+ if(!*s)
+ return CURL_FNMATCH_NOMATCH;
+ if(charset[(unsigned int)*s])
+ found = TRUE;
+ else if(charset[CURLFNM_ALNUM])
+ found = ISALNUM(*s);
+ else if(charset[CURLFNM_ALPHA])
+ found = ISALPHA(*s);
+ else if(charset[CURLFNM_DIGIT])
+ found = ISDIGIT(*s);
+ else if(charset[CURLFNM_XDIGIT])
+ found = ISXDIGIT(*s);
+ else if(charset[CURLFNM_PRINT])
+ found = ISPRINT(*s);
+ else if(charset[CURLFNM_SPACE])
+ found = ISSPACE(*s);
+ else if(charset[CURLFNM_UPPER])
+ found = ISUPPER(*s);
+ else if(charset[CURLFNM_LOWER])
+ found = ISLOWER(*s);
+ else if(charset[CURLFNM_BLANK])
+ found = ISBLANK(*s);
+ else if(charset[CURLFNM_GRAPH])
+ found = ISGRAPH(*s);
- if(charset[CURLFNM_NEGATE])
- found = !found;
+ if(charset[CURLFNM_NEGATE])
+ found = !found;
- if(!found)
+ if(!found)
return CURL_FNMATCH_NOMATCH;
- p = pp + 1;
- s++;
- break;
+ p = pp + 1;
+ s++;
+ break;
}
- /* Syntax error in set; mismatch! */
- return CURL_FNMATCH_NOMATCH;
-
- default:
- if(*p++ != *s++)
- return CURL_FNMATCH_NOMATCH;
+ /* Syntax error in set; mismatch! */
+ return CURL_FNMATCH_NOMATCH;
+
+ default:
+ if(*p++ != *s++)
+ return CURL_FNMATCH_NOMATCH;
break;
}
}
@@ -357,33 +357,33 @@ int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
if(!pattern || !string) {
return CURL_FNMATCH_FAIL;
}
- return loop((unsigned char *)pattern, (unsigned char *)string, 2);
+ return loop((unsigned char *)pattern, (unsigned char *)string, 2);
}
-#else
-#include <fnmatch.h>
-/*
- * @unittest: 1307
- */
-int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
-{
- int rc;
- (void)ptr; /* the argument is specified by the curl_fnmatch_callback
- prototype, but not used by Curl_fnmatch() */
- if(!pattern || !string) {
- return CURL_FNMATCH_FAIL;
- }
- rc = fnmatch(pattern, string, 0);
- switch(rc) {
- case 0:
- return CURL_FNMATCH_MATCH;
- case FNM_NOMATCH:
- return CURL_FNMATCH_NOMATCH;
- default:
- return CURL_FNMATCH_FAIL;
- }
- /* not reached */
-}
-
-#endif
+#else
+#include <fnmatch.h>
+/*
+ * @unittest: 1307
+ */
+int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
+{
+ int rc;
+ (void)ptr; /* the argument is specified by the curl_fnmatch_callback
+ prototype, but not used by Curl_fnmatch() */
+ if(!pattern || !string) {
+ return CURL_FNMATCH_FAIL;
+ }
+ rc = fnmatch(pattern, string, 0);
+ switch(rc) {
+ case 0:
+ return CURL_FNMATCH_MATCH;
+ case FNM_NOMATCH:
+ return CURL_FNMATCH_NOMATCH;
+ default:
+ return CURL_FNMATCH_FAIL;
+ }
+ /* not reached */
+}
+
+#endif
#endif /* if FTP is disabled */