diff options
author | Shav Kinderlehrer <[email protected]> | 2023-04-13 09:03:33 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-04-13 09:03:33 -0400 |
commit | 5f01703842daf79a5beb9b2d87bf42034346de03 (patch) | |
tree | 652ef2af1318c015954edbc1fe5d70ba8e2812a6 /src/lib/arg.c | |
parent | 58e0d435c38c0b4e6c59244436556dba6ed96abf (diff) | |
download | lat-5f01703842daf79a5beb9b2d87bf42034346de03.tar.gz lat-5f01703842daf79a5beb9b2d87bf42034346de03.zip |
Add argsv0.5.0
- --help
- --version
Diffstat (limited to 'src/lib/arg.c')
-rw-r--r-- | src/lib/arg.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/lib/arg.c b/src/lib/arg.c index 6178156..4b98f2b 100644 --- a/src/lib/arg.c +++ b/src/lib/arg.c @@ -4,9 +4,25 @@ #include <stdlib.h> #include <string.h> +#define LAT_USAGE "usage: lat [cnVh] [files..]" + +void help(void) { + printf("%s\n", LAT_USAGE); + printf("options:\n" + "\t-c, --color\t toggle whether to print color or not\n" + "\t-n, --lines\t toggle whether to print line numbers or not\n" + "\t-V, --version\t show program version\n" + "\t-h, --help\t display this help text\n"); +} + +void version(void) { + printf("lat - v%s | %s:%s\n", LAT_VERSION, __DATE__, __TIME__); +} + struct config conf; void argerr(char *r, char *arg) { - fprintf(stderr, "lat: %s '%s'\n", r, arg); + printf("lat: %s '%s'\n", r, arg); + printf("%s\n", LAT_USAGE); exit(EXIT_FAILURE); } @@ -21,6 +37,18 @@ void parselongarg(char *arg) { return; } + if (strcmp(arg, "--help") == 0) { + help(); + exit(EXIT_SUCCESS); + return; + } + + if (strcmp(arg, "--version") == 0) { + version(); + exit(EXIT_SUCCESS); + return; + } + argerr("unrecognized arg", arg); } @@ -35,9 +63,22 @@ void parseshortarg(char *arg) { case 'n': conf.lines = !conf.lines; break; - default: - argerr("unrecognized flag", &c); + case 'h': + help(); + exit(EXIT_SUCCESS); break; + case 'V': + version(); + exit(EXIT_SUCCESS); + break; + default: { + char *str = malloc(2); + str[0] = c; + str[1] = '\0'; + argerr("unrecognized flag", str); + free(str); + break; + } } i++; } |