aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-08-22 21:48:40 +0100
committerHarry Jeffery <harry@exec64.co.uk>2017-08-22 21:48:40 +0100
commit9587c93fd59d1e1972536e48797fa8c8648a82ff (patch)
tree7c2a7b42906452837d152d0a2600ec8532c002c3 /src
parent39509816cf9162c8a4656379c390f35b17daa8d7 (diff)
downloadimv-9587c93fd59d1e1972536e48797fa8c8648a82ff.tar.gz
Reimplement -n flag
Diffstat (limited to 'src')
-rw-r--r--src/imv.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/imv.c b/src/imv.c
index 84e2317..63addcf 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -17,14 +17,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "imv.h"
+#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <poll.h>
-#include <stdlib.h>
#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
-#include <unistd.h>
#include "commands.h"
#include "list.h"
@@ -364,6 +366,23 @@ int imv_run(struct imv *imv)
if(!setup_window(imv))
return 1;
+ if(imv->starting_path) {
+ int index = imv_navigator_find_path(imv->navigator, imv->starting_path);
+ if(index == -1) {
+ index = (int) strtol(imv->starting_path, NULL, 10);
+ index -= 1; /* input is 1-indexed, internally we're 0 indexed */
+ if(errno == EINVAL) {
+ index = -1;
+ }
+ }
+
+ if(index >= 0) {
+ imv_navigator_select_str(imv->navigator, index);
+ } else {
+ fprintf(stderr, "Invalid starting image: %s\n", imv->starting_path);
+ }
+ }
+
/* cache current image's dimensions */
int iw = 0;
int ih = 0;