X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=abook.c;h=42c04c1f37022eceb632739fd38098673867c4a5;hb=0c57d01df43a4d9d02456d694c2a0cd6cb80a637;hp=9458cfd44db0777c9c1812840aed13412c751bdd;hpb=b7e40d5b0aef77bca4ee3e90b85daf94c5d95a26;p=pkg%2Fabook.git diff --git a/abook.c b/abook.c index 9458cfd..42c04c1 100644 --- a/abook.c +++ b/abook.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include "options.h" #include "getname.h" #include "getopt.h" +#include "views.h" #include "xmalloc.h" static void init_abook(); @@ -51,6 +53,7 @@ static char *rcfile = NULL; bool alternative_datafile = FALSE; bool alternative_rcfile = FALSE; + static int datafile_writeable() { @@ -125,16 +128,19 @@ init_abook() printf(_("Press enter to continue...\n")); fgetc(stdin); } + init_default_views(); signal(SIGTERM, quit_abook_sig); + init_index(); + if(init_ui()) exit(EXIT_FAILURE); umask(DEFAULT_UMASK); if(!datafile_writeable()) { - char *s = mkstr(_("File %s is not writeable"), datafile); + char *s = strdup_printf(_("File %s is not writeable"), datafile); refresh_screen(); statusline_msg(s); free(s); @@ -181,14 +187,18 @@ 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); xmalloc_set_error_handler(xmalloc_error_handler); + prepare_database_internals(); + parse_command_line(argc, argv); init_abook(); @@ -374,7 +384,7 @@ parse_command_line(int argc, char **argv) } } - if (optind < argc) { + if(optind < argc) { fprintf(stderr, _("%s: unrecognized arguments on command line\n"), argv[0]); exit(EXIT_FAILURE); @@ -426,7 +436,6 @@ show_usage() * end of CLI */ -extern list_item *database; static void quit_mutt_query(int status) @@ -440,19 +449,20 @@ quit_mutt_query(int status) static void muttq_print_item(FILE *file, int item) { - char emails[MAX_EMAILS][MAX_EMAIL_LEN]; - int i; - - split_emailstr(item, emails); - - for(i = 0; i < (opt_get_bool(BOOL_MUTT_RETURN_ALL_EMAILS) ? - MAX_EMAILS : 1) ; i++) - if( *emails[i] ) - fprintf(file, "%s\t%s\t%s\n", emails[i], - database[item][NAME], - database[item][NOTES] == NULL ? " " : - database[item][NOTES] + 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 @@ -502,12 +512,12 @@ make_mailstr(int item) { char email[MAX_EMAIL_LEN]; char *ret; - char *name = mkstr("\"%s\"", database[item][NAME]); + char *name = strdup_printf("\"%s\"", db_name_get(item)); get_first_email(email, item); - ret = *database[item][EMAIL] ? - mkstr("%s <%s>", name, email) : + ret = *email ? + strdup_printf("%s <%s>", name, email) : xstrdup(name); free(name); @@ -576,10 +586,10 @@ launch_wwwbrowser(int item) if( !is_valid_item(item) ) return; - if( database[item][URL] ) - cmd = mkstr("%s '%s'", + if(db_fget(item, URL)) + cmd = strdup_printf("%s '%s'", opt_get_str(STR_WWW_COMMAND), - safe_str(database[item][URL])); + safe_str(db_fget(item, URL))); else return; @@ -631,6 +641,7 @@ convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile) set_filenames(); init_opts(); load_opts(rcfile); + init_standard_fields(); switch(import_file(srcformat, srcfile)) { case -1: @@ -699,6 +710,7 @@ init_add_email() check_abook_directory(); init_opts(); load_opts(rcfile); + init_standard_fields(); atexit(free_opts); /* @@ -740,21 +752,22 @@ add_email_add_item(int quiet, char *name, char *email) name, email, datafile, - *_("keybinding for yes|y"), - *_("keybinding for no|n")); + *S_("keybinding for yes|y"), + *S_("keybinding for no|n")); c = tolower(getc(in)); - if(c == *_("keybinding for no|n")) { + if(c == *S_("keybinding for no|n")) { fclose(in); return 0; } - } while(c != *_("keybinding for yes|y")); + } while(c != *S_("keybinding for yes|y")); fclose(in); } - memset(item, 0, sizeof(item)); - item[NAME] = xstrdup(name); - item[EMAIL] = xstrdup(email); + item = item_create(); + item_fput(item, NAME, xstrdup(name)); + item_fput(item, EMAIL, xstrdup(email)); add_item2database(item); + item_free(&item); return 1; }