commit f81014735b68a607ffcabad14a8eda51a34c1383
parent a070db77245acdab7cee5aa2d67e145959aed08c
Author: Christoph Lohmann <20h@r-36.net>
Date: Fri, 21 Dec 2012 18:42:43 +0100
Fixing pick syntax parsing to support AND.
Diffstat:
pick.c | | | 110 | +++++++++++++++++++++++++++++++++++++++++++------------------------------------ |
1 file changed, 60 insertions(+), 50 deletions(-)
diff --git a/pick.c b/pick.c
@@ -112,68 +112,78 @@ pick_mksearchstring(char **argv[])
{
int j;
expression_t *expr;
- char *rstr, *estr, *astr;
+ char *rstr, *estr, *nestr, *astr;
rstr = NULL;
+ estr = NULL;
- if ((*argv)[0][0] != ':')
- die("Missing ':' at %s\n", (*argv)[0]);
+ do {
+ if ((*argv)[0][0] != ':')
+ die("Missing ':' at %s\n", (*argv)[0]);
- expr = NULL;
- for (j = 0; j < nelem(expressions); j++) {
- if (!strcasecmp((*argv)[0]+1, expressions[j].expr)) {
- expr = &expressions[j];
- break;
- }
- }
- if (expr == NULL)
- die("Expression '%s' unknown.\n", (*argv)[0]);
-
- switch (expr->syntax[0]) {
- case PICK_HEADERPREP:
- estr = smprintf("HEADER %s", expr->expr);
- break;
- case PICK_SEQ:
- estr = smprintf("");
- break;
- default:
- estr = smprintf("%s", expr->expr);
- break;
- }
-
- for (j = 0; expr->syntax[j] != PICK_END; j++) {
- if (!(*argv)[1]) {
- die("Expected argument of type %s at '%s'\n",
- desc[(int)expr->syntax[j]],
- (*argv)[0]);
+ expr = NULL;
+ for (j = 0; j < nelem(expressions); j++) {
+ if (!strcasecmp((*argv)[0]+1, expressions[j].expr)) {
+ expr = &expressions[j];
+ break;
+ }
}
+ if (expr == NULL)
+ die("Expression '%s' unknown.\n", (*argv)[0]);
- astr = estr;
- switch (expr->syntax[j]) {
+ switch (expr->syntax[0]) {
case PICK_HEADERPREP:
- continue;
- case PICK_STR:
- estr = smprintf("%s \"%s\"", estr, (*argv)[1]);
+ nestr = smprintf("HEADER %s", expr->expr);
break;
- case PICK_NUM:
- case PICK_KEY:
case PICK_SEQ:
- case PICK_DATE:
- estr = smprintf("%s %s", estr, (*argv)[1]);
+ nestr = smprintf("");
break;
- case PICK_EXPR:
- *argv = &(*argv)[1];
- rstr = pick_mksearchstring(argv);
- estr = smprintf("%s %s", estr, rstr);
- free(rstr);
- free(astr);
- continue;
default:
- continue;
+ nestr = smprintf("%s", expr->expr);
+ break;
}
- free(astr);
- *argv = &(*argv)[1];
- }
+ if (estr == NULL) {
+ estr = nestr;
+ } else {
+ estr = smprintf("%s %s", estr, nestr);
+ }
+
+ for (j = 0; expr->syntax[j] != PICK_END; j++) {
+ if (!(*argv)[1]) {
+ die("Expected argument of type %s at '%s'\n",
+ desc[(int)expr->syntax[j]],
+ (*argv)[0]);
+ }
+
+ astr = estr;
+ switch (expr->syntax[j]) {
+ case PICK_HEADERPREP:
+ continue;
+ case PICK_STR:
+ estr = smprintf("%s \"%s\"", estr, (*argv)[1]);
+ *argv = &(*argv)[2];
+ break;
+ case PICK_NUM:
+ case PICK_KEY:
+ case PICK_SEQ:
+ case PICK_DATE:
+ estr = smprintf("%s %s", estr, (*argv)[1]);
+ *argv = &(*argv)[2];
+ break;
+ case PICK_EXPR:
+ *argv = &(*argv)[1];
+ rstr = pick_mksearchstring(argv);
+ estr = smprintf("%s %s", estr, rstr);
+ free(rstr);
+ free(astr);
+ continue;
+ default:
+ *argv = &(*argv)[1];
+ continue;
+ }
+ free(astr);
+ }
+ } while((*argv)[0] != NULL);
return estr;
}