diff options
author | Bert <ber.t@gmx.com> | 2011-02-14 17:51:04 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-02-14 17:51:04 +0100 |
commit | 26cc5aff69856caf01a925ee1357b3650d806d67 (patch) | |
tree | e0ecd554c2a910f896e082271d8bc50905e51e68 /main.c | |
parent | ea65610747bf324c98f390fba91b8a7c8818006a (diff) | |
download | nsxiv-26cc5aff69856caf01a925ee1357b3650d806d67.tar.zst |
Read filenames from stdin
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 27 |
1 files changed, 17 insertions, 10 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); + } } } |