From ae9ef127877e757356a952d862d0bc567b59cae1 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Fri, 6 Nov 2015 17:18:30 +0000 Subject: Accept paths from stdin --- main.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'main.c') 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) { -- cgit v1.2.3