nsxivecc363e
Add -p flag to disable writing of cache and temporary files
Closes #285.
+16 −4
4 files changed
| @@ -32,7 +32,7 @@ const options_t *options = (const options_t*) &_options; | |||
| 32 | 32 | ||
| 33 | 33 | void print_usage(void) | |
| 34 | 34 | { | |
| 35 | − | printf("usage: sxiv [-abcfhioqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " | |
| 35 | + | printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " | |
| 36 | 36 | "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] " | |
| 37 | 37 | "FILES...\n"); | |
| 38 | 38 | } | |
| @@ -72,8 +72,9 @@ void parse_options(int argc, char **argv) | |||
| 72 | 72 | _options.quiet = false; | |
| 73 | 73 | _options.thumb_mode = false; | |
| 74 | 74 | _options.clean_cache = false; | |
| 75 | + | _options.private_mode = false; | |
| 75 | 76 | ||
| 76 | − | while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:oqrS:s:tvZz:")) != -1) { | |
| 77 | + | while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) { | |
| 77 | 78 | switch (opt) { | |
| 78 | 79 | case '?': | |
| 79 | 80 | print_usage(); | |
| @@ -129,6 +130,9 @@ void parse_options(int argc, char **argv) | |||
| 129 | 130 | case 'o': | |
| 130 | 131 | _options.to_stdout = true; | |
| 131 | 132 | break; | |
| 133 | + | case 'p': | |
| 134 | + | _options.private_mode = true; | |
| 135 | + | break; | |
| 132 | 136 | case 'q': | |
| 133 | 137 | _options.quiet = true; | |
| 134 | 138 | break; | |
| @@ -50,6 +50,7 @@ typedef struct { | |||
| 50 | 50 | bool quiet; | |
| 51 | 51 | bool thumb_mode; | |
| 52 | 52 | bool clean_cache; | |
| 53 | + | bool private_mode; | |
| 53 | 54 | } options_t; | |
| 54 | 55 | ||
| 55 | 56 | extern const options_t *options; | |
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | sxiv \- Simple X Image Viewer | |
| 4 | 4 | .SH SYNOPSIS | |
| 5 | 5 | .B sxiv | |
| 6 | − | .RB [ \-abcfhioqrtvZ ] | |
| 6 | + | .RB [ \-abcfhiopqrtvZ ] | |
| 7 | 7 | .RB [ \-A | |
| 8 | 8 | .IR FRAMERATE ] | |
| 9 | 9 | .RB [ \-e | |
| @@ -80,6 +80,9 @@ with | |||
| 80 | 80 | .B \-i | |
| 81 | 81 | sxiv can be used as a visual filter/pipe. | |
| 82 | 82 | .TP | |
| 83 | + | .B \-p | |
| 84 | + | Enable private mode, in which sxiv does not write any cache or temporary files. | |
| 85 | + | .TP | |
| 83 | 86 | .B \-q | |
| 84 | 87 | Be quiet, disable warnings to standard error stream. | |
| 85 | 88 | .TP | |
| @@ -25,6 +25,7 @@ | |||
| 25 | 25 | #include <unistd.h> | |
| 26 | 26 | #include <utime.h> | |
| 27 | 27 | ||
| 28 | + | #include "options.h" | |
| 28 | 29 | #include "thumbs.h" | |
| 29 | 30 | #include "util.h" | |
| 30 | 31 | ||
| @@ -83,6 +84,9 @@ void tns_cache_write(Imlib_Image im, const char *filepath, bool force) | |||
| 83 | 84 | struct utimbuf times; | |
| 84 | 85 | Imlib_Load_Error err = 0; | |
| 85 | 86 | ||
| 87 | + | if (options->private_mode) | |
| 88 | + | return; | |
| 89 | + | ||
| 86 | 90 | if (stat(filepath, &fstats) < 0) | |
| 87 | 91 | return; | |
| 88 | 92 | ||
| @@ -270,7 +274,7 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) | |||
| 270 | 274 | cache_hit = true; | |
| 271 | 275 | } | |
| 272 | 276 | #if HAVE_LIBEXIF | |
| 273 | − | } else if (!force) { | |
| 277 | + | } else if (!force && !options->private_mode) { | |
| 274 | 278 | int pw = 0, ph = 0, w, h, x = 0, y = 0; | |
| 275 | 279 | bool err; | |
| 276 | 280 | float zw, zh; | |