]> 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 43f0294a6b418642ec6ebe8396964896db1aa4d3..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;
 
@@ -132,6 +138,8 @@ init_abook()
 
        signal(SIGTERM, quit_abook_sig);
 
+       init_index();
+
        if(init_ui())
                exit(EXIT_FAILURE);
 
@@ -185,9 +193,11 @@ int
 main(int argc, char **argv)
 {
 #if defined(HAVE_SETLOCALE) && defined(HAVE_LOCALE_H)
-       setlocale(LC_ALL, "");
+       setlocale(LC_MESSAGES, "");
+       setlocale(LC_TIME, "");
+       setlocale(LC_CTYPE, "");
+       setlocale(LC_COLLATE, "");
 #endif
-
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
@@ -299,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;
@@ -364,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);
@@ -380,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]);
@@ -442,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;
@@ -480,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);
                }
        }
@@ -706,6 +698,7 @@ init_add_email()
        check_abook_directory();
        init_opts();
        load_opts(rcfile);
+       init_standard_fields();
        atexit(free_opts);
 
        /*