* Copyright (C) Jaakko Heinonen
*/
-#include <string.h>
+#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
set_filenames();
check_abook_directory();
init_opts();
- if(load_opts(rcfile)) {
+ if(load_opts(rcfile) > 0) {
printf("Press enter to continue...\n");
fgetc(stdin);
}
}
void
-quit_abook()
+quit_abook(int save_db)
{
- if( opt_get_bool(BOOL_AUTOSAVE) )
- save_database();
- else if( statusline_ask_boolean("Save database", TRUE) )
- save_database();
+ if(save_db) {
+ if(opt_get_bool(BOOL_AUTOSAVE))
+ save_database();
+ else if(statusline_ask_boolean("Save database", TRUE))
+ save_database();
+ } else if(!statusline_ask_boolean("Quit without saving", FALSE))
+ return;
free_opts();
close_database();
static void
quit_abook_sig(int i)
{
- quit_abook();
+ quit_abook(QUIT_SAVE);
}
int
main(int argc, char **argv)
{
#if defined(HAVE_SETLOCALE) && defined(HAVE_LOCALE_H)
- setlocale(LC_ALL, "" );
+ setlocale(LC_ALL, "");
#endif
parse_command_line(argc, argv);
get_commands();
- quit_abook();
+ quit_abook(QUIT_SAVE);
return 0;
}
putchar('\n');
while(i >= 0) {
muttq_print_item(stdout, i);
- i = find_item(str, i+1, search_fields);
+ i = find_item(str, i + 1, search_fields);
}
}
}
}
- cmd = strconcat(mutt_command, " \'", mailstr,
- "\'", NULL);
+ cmd = strconcat(mutt_command, " \'", mailstr, "\'", NULL);
free(mailstr);
#ifdef DEBUG
fprintf(stderr, "cmd: %s\n", cmd);
if ( (ptr = malloc(size)) == NULL ) {
if( is_ui_initialized() )
- quit_abook();
+ quit_abook(QUIT_SAVE);
perror("malloc() failed");
exit(1);
}
{
ptr = realloc(ptr, size);
- if( size == 0 )
+ if(size == 0)
return NULL;
- if( ptr == NULL ) {
- if( is_ui_initialized() )
- quit_abook();
+ if(ptr == NULL) {
+ if(is_ui_initialized())
+ quit_abook(QUIT_SAVE);
perror("realloc() failed");
exit(1);
}
init_opts();
load_opts(rcfile);
- switch( import_file(srcformat, srcfile) ) {
+ switch(import_file(srcformat, srcfile)) {
case -1:
fprintf(stderr,
"input format %s not supported\n", srcformat);
}
if(!ret)
- switch( export_file(dstformat, dstfile) ) {
+ switch(export_file(dstformat, dstfile)) {
case -1:
fprintf(stderr,
"output format %s not supported\n",
{
set_filenames();
atexit(free_filenames);
+ check_abook_directory();
init_opts();
load_opts(rcfile);
atexit(free_opts);
"you may want to use --add-email-quiet\n");
exit(1);
}
- printf("Add ``%s <%s>'' to %s ? (y/n)\n",
- name,
- email,
- datafile
- );
+
do {
- c = fgetc(in);
+ printf("Add ``%s <%s>'' to %s ? (y/n)\n",
+ name,
+ email,
+ datafile);
+ c = getc(in);
if(c == 'n' || c == 'N') {
fclose(in);
return 0;
char *name = NULL, *email = NULL;
struct stat s;
- if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode)) {
+ if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode) ) {
fprintf(stderr, "stdin is a directory or cannot stat stdin\n");
exit(1);
}