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

@@ -23,65 +23,65 @@ pthread_mutex_t stdout_mutex = PTHREAD_MUTEX_INITIALIZER;
#include "histogram.h"
int main(int argc, char * const *argv) {
if (argc < 2) {
err(1, "usage: paths...");
exit(1);
}
int num_threads = 1;
char * const *paths = &argv[1];
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: paths...");
exit(1);
}
paths = &argv[3];
} else {
paths = &argv[1];
}
int num_threads = 1;
char * const *paths = &argv[1];
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;
}
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;
paths = &argv[3];
} else {
paths = &argv[1];
}
}
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;
move_lines(9);
FTS *ftsp;
if ((ftsp = fts_open(paths, fts_options, NULL)) == NULL) {
err(1, "fts_open() failed");
return -1;
}
return 0;
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.
move_lines(9);
return 0;
}