nsxiv2252a01
New option: -n, start at given picture
+27 −9
6 files changed
- M Makefile +1 −1
- M README.md +1 −0
- M main.c +4 −4
- M options.c +14 −3
- M options.h +2 −1
- M sxiv.1 +5 −0
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110522 | |
| 3 | + | VERSION=git-20110525 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | DESTDIR?= | |
| @@ -40,6 +40,7 @@ sxiv supports the following command-line options: | |||
| 40 | 40 | -f Start in fullscreen mode | |
| 41 | 41 | -g GEOMETRY Set window position and size | |
| 42 | 42 | (see section GEOMETRY SPECIFICATIONS of X(7)) | |
| 43 | + | -n NUM Start at picture NUM | |
| 43 | 44 | -p Pixelize, i.e. turn off image anti-aliasing | |
| 44 | 45 | -q Be quiet, disable warnings | |
| 45 | 46 | -r Search given directories recursively for images | |
| @@ -231,14 +231,14 @@ int main(int argc, char **argv) { | |||
| 231 | 231 | } | |
| 232 | 232 | } | |
| 233 | 233 | ||
| 234 | − | filecnt = fileidx; | |
| 235 | − | fileidx = 0; | |
| 236 | − | ||
| 237 | − | if (!filecnt) { | |
| 234 | + | if (!fileidx) { | |
| 238 | 235 | fprintf(stderr, "sxiv: no valid image file given, aborting\n"); | |
| 239 | 236 | exit(1); | |
| 240 | 237 | } | |
| 241 | 238 | ||
| 239 | + | filecnt = fileidx; | |
| 240 | + | fileidx = options->startnum < filecnt ? options->startnum : filecnt - 1; | |
| 241 | + | ||
| 242 | 242 | win_init(&win); | |
| 243 | 243 | img_init(&img, &win); | |
| 244 | 244 | ||
| @@ -31,7 +31,7 @@ options_t _options; | |||
| 31 | 31 | const options_t *options = (const options_t*) &_options; | |
| 32 | 32 | ||
| 33 | 33 | void print_usage() { | |
| 34 | − | printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); | |
| 34 | + | printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] [-z ZOOM] FILES...\n"); | |
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | void print_version() { | |
| @@ -40,7 +40,9 @@ void print_version() { | |||
| 40 | 40 | ||
| 41 | 41 | void parse_options(int argc, char **argv) { | |
| 42 | 42 | float z; | |
| 43 | − | int opt; | |
| 43 | + | int n, opt; | |
| 44 | + | ||
| 45 | + | _options.startnum = 0; | |
| 44 | 46 | ||
| 45 | 47 | _options.scalemode = SCALE_MODE; | |
| 46 | 48 | _options.zoom = 1.0; | |
| @@ -55,7 +57,7 @@ void parse_options(int argc, char **argv) { | |||
| 55 | 57 | _options.clean_cache = 0; | |
| 56 | 58 | _options.recursive = 0; | |
| 57 | 59 | ||
| 58 | − | while ((opt = getopt(argc, argv, "cdFfg:hpqrstvZz:")) != -1) { | |
| 60 | + | while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) { | |
| 59 | 61 | switch (opt) { | |
| 60 | 62 | case '?': | |
| 61 | 63 | print_usage(); | |
| @@ -78,6 +80,15 @@ void parse_options(int argc, char **argv) { | |||
| 78 | 80 | case 'h': | |
| 79 | 81 | print_usage(); | |
| 80 | 82 | exit(0); | |
| 83 | + | case 'n': | |
| 84 | + | if (!sscanf(optarg, "%d", &n) || n < 1) { | |
| 85 | + | fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", | |
| 86 | + | optarg); | |
| 87 | + | exit(1); | |
| 88 | + | } else { | |
| 89 | + | _options.startnum = n - 1; | |
| 90 | + | } | |
| 91 | + | break; | |
| 81 | 92 | case 'p': | |
| 82 | 93 | _options.aa = 0; | |
| 83 | 94 | break; | |
| @@ -23,8 +23,9 @@ | |||
| 23 | 23 | ||
| 24 | 24 | typedef struct { | |
| 25 | 25 | const char **filenames; | |
| 26 | − | int filecnt; | |
| 27 | 26 | unsigned char from_stdin; | |
| 27 | + | int filecnt; | |
| 28 | + | int startnum; | |
| 28 | 29 | ||
| 29 | 30 | scalemode_t scalemode; | |
| 30 | 31 | float zoom; | |
| @@ -6,6 +6,8 @@ sxiv \- Simple (or small or suckless) X Image Viewer | |||
| 6 | 6 | .RB [ \-cdFfhpqrstvZ ] | |
| 7 | 7 | .RB [ \-g | |
| 8 | 8 | .IR GEOMETRY ] | |
| 9 | + | .RB [ \-n | |
| 10 | + | .IR NUM ] | |
| 9 | 11 | .RB [ \-z | |
| 10 | 12 | .IR ZOOM ] | |
| 11 | 13 | .IR FILE ... | |
| @@ -49,6 +51,9 @@ Set window position and size. See section GEOMETRY SPECIFICATIONS of X(7) for | |||
| 49 | 51 | more information on | |
| 50 | 52 | .IR GEOMETRY . | |
| 51 | 53 | .TP | |
| 54 | + | .BI "\-n " NUM | |
| 55 | + | Start at picture number NUM. | |
| 56 | + | .TP | |
| 52 | 57 | .B \-h | |
| 53 | 58 | Print brief usage information to standard output and exit. | |
| 54 | 59 | .TP | |