} KeyValue;
/* search matcher flags */
-#define SEARCH_STRINGMASK 15
-#define SEARCH_STRING 1
-#define SEARCH_SUBSTRING 2
-#define SEARCH_GLOB 3
-#define SEARCH_REGEX 4
-#define SEARCH_ERROR 5
+#define SEARCH_STRINGMASK 15
+#define SEARCH_STRING 1
+#define SEARCH_STRINGSTART 2
+#define SEARCH_STRINGEND 3
+#define SEARCH_SUBSTRING 4
+#define SEARCH_GLOB 5
+#define SEARCH_REGEX 6
+#define SEARCH_ERROR 15
#define SEARCH_NOCASE (1<<7)
/* iterator control */
int
datamatcher_match(Datamatcher *ma, const char *str)
{
+ int l;
switch ((ma->flags & SEARCH_STRINGMASK))
{
case SEARCH_SUBSTRING:
return 0;
}
break;
+ case SEARCH_STRINGSTART:
+ if (ma->flags & SEARCH_NOCASE)
+ {
+ if (strncasecmp(ma->match, str, strlen(ma->match)))
+ return 0;
+ }
+ else
+ {
+ if (strncmp(ma->match, str, strlen(ma->match)))
+ return 0;
+ }
+ break;
+ case SEARCH_STRINGEND:
+ l = strlen(str) - strlen(ma->match);
+ if (l < 0)
+ return 0;
+ if (ma->flags & SEARCH_NOCASE)
+ {
+ if (strcasecmp(ma->match, str + l))
+ return 0;
+ }
+ else
+ {
+ if (strcmp(ma->match, str + l))
+ return 0;
+ }
+ break;
case SEARCH_GLOB:
if (fnmatch(ma->match, str, (ma->flags & SEARCH_NOCASE) ? FNM_CASEFOLD : 0))
return 0;