From 0b2be425c3427f0c1d311b4523c107b25a0e8c0c Mon Sep 17 00:00:00 2001 From: Michal Koutenský Date: Fri, 13 Nov 2015 21:54:38 +0100 Subject: sxiv-like 'start at' option --- src/main.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index fc73455..9cd9563 100644 --- a/src/main.c +++ b/src/main.c @@ -31,13 +31,14 @@ struct { int stdin; int recursive; int actual; -} g_options = {0,0,0,0}; + long int start_at; +} g_options = {0,0,0,0,0}; void print_usage(const char* name) { fprintf(stdout, "imv %s\n" - "Usage: %s [-irfah] [images...]\n" + "Usage: %s [-irfah] [-n NUM] [images...]\n" "\n" "Flags:\n" " -i: Read paths from stdin. One path per line.\n" @@ -46,6 +47,9 @@ void print_usage(const char* name) " -a: Default to images' actual size\n" " -h: Print this help\n" "\n" + "Options:\n" + " -n NUM: Starts at picture number NUM.\n" + "\n" "Mouse:\n" " Click+Drag to Pan\n" " MouseWheel to Zoom\n" @@ -88,8 +92,10 @@ void parse_args(int argc, char** argv) const char* name = argv[0]; char o; + char* end; + long int n; - while((o = getopt(argc, argv, "firah")) != -1) { + while((o = getopt(argc, argv, "firahn:")) != -1) { switch(o) { case 'f': g_options.fullscreen = 1; break; case 'i': @@ -99,6 +105,14 @@ void parse_args(int argc, char** argv) case 'r': g_options.recursive = 1; break; case 'a': g_options.actual = 1; break; case 'h': print_usage(name); exit(0); break; + case 'n': + n = strtol(optarg,&end,0); + if(*end != '\0' || n <= 0) { + fprintf(stderr, "Warning: wrong value for '-n'.\n"); + } else { + g_options.start_at = n - 1; + } + break; case '?': fprintf(stderr, "Unknown argument '%c'. Aborting.\n", optopt); exit(1); @@ -189,6 +203,10 @@ int main(int argc, char** argv) double last_time = SDL_GetTicks() / 1000.0; + for(long int i = 0; i < g_options.start_at; ++i) { + imv_navigator_next_path(&nav); + } + int quit = 0; while(!quit) { SDL_Event e; -- cgit v1.2.3