diff options
Diffstat (limited to 'lib/parser.c')
| -rw-r--r-- | lib/parser.c | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/lib/parser.c b/lib/parser.c index 807b2aaa33fa..b6d11631231b 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
| @@ -113,6 +113,7 @@ int match_token(char *s, const match_table_t table, substring_t args[]) | |||
| 113 | 113 | ||
| 114 | return p->token; | 114 | return p->token; |
| 115 | } | 115 | } |
| 116 | EXPORT_SYMBOL(match_token); | ||
| 116 | 117 | ||
| 117 | /** | 118 | /** |
| 118 | * match_number: scan a number in the given base from a substring_t | 119 | * match_number: scan a number in the given base from a substring_t |
| @@ -163,6 +164,7 @@ int match_int(substring_t *s, int *result) | |||
| 163 | { | 164 | { |
| 164 | return match_number(s, result, 0); | 165 | return match_number(s, result, 0); |
| 165 | } | 166 | } |
| 167 | EXPORT_SYMBOL(match_int); | ||
| 166 | 168 | ||
| 167 | /** | 169 | /** |
| 168 | * match_octal: - scan an octal representation of an integer from a substring_t | 170 | * match_octal: - scan an octal representation of an integer from a substring_t |
| @@ -177,6 +179,7 @@ int match_octal(substring_t *s, int *result) | |||
| 177 | { | 179 | { |
| 178 | return match_number(s, result, 8); | 180 | return match_number(s, result, 8); |
| 179 | } | 181 | } |
| 182 | EXPORT_SYMBOL(match_octal); | ||
| 180 | 183 | ||
| 181 | /** | 184 | /** |
| 182 | * match_hex: - scan a hex representation of an integer from a substring_t | 185 | * match_hex: - scan a hex representation of an integer from a substring_t |
| @@ -191,6 +194,58 @@ int match_hex(substring_t *s, int *result) | |||
| 191 | { | 194 | { |
| 192 | return match_number(s, result, 16); | 195 | return match_number(s, result, 16); |
| 193 | } | 196 | } |
| 197 | EXPORT_SYMBOL(match_hex); | ||
| 198 | |||
| 199 | /** | ||
| 200 | * match_wildcard: - parse if a string matches given wildcard pattern | ||
| 201 | * @pattern: wildcard pattern | ||
| 202 | * @str: the string to be parsed | ||
| 203 | * | ||
| 204 | * Description: Parse the string @str to check if matches wildcard | ||
| 205 | * pattern @pattern. The pattern may contain two type wildcardes: | ||
| 206 | * '*' - matches zero or more characters | ||
| 207 | * '?' - matches one character | ||
| 208 | * If it's matched, return true, else return false. | ||
| 209 | */ | ||
| 210 | bool match_wildcard(const char *pattern, const char *str) | ||
| 211 | { | ||
| 212 | const char *s = str; | ||
| 213 | const char *p = pattern; | ||
| 214 | bool star = false; | ||
| 215 | |||
| 216 | while (*s) { | ||
| 217 | switch (*p) { | ||
| 218 | case '?': | ||
| 219 | s++; | ||
| 220 | p++; | ||
| 221 | break; | ||
| 222 | case '*': | ||
| 223 | star = true; | ||
| 224 | str = s; | ||
| 225 | if (!*++p) | ||
| 226 | return true; | ||
| 227 | pattern = p; | ||
| 228 | break; | ||
| 229 | default: | ||
| 230 | if (*s == *p) { | ||
| 231 | s++; | ||
| 232 | p++; | ||
| 233 | } else { | ||
| 234 | if (!star) | ||
| 235 | return false; | ||
| 236 | str++; | ||
| 237 | s = str; | ||
| 238 | p = pattern; | ||
| 239 | } | ||
| 240 | break; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | if (*p == '*') | ||
| 245 | ++p; | ||
| 246 | return !*p; | ||
| 247 | } | ||
| 248 | EXPORT_SYMBOL(match_wildcard); | ||
| 194 | 249 | ||
| 195 | /** | 250 | /** |
| 196 | * match_strlcpy: - Copy the characters from a substring_t to a sized buffer | 251 | * match_strlcpy: - Copy the characters from a substring_t to a sized buffer |
| @@ -213,6 +268,7 @@ size_t match_strlcpy(char *dest, const substring_t *src, size_t size) | |||
| 213 | } | 268 | } |
| 214 | return ret; | 269 | return ret; |
| 215 | } | 270 | } |
| 271 | EXPORT_SYMBOL(match_strlcpy); | ||
| 216 | 272 | ||
| 217 | /** | 273 | /** |
| 218 | * match_strdup: - allocate a new string with the contents of a substring_t | 274 | * match_strdup: - allocate a new string with the contents of a substring_t |
| @@ -230,10 +286,4 @@ char *match_strdup(const substring_t *s) | |||
| 230 | match_strlcpy(p, s, sz); | 286 | match_strlcpy(p, s, sz); |
| 231 | return p; | 287 | return p; |
| 232 | } | 288 | } |
| 233 | |||
| 234 | EXPORT_SYMBOL(match_token); | ||
| 235 | EXPORT_SYMBOL(match_int); | ||
| 236 | EXPORT_SYMBOL(match_octal); | ||
| 237 | EXPORT_SYMBOL(match_hex); | ||
| 238 | EXPORT_SYMBOL(match_strlcpy); | ||
| 239 | EXPORT_SYMBOL(match_strdup); | 289 | EXPORT_SYMBOL(match_strdup); |
