From 8ead883c321c1c16192e862585dab9c1c0b398c8 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 6 Aug 2014 15:59:15 +0200 Subject: io.c: Error out on non-existent calendar file Show an error message and die if the user specified a non-existent custom calendar file. This fixes some random hangs when calcurse is used in non-interactive mode within scripts. Signed-off-by: Lukas Fleischer --- src/io.c | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/io.c b/src/io.c index 4733802..a6f5958 100644 --- a/src/io.c +++ b/src/io.c @@ -226,10 +226,7 @@ unsigned io_fprintln(const char *fname, const char *fmt, ...) */ void io_init(const char *cfile, const char *datadir) { - FILE *data_file; const char *home; - char apts_file[BUFSIZ] = ""; - int ch; if (datadir != NULL) { home = datadir; @@ -265,41 +262,9 @@ void io_init(const char *cfile, const char *datadir) snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home); } } else { - snprintf(apts_file, BUFSIZ, "%s", cfile); - strncpy(path_apts, apts_file, BUFSIZ); - /* check if the file exists, otherwise create it */ - data_file = fopen(path_apts, "r"); - if (data_file == NULL) { - printf(_("%s does not exist, create it now [y/n]? "), - path_apts); - ch = getchar(); - switch (ch) { - case 'N': - case 'n': - puts(_("aborting...\n")); - exit_calcurse(EXIT_FAILURE); - break; - - case 'Y': - case 'y': - data_file = fopen(path_apts, "w"); - if (data_file == NULL) { - perror(path_apts); - exit_calcurse(EXIT_FAILURE); - } else { - printf(_("%s successfully created\n"), - path_apts); - puts(_("starting interactive mode...\n")); - } - break; - - default: - puts(_("aborting...\n")); - exit_calcurse(EXIT_FAILURE); - break; - } - } - file_close(data_file, __FILE_POS__); + snprintf(path_apts, BUFSIZ, "%s", cfile); + EXIT_IF(!io_file_exists(path_apts), _("%s does not exist"), + path_apts); } } -- cgit v1.2.3-70-g09d2