From c08eb8f347ee9a40594bdab64447baae10f39168 Mon Sep 17 00:00:00 2001 From: Lieuwe Rooijakkers Date: Sun, 18 Aug 2024 17:56:56 +0200 Subject: boom: improve flags --- src/boom.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/boom.c b/src/boom.c index 5d2a6d7..279f0ca 100644 --- a/src/boom.c +++ b/src/boom.c @@ -21,9 +21,10 @@ static void usage(FILE *f) { fprintf(f, "Gebruik: boom [-thV] [STARTPUNTEN]...\n" "\n" - "TODO\n" + "Geef inhoud van mapjes weer in een boom-achtig formaat.\n" "\n" - " -t Bestandtypes om weer te geven, kan zijn b(estand), m(apje) of een combinatie gescheiden door komma's\n" + " -a Alle bestanden worden weergegeven, ookal beginnen ze met een puntje\n" + " -m Geef alleen mapjes weer\n" " -d Maximale diepte\n" " -o Omvang van n beten (+, - voor meer of minder)\n" " -h Toon deze hulptekst\n" @@ -33,16 +34,24 @@ static void usage(FILE *f) { // Returns pointer to argument array containing the starting points static char** parse_options(int argc, char **argv) { int opt; - while ((opt = getopt(argc, argv, "adhV")) != -1) { + while ((opt = getopt(argc, argv, "amd:hV")) != -1) { switch (opt) { case 'a': show_hidden = true; break; - case 'd': + case 'm': dirs_only = true; break; + case 'd': + max_depth = atoi(optarg); + if (max_depth <= 0) { + fprintf(stderr, "boom: maximale diepte moet groter zijn dan 0\n"); + exit(1); + } + break; + case 'h': usage(stdout); exit(0); @@ -77,7 +86,7 @@ static int f(const char *fpath, const struct stat *, int typeflag, struct FTW *f } // check max depth - if (max_depth >= 0 && level >= max_depth) return 0; + if (max_depth >= 0 && level >= (max_depth + 1)) return 0; const char *fname = basename(fpath); -- cgit v1.2.3-70-g09d2