aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-02-14 17:51:04 +0100
committerBert <ber.t@gmx.com>2011-02-14 17:51:04 +0100
commit26cc5aff69856caf01a925ee1357b3650d806d67 (patch)
treee0ecd554c2a910f896e082271d8bc50905e51e68 /main.c
parentea65610747bf324c98f390fba91b8a7c8818006a (diff)
downloadnsxiv-26cc5aff69856caf01a925ee1357b3650d806d67.tar.zst
Read filenames from stdin
Diffstat (limited to 'main.c')
-rw-r--r--main.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/main.c b/main.c
index f449df9..35cf44a 100644
--- a/main.c
+++ b/main.c
@@ -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);
+ }
}
}