aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-06 17:18:30 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-06 17:18:30 +0000
commitae9ef127877e757356a952d862d0bc567b59cae1 (patch)
tree3e5d8986fdd9a4c870ce0203f0f4895c0289f0b4
parent4df9227dadb4fc34b6a47bcb9b6055cc5c0c2ec4 (diff)
downloadimv-ae9ef127877e757356a952d862d0bc567b59cae1.tar.gz
Accept paths from stdin
-rw-r--r--main.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/main.c b/main.c
index 827cc3c..b5eee89 100644
--- a/main.c
+++ b/main.c
@@ -89,7 +89,7 @@ void add_path(const char* path)
new_path->prev = g_path.last;
g_path.first->prev = new_path;
new_path->next = g_path.first;
- g_path.last= new_path;
+ g_path.last = new_path;
}
}
@@ -161,6 +161,25 @@ int main(int argc, char** argv)
exit(1);
}
+ if(argc == 2 && argv[1][0] == '-') {
+ char buf[512];
+ while(fgets(buf, sizeof(buf), stdin)) {
+ size_t len = strlen(buf);
+ if(buf[len-1] == '\n') {
+ buf[--len] = 0;
+ }
+ if(len > 0) {
+ char *str = (char*)malloc(len + 1);
+ memcpy(str, buf, len + 1);
+ add_path(str);
+ }
+ }
+ } else {
+ for(int i = 1; i < argc; ++i) {
+ add_path(argv[i]);
+ }
+ }
+
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "SDL Failed to Init: %s\n", SDL_GetError());
exit(1);
@@ -178,10 +197,6 @@ int main(int argc, char** argv)
g_renderer = SDL_CreateRenderer(g_window, -1, SDL_RENDERER_ACCELERATED);
- for(int i = 1; i < argc; ++i) {
- add_path(argv[i]);
- }
-
int quit = 0;
while(!quit) {