Krolyxon
Commit 2252a01

Branches

Refs →

nsxiv2252a01

New option: -n, start at given picture

Author
Bert
Date
2011-05-25 09:23 +0200
Parent
00e6cd2
Commit
2252a0148d11fc988131eb0bf6397453427d67e8

+27 −9

6 files changed

  1. M Makefile +1 −1
  2. M README.md +1 −0
  3. M main.c +4 −4
  4. M options.c +14 −3
  5. M options.h +2 −1
  6. M sxiv.1 +5 −0
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110522
3+VERSION=git-20110525
44
55 CC?=gcc
66 DESTDIR?=
M README.md View
@@ -40,6 +40,7 @@ sxiv supports the following command-line options:
4040 -f Start in fullscreen mode
4141 -g GEOMETRY Set window position and size
4242 (see section GEOMETRY SPECIFICATIONS of X(7))
43+ -n NUM Start at picture NUM
4344 -p Pixelize, i.e. turn off image anti-aliasing
4445 -q Be quiet, disable warnings
4546 -r Search given directories recursively for images
M main.c View
@@ -231,14 +231,14 @@ int main(int argc, char **argv) {
231231 }
232232 }
233233
234− filecnt = fileidx;
235− fileidx = 0;
236−
237− if (!filecnt) {
234+ if (!fileidx) {
238235 fprintf(stderr, "sxiv: no valid image file given, aborting\n");
239236 exit(1);
240237 }
241238
239+ filecnt = fileidx;
240+ fileidx = options->startnum < filecnt ? options->startnum : filecnt - 1;
241+
242242 win_init(&win);
243243 img_init(&img, &win);
244244
M options.c View
@@ -31,7 +31,7 @@ options_t _options;
3131 const options_t *options = (const options_t*) &_options;
3232
3333 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");
3535 }
3636
3737 void print_version() {
@@ -40,7 +40,9 @@ void print_version() {
4040
4141 void parse_options(int argc, char **argv) {
4242 float z;
43− int opt;
43+ int n, opt;
44+
45+ _options.startnum = 0;
4446
4547 _options.scalemode = SCALE_MODE;
4648 _options.zoom = 1.0;
@@ -55,7 +57,7 @@ void parse_options(int argc, char **argv) {
5557 _options.clean_cache = 0;
5658 _options.recursive = 0;
5759
58− while ((opt = getopt(argc, argv, "cdFfg:hpqrstvZz:")) != -1) {
60+ while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
5961 switch (opt) {
6062 case '?':
6163 print_usage();
@@ -78,6 +80,15 @@ void parse_options(int argc, char **argv) {
7880 case 'h':
7981 print_usage();
8082 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;
8192 case 'p':
8293 _options.aa = 0;
8394 break;
M options.h View
@@ -23,8 +23,9 @@
2323
2424 typedef struct {
2525 const char **filenames;
26− int filecnt;
2726 unsigned char from_stdin;
27+ int filecnt;
28+ int startnum;
2829
2930 scalemode_t scalemode;
3031 float zoom;
M sxiv.1 View
@@ -6,6 +6,8 @@ sxiv \- Simple (or small or suckless) X Image Viewer
66 .RB [ \-cdFfhpqrstvZ ]
77 .RB [ \-g
88 .IR GEOMETRY ]
9+.RB [ \-n
10+.IR NUM ]
911 .RB [ \-z
1012 .IR ZOOM ]
1113 .IR FILE ...
@@ -49,6 +51,9 @@ Set window position and size. See section GEOMETRY SPECIFICATIONS of X(7) for
4951 more information on
5052 .IR GEOMETRY .
5153 .TP
54+.BI "\-n " NUM
55+Start at picture number NUM.
56+.TP
5257 .B \-h
5358 Print brief usage information to standard output and exit.
5459 .TP