summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2009-02-08 13:08:15 +0100
committerTobias Klauser <tklauser@distanz.ch>2009-02-08 13:08:15 +0100
commit41d2b1e8332e80b71e3d8b96c94d0407f39d6a66 (patch)
tree16ae66d9e4668bd63790028eab151de588852ae5
parenta76fa322044d2de630a28b493b953da5aa38c906 (diff)
Implement argument parsing for --follow
-rw-r--r--inotail.c18
1 files changed, 17 insertions, 1 deletions
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;