Mercurial > hg > th-libs
annotate th_args.h @ 767:449a031c297c
Un-macroify th_vprintf_buf_*() function prototypes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 10 Feb 2023 02:45:34 +0200 |
parents | 31bc1ed07cf5 |
children |
rev | line source |
---|---|
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
473 | 2 * Simple commandline argument processing functions |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
726 | 4 * (C) Copyright 2002-2022 Tecnic Software productions (TNSP) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
8 /// @file |
473 | 9 /// @brief Simple commandline argument processing functions |
442
54081d784d75
Rename header #ifdef guards.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
10 #ifndef TH_ARGS_H |
54081d784d75
Rename header #ifdef guards.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
11 #define TH_ARGS_H |
49
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
12 |
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
13 #include "th_util.h" |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 extern "C" { |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 #endif |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
19 /** @def Option argument flags |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 */ |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
21 #define OPT_NONE (0) ///< Simple option with no arguments |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
22 #define OPT_ARGREQ (1) ///< Option requires an argument |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
23 #define OPT_ARGMASK (1) ///< Mask for option argument flags |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
25 /** @def Option processing flags |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
26 */ |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
27 #define OPTH_BAILOUT 0x0001 ///< Bail out on errors |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
28 #define OPTH_ONLY_OPTS 0x0010 ///< Handle only options |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
29 #define OPTH_ONLY_OTHER 0x0020 ///< Handle only "non-options" |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
30 #define OPTH_ONLY_MASK 0x00f0 ///< Mask |
137
0f43a94516f4
Improve argument handling module.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
31 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
33 /** Option argument structure |
140 | 34 */ |
136 | 35 typedef struct |
36 { | |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
37 int id; ///< Option ID (should be unique for each option) |
583 | 38 char o_short; ///< Short option name (one character, can be 0 for none) |
39 char *o_long; ///< Long option name (can be NULL for none) | |
587
98812eb78d8e
Add new compile-time optional th_optarg struct field o_arg for specifying the option argument description/name. TH_USE_OPT_ARG must be defined at compile time.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
40 #ifdef TH_USE_OPT_ARG |
98812eb78d8e
Add new compile-time optional th_optarg struct field o_arg for specifying the option argument description/name. TH_USE_OPT_ARG must be defined at compile time.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
41 char *o_arg; ///< Option argument name (can be NULL for none/default) |
98812eb78d8e
Add new compile-time optional th_optarg struct field o_arg for specifying the option argument description/name. TH_USE_OPT_ARG must be defined at compile time.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
42 #endif |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
43 char *desc; ///< Option description |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
44 int flags; ///< Flags (see OPT_*) |
380
ac10155d2b4a
Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
45 } th_optarg; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
735
31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
48 bool th_args_process(int argc, char *argv[], |
584
390c66af09cf
Move th_print_wrap() and th_print_pad() to th_args from th_string.
Matti Hamalainen <ccr@tnsp.org>
parents:
583
diff
changeset
|
49 const th_optarg *opts, const int nopts, |
735
31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
50 bool (*handle_option)(int id, char *, char *), |
31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
51 bool (*handle_other)(char *), const int flags); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
584
390c66af09cf
Move th_print_wrap() and th_print_pad() to th_args from th_string.
Matti Hamalainen <ccr@tnsp.org>
parents:
583
diff
changeset
|
53 void th_args_help(FILE *fh, const th_optarg *opts, |
590
041c8d3030e0
Add new argument to th_args_help() to specify the desired print width.
Matti Hamalainen <ccr@tnsp.org>
parents:
588
diff
changeset
|
54 const int nopts, const int flags, const int width); |
584
390c66af09cf
Move th_print_wrap() and th_print_pad() to th_args from th_string.
Matti Hamalainen <ccr@tnsp.org>
parents:
583
diff
changeset
|
55 |
588
ef71ef9b5862
Change th_print_wrap() API and move the string argument last.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
56 void th_print_wrap(FILE *fh, const int spad, |
ef71ef9b5862
Change th_print_wrap() API and move the string argument last.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
57 const int rpad, const int width, const char *str); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 #endif |
442
54081d784d75
Rename header #ifdef guards.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
62 #endif // TH_ARGS_H |