]> git.deb.at Git - pkg/abook.git/blobdiff - abook.c
custom output format (2/4): item-based and the other database-based output functions
[pkg/abook.git] / abook.c
diff --git a/abook.c b/abook.c
index 42c04c1f37022eceb632739fd38098673867c4a5..9f956559b361cdcc01662d36a5e3d0d207d319e0 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -50,6 +50,12 @@ static void          add_email(int);
 char *datafile = NULL;
 static char *rcfile = NULL;
 
+// custom formatting
+char custom_format[FORMAT_STRING_LEN] = "{nick} ({name}): {mobile}";
+char *parsed_custom_format = NULL;
+enum field_types *custom_format_fields = 0;
+struct abook_output_item_filter selected_item_filter;
+
 bool alternative_datafile = FALSE;
 bool alternative_rcfile = FALSE;
 
@@ -303,6 +309,7 @@ parse_command_line(int argc, char **argv)
                *infile = "-",
                *outfile = "-";
        int c;
+       selected_item_filter = select_output_item_filter("muttq");
 
        for(;;) {
                int option_index = 0;
@@ -368,7 +375,8 @@ parse_command_line(int argc, char **argv)
                                set_convert_var(informat);
                                break;
                        case OPT_OUTFORMAT:
-                               set_convert_var(outformat);
+                               outformat = optarg;
+                               selected_item_filter = select_output_item_filter(outformat);
                                break;
                        case OPT_INFILE:
                                set_convert_var(infile);
@@ -384,6 +392,8 @@ parse_command_line(int argc, char **argv)
                }
        }
 
+       if(! selected_item_filter.func)
+               selected_item_filter = select_output_item_filter("muttq");
        if(optind < argc) {
                fprintf(stderr, _("%s: unrecognized arguments on command line\n"),
                                argv[0]);
@@ -446,35 +456,13 @@ quit_mutt_query(int status)
        exit(status);
 }
 
-static void
-muttq_print_item(FILE *file, int item)
-{
-       abook_list *emails, *e;
-       char *tmp = db_email_get(item);
-
-       emails = csv_to_abook_list(tmp);
-       free(tmp);
-
-       for(e = emails; e; e = e->next) {
-               fprintf(file, "%s\t%s\t%s\n", e->data, db_name_get(item),
-                               !db_fget(item, NOTES) ?" " :db_fget(item, NOTES)
-                               );
-               if(!opt_get_bool(BOOL_MUTT_RETURN_ALL_EMAILS))
-                       break;
-       }
-       abook_list_free(&emails);
-}
-
 static void
 mutt_query(char *str)
 {
        init_mutt_query();
 
        if( str == NULL || !strcasecmp(str, "all") ) {
-               struct db_enumerator e = init_db_enumerator(ENUM_ALL);
-               printf("All items\n");
-               db_enumerate_items(e)
-                       muttq_print_item(stdout, e.item);
+               export_file("muttq", "-");
        } else {
                int search_fields[] = {NAME, EMAIL, NICK, -1};
                int i;
@@ -484,7 +472,7 @@ mutt_query(char *str)
                }
                putchar('\n');
                while(i >= 0) {
-                       muttq_print_item(stdout, i);
+                       e_write_item(stdout, i, selected_item_filter.func);
                        i = find_item(str, i + 1, search_fields);
                }
        }