]> git.deb.at Git - pkg/abook.git/blobdiff - abook.c
applied "quit and print" patch correctly
[pkg/abook.git] / abook.c
diff --git a/abook.c b/abook.c
index 57db4e46be931493510da3f2e981595020e126ad..af0d9d03e20d16f9da94e152722184e360822d28 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * by JH <jheinonen@bigfoot.com>
+ * by JH <jheinonen@users.sourceforge.net>
  *
  * Copyright (C) Jaakko Heinonen
  */
@@ -206,7 +206,7 @@ show_usage()
 extern list_item *database;
 
 static void
-muttq_print_item(int item)
+muttq_print_item(FILE *file, int item)
 {
        char emails[MAX_EMAILS][MAX_EMAIL_LEN];
        int i;
@@ -216,7 +216,7 @@ muttq_print_item(int item)
        for(i = 0; i < (options_get_int("mutt_return_all_emails") ?
                        MAX_EMAILS : 1) ; i++)
                if( *emails[i] )
-                       printf("%s\t%s\t%s\n", emails[i],
+                       fprintf(file, "%s\t%s\t%s\n", emails[i],
                                database[item][NAME],
                                database[item][NOTES] == NULL ? " " :
                                        database[item][NOTES]
@@ -232,7 +232,7 @@ mutt_query(char *str)
                struct db_enumerator e = init_db_enumerator(ENUM_ALL);
                printf("All items\n");
                db_enumerate_items(e)
-                       muttq_print_item(e.item);
+                       muttq_print_item(stdout, e.item);
        } else {
                int search_fields[] = {NAME, EMAIL, NICK, -1};
                int i;
@@ -242,7 +242,7 @@ mutt_query(char *str)
                }
                putchar('\n');
                while(i >= 0) {
-                       muttq_print_item(i);
+                       muttq_print_item(stdout, i);
                        i = find_item(str, i+1, search_fields);
                }
        }
@@ -284,34 +284,53 @@ make_mailstr(int item)
 
        ret = *database[item][EMAIL] ?
                mkstr("%s <%s>", name, email) :
-               name;
+               strdup(name);
 
        free(name);
        
        return ret;
 }
 
+void
+print_stderr(int item)
+{
+    fprintf (stderr, "%c", '\n');
+
+       if( is_valid_item(item) )
+               muttq_print_item(stderr, item);
+       else {
+               struct db_enumerator e = init_db_enumerator(ENUM_SELECTED);
+               db_enumerate_items(e) {
+                       muttq_print_item(stderr, e.item);
+               }
+       }
+
+}
+
 void
 launch_mutt(int item)
 {
        char *cmd = NULL, *mailstr = NULL;
+       char *mutt_command = options_get_str("mutt_command");
+
+       if(mutt_command == NULL || !*mutt_command)
+               return;
 
        if( is_valid_item(item) )
                mailstr = make_mailstr(item);
-
-       /*
-        * need to implement for multiple addresses
-        */
-               /*
-       } else {
+       else {
                struct db_enumerator e = init_db_enumerator(ENUM_SELECTED);
+               char *tmp = NULL;
                db_enumerate_items(e) {
                        tmp = mailstr;
-                       mailstr = strconcat(tmp, make_mailstr(e.item);
-                       
-       }*/
+                       mailstr = tmp ?
+                               strconcat(tmp, ",", make_mailstr(e.item), NULL):
+                               strconcat(make_mailstr(e.item), NULL);
+                       free(tmp);
+               }
+       }
 
-       cmd = strconcat(options_get_str("mutt_command"), " \'", mailstr,
+       cmd = strconcat(mutt_command, " \'", mailstr,
                                "\'", NULL);
        free(mailstr);
 #ifdef DEBUG
@@ -319,6 +338,11 @@ launch_mutt(int item)
 #endif
        system(cmd);    
        free(cmd);
+       
+       /*
+        * we need to make sure that curses settings are correct
+        */
+       ui_init_curses();
 }
 
 void
@@ -340,6 +364,11 @@ launch_wwwbrowser(int item)
                system(cmd);
 
        free(cmd);
+
+       /*
+        * we need to make sure that curses settings are correct
+        */
+       ui_init_curses();
 }
 
 void *
@@ -404,11 +433,13 @@ convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile)
        strlower(srcformat);
        strlower(dstformat);
 
+#ifndef DEBUG
        if( !strcmp(srcformat, dstformat) ) {
                printf( "input and output formats are the same\n"
                        "exiting...\n");
                exit(1);
        }
+#endif
 
        set_filenames();
        init_options();
@@ -440,4 +471,3 @@ convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile)
        exit(ret);
 }
 
-