From 1c23bb348dd09edae2aada1251339ea721dff6af Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 27 Oct 2022 13:36:43 +0200 Subject: [PATCH] feat: make configuration options from argtable3.h configurable Currently several argtable3 options can be modified only by changing them in source code. This commit makes these options configurable by adding ifndef guards: ARG_DSTR_SIZE, ARG_CMD_NAME_LEN, ARG_CMD_DESCRIPTION_LEN. ARG_DSTR_SIZE option is moved to argtable_private.h for two reasons: - Having them in argtable_private.h allows defining compiler flags (such as -DARG_DSTR_SIZE=100) for argtable3 files only. If the definitions are in the public header file (argtable3.h) then technically we have to pass -DARG_DSTR_SIZE=100 also to other files in the project, so that they evaluate argtable3.h in the same way. - Having them in argtable3.h is actually not necessary, since they are not used anywhere in the public interface. For the same two reasons, ARG_REPLACE_GETOPT has also been moved into argtable3_private.h in the same commit. --- src/arg_getopt_long.c | 3 +++ src/argtable3.h | 13 ++++++++----- src/argtable3_private.h | 12 ++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/arg_getopt_long.c b/src/arg_getopt_long.c index 0782713..b2dc4d8 100644 --- a/src/arg_getopt_long.c +++ b/src/arg_getopt_long.c @@ -50,6 +50,9 @@ */ #include "argtable3.h" +#ifndef ARG_AMALGAMATION +#include "argtable3_private.h" +#endif #if ARG_REPLACE_GETOPT == 1 diff --git a/src/argtable3.h b/src/argtable3.h index a8ee95d..0353eea 100644 --- a/src/argtable3.h +++ b/src/argtable3.h @@ -41,13 +41,16 @@ extern "C" { #endif #define ARG_REX_ICASE 1 -#define ARG_DSTR_SIZE 200 + +/* Maximum length of the command name */ +#ifndef ARG_CMD_NAME_LEN #define ARG_CMD_NAME_LEN 100 -#define ARG_CMD_DESCRIPTION_LEN 256 +#endif /* ARG_CMD_NAME_LEN */ -#ifndef ARG_REPLACE_GETOPT -#define ARG_REPLACE_GETOPT 1 /* use the embedded getopt as the system getopt(3) */ -#endif /* ARG_REPLACE_GETOPT */ +/* Maximum length of the command description */ +#ifndef ARG_CMD_DESCRIPTION_LEN +#define ARG_CMD_DESCRIPTION_LEN 256 +#endif /* ARG_CMD_DESCRIPTION_LEN */ /* bit masks for arg_hdr.flag */ enum { ARG_TERMINATOR = 0x1, ARG_HASVALUE = 0x2, ARG_HASOPTVALUE = 0x4 }; diff --git a/src/argtable3_private.h b/src/argtable3_private.h index 78725b4..5eb7a1b 100644 --- a/src/argtable3_private.h +++ b/src/argtable3_private.h @@ -43,6 +43,18 @@ #define ARG_ENABLE_LOG 1 #endif /* ARG_ENABLE_LOG */ +/* Use the embedded getopt as the system getopt(3) */ +#ifndef ARG_REPLACE_GETOPT +#define ARG_REPLACE_GETOPT 1 +#endif /* ARG_REPLACE_GETOPT */ + +/* Size of the buffer pre-allocated for dynamic strings. + * If the length exceeds this size, the buffer will be dynamically allocated. + */ +#ifndef ARG_DSTR_SIZE +#define ARG_DSTR_SIZE 200 +#endif /* ARG_DSTR_SIZE */ + #ifdef __cplusplus extern "C" { #endif