diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -81,7 +81,7 @@ int main(int argc, char **argv) { exit(1); } - if (options->recursive) + if (options->recursive || options->from_stdin) filecnt = FNAME_CNT; else filecnt = options->filecnt; @@ -89,15 +89,22 @@ int main(int argc, char **argv) { filenames = (const char**) s_malloc(filecnt * sizeof(const char*)); fileidx = 0; - for (i = 0; i < options->filecnt; ++i) { - filename = options->filenames[i]; - if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) { - if (options->recursive) - read_dir_rec(filename); - else - warn("ignoring directory: %s", filename); - } else { - check_append(filename); + if (options->from_stdin) { + while ((filename = readline(stdin))) { + if (!check_append(filename)) + free((void*) filename); + } + } else { + for (i = 0; i < options->filecnt; ++i) { + filename = options->filenames[i]; + if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) { + if (options->recursive) + read_dir_rec(filename); + else + warn("ignoring directory: %s", filename); + } else { + check_append(filename); + } } } @@ -132,8 +139,8 @@ void update_title() { size = filesize; size_readable(&size, &unit); n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> (%.2f%s) %s", - fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit, - filenames[fileidx]); + fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit, + filenames[fileidx]); } else { n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] broken: %s", fileidx + 1, filecnt, filenames[fileidx]); @@ -156,7 +163,7 @@ int check_append(const char *filename) { if (fileidx == filecnt) { filecnt *= 2; filenames = (const char**) s_realloc(filenames, - filecnt * sizeof(const char*)); + filecnt * sizeof(const char*)); } filenames[fileidx++] = filename; return 1; @@ -200,7 +207,7 @@ void read_dir_rec(const char *dirname) { if (diridx == dircnt) { dircnt *= 2; dirnames = (const char**) s_realloc(dirnames, - dircnt * sizeof(const char*)); + dircnt * sizeof(const char*)); } dirnames[diridx++] = filename; } else { |