diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-09 23:31:36 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-09 23:31:36 +0000 |
commit | 84580dd785cd13f0304bc07505a958f6ef97ee5c (patch) | |
tree | a6c81aa21a92b2a0bb1c2a905890e9cb6bcaac06 | |
parent | 52e32329c935cd5b17f86511fb6d80879b597e60 (diff) | |
download | mandoc-84580dd785cd13f0304bc07505a958f6ef97ee5c.tar.gz |
Use proper infix expressions and provide a default. (Exact match.)
-rw-r--r-- | db.c | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -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; |