From: Raphaƫl Droz Date: Tue, 6 Nov 2012 22:55:17 +0000 (+0100) Subject: * exit() if an unsupported outformat is given after --mutt-query. X-Git-Tag: upstream/0.6.1~2^2~46 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=6e4a7610dcb671089f011061603a6bc7c604881d;p=pkg%2Fabook.git * exit() if an unsupported outformat is given after --mutt-query. * More documentation about (query + formats) possibilities (comments + manpage) --- diff --git a/abook.1 b/abook.1 index 3e37f98..cec6047 100644 --- a/abook.1 +++ b/abook.1 @@ -27,12 +27,14 @@ Use an alternative configuration file (default is \fI$HOME/.abook/abookrc\fR). \fB\-\-datafile\fP \fI\fR Use an alternative addressbook file (default is \fI$HOME/.abook/addressbook\fR). .TP -\fB\-\-mutt\-query\fP \fI\fR +\fB\-\-mutt\-query\fP \fI\fR [ \fB\-\-outformat\fP \fI\fR ] Make a query for mutt (search the addressbook for \fI\fR). .br The \fB\-\-datafile\fP option, as documented above, may be used .BI BEFORE this option to search a different addressbook file. +.br +Only a subset of the below \fI\fR are allowed: \fBmutt\fP (default), \fBvcard\fP and \fBcustom\fP .TP \fB\-\-convert\fP [ \fB\-\-informat\fP \fI\fR ] [ \fB\-\-infile\fP \fI\fR ] [ \fB\-\-outformat\fP \fI\fR ] [ \fB\-\-outfile\fP \fI\fR ] Converts \fI\fR in \fI\fR to \fI\fR in \fI\fR @@ -87,11 +89,13 @@ The following \fIoutputformats\fR are supported: - \fBcustom\fP Custom output format, see below .TP \fB\-\-outformatstr\fP \fI\fR -Only used in the context of \fB\-\-mutt\-query\fP \fIand\fR \fB\-\-outformat\fP=\fIcustom\fR. \fI\fR is a format string allowing placeholders. -A placeholder can be any of the standard fields names (see \fBabookrc\fP(5)) and must be -encapsulated by curly brackets. +Only used if \fB\-\-mutt\-query\fP \fIor\fR \fB\-\-convert\fP is specified \fIand\fR \fB\-\-outformat\fP=\fIcustom\fR. \fI\fR is a format string allowing placeholders. +.br +A placeholder can be any of the standard fields names (see \fBabookrc\fP(5)) and must be encapsulated by curly brackets. +.br The default value is "{nick} ({name}): {mobile}" -If \fI\fR starts with \fI!\fR only entries whose every fields from \fI\fR are non-NULL are part of the output. +.br +If \fI\fR starts with \fI!\fR only entries whose all fields from \fI\fR are non-NULL are included. .TP \fB\-\-add-email\fP Read an e-mail message from stdin and add the sender to the addressbook. diff --git a/abook.c b/abook.c index b5a941e..8521058 100644 --- a/abook.c +++ b/abook.c @@ -377,7 +377,11 @@ parse_command_line(int argc, char **argv) set_convert_var(informat); break; case OPT_OUTFORMAT: + // ascii-name is stored, it's used to traverse + // e_filters[] in MODE_CONVERT (see export_file()) outformat = optarg; + // but in case a query-compatible filter is requested + // try to guess right now which one it is, from u_filters[] selected_item_filter = select_output_item_filter(outformat); break; case OPT_OUTFORMAT_STR: @@ -398,6 +402,12 @@ parse_command_line(int argc, char **argv) } } + // if the output format requested does not allow filtered querying + // (not in u_filter[]) and --convert has not been specified; bailout + if(! selected_item_filter.func && mode != MODE_CONVERT) { + printf("output format %s not supported or incompatible with --mutt-query\n", outformat); + exit(EXIT_FAILURE); + } if(! selected_item_filter.func) selected_item_filter = select_output_item_filter("muttq"); else if (! strcmp(outformat, "custom") && *custom_format) { diff --git a/filter.c b/filter.c index 653f7af..1c96a88 100644 --- a/filter.c +++ b/filter.c @@ -73,7 +73,8 @@ static int custom_export_database(FILE *out, struct db_enumerator e); */ void vcard_export_item(FILE *out, int item); - +void muttq_print_item(FILE *file, int item); +void custom_print_item(FILE *out, int item); /* * end of function declarations @@ -127,21 +128,21 @@ print_filters() { int i; - puts(_("input:")); + puts(_("input formats:")); for(i=0; *i_filters[i].filtname ; i++) printf("\t%s\t%s\n", i_filters[i].filtname, gettext(i_filters[i].desc)); putchar('\n'); - puts(_("output:")); + puts(_("output formats:")); for(i=0; *e_filters[i].filtname ; i++) printf("\t%s\t%s\n", e_filters[i].filtname, gettext(e_filters[i].desc)); putchar('\n'); - puts(_("output (with query):")); + puts(_("query-compatible output formats:")); for(i=0; *u_filters[i].filtname ; i++) printf("\t%s\t%s\n", u_filters[i].filtname, gettext(u_filters[i].desc));