summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/calcurse.1.txt6
-rw-r--r--doc/manual.txt6
-rw-r--r--src/args.c7
-rw-r--r--src/calcurse.h1
-rw-r--r--src/config.c13
-rw-r--r--src/io.c32
-rw-r--r--src/vars.c3
7 files changed, 50 insertions, 18 deletions
diff --git a/doc/calcurse.1.txt b/doc/calcurse.1.txt
index f611079..b7870f1 100644
--- a/doc/calcurse.1.txt
+++ b/doc/calcurse.1.txt
@@ -128,6 +128,12 @@ the *-c* flag.
Print events and appointments for the 'num' number of days and exit. If no
'num' is given, a range of 1 day is considered.
+*--read-only*::
+ Don't save configuration nor appointments/todos.
++
+'Warning:' Use this this with care! If you run an interactive calcurse instance
+in read-only mode, all changes from this session will be lost without warning!
+
*-s*[date], *--startday*[=date]::
Print events and appointments from 'date' and exit. If no 'date' is given,
the current day is considered.
diff --git a/doc/manual.txt b/doc/manual.txt
index 4964a21..b3369b7 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -234,6 +234,12 @@ the `-c` flag.
Print events and appointments for the num number of days and exit. If no num
is given, a range of 1 day is considered.
+`--read-only`::
+ Don't save configuration nor appointments/todos.
++
+WARNING: Use this this with care! If you run an interactive calcurse instance
+in read-only mode, all changes from this session will be lost without warning!
+
`-s[date], --startday[=date]`::
Print events and appointments from date and exit. If no date is given, the
current day is considered.
diff --git a/src/args.c b/src/args.c
index 04dd690..4583d44 100644
--- a/src/args.c
+++ b/src/args.c
@@ -51,7 +51,8 @@ enum {
OPT_FMT_RAPT,
OPT_FMT_EV,
OPT_FMT_REV,
- OPT_FMT_TODO
+ OPT_FMT_TODO,
+ OPT_READ_ONLY
};
/*
@@ -665,6 +666,7 @@ parse_args (int argc, char **argv)
{"format-event", required_argument, NULL, OPT_FMT_EV},
{"format-recur-event", required_argument, NULL, OPT_FMT_REV},
{"format-todo", required_argument, NULL, OPT_FMT_TODO},
+ {"read-only", no_argument, NULL, OPT_READ_ONLY},
{NULL, no_argument, NULL, 0}
};
@@ -793,6 +795,9 @@ parse_args (int argc, char **argv)
case OPT_FMT_TODO:
fmt_todo = optarg;
break;
+ case OPT_READ_ONLY:
+ read_only = 1;
+ break;
default:
usage ();
usage_try ();
diff --git a/src/calcurse.h b/src/calcurse.h
index 5104d45..16ef558 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -946,6 +946,7 @@ extern int resize;
extern unsigned colorize;
extern int foreground, background;
extern enum ui_mode ui_mode;
+extern int read_only;
extern int days[12];
extern char *monthnames[12];
extern char *daynames[8];
diff --git a/src/config.c b/src/config.c
index e965c1a..6355781 100644
--- a/src/config.c
+++ b/src/config.c
@@ -451,19 +451,11 @@ config_file_walk (config_fn_walk_cb_t fn_cb,
config_fn_walk_junk_cb_t fn_junk_cb, void *data)
{
FILE *data_file;
- char *mesg_line1 = _("Failed to open config file");
- char *mesg_line2 = _("Press [ENTER] to continue");
char buf[BUFSIZ], e_conf[BUFSIZ];
char *key, *value;
data_file = fopen (path_conf, "r");
- if (data_file == NULL)
- {
- status_mesg (mesg_line1, mesg_line2);
- wnoutrefresh (win[STA].p);
- wins_doupdate ();
- keys_getch (win[STA].p, NULL);
- }
+ EXIT_IF (data_file == NULL, _("failed to open configuration file"));
pthread_mutex_lock (&nbar.mutex);
for (;;)
@@ -561,6 +553,9 @@ config_save (void)
struct config_save_status status;
int i;
+ if (read_only)
+ return 1;
+
strncpy (tmppath, get_tempdir (), BUFSIZ);
strncat (tmppath, "/" CONF_PATH_NAME ".", BUFSIZ - strlen (tmppath) - 1);
if ((tmpext = new_tempfile (tmppath, TMPEXTSIZ)) == NULL)
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))
{
diff --git a/src/vars.c b/src/vars.c
index 10c87a0..807e206 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -58,6 +58,9 @@ int foreground, background;
*/
enum ui_mode ui_mode = UI_CMDLINE;
+/* Don't save anything if this is set. */
+int read_only = 0;
+
/*
* variables to store calendar names
*/