comparison src/dmargs.c @ 2425:85b6d7ce8ca5

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