test/t_fscrawl.c: cleanup
This commit is contained in:
parent
ad06c58ba5
commit
9378c5824e
1 changed files with 28 additions and 14 deletions
|
|
@ -1,40 +1,54 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "../src/fscrawl.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
fscrawl_t crawl;
|
||||
unsigned int c_ent = 0;
|
||||
|
||||
unsigned int c_ent = 0, verbose = 0;
|
||||
time_t t1, t2, tdiff;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
|
||||
if (argc > 2 && (argv[2][0] == '1' && argv[2][1] == '\0'))
|
||||
verbose = 1;
|
||||
|
||||
crawl = fsc_open(argv[1]);
|
||||
|
||||
if (crawl == NULL) {
|
||||
printf("Invalid path\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
t1 = time(NULL);
|
||||
for(;;) {
|
||||
|
||||
fs_entry *ent = fsc_read(crawl);
|
||||
|
||||
if (!ent)
|
||||
break;
|
||||
|
||||
printf("%s%s", ent->base, ent->name);
|
||||
|
||||
if (ent->dir)
|
||||
printf("/\n");
|
||||
else
|
||||
printf("\n");
|
||||
|
||||
if (verbose)
|
||||
printf("%s%s%c\n", ent->base, ent->name,
|
||||
ent->dir ? '/' : '\0');
|
||||
|
||||
c_ent++;
|
||||
}
|
||||
|
||||
printf("%i Entries\n", c_ent);
|
||||
t2 = time(NULL);
|
||||
|
||||
fsc_close(crawl);
|
||||
|
||||
tdiff = t2 - t1;
|
||||
printf("Nodes: %u\n"
|
||||
"Time (sec): %ld\n", c_ent, tdiff);
|
||||
|
||||
printf("Node/sec: ");
|
||||
if (tdiff) {
|
||||
printf("%ld\n", c_ent / tdiff);
|
||||
} else {
|
||||
puts("INF");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue