]> git.deb.at Git - pkg/abook.git/commitdiff
convert (1/1): introduced prototypes for per-item filtering functions.
authorRaphaël Droz <raphael.droz+floss@gmail.com>
Tue, 30 Aug 2011 09:53:36 +0000 (11:53 +0200)
committerRaphaël Droz <raphael.droz+floss@gmail.com>
Wed, 24 Oct 2012 16:23:43 +0000 (18:23 +0200)
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
filter.h

index 184128017b9b4bdd8c4c6942be77535334f90ac6..51445ee1f1bf9947c323bc478a4f7fcafb22f9da 100644 (file)
--- 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)
index 6957b0405b32d1b6957f54d0038ad6a781a3bcc7..290725fde89981b6ba1b983108a6f82644889620 100644 (file)
--- 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);