From 41d2b1e8332e80b71e3d8b96c94d0407f39d6a66 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 8 Feb 2009 13:08:15 +0100 Subject: Implement argument parsing for --follow --- inotail.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/inotail.c b/inotail.c index 7c49c4a..1162516 100644 --- a/inotail.c +++ b/inotail.c @@ -88,6 +88,13 @@ static void *emalloc(const size_t size) return ret; } +static inline int xargmatch(const char *context, const char *arg) +{ + size_t ctx_len = strlen(context); + + return (strlen(arg) == ctx_len && strncmp(arg, context, ctx_len) == 0); +} + static void usage(const int status) { fprintf(stdout, "Usage: %s [OPTION]... [FILE]...\n\n" @@ -770,7 +777,16 @@ int main(int argc, char **argv) n_units = strtoul(optarg, NULL, 0); break; case 'f': - follow = FOLLOW_DESCRIPTOR; + /* Just -f or --follow=descriptor */ + if (!optarg || xargmatch("descriptor", optarg)) + follow = FOLLOW_DESCRIPTOR; + else if (xargmatch("name", optarg)) + follow = FOLLOW_NAME; + else { + fprintf(stderr, "Error: Invalid argument '%s' for --follow.\n" + "Try '%s --help' for more information\n", optarg, PROGRAM_NAME); + exit(EXIT_FAILURE); + } break; case 'F': follow = FOLLOW_NAME; -- cgit v1.2.3-54-g00ecf