From a6762de0a3ccf6ff7a11f43c3cfe517f38fbb111 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Droz?= Date: Tue, 30 Aug 2011 11:53:36 +0200 Subject: [PATCH] convert (1/1): introduced prototypes for per-item filtering functions. Filtering and output on a per-entry basis rather than in a main-loop is needed as soon as we want both query + formatting. The abook_output_item_filter is aimed to store query-compatible output filters. For most output formats generate a strict and standard-compliant output and won't need this. But the goal is the have a generic customizable format compatible with an hypothetic --query switch. As a future example, --mutt-query could be seen as: --query --format="{email} {name}" (see the 6 following patches) --- filter.c | 30 ++++++++++++++++++++++++++++++ filter.h | 12 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/filter.c b/filter.c index 1841280..51445ee 100644 --- a/filter.c +++ b/filter.c @@ -100,6 +100,10 @@ struct abook_output_filter e_filters[] = { { "\0", NULL, NULL } }; +struct abook_output_item_filter u_filters[] = { + { "\0", NULL } +}; + /* * common functions */ @@ -122,6 +126,13 @@ print_filters() gettext(e_filters[i].desc)); putchar('\n'); + + puts(_("output (with query):")); + for(i=0; *u_filters[i].filtname ; i++) + printf("\t%s\t%s\n", u_filters[i].filtname, + gettext(u_filters[i].desc)); + + putchar('\n'); } static int @@ -361,6 +372,25 @@ export_database() return 0; } +struct abook_output_item_filter select_output_item_filter(char filtname[FILTNAME_LEN]) { + int i; + for(i=0;; i++) { + if(!strncasecmp(u_filters[i].filtname, filtname, FILTNAME_LEN)) + break; + if(!*u_filters[i].filtname) { + i = -1; + break; + } + } + return u_filters[i]; +} + +void +e_write_item(FILE *out, int item, void (*func) (FILE *in, int item)) +{ + (*func) (out, item); +} + static int e_write_file(char *filename, int (*func) (FILE *in, struct db_enumerator e), int mode) diff --git a/filter.h b/filter.h index 6957b04..290725f 100644 --- a/filter.h +++ b/filter.h @@ -12,6 +12,12 @@ struct abook_output_filter { int (*func) (FILE *handle, struct db_enumerator e); }; +struct abook_output_item_filter { + char filtname[FILTNAME_LEN]; + char *desc; + void (*func) (FILE *handle, int item); +}; + struct abook_input_filter { char filtname[FILTNAME_LEN]; char *desc; @@ -24,6 +30,12 @@ int import_file(char filtname[FILTNAME_LEN], char *filename); int export_database(); int export_file(char filtname[FILTNAME_LEN], char *filename); + +struct abook_output_item_filter + select_output_item_filter(char filtname[FILTNAME_LEN]); + +void e_write_item(FILE *out, int item, void (*func) (FILE *in, int item)); + int fexport(char filtname[FILTNAME_LEN], FILE *handle, int enum_mode); -- 2.39.5