aboutsummaryrefslogtreecommitdiff
path: root/src/lib/arg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/arg.c')
-rw-r--r--src/lib/arg.c47
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++;
}