summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-02-22 11:36:33 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2012-02-24 22:48:26 +0100
commit3bc9497fc84abca0493083c3c208f0d2738bed38 (patch)
tree5f50bbd93b1885298df17c1d24848547c7813aa1 /src/io.c
parentf76e1cce404418cef74772536f2f5ac3a79b7b99 (diff)
downloadcalcurse-3bc9497fc84abca0493083c3c208f0d2738bed38.zip
Add a read-only option
We don't save any configuration nor items if this is set. This should be used with care, and hence there's no short option for this. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/io.c b/src/io.c
index e5b6f0d..03756b2 100644
--- a/src/io.c
+++ b/src/io.c
@@ -355,6 +355,9 @@ io_save_apts (void)
llist_item_t *i;
FILE *fp;
+ if (read_only)
+ return 1;
+
if ((fp = fopen (path_apts, "w")) == NULL)
return 0;
@@ -387,6 +390,9 @@ io_save_todo (void)
llist_item_t *i;
FILE *fp;
+ if (read_only)
+ return 1;
+
if ((fp = fopen (path_todo, "w")) == NULL)
return 0;
@@ -406,6 +412,9 @@ io_save_keys (void)
{
FILE *fp;
+ if (read_only)
+ return 1;
+
if ((fp = fopen (path_keys, "w")) == NULL)
return 0;
@@ -424,6 +433,9 @@ io_save_cal (enum save_display display)
char *enter = _("Press [ENTER] to continue");
int show_bar;
+ if (read_only)
+ return;
+
pthread_mutex_lock (&io_save_mutex);
show_bar = 0;
@@ -487,6 +499,8 @@ io_load_app (void)
start = end = until = *lt;
data_file = fopen (path_apts, "r");
+ EXIT_IF (data_file == NULL, _("failed to open appointment file"));
+
for (;;)
{
LLIST_INIT (&exc);
@@ -659,19 +673,14 @@ void
io_load_todo (void)
{
FILE *data_file;
- char *mesg_line1 = _("Failed to open todo file");
- char *mesg_line2 = _("Press [ENTER] to continue");
char *newline;
int nb_tod = 0;
int c, id;
char buf[BUFSIZ], e_todo[BUFSIZ], note[MAX_NOTESIZ + 1];
data_file = fopen (path_todo, "r");
- if (data_file == NULL)
- {
- status_mesg (mesg_line1, mesg_line2);
- wgetch (win[STA].p);
- }
+ EXIT_IF (data_file == NULL, _("failed to open todo file"));
+
for (;;)
{
c = getc (data_file);
@@ -771,7 +780,8 @@ io_load_keys (char *pager)
}
keyfp = fopen (path_keys, "r");
- EXIT_IF (keyfp == NULL, _("could not find any key file."));
+ EXIT_IF (keyfp == NULL, _("failed to open key file"));
+
log = io_log_init ();
skipped = loaded = line = 0;
while (fgets (buf, BUFSIZ, keyfp) != NULL)
@@ -883,6 +893,9 @@ io_load_keys (char *pager)
void
io_check_dir (char *dir, int *missing)
{
+ if (read_only)
+ return;
+
errno = 0;
if (mkdir (dir, 0700) != 0)
{
@@ -919,6 +932,9 @@ io_file_exist (char *file)
void
io_check_file (char *file, int *missing)
{
+ if (read_only)
+ return;
+
errno = 0;
if (!io_file_exist (file))
{