Browse Source

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.
pull/79/head
Ivan Grokhotkov 2 years ago
parent
commit
1c23bb348d
No known key found for this signature in database GPG Key ID: 1E050E141B280628
  1. 3
      src/arg_getopt_long.c
  2. 13
      src/argtable3.h
  3. 12
      src/argtable3_private.h

3
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

13
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 };

12
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

Loading…
Cancel
Save