Read filenames from stdin

This commit is contained in:
Bert
2011-02-14 17:51:04 +01:00
parent ea65610747
commit 26cc5aff69
6 changed files with 64 additions and 12 deletions

27
main.c
View File

@ -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);
}
}
}