annotate th_args.h @ 789:d61d3eb29053 default tip

Bump copyright.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 08 Mar 2024 15:26:24 +0200
parents 31bc1ed07cf5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ea8c37f03e2c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
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
29e44a58bc73 Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 722
diff changeset
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
ea8c37f03e2c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
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
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
34 */
136
286b2249c5d2 Clean up th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
35 typedef struct
286b2249c5d2 Clean up th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
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
d60e1d751b5b Improve few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
38 char o_short; ///< Short option name (one character, can be 0 for none)
d60e1d751b5b Improve few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
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