Mercurial > hg > th-libs
comparison th_args.c @ 634:c09b068ecb32
Rename some variables.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Jan 2020 05:00:53 +0200 |
parents | e3c4d8e28695 |
children | c5ce9a4bfc3e |
comparison
equal
deleted
inserted
replaced
633:e3c4d8e28695 | 634:c09b068ecb32 |
---|---|
17 * @param argc number of arguments | 17 * @param argc number of arguments |
18 * @param argv argument string array | 18 * @param argv argument string array |
19 * @param[in] opts options list array | 19 * @param[in] opts options list array |
20 * @param[in] nopts number of elements in options list array | 20 * @param[in] nopts number of elements in options list array |
21 * @param[in] handle_option function pointer to callback that handles option arguments | 21 * @param[in] handle_option function pointer to callback that handles option arguments |
22 * @param[in] doProcess if TRUE, actually handle the argument, aka call the handle_option() function. if FALSE, only validity of options are checked. | 22 * @param[in] process if TRUE, actually handle the argument, aka call the handle_option() function. if FALSE, only validity of options are checked. |
23 * @param[in] isLong TRUE if the option is a --long-format one | 23 * @param[in] isLong TRUE if the option is a --long-format one |
24 * @returns returns @c TRUE if option processing was successful | 24 * @returns returns @c TRUE if option processing was successful |
25 */ | 25 */ |
26 static BOOL th_args_process_opt( | 26 static BOOL th_args_process_opt( |
27 char *currArg, int *argIndex, | 27 char *currArg, int *argIndex, |
28 int argc, char *argv[], | 28 int argc, char *argv[], |
29 const th_optarg opts[], int nopts, | 29 const th_optarg opts[], int nopts, |
30 BOOL (*handle_option)(int id, char *, char *), | 30 BOOL (*handle_option)(int id, char *, char *), |
31 BOOL doProcess, BOOL isLong) | 31 BOOL process, BOOL isLong) |
32 { | 32 { |
33 const th_optarg *opt = NULL; | 33 const th_optarg *opt = NULL; |
34 char *optArg = NULL; | 34 char *optArg = NULL; |
35 int optIndex; | 35 |
36 | 36 for (int optIndex = 0; optIndex < nopts; optIndex++) |
37 for (optIndex = 0; optIndex < nopts; optIndex++) | |
38 { | 37 { |
39 const th_optarg *node = &opts[optIndex]; | 38 const th_optarg *node = &opts[optIndex]; |
40 if (isLong && node->o_long != NULL) | 39 if (isLong && node->o_long != NULL) |
41 { | 40 { |
42 if (strcmp(currArg, node->o_long) == 0) | 41 if (strcmp(currArg, node->o_long) == 0) |
85 return FALSE; | 84 return FALSE; |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 // Option was given succesfully, try to process it | 88 // Option was given succesfully, try to process it |
90 if (doProcess && !handle_option(opt->id, optArg, currArg)) | 89 if (process && !handle_option(opt->id, optArg, currArg)) |
91 return FALSE; | 90 return FALSE; |
92 } | 91 } |
93 else | 92 else |
94 { | 93 { |
95 THERR("Unknown %s option '%s%s'\n", | 94 THERR("Unknown %s option '%s%s'\n", |
120 BOOL th_args_process(int argc, char *argv[], | 119 BOOL th_args_process(int argc, char *argv[], |
121 const th_optarg *opts, const int nopts, | 120 const th_optarg *opts, const int nopts, |
122 BOOL(*handle_option)(int id, char *, char *), | 121 BOOL(*handle_option)(int id, char *, char *), |
123 BOOL(*handle_other)(char *), const int flags) | 122 BOOL(*handle_other)(char *), const int flags) |
124 { | 123 { |
125 int argIndex, handleFlags = flags & OPTH_ONLY_MASK; | 124 int handleFlags = flags & OPTH_ONLY_MASK; |
126 BOOL optionsOK = TRUE, endOfOptions = FALSE; | 125 BOOL optionsOK = TRUE, endOfOptions = FALSE; |
127 | 126 |
128 for (argIndex = 1; argIndex < argc; argIndex++) | 127 for (int argIndex = 1; argIndex < argc; argIndex++) |
129 { | 128 { |
130 char *str = argv[argIndex]; | 129 char *str = argv[argIndex]; |
131 if (*str == '-' && !endOfOptions) | 130 if (*str == '-' && !endOfOptions) |
132 { | 131 { |
133 // Should we process options? | 132 // Should we process options? |
134 BOOL doProcess = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; | 133 BOOL process = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; |
135 BOOL isLong; | 134 BOOL isLong; |
136 | 135 |
137 str++; | 136 str++; |
138 if (*str == '-') | 137 if (*str == '-') |
139 { | 138 { |
150 } | 149 } |
151 else | 150 else |
152 isLong = FALSE; | 151 isLong = FALSE; |
153 | 152 |
154 if (!th_args_process_opt(str, &argIndex, argc, argv, | 153 if (!th_args_process_opt(str, &argIndex, argc, argv, |
155 opts, nopts, handle_option, doProcess, isLong)) | 154 opts, nopts, handle_option, process, isLong)) |
156 optionsOK = FALSE; | 155 optionsOK = FALSE; |
157 } | 156 } |
158 else | 157 else |
159 if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) | 158 if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) |
160 { | 159 { |