diff options
author | Dave Reisner <d@falconindy.com> | 2010-11-30 22:59:54 -0500 |
---|---|---|
committer | Dave Reisner <d@falconindy.com> | 2010-11-30 22:59:54 -0500 |
commit | 7e66cffa9e16a425402634bfb918455e604b9c1a (patch) | |
tree | 240e3c5d3125c2de9ed176104ea7e18ba044f006 /expac.c | |
parent | f7f40808c6efed7dc984ee8ec0612294041da26e (diff) | |
download | expac-7e66cffa9e16a425402634bfb918455e604b9c1a.tar.xz |
filter token availability based on query type
use verify_format_string to halt expac if a token is provided that is
query type dependent and we don't match the query type.
Diffstat (limited to 'expac.c')
-rw-r--r-- | expac.c | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -34,13 +34,16 @@ #include <stdlib.h> #include <string.h> -#define FORMAT_TOKENS "BCDEFGLNOPRSabdfiklmnprsuvw%" -#define ESCAPE_TOKENS "\"\\abefnrtv" +#define FORMAT_TOKENS "BCDEGLNOPRSabdkmnprsuvw%" +#define FORMAT_TOKENS_LOCAL "ilFw" +#define FORMAT_TOKENS_SYNC "f" +#define ESCAPE_TOKENS "\"\\abefnrtv" alpm_list_t *dblist = NULL, *targets = NULL; pmdb_t *db_local; bool verbose = false; bool search = false; +bool local = false; const char *format = NULL; const char *timefmt = NULL; const char *listdelim = NULL; @@ -197,6 +200,7 @@ static int parse_options(int argc, char *argv[]) { return(1); } dblist = alpm_list_add(dblist, db_local); + local = true; break; case 'd': delim = optarg; @@ -458,9 +462,21 @@ int verify_format_string(const char *format) { const char *p; for (p = format; *p != '\0'; p++) { - if (*p == '%' && !strchr(FORMAT_TOKENS, *++p)) { - fprintf(stderr, "error: bad token in format string: %%%c\n", *p); - return(1); + if (*p == '%') { + ++p; + if (!strchr(FORMAT_TOKENS FORMAT_TOKENS_LOCAL FORMAT_TOKENS_SYNC, *p)) { + fprintf(stderr, "error: bad token in format string: %%%c\n", *p); + return(1); + } + + /* check for querytype dependent tokens */ + if (!local && strchr(FORMAT_TOKENS_LOCAL, *p)) { + fprintf(stderr, "error: token not available with local queries: %%%c\n", *p); + return(1); + } else if (local && strchr(FORMAT_TOKENS_SYNC, *p)) { + fprintf(stderr, "error: token not available with sync queries: %%%c\n", *p); + return(1); + } } else if (*p == '\\' && !strchr(ESCAPE_TOKENS, *++p)) { fprintf(stderr, "error: bad token in format string: \\%c\n", *p); return(1); @@ -532,6 +548,7 @@ int main(int argc, char *argv[]) { /* ensure sane defaults */ if (!dblist) { + local = true; dblist = alpm_list_add(dblist, db_local); } delim = delim ? delim : "\n"; |