From 7e66cffa9e16a425402634bfb918455e604b9c1a Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 30 Nov 2010 22:59:54 -0500 Subject: 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. --- expac.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'expac.c') diff --git a/expac.c b/expac.c index 528db51..6582fad 100644 --- a/expac.c +++ b/expac.c @@ -34,13 +34,16 @@ #include #include -#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"; -- cgit v1.2.3-54-g00ecf