summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/calcurse.c6
-rw-r--r--src/calcurse.h3
-rw-r--r--src/io.c24
3 files changed, 23 insertions, 10 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index 31be357..16d979f 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -309,7 +309,9 @@ static inline void key_generic_reload(void)
int ret;
ret = io_reload_data();
- if (ret != IO_RELOAD_CANCEL && ret != IO_RELOAD_NOOP) {
+ if (ret == IO_RELOAD_LOAD ||
+ ret == IO_RELOAD_CTINUE ||
+ ret == IO_RELOAD_MERGE) {
ui_todo_load_items();
ui_todo_sel_reset();
do_storage(0);
@@ -331,6 +333,8 @@ static inline void key_generic_reload(void)
case IO_RELOAD_NOOP:
msg = _("Data were already loaded");
break;
+ case IO_RELOAD_ERROR:
+ EXIT(_("Cannot open data file"));
}
status_mesg(msg, "");
}
diff --git a/src/calcurse.h b/src/calcurse.h
index 49b1a70..4f41deb 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -673,7 +673,8 @@ enum {
IO_RELOAD_CTINUE,
IO_RELOAD_MERGE,
IO_RELOAD_CANCEL,
- IO_RELOAD_NOOP
+ IO_RELOAD_NOOP,
+ IO_RELOAD_ERROR
};
/* Week days. */
diff --git a/src/io.c b/src/io.c
index 72b2bba..9f20a18 100644
--- a/src/io.c
+++ b/src/io.c
@@ -444,12 +444,15 @@ static int resolve_save_conflict(void)
return ret;
}
-/* Return codes for new_data(). */
+/*
+ * Return codes for new_data() and io_load_data().
+ * Note that they are file internal.
+ */
#define NONEW 0
-#define APTS 1
-#define TODO 2
-#define APTS_TODO 3
-#define NOKNOW 4
+#define APTS (1 << 0)
+#define TODO (1 << 1)
+#define APTS_TODO APTS | TODO
+#define NOKNOW -1
static int new_data()
{
char sha1_new[SHA1_DIGESTLEN * 2 + 1];
@@ -813,8 +816,8 @@ void io_load_todo(struct item_filter *filter)
/*
* Load appointments and todo items.
* Unless told otherwise, the function will only load a file that has changed
- * since last saved or loaded, see new_data() return codes.
- * Return codes are for use in io_reload_data() only.
+ * since last saved or loaded. The new_data() return code is passed on when
+ * force is false. When force is true (FORCE), the return code is of no use.
*/
int io_load_data(struct item_filter *filter, int force)
{
@@ -824,6 +827,9 @@ int io_load_data(struct item_filter *filter, int force)
else
force = new_data();
+ if (force == NOKNOW)
+ goto exit;
+
if (force & APTS) {
apoint_llist_free();
event_llist_free();
@@ -842,7 +848,7 @@ int io_load_data(struct item_filter *filter, int force)
}
io_unset_modified();
-
+ exit:
run_hook("post-load");
return force;
}
@@ -889,6 +895,8 @@ int io_reload_data(void)
load = io_load_data(NULL, load);
if (load == NONEW)
ret = IO_RELOAD_NOOP;
+ else if (load == NOKNOW)
+ ret = IO_RELOAD_ERROR;
cleanup:
io_mutex_unlock();
mem_free(msg_um_asktype);