summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/db.c b/db.c
index e482243d..c2d13705 100644
--- a/db.c
+++ b/db.c
@@ -462,30 +462,43 @@ exprcomp(int cs, char *argv[], int argc)
{
struct expr *p;
struct expr e;
- int i, ch;
+ int i, pos, ch;
- if (3 != argc)
+ pos = 0;
+
+ if (pos > argc)
+ return(NULL);
+
+ for (i = 0; 0 != types[i].mask; i++)
+ if (0 == strcmp(types[i].name, argv[pos]))
+ break;
+
+ if (0 == (e.mask = types[i].mask))
+ return(NULL);
+
+ if (++pos > argc--)
return(NULL);
- if (0 == strcmp("-eq", argv[0]))
+ if ('-' != *argv[pos])
+ e.match = cs ? MATCH_STRCASE : MATCH_STR;
+ else if (0 == strcmp("-eq", argv[pos]))
e.match = cs ? MATCH_STRCASE : MATCH_STR;
- else if (0 == strcmp("-ieq", argv[0]))
+ else if (0 == strcmp("-ieq", argv[pos]))
e.match = MATCH_STRCASE;
- else if (0 == strcmp("-re", argv[0]))
+ else if (0 == strcmp("-re", argv[pos]))
e.match = cs ? MATCH_REGEXCASE : MATCH_REGEX;
- else if (0 == strcmp("-ire", argv[0]))
+ else if (0 == strcmp("-ire", argv[pos]))
e.match = MATCH_REGEXCASE;
else
return(NULL);
- for (i = 0; 0 != types[i].mask; i++)
- if (0 == strcmp(types[i].name, argv[1]))
- break;
+ if ('-' == *argv[pos])
+ pos++;
- if (0 == (e.mask = types[i].mask))
+ if (pos > argc--)
return(NULL);
- e.v = mandoc_strdup(argv[2]);
+ e.v = mandoc_strdup(argv[pos]);
if (MATCH_REGEX == e.match || MATCH_REGEXCASE == e.match) {
ch = REG_EXTENDED | REG_NOSUB;