plain text document attachment (match_regex.patch)
Patch: match_regex.patch
Description:
Add rudimentary regular expression matching support to lib/parser.c
Signed-Off-By: Matt Helsley <[EMAIL PROTECTED]>
%patch
Index: linux-2.6.12-rc3/lib/parser.c
===================================================================
--- linux-2.6.12-rc3.orig/lib/parser.c 2005-05-23 21:25:12.954705272 -0700
+++ linux-2.6.12-rc3/lib/parser.c 2005-05-23 21:26:21.467289776 -0700
@@ -219,11 +219,82 @@ char *match_strdup(substring_t *s)
if (p)
match_strcpy(p, s);
return p;
}
+/*
+ * '?' any single character
+ * '\' escape next character -- i.e. \* is a literal *
+ * rest must match
+ *
+ */
+#ifdef DO_REGEX_ESCAPE
+static inline int matchp(const_substring_t *str, const_substring_t *re)
+{
+ if (*re->from == '\\')
+ return (*str->from == *(re->from + 1));
+ else
+ return (*str->from == *re->from);
+}
+
+static inline void advance_re(const_substring_t *re)
+{
+ if (*re->from == '\\')
+ re->from += 2;
+ else
+ re->from++;
+}
+#else /* if ! defined(DO_REGEX_ESCAPE) */
+static inline int matchp(const_substring_t *str, const_substring_t *re)
+{
+ return (*str->from == *re->from);
+}
+
+static inline void advance_re(const_substring_t *re)
+{
+ re->from++;
+}
+#endif /* if ! defined(DO_REGEX_ESCAPE) */
+
+static inline void advance(const_substring_t *str, const_substring_t *re)
+{
+ advance_re(re);
+ str->from++;
+}
+
+static inline int eosubstr (const_substring_t *str)
+{
+ return ((str->from >= str->to) || !*(str->from));
+}
+
+/*
+ * Match a substring with a given regular expression. Return
+ * 0 if the substring does not match, non-zero otherwise.
+ *
+ * substr and re must not be NULL
+ */
+int match_regex(const_substring_t str, const_substring_t re)
+{
+ while (!eosubstr(&re) && !eosubstr(&str)) {
+ switch (*(re.from)) {
+ case '?':
+ advance(&str, &re);
+ break;
+ default:
+ if (!matchp(&str, &re))
+ return 0;
+ advance(&str, &re);
+ break;
+ }
+ }
+
+ /* Must be at the end of both strings to have matched */
+ return ((!*re) && (!*str));
+}
+
EXPORT_SYMBOL(match_token);
EXPORT_SYMBOL(match_int);
EXPORT_SYMBOL(match_octal);
EXPORT_SYMBOL(match_hex);
EXPORT_SYMBOL(match_strcpy);
EXPORT_SYMBOL(match_strdup);
+EXPORT_SYMBOL(match_regex);
Index: linux-2.6.12-rc3/include/linux/parser.h
===================================================================
--- linux-2.6.12-rc3.orig/include/linux/parser.h 2005-05-23
21:17:18.798787928 -0700
+++ linux-2.6.12-rc3/include/linux/parser.h 2005-05-23 21:26:21.465290080
-0700
@@ -19,15 +19,22 @@ typedef struct match_token match_table_t
/* Maximum number of arguments that match_token will find in a pattern */
enum {MAX_OPT_ARGS = 3};
/* Describe the location within a string of a substring */
typedef struct {
- char *from;
- char *to;
+ char *from; /* inclusive */
+ char *to; /* non-inclusive */
} substring_t;
+/* Describe the location of a substring within a non-modifiable string */
+typedef struct {
+ const char *from; /* inclusive */
+ const char *to; /* non-inclusive */
+} const_substring_t;
+
int match_token(char *, match_table_t table, substring_t args[]);
int match_int(substring_t *, int *result);
int match_octal(substring_t *, int *result);
int match_hex(substring_t *, int *result);
void match_strcpy(char *, substring_t *);
char *match_strdup(substring_t *);
+int match_regex(const_substring_t str, const_substring_t re);
--
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
ckrm-tech mailing list
https://lists.sourceforge.net/lists/listinfo/ckrm-tech