From c9328b50310acaa46c65c4b2591cfc0f2468125e Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 5 Nov 2023 06:54:50 +0100 Subject: [PATCH] WIP: cli args --- doc/ulas.man | 14 +++++++++----- include/ulas.h | 6 ++++-- src/main.c | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/doc/ulas.man b/doc/ulas.man index 9360001..f7dbcdb 100644 --- a/doc/ulas.man +++ b/doc/ulas.man @@ -1,22 +1,26 @@ .\" Manpage for ulas. .\" Contact lukas@krickl.dev to correct errors or typos. -.TH man 8 "21 August 2023" "0.0.1" "ulas manual" +.TH man 1 "21 August 2023" "0.0.1" "ulas manual" .SH NAME ulas .SH SYNOPSIS - ulas [-v] [--help] [--version] + ulas [-hvV] .SH DESCRIPTION ulas - --help + -h display this help and exit - --version + -v display version info and exit -v, --verbose verbose output - + +.SH SYNTAX + + + .SH EXAMPLES .SH SEE ALSO diff --git a/include/ulas.h b/include/ulas.h index d7d3caa..f916a91 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -9,8 +9,6 @@ #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#define ULAS_COMMENT ';' - // Config variables #define ULAS_CFG_FMT_GREEN "\x1B[32m" #define ULAS_CFG_FMT_YELLOW "\x1B[33m" @@ -20,6 +18,10 @@ #define ULAS_CFG_FMT_BLUE "\x1B[34m" #define ULAS_CFG_FMT_RESET "\x1B[0m" +// configurable tokens +#define ULAS_TOK_COMMENT ';' +#define ULAS_TOK_DIRECTIVE_BEGIN '#' + // format macros #define ULAS_FMT(f, fmt) \ if (isatty(fileno(f)) && ulascfg.color) { \ diff --git a/src/main.c b/src/main.c index 9b2f4ee..d591da6 100644 --- a/src/main.c +++ b/src/main.c @@ -8,19 +8,27 @@ #define ULAS_NAME "ulas" #define ULAS_VER "0.0.1" +// args without value +#define ULAS_OPTS "hvV" + +// args with value +#define ULAS_OPTS_ARG "" + +#define ULAS_HELP(a, desc) printf("\t%s\t%s\n", (a), desc); + void ulas_help(void) { printf("%s\n", ULAS_NAME); - printf("Usage %s [-h] [-V] [-v]\n\n", ULAS_NAME); - printf("\t-h\tdisplay this help and exit\n"); - printf("\t-V\tdisplay version info and exit\n"); - printf("\t-v\tverbose output\n"); + printf("Usage %s [-%s]\n\n", ULAS_NAME, ULAS_OPTS); + ULAS_HELP("-h", "display this help and exit"); + ULAS_HELP("-V", "display version info and exit"); + ULAS_HELP("-v", "verbose output"); } void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); } void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) { int c = 0; - while ((c = getopt(argc, argv, "hvV")) != -1) { + while ((c = getopt(argc, argv, ULAS_OPTS ULAS_OPTS_ARG)) != -1) { switch (c) { case 'h': ulas_help(); -- 2.30.2