This commit is contained in:
Nikolaj
2021-10-26 16:12:26 +02:00
parent a988405fd3
commit 456adc7611
11 changed files with 418 additions and 327 deletions

View File

@@ -20,68 +20,68 @@
#include "job_queue.h"
int main(int argc, char * const *argv) {
if (argc < 2) {
err(1, "usage: [-n INT] STRING paths...");
exit(1);
}
int num_threads = 1;
char const *needle = argv[1];
char * const *paths = &argv[2];
if (argc > 3 && strcmp(argv[1], "-n") == 0) {
// Since atoi() simply returns zero on syntax errors, we cannot
// distinguish between the user entering a zero, or some
// non-numeric garbage. In fact, we cannot even tell whether the
// given option is suffixed by garbage, i.e. '123foo' returns
// '123'. A more robust solution would use strtol(), but its
// interface is more complicated, so here we are.
num_threads = atoi(argv[2]);
if (num_threads < 1) {
err(1, "invalid thread count: %s", argv[2]);
if (argc < 2) {
err(1, "usage: [-n INT] STRING paths...");
exit(1);
}
needle = argv[3];
paths = &argv[4];
int num_threads = 1;
char const *needle = argv[1];
char * const *paths = &argv[2];
} else {
needle = argv[1];
paths = &argv[2];
}
assert(0); // Initialise the job queue and some worker threads here.
if (argc > 3 && strcmp(argv[1], "-n") == 0) {
// Since atoi() simply returns zero on syntax errors, we cannot
// distinguish between the user entering a zero, or some
// non-numeric garbage. In fact, we cannot even tell whether the
// given option is suffixed by garbage, i.e. '123foo' returns
// '123'. A more robust solution would use strtol(), but its
// interface is more complicated, so here we are.
num_threads = atoi(argv[2]);
// FTS_LOGICAL = follow symbolic links
// FTS_NOCHDIR = do not change the working directory of the process
//
// (These are not particularly important distinctions for our simple
// uses.)
int fts_options = FTS_LOGICAL | FTS_NOCHDIR;
if (num_threads < 1) {
err(1, "invalid thread count: %s", argv[2]);
}
FTS *ftsp;
if ((ftsp = fts_open(paths, fts_options, NULL)) == NULL) {
err(1, "fts_open() failed");
return -1;
}
needle = argv[3];
paths = &argv[4];
FTSENT *p;
while ((p = fts_read(ftsp)) != NULL) {
switch (p->fts_info) {
case FTS_D:
break;
case FTS_F:
assert(0); // Process the file p->fts_path, somehow.
break;
default:
break;
} else {
needle = argv[1];
paths = &argv[2];
}
}
fts_close(ftsp);
assert(0); // Initialise the job queue and some worker threads here.
assert(0); // Shut down the job queue and the worker threads here.
// FTS_LOGICAL = follow symbolic links
// FTS_NOCHDIR = do not change the working directory of the process
//
// (These are not particularly important distinctions for our simple
// uses.)
int fts_options = FTS_LOGICAL | FTS_NOCHDIR;
return 0;
FTS *ftsp;
if ((ftsp = fts_open(paths, fts_options, NULL)) == NULL) {
err(1, "fts_open() failed");
return -1;
}
FTSENT *p;
while ((p = fts_read(ftsp)) != NULL) {
switch (p->fts_info) {
case FTS_D:
break;
case FTS_F:
assert(0); // Process the file p->fts_path, somehow.
break;
default:
break;
}
}
fts_close(ftsp);
assert(0); // Shut down the job queue and the worker threads here.
return 0;
}