From 26cc5aff69856caf01a925ee1357b3650d806d67 Mon Sep 17 00:00:00 2001 From: Bert Date: Mon, 14 Feb 2011 17:51:04 +0100 Subject: Read filenames from stdin --- main.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'main.c') 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); + } } } -- cgit v1.2.3-54-g00ecf