From ecc363ec10dec864dd2c956b478549ff235fb3d6 Mon Sep 17 00:00:00 2001 From: Antti Korpi Date: Thu, 13 Jul 2017 01:15:51 +0100 Subject: Add -p flag to disable writing of cache and temporary files Closes #285. --- options.c | 8 ++++++-- options.h | 1 + sxiv.1 | 5 ++++- thumbs.c | 6 +++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/options.c b/options.c index 258dc37..66cfcc5 100644 --- a/options.c +++ b/options.c @@ -32,7 +32,7 @@ const options_t *options = (const options_t*) &_options; void print_usage(void) { - printf("usage: sxiv [-abcfhioqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " + printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] " "FILES...\n"); } @@ -72,8 +72,9 @@ void parse_options(int argc, char **argv) _options.quiet = false; _options.thumb_mode = false; _options.clean_cache = false; + _options.private_mode = false; - while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:oqrS:s:tvZz:")) != -1) { + while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -129,6 +130,9 @@ void parse_options(int argc, char **argv) case 'o': _options.to_stdout = true; break; + case 'p': + _options.private_mode = true; + break; case 'q': _options.quiet = true; break; diff --git a/options.h b/options.h index c9879f3..53153da 100644 --- a/options.h +++ b/options.h @@ -50,6 +50,7 @@ typedef struct { bool quiet; bool thumb_mode; bool clean_cache; + bool private_mode; } options_t; extern const options_t *options; diff --git a/sxiv.1 b/sxiv.1 index dd2d7c5..bf738f8 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -3,7 +3,7 @@ sxiv \- Simple X Image Viewer .SH SYNOPSIS .B sxiv -.RB [ \-abcfhioqrtvZ ] +.RB [ \-abcfhiopqrtvZ ] .RB [ \-A .IR FRAMERATE ] .RB [ \-e @@ -80,6 +80,9 @@ with .B \-i sxiv can be used as a visual filter/pipe. .TP +.B \-p +Enable private mode, in which sxiv does not write any cache or temporary files. +.TP .B \-q Be quiet, disable warnings to standard error stream. .TP diff --git a/thumbs.c b/thumbs.c index 4f6c181..a9f4fe0 100644 --- a/thumbs.c +++ b/thumbs.c @@ -25,6 +25,7 @@ #include #include +#include "options.h" #include "thumbs.h" #include "util.h" @@ -83,6 +84,9 @@ void tns_cache_write(Imlib_Image im, const char *filepath, bool force) struct utimbuf times; Imlib_Load_Error err = 0; + if (options->private_mode) + return; + if (stat(filepath, &fstats) < 0) return; @@ -270,7 +274,7 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) cache_hit = true; } #if HAVE_LIBEXIF - } else if (!force) { + } else if (!force && !options->private_mode) { int pw = 0, ph = 0, w, h, x = 0, y = 0; bool err; float zw, zh; -- cgit v1.2.3