diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_getopt_lib.h | 286 | ||||
-rw-r--r-- | src/util/getopt_helpers.c | 450 | ||||
-rw-r--r-- | src/util/gnunet-config.c | 58 | ||||
-rw-r--r-- | src/util/gnunet-ecc.c | 56 | ||||
-rw-r--r-- | src/util/gnunet-resolver.c | 9 | ||||
-rw-r--r-- | src/util/gnunet-scrypt.c | 41 | ||||
-rw-r--r-- | src/util/service.c | 7 | ||||
-rw-r--r-- | src/util/service_new.c | 7 |
8 files changed, 649 insertions, 265 deletions
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index b04020a70..cd546905e 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h | |||
@@ -97,6 +97,7 @@ typedef int | |||
97 | const char *option, | 97 | const char *option, |
98 | const char *value); | 98 | const char *value); |
99 | 99 | ||
100 | |||
100 | /** | 101 | /** |
101 | * @brief Definition of a command line option. | 102 | * @brief Definition of a command line option. |
102 | */ | 103 | */ |
@@ -141,244 +142,215 @@ struct GNUNET_GETOPT_CommandLineOption | |||
141 | 142 | ||
142 | }; | 143 | }; |
143 | 144 | ||
145 | |||
144 | /** | 146 | /** |
145 | * Macro defining the option to print the command line | 147 | * Defining the option to print the command line |
146 | * help text (-h option). | 148 | * help text (-h option). |
147 | * | 149 | * |
148 | * @param about string with brief description of the application | 150 | * @param about string with brief description of the application |
149 | */ | 151 | */ |
150 | #define GNUNET_GETOPT_OPTION_HELP(about) \ | 152 | struct GNUNET_GETOPT_CommandLineOption |
151 | { 'h', "help", (const char *) NULL, gettext_noop("print this help"), 0, &GNUNET_GETOPT_format_help_, (void *) about } | 153 | GNUNET_GETOPT_OPTION_HELP (const char *about); |
152 | 154 | ||
153 | 155 | ||
154 | /** | 156 | /** |
155 | * Macro defining the option to print the version of | 157 | * Define the option to print the version of |
156 | * the application (-v option) | 158 | * the application (-v option) |
157 | * | 159 | * |
158 | * @param version string with the version number | 160 | * @param version string with the version number |
159 | */ | 161 | */ |
160 | #define GNUNET_GETOPT_OPTION_VERSION(version) \ | 162 | struct GNUNET_GETOPT_CommandLineOption |
161 | { 'v', "version", (const char *) NULL, gettext_noop("print the version number"), 0, &GNUNET_GETOPT_print_version_, (void *) version } | 163 | GNUNET_GETOPT_OPTION_VERSION (const char *version); |
164 | |||
162 | 165 | ||
163 | 166 | ||
164 | /** | 167 | /** |
165 | * Allow user to specify log file name (-l option) | 168 | * Allow user to specify log file name (-l option) |
166 | * | 169 | * |
167 | * @param logfn set to the name of the logfile | 170 | * @param[out] logfn set to the name of the logfile |
168 | */ | 171 | */ |
169 | #define GNUNET_GETOPT_OPTION_LOGFILE(logfn) \ | 172 | struct GNUNET_GETOPT_CommandLineOption |
170 | { 'l', "logfile", "LOGFILE", gettext_noop("configure logging to write logs to LOGFILE"), 1, &GNUNET_GETOPT_set_string, (void *) logfn } | 173 | GNUNET_GETOPT_OPTION_LOGFILE (char **logfn); |
171 | 174 | ||
172 | 175 | ||
173 | /** | 176 | /** |
174 | * Allow user to specify log level (-L option) | 177 | * Allow user to specify a string. |
175 | * | 178 | * |
176 | * @param loglev set to the log level | 179 | * @param shortName short name of the option |
180 | * @param name long name of the option | ||
181 | * @param argumentHelp help text for the option argument | ||
182 | * @param description long help text for the option | ||
183 | * @param[out] str set to the string | ||
177 | */ | 184 | */ |
178 | #define GNUNET_GETOPT_OPTION_LOGLEVEL(loglev) \ | 185 | struct GNUNET_GETOPT_CommandLineOption |
179 | { 'L', "log", "LOGLEVEL", gettext_noop("configure logging to use LOGLEVEL"), 1, &GNUNET_GETOPT_set_string, (void *) loglev } | 186 | GNUNET_GETOPT_OPTION_STRING (char shortName, |
180 | 187 | const char *name, | |
188 | const char *argumentHelp, | ||
189 | const char *description, | ||
190 | char **str); | ||
181 | 191 | ||
182 | /** | 192 | /** |
183 | * Get number of verbose (-V) flags | 193 | * Allow user to specify a filename (automatically path expanded). |
184 | * | 194 | * |
185 | * @param level where to store the verbosity level (should be an 'int') | 195 | * @param shortName short name of the option |
196 | * @param name long name of the option | ||
197 | * @param argumentHelp help text for the option argument | ||
198 | * @param description long help text for the option | ||
199 | * @param[out] str set to the string | ||
186 | */ | 200 | */ |
187 | #define GNUNET_GETOPT_OPTION_VERBOSE(level) \ | 201 | struct GNUNET_GETOPT_CommandLineOption |
188 | { 'V', "verbose", (const char *) NULL, gettext_noop("be verbose"), 0, &GNUNET_GETOPT_increment_value, (void *) level } | 202 | GNUNET_GETOPT_OPTION_FILENAME (char shortName, |
203 | const char *name, | ||
204 | const char *argumentHelp, | ||
205 | const char *description, | ||
206 | char **str); | ||
189 | 207 | ||
190 | 208 | ||
191 | /** | 209 | /** |
192 | * Get configuration file name (-c option) | 210 | * Allow user to specify a flag (which internally means setting |
211 | * an integer to 1/#GNUNET_YES/#GNUNET_OK. | ||
193 | * | 212 | * |
194 | * @param fn set to the configuration file name | 213 | * @param shortName short name of the option |
214 | * @param name long name of the option | ||
215 | * @param description long help text for the option | ||
216 | * @param[out] val set to 1 if the option is present | ||
195 | */ | 217 | */ |
196 | #define GNUNET_GETOPT_OPTION_CFG_FILE(fn) \ | 218 | struct GNUNET_GETOPT_CommandLineOption |
197 | { 'c', "config", "FILENAME", gettext_noop("use configuration file FILENAME"), 1, &GNUNET_GETOPT_set_string, (void *) fn } | 219 | GNUNET_GETOPT_OPTION_SET_ONE (char shortName, |
220 | const char *name, | ||
221 | const char *description, | ||
222 | int *val); | ||
198 | 223 | ||
199 | 224 | ||
200 | /** | 225 | /** |
201 | * Marker for the end of the list of options. | 226 | * Allow user to specify an `unsigned int`. |
227 | * | ||
228 | * @param shortName short name of the option | ||
229 | * @param name long name of the option | ||
230 | * @param argumentHelp help text for the option argument | ||
231 | * @param description long help text for the option | ||
232 | * @param[out] val set to the value specified at the command line | ||
202 | */ | 233 | */ |
203 | #define GNUNET_GETOPT_OPTION_END \ | 234 | struct GNUNET_GETOPT_CommandLineOption |
204 | { '\0', NULL, NULL, NULL, 0, NULL, NULL } | 235 | GNUNET_GETOPT_OPTION_SET_UINT (char shortName, |
236 | const char *name, | ||
237 | const char *argumentHelp, | ||
238 | const char *description, | ||
239 | unsigned int *val); | ||
205 | 240 | ||
206 | 241 | ||
207 | /** | 242 | /** |
208 | * Parse the command line. | 243 | * Allow user to specify an `unsigned long long`. |
209 | * | 244 | * |
210 | * @param binaryOptions Name of application with option summary | 245 | * @param shortName short name of the option |
211 | * @param allOptions defined options and handlers | 246 | * @param name long name of the option |
212 | * @param argc number of arguments in @a argv | 247 | * @param argumentHelp help text for the option argument |
213 | * @param argv actual arguments | 248 | * @param description long help text for the option |
214 | * @return index into argv with first non-option | 249 | * @param[out] val set to the value specified at the command line |
215 | * argument, or #GNUNET_SYSERR on error | ||
216 | */ | 250 | */ |
217 | int | 251 | struct GNUNET_GETOPT_CommandLineOption |
218 | GNUNET_GETOPT_run (const char *binaryOptions, | 252 | GNUNET_GETOPT_OPTION_SET_ULONG (char shortName, |
219 | const struct GNUNET_GETOPT_CommandLineOption *allOptions, | 253 | const char *name, |
220 | unsigned int argc, char *const *argv); | 254 | const char *argumentHelp, |
255 | const char *description, | ||
256 | unsigned long long *val); | ||
221 | 257 | ||
222 | 258 | ||
223 | /** | 259 | /** |
224 | * Set an option of type 'unsigned long long' from the command line. | 260 | * Allow user to specify a `struct GNUNET_TIME_Relative` |
225 | * A pointer to this function should be passed as part of the | 261 | * (using human-readable "fancy" time). |
226 | * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options | ||
227 | * of this type. It should be followed by a pointer to a value of | ||
228 | * type `unsigned long long`. | ||
229 | * | 262 | * |
230 | * @param ctx command line processing context | 263 | * @param shortName short name of the option |
231 | * @param scls additional closure (will point to the 'unsigned long long') | 264 | * @param name long name of the option |
232 | * @param option name of the option | 265 | * @param argumentHelp help text for the option argument |
233 | * @param value actual value of the option as a string. | 266 | * @param description long help text for the option |
234 | * @return #GNUNET_OK if parsing the value worked | 267 | * @param[out] val set to the time specified at the command line |
235 | */ | 268 | */ |
236 | int | 269 | struct GNUNET_GETOPT_CommandLineOption |
237 | GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 270 | GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME (char shortName, |
238 | void *scls, const char *option, const char *value); | 271 | const char *name, |
272 | const char *argumentHelp, | ||
273 | const char *description, | ||
274 | struct GNUNET_TIME_Relative *val); | ||
239 | 275 | ||
240 | 276 | ||
241 | /** | 277 | /** |
242 | * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. | 278 | * Increment @a val each time the option flag is given by one. |
243 | * A pointer to this function should be passed as part of the | ||
244 | * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options | ||
245 | * of this type. It should be followed by a pointer to a value of | ||
246 | * type `struct GNUNET_TIME_Relative`. | ||
247 | * | 279 | * |
248 | * @param ctx command line processing context | 280 | * @param shortName short name of the option |
249 | * @param scls additional closure (will point to the 'struct GNUNET_TIME_Relative') | 281 | * @param name long name of the option |
250 | * @param option name of the option | 282 | * @param argumentHelp help text for the option argument |
251 | * @param value actual value of the option as a string. | 283 | * @param description long help text for the option |
252 | * @return #GNUNET_OK if parsing the value worked | 284 | * @param[out] val set to 1 if the option is present |
253 | */ | 285 | */ |
254 | int | 286 | struct GNUNET_GETOPT_CommandLineOption |
255 | GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 287 | GNUNET_GETOPT_OPTION_INCREMENT_VALUE (char shortName, |
256 | void *scls, const char *option, const char *value); | 288 | const char *name, |
289 | const char *description, | ||
290 | unsigned int *val); | ||
257 | 291 | ||
258 | 292 | ||
259 | /** | 293 | /** |
260 | * Set an option of type 'unsigned int' from the command line. | 294 | * Define the '-L' log level option. Note that we do not check |
261 | * A pointer to this function should be passed as part of the | 295 | * that the log level is valid here. |
262 | * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options | ||
263 | * of this type. It should be followed by a pointer to a value of | ||
264 | * type `unsigned int`. | ||
265 | * | 296 | * |
266 | * @param ctx command line processing context | 297 | * @param[out] level set to the log level |
267 | * @param scls additional closure (will point to the 'unsigned int') | ||
268 | * @param option name of the option | ||
269 | * @param value actual value of the option as a string. | ||
270 | * @return #GNUNET_OK if parsing the value worked | ||
271 | */ | 298 | */ |
272 | int | 299 | struct GNUNET_GETOPT_CommandLineOption |
273 | GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 300 | GNUNET_GETOPT_OPTION_LOGLEVEL (char **level); |
274 | void *scls, const char *option, const char *value); | ||
275 | 301 | ||
276 | 302 | ||
277 | /** | 303 | /** |
278 | * Set an option of type 'int' from the command line to 1 if the | 304 | * Define the '-V' verbosity option. Using the option more |
279 | * given option is present. | 305 | * than once increments @a level each time. |
280 | * A pointer to this function should be passed as part of the | ||
281 | * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options | ||
282 | * of this type. It should be followed by a pointer to a value of | ||
283 | * type `int`. | ||
284 | * | 306 | * |
285 | * @param ctx command line processing context | 307 | * @param[out] level set to the verbosity level |
286 | * @param scls additional closure (will point to the `int`) | ||
287 | * @param option name of the option | ||
288 | * @param value not used (NULL) | ||
289 | * @return #GNUNET_OK (always) | ||
290 | */ | 308 | */ |
291 | int | 309 | struct GNUNET_GETOPT_CommandLineOption |
292 | GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 310 | GNUNET_GETOPT_OPTION_VERBOSE (int *level); |
293 | void *scls, const char *option, const char *value); | ||
294 | 311 | ||
295 | 312 | ||
296 | /** | 313 | /** |
297 | * Set an option of type 'char *' from the command line. | 314 | * Allow user to specify log file name (-l option) |
298 | * A pointer to this function should be passed as part of the | ||
299 | * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options | ||
300 | * of this type. It should be followed by a pointer to a value of | ||
301 | * type `char *`, which will be allocated with the requested string. | ||
302 | * | 315 | * |
303 | * @param ctx command line processing context | 316 | * @param[out] logfn set to the name of the logfile |
304 | * @param scls additional closure (will point to the `char *`, | ||
305 | * which will be allocated) | ||
306 | * @param option name of the option | ||
307 | * @param value actual value of the option (a string) | ||
308 | * @return #GNUNET_OK (always) | ||
309 | */ | 317 | */ |
310 | int | 318 | struct GNUNET_GETOPT_CommandLineOption |
311 | GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 319 | GNUNET_GETOPT_OPTION_LOGFILE (char **logfn); |
312 | void *scls, const char *option, const char *value); | ||
313 | 320 | ||
314 | 321 | ||
315 | /** | 322 | /** |
316 | * Set an option of type 'char *' from the command line doing fs expansion. | 323 | * Allow user to specify configuration file name (-c option) |
317 | * A pointer to this function should be passed as part of the | ||
318 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | ||
319 | * of this type. It should be followed by a pointer to a value of | ||
320 | * type 'char *', which will be allocated with the requested string. | ||
321 | * | 324 | * |
322 | * @param ctx command line processing context | 325 | * @param[out] fn set to the name of the configuration file |
323 | * @param scls additional closure (will point to the 'char *', | ||
324 | * which will be allocated) | ||
325 | * @param option name of the option | ||
326 | * @param value actual value of the option (a string) | ||
327 | * @return #GNUNET_OK (always) | ||
328 | */ | 326 | */ |
329 | int | 327 | struct GNUNET_GETOPT_CommandLineOption |
330 | GNUNET_GETOPT_set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 328 | GNUNET_GETOPT_OPTION_CFG_FILE (char **fn); |
331 | void *scls, const char *option, const char *value); | 329 | |
332 | 330 | ||
333 | /** | 331 | /** |
334 | * Set an option of type 'unsigned int' from the command line. Each | 332 | * Marker for the end of the list of options. |
335 | * time the option flag is given, the value is incremented by one. | ||
336 | * A pointer to this function should be passed as part of the | ||
337 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | ||
338 | * of this type. It should be followed by a pointer to a value of | ||
339 | * type 'int'. | ||
340 | * | ||
341 | * @param ctx command line processing context | ||
342 | * @param scls additional closure (will point to the 'int') | ||
343 | * @param option name of the option | ||
344 | * @param value not used (NULL) | ||
345 | * @return #GNUNET_OK (always) | ||
346 | */ | 333 | */ |
347 | int | 334 | #define GNUNET_GETOPT_OPTION_END \ |
348 | GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext | 335 | { '\0', NULL, NULL, NULL, 0, NULL, NULL } |
349 | *ctx, void *scls, const char *option, | ||
350 | const char *value); | ||
351 | |||
352 | 336 | ||
353 | /* *************** internal prototypes - use macros above! ************* */ | ||
354 | 337 | ||
355 | /** | 338 | /** |
356 | * Print out details on command line options (implements --help). | 339 | * Parse the command line. |
357 | * | 340 | * |
358 | * @param ctx command line processing context | 341 | * @param binaryOptions Name of application with option summary |
359 | * @param scls additional closure (points to about text) | 342 | * @param allOptions defined options and handlers |
360 | * @param option name of the option | 343 | * @param argc number of arguments in @a argv |
361 | * @param value not used (NULL) | 344 | * @param argv actual arguments |
362 | * @return #GNUNET_NO (do not continue, not an error) | 345 | * @return index into argv with first non-option |
346 | * argument, or #GNUNET_SYSERR on error | ||
363 | */ | 347 | */ |
364 | int | 348 | int |
365 | GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext | 349 | GNUNET_GETOPT_run (const char *binaryOptions, |
366 | *ctx, void *scls, const char *option, | 350 | const struct GNUNET_GETOPT_CommandLineOption *allOptions, |
367 | const char *value); | 351 | unsigned int argc, |
352 | char *const *argv); | ||
368 | 353 | ||
369 | /** | ||
370 | * Print out program version (implements --version). | ||
371 | * | ||
372 | * @param ctx command line processing context | ||
373 | * @param scls additional closure (points to version string) | ||
374 | * @param option name of the option | ||
375 | * @param value not used (NULL) | ||
376 | * @return #GNUNET_NO (do not continue, not an error) | ||
377 | */ | ||
378 | int | ||
379 | GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext | ||
380 | *ctx, void *scls, const char *option, | ||
381 | const char *value); | ||
382 | 354 | ||
383 | #if 0 /* keep Emacsens' auto-indent happy */ | 355 | #if 0 /* keep Emacsens' auto-indent happy */ |
384 | { | 356 | { |
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index 4d7104503..234f5371f 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -38,11 +38,11 @@ | |||
38 | * @param value not used (NULL) | 38 | * @param value not used (NULL) |
39 | * @return #GNUNET_NO (do not continue, not an error) | 39 | * @return #GNUNET_NO (do not continue, not an error) |
40 | */ | 40 | */ |
41 | int | 41 | static int |
42 | GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 42 | print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
43 | void *scls, | 43 | void *scls, |
44 | const char *option, | 44 | const char *option, |
45 | const char *value) | 45 | const char *value) |
46 | { | 46 | { |
47 | const char *version = scls; | 47 | const char *version = scls; |
48 | 48 | ||
@@ -54,6 +54,26 @@ GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext * | |||
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Define the option to print the version of | ||
58 | * the application (-v option) | ||
59 | * | ||
60 | * @param version string with the version number | ||
61 | */ | ||
62 | struct GNUNET_GETOPT_CommandLineOption | ||
63 | GNUNET_GETOPT_OPTION_VERSION (const char *version) | ||
64 | { | ||
65 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
66 | .shortName = 'v', | ||
67 | .name = "version", | ||
68 | .description = gettext_noop("print the version number"), | ||
69 | .processor = &print_version, | ||
70 | .scls = (void *) version | ||
71 | }; | ||
72 | return clo; | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
57 | * At what offset does the help text start? | 77 | * At what offset does the help text start? |
58 | */ | 78 | */ |
59 | #define BORDER 29 | 79 | #define BORDER 29 |
@@ -67,11 +87,11 @@ GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext * | |||
67 | * @param value not used (NULL) | 87 | * @param value not used (NULL) |
68 | * @return #GNUNET_NO (do not continue, not an error) | 88 | * @return #GNUNET_NO (do not continue, not an error) |
69 | */ | 89 | */ |
70 | int | 90 | static int |
71 | GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 91 | format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
72 | void *scls, | 92 | void *scls, |
73 | const char *option, | 93 | const char *option, |
74 | const char *value) | 94 | const char *value) |
75 | { | 95 | { |
76 | const char *about = scls; | 96 | const char *about = scls; |
77 | size_t slen; | 97 | size_t slen; |
@@ -165,6 +185,27 @@ OUTER: | |||
165 | 185 | ||
166 | 186 | ||
167 | /** | 187 | /** |
188 | * Defining the option to print the command line | ||
189 | * help text (-h option). | ||
190 | * | ||
191 | * @param about string with brief description of the application | ||
192 | */ | ||
193 | struct GNUNET_GETOPT_CommandLineOption | ||
194 | GNUNET_GETOPT_OPTION_HELP (const char *about) | ||
195 | { | ||
196 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
197 | .shortName = 'h', | ||
198 | .name = "help", | ||
199 | .description = gettext_noop("print this help"), | ||
200 | .processor = format_help, | ||
201 | .scls = (void *) about | ||
202 | }; | ||
203 | |||
204 | return clo; | ||
205 | } | ||
206 | |||
207 | |||
208 | /** | ||
168 | * Set an option of type 'unsigned int' from the command line. Each | 209 | * Set an option of type 'unsigned int' from the command line. Each |
169 | * time the option flag is given, the value is incremented by one. | 210 | * time the option flag is given, the value is incremented by one. |
170 | * A pointer to this function should be passed as part of the | 211 | * A pointer to this function should be passed as part of the |
@@ -173,17 +214,18 @@ OUTER: | |||
173 | * type 'int'. | 214 | * type 'int'. |
174 | * | 215 | * |
175 | * @param ctx command line processing context | 216 | * @param ctx command line processing context |
176 | * @param scls additional closure (will point to the 'int') | 217 | * @param scls additional closure (will point to the 'unsigned int') |
177 | * @param option name of the option | 218 | * @param option name of the option |
178 | * @param value not used (NULL) | 219 | * @param value not used (NULL) |
179 | * @return #GNUNET_OK | 220 | * @return #GNUNET_OK |
180 | */ | 221 | */ |
181 | int | 222 | static int |
182 | GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext | 223 | increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
183 | *ctx, void *scls, const char *option, | 224 | void *scls, |
184 | const char *value) | 225 | const char *option, |
226 | const char *value) | ||
185 | { | 227 | { |
186 | int *val = scls; | 228 | unsigned int *val = scls; |
187 | 229 | ||
188 | (*val)++; | 230 | (*val)++; |
189 | return GNUNET_OK; | 231 | return GNUNET_OK; |
@@ -191,6 +233,54 @@ GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
191 | 233 | ||
192 | 234 | ||
193 | /** | 235 | /** |
236 | * Increment @a val each time the option flag is given by one. | ||
237 | * | ||
238 | * @param shortName short name of the option | ||
239 | * @param name long name of the option | ||
240 | * @param argumentHelp help text for the option argument | ||
241 | * @param description long help text for the option | ||
242 | * @param[out] val increment by 1 each time the option is present | ||
243 | */ | ||
244 | struct GNUNET_GETOPT_CommandLineOption | ||
245 | GNUNET_GETOPT_OPTION_INCREMENT_VALUE (char shortName, | ||
246 | const char *name, | ||
247 | const char *description, | ||
248 | unsigned int *val) | ||
249 | { | ||
250 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
251 | .shortName = shortName, | ||
252 | .name = name, | ||
253 | .description = description, | ||
254 | .processor = &increment_value, | ||
255 | .scls = (void *) val | ||
256 | }; | ||
257 | |||
258 | return clo; | ||
259 | } | ||
260 | |||
261 | |||
262 | /** | ||
263 | * Define the '-V' verbosity option. Using the option more | ||
264 | * than once increments @a level each time. | ||
265 | * | ||
266 | * @param[out] level set to the verbosity level | ||
267 | */ | ||
268 | struct GNUNET_GETOPT_CommandLineOption | ||
269 | GNUNET_GETOPT_OPTION_VERBOSE (int *level) | ||
270 | { | ||
271 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
272 | .shortName = 'V', | ||
273 | .name = "verbose", | ||
274 | .description = gettext_noop("be verbose"), | ||
275 | .processor = &increment_value, | ||
276 | .scls = (void *) level | ||
277 | }; | ||
278 | |||
279 | return clo; | ||
280 | } | ||
281 | |||
282 | |||
283 | /** | ||
194 | * Set an option of type 'int' from the command line to 1 if the | 284 | * Set an option of type 'int' from the command line to 1 if the |
195 | * given option is present. | 285 | * given option is present. |
196 | * A pointer to this function should be passed as part of the | 286 | * A pointer to this function should be passed as part of the |
@@ -204,9 +294,11 @@ GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
204 | * @param value not used (NULL) | 294 | * @param value not used (NULL) |
205 | * @return #GNUNET_OK | 295 | * @return #GNUNET_OK |
206 | */ | 296 | */ |
207 | int | 297 | static int |
208 | GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 298 | set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
209 | void *scls, const char *option, const char *value) | 299 | void *scls, |
300 | const char *option, | ||
301 | const char *value) | ||
210 | { | 302 | { |
211 | int *val = scls; | 303 | int *val = scls; |
212 | 304 | ||
@@ -216,6 +308,34 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
216 | 308 | ||
217 | 309 | ||
218 | /** | 310 | /** |
311 | * Allow user to specify a flag (which internally means setting | ||
312 | * an integer to 1/#GNUNET_YES/#GNUNET_OK. | ||
313 | * | ||
314 | * @param shortName short name of the option | ||
315 | * @param name long name of the option | ||
316 | * @param argumentHelp help text for the option argument | ||
317 | * @param description long help text for the option | ||
318 | * @param[out] val set to 1 if the option is present | ||
319 | */ | ||
320 | struct GNUNET_GETOPT_CommandLineOption | ||
321 | GNUNET_GETOPT_OPTION_SET_ONE (char shortName, | ||
322 | const char *name, | ||
323 | const char *description, | ||
324 | int *val) | ||
325 | { | ||
326 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
327 | .shortName = shortName, | ||
328 | .name = name, | ||
329 | .description = description, | ||
330 | .processor = &set_one, | ||
331 | .scls = (void *) val | ||
332 | }; | ||
333 | |||
334 | return clo; | ||
335 | } | ||
336 | |||
337 | |||
338 | /** | ||
219 | * Set an option of type 'char *' from the command line. | 339 | * Set an option of type 'char *' from the command line. |
220 | * A pointer to this function should be passed as part of the | 340 | * A pointer to this function should be passed as part of the |
221 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | 341 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options |
@@ -229,9 +349,11 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
229 | * @param value actual value of the option (a string) | 349 | * @param value actual value of the option (a string) |
230 | * @return #GNUNET_OK | 350 | * @return #GNUNET_OK |
231 | */ | 351 | */ |
232 | int | 352 | static int |
233 | GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 353 | set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
234 | void *scls, const char *option, const char *value) | 354 | void *scls, |
355 | const char *option, | ||
356 | const char *value) | ||
235 | { | 357 | { |
236 | char **val = scls; | 358 | char **val = scls; |
237 | 359 | ||
@@ -242,18 +364,159 @@ GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
242 | } | 364 | } |
243 | 365 | ||
244 | 366 | ||
245 | int | 367 | /** |
246 | GNUNET_GETOPT_set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 368 | * Allow user to specify a string. |
247 | void *scls, const char *option, const char *value) | 369 | * |
370 | * @param shortName short name of the option | ||
371 | * @param name long name of the option | ||
372 | * @param argumentHelp help text for the option argument | ||
373 | * @param description long help text for the option | ||
374 | * @param[out] str set to the string | ||
375 | */ | ||
376 | struct GNUNET_GETOPT_CommandLineOption | ||
377 | GNUNET_GETOPT_OPTION_STRING (char shortName, | ||
378 | const char *name, | ||
379 | const char *argumentHelp, | ||
380 | const char *description, | ||
381 | char **str) | ||
382 | { | ||
383 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
384 | .shortName = shortName, | ||
385 | .name = name, | ||
386 | .argumentHelp = argumentHelp, | ||
387 | .description = description, | ||
388 | .require_argument = 1, | ||
389 | .processor = &set_string, | ||
390 | .scls = (void *) str | ||
391 | }; | ||
392 | |||
393 | return clo; | ||
394 | } | ||
395 | |||
396 | |||
397 | /** | ||
398 | * Define the '-L' log level option. Note that we do not check | ||
399 | * that the log level is valid here. | ||
400 | * | ||
401 | * @param[out] level set to the log level | ||
402 | */ | ||
403 | struct GNUNET_GETOPT_CommandLineOption | ||
404 | GNUNET_GETOPT_OPTION_LOGLEVEL (char **level) | ||
405 | { | ||
406 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
407 | .shortName = 'L', | ||
408 | .name = "log", | ||
409 | .argumentHelp = "LOGLEVEL", | ||
410 | .description = gettext_noop("configure logging to use LOGLEVEL"), | ||
411 | .require_argument = 1, | ||
412 | .processor = &set_string, | ||
413 | .scls = (void *) level | ||
414 | }; | ||
415 | |||
416 | return clo; | ||
417 | } | ||
418 | |||
419 | |||
420 | /** | ||
421 | * Set an option of type 'char *' from the command line with | ||
422 | * filename expansion a la #GNUNET_STRINGS_filename_expand(). | ||
423 | * | ||
424 | * @param ctx command line processing context | ||
425 | * @param scls additional closure (will point to the `char *`, | ||
426 | * which will be allocated) | ||
427 | * @param option name of the option | ||
428 | * @param value actual value of the option (a string) | ||
429 | * @return #GNUNET_OK | ||
430 | */ | ||
431 | static int | ||
432 | set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | ||
433 | void *scls, | ||
434 | const char *option, | ||
435 | const char *value) | ||
248 | { | 436 | { |
249 | char **val = scls; | 437 | char **val = scls; |
250 | 438 | ||
251 | GNUNET_assert (value != NULL); | 439 | GNUNET_assert (NULL != value); |
252 | GNUNET_free_non_null (*val); | 440 | GNUNET_free_non_null (*val); |
253 | *val = GNUNET_STRINGS_filename_expand (value); | 441 | *val = GNUNET_STRINGS_filename_expand (value); |
254 | return GNUNET_OK; | 442 | return GNUNET_OK; |
255 | } | 443 | } |
256 | 444 | ||
445 | |||
446 | /** | ||
447 | * Allow user to specify a filename (automatically path expanded). | ||
448 | * | ||
449 | * @param shortName short name of the option | ||
450 | * @param name long name of the option | ||
451 | * @param argumentHelp help text for the option argument | ||
452 | * @param description long help text for the option | ||
453 | * @param[out] str set to the string | ||
454 | */ | ||
455 | struct GNUNET_GETOPT_CommandLineOption | ||
456 | GNUNET_GETOPT_OPTION_FILENAME (char shortName, | ||
457 | const char *name, | ||
458 | const char *argumentHelp, | ||
459 | const char *description, | ||
460 | char **str) | ||
461 | { | ||
462 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
463 | .shortName = shortName, | ||
464 | .name = name, | ||
465 | .argumentHelp = argumentHelp, | ||
466 | .description = description, | ||
467 | .require_argument = 1, | ||
468 | .processor = &set_filename, | ||
469 | .scls = (void *) str | ||
470 | }; | ||
471 | |||
472 | return clo; | ||
473 | } | ||
474 | |||
475 | |||
476 | /** | ||
477 | * Allow user to specify log file name (-l option) | ||
478 | * | ||
479 | * @param[out] logfn set to the name of the logfile | ||
480 | */ | ||
481 | struct GNUNET_GETOPT_CommandLineOption | ||
482 | GNUNET_GETOPT_OPTION_LOGFILE (char **logfn) | ||
483 | { | ||
484 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
485 | .shortName = 'l', | ||
486 | .name = "logfile", | ||
487 | .argumentHelp = "FILENAME", | ||
488 | .description = gettext_noop ("configure logging to write logs to FILENAME"), | ||
489 | .require_argument = 1, | ||
490 | .processor = &set_filename, | ||
491 | .scls = (void *) logfn | ||
492 | }; | ||
493 | |||
494 | return clo; | ||
495 | } | ||
496 | |||
497 | |||
498 | /** | ||
499 | * Allow user to specify configuration file name (-c option) | ||
500 | * | ||
501 | * @param[out] fn set to the name of the configuration file | ||
502 | */ | ||
503 | struct GNUNET_GETOPT_CommandLineOption | ||
504 | GNUNET_GETOPT_OPTION_CFG_FILE (char **fn) | ||
505 | { | ||
506 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
507 | .shortName = 'c', | ||
508 | .name = "config", | ||
509 | .argumentHelp = "FILENAME", | ||
510 | .description = gettext_noop("use configuration file FILENAME"), | ||
511 | .require_argument = 1, | ||
512 | .processor = &set_filename, | ||
513 | .scls = (void *) fn | ||
514 | }; | ||
515 | |||
516 | return clo; | ||
517 | } | ||
518 | |||
519 | |||
257 | /** | 520 | /** |
258 | * Set an option of type 'unsigned long long' from the command line. | 521 | * Set an option of type 'unsigned long long' from the command line. |
259 | * A pointer to this function should be passed as part of the | 522 | * A pointer to this function should be passed as part of the |
@@ -267,15 +530,21 @@ GNUNET_GETOPT_set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ct | |||
267 | * @param value actual value of the option as a string. | 530 | * @param value actual value of the option as a string. |
268 | * @return #GNUNET_OK if parsing the value worked | 531 | * @return #GNUNET_OK if parsing the value worked |
269 | */ | 532 | */ |
270 | int | 533 | static int |
271 | GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 534 | set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
272 | void *scls, const char *option, const char *value) | 535 | void *scls, |
536 | const char *option, | ||
537 | const char *value) | ||
273 | { | 538 | { |
274 | unsigned long long *val = scls; | 539 | unsigned long long *val = scls; |
275 | 540 | ||
276 | if (1 != SSCANF (value, "%llu", val)) | 541 | if (1 != SSCANF (value, |
542 | "%llu", | ||
543 | val)) | ||
277 | { | 544 | { |
278 | FPRINTF (stderr, _("You must pass a number to the `%s' option.\n"), option); | 545 | FPRINTF (stderr, |
546 | _("You must pass a number to the `%s' option.\n"), | ||
547 | option); | ||
279 | return GNUNET_SYSERR; | 548 | return GNUNET_SYSERR; |
280 | } | 549 | } |
281 | return GNUNET_OK; | 550 | return GNUNET_OK; |
@@ -283,6 +552,36 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
283 | 552 | ||
284 | 553 | ||
285 | /** | 554 | /** |
555 | * Allow user to specify an `unsigned long long` | ||
556 | * | ||
557 | * @param shortName short name of the option | ||
558 | * @param name long name of the option | ||
559 | * @param argumentHelp help text for the option argument | ||
560 | * @param description long help text for the option | ||
561 | * @param[out] val set to the value specified at the command line | ||
562 | */ | ||
563 | struct GNUNET_GETOPT_CommandLineOption | ||
564 | GNUNET_GETOPT_OPTION_SET_ULONG (char shortName, | ||
565 | const char *name, | ||
566 | const char *argumentHelp, | ||
567 | const char *description, | ||
568 | unsigned long long *val) | ||
569 | { | ||
570 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
571 | .shortName = shortName, | ||
572 | .name = name, | ||
573 | .argumentHelp = argumentHelp, | ||
574 | .description = description, | ||
575 | .require_argument = 1, | ||
576 | .processor = &set_ulong, | ||
577 | .scls = (void *) val | ||
578 | }; | ||
579 | |||
580 | return clo; | ||
581 | } | ||
582 | |||
583 | |||
584 | /** | ||
286 | * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. | 585 | * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. |
287 | * A pointer to this function should be passed as part of the | 586 | * A pointer to this function should be passed as part of the |
288 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | 587 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options |
@@ -295,9 +594,11 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
295 | * @param value actual value of the option as a string. | 594 | * @param value actual value of the option as a string. |
296 | * @return #GNUNET_OK if parsing the value worked | 595 | * @return #GNUNET_OK if parsing the value worked |
297 | */ | 596 | */ |
298 | int | 597 | static int |
299 | GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 598 | set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
300 | void *scls, const char *option, const char *value) | 599 | void *scls, |
600 | const char *option, | ||
601 | const char *value) | ||
301 | { | 602 | { |
302 | struct GNUNET_TIME_Relative *val = scls; | 603 | struct GNUNET_TIME_Relative *val = scls; |
303 | 604 | ||
@@ -305,7 +606,9 @@ GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContex | |||
305 | GNUNET_STRINGS_fancy_time_to_relative (value, | 606 | GNUNET_STRINGS_fancy_time_to_relative (value, |
306 | val)) | 607 | val)) |
307 | { | 608 | { |
308 | FPRINTF (stderr, _("You must pass relative time to the `%s' option.\n"), option); | 609 | FPRINTF (stderr, |
610 | _("You must pass relative time to the `%s' option.\n"), | ||
611 | option); | ||
309 | return GNUNET_SYSERR; | 612 | return GNUNET_SYSERR; |
310 | } | 613 | } |
311 | return GNUNET_OK; | 614 | return GNUNET_OK; |
@@ -313,6 +616,37 @@ GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContex | |||
313 | 616 | ||
314 | 617 | ||
315 | /** | 618 | /** |
619 | * Allow user to specify a `struct GNUNET_TIME_Relative` | ||
620 | * (using human-readable "fancy" time). | ||
621 | * | ||
622 | * @param shortName short name of the option | ||
623 | * @param name long name of the option | ||
624 | * @param argumentHelp help text for the option argument | ||
625 | * @param description long help text for the option | ||
626 | * @param[out] val set to the time specified at the command line | ||
627 | */ | ||
628 | struct GNUNET_GETOPT_CommandLineOption | ||
629 | GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME (char shortName, | ||
630 | const char *name, | ||
631 | const char *argumentHelp, | ||
632 | const char *description, | ||
633 | struct GNUNET_TIME_Relative *val) | ||
634 | { | ||
635 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
636 | .shortName = shortName, | ||
637 | .name = name, | ||
638 | .argumentHelp = argumentHelp, | ||
639 | .description = description, | ||
640 | .require_argument = 1, | ||
641 | .processor = &set_relative_time, | ||
642 | .scls = (void *) val | ||
643 | }; | ||
644 | |||
645 | return clo; | ||
646 | } | ||
647 | |||
648 | |||
649 | /** | ||
316 | * Set an option of type 'unsigned int' from the command line. | 650 | * Set an option of type 'unsigned int' from the command line. |
317 | * A pointer to this function should be passed as part of the | 651 | * A pointer to this function should be passed as part of the |
318 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | 652 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options |
@@ -325,19 +659,55 @@ GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContex | |||
325 | * @param value actual value of the option as a string. | 659 | * @param value actual value of the option as a string. |
326 | * @return #GNUNET_OK if parsing the value worked | 660 | * @return #GNUNET_OK if parsing the value worked |
327 | */ | 661 | */ |
328 | int | 662 | static int |
329 | GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 663 | set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
330 | void *scls, const char *option, const char *value) | 664 | void *scls, |
665 | const char *option, | ||
666 | const char *value) | ||
331 | { | 667 | { |
332 | unsigned int *val = scls; | 668 | unsigned int *val = scls; |
333 | 669 | ||
334 | if (1 != SSCANF (value, "%u", val)) | 670 | if (1 != SSCANF (value, |
671 | "%u", | ||
672 | val)) | ||
335 | { | 673 | { |
336 | FPRINTF (stderr, _("You must pass a number to the `%s' option.\n"), option); | 674 | FPRINTF (stderr, |
675 | _("You must pass a number to the `%s' option.\n"), | ||
676 | option); | ||
337 | return GNUNET_SYSERR; | 677 | return GNUNET_SYSERR; |
338 | } | 678 | } |
339 | return GNUNET_OK; | 679 | return GNUNET_OK; |
340 | } | 680 | } |
341 | 681 | ||
342 | 682 | ||
683 | /** | ||
684 | * Allow user to specify an unsigned integer. | ||
685 | * | ||
686 | * @param shortName short name of the option | ||
687 | * @param name long name of the option | ||
688 | * @param argumentHelp help text for the option argument | ||
689 | * @param description long help text for the option | ||
690 | * @param[out] val set to the value specified at the command line | ||
691 | */ | ||
692 | struct GNUNET_GETOPT_CommandLineOption | ||
693 | GNUNET_GETOPT_OPTION_SET_UINT (char shortName, | ||
694 | const char *name, | ||
695 | const char *argumentHelp, | ||
696 | const char *description, | ||
697 | unsigned int *val) | ||
698 | { | ||
699 | struct GNUNET_GETOPT_CommandLineOption clo = { | ||
700 | .shortName = shortName, | ||
701 | .name = name, | ||
702 | .argumentHelp = argumentHelp, | ||
703 | .description = description, | ||
704 | .require_argument = 1, | ||
705 | .processor = &set_uint, | ||
706 | .scls = (void *) val | ||
707 | }; | ||
708 | |||
709 | return clo; | ||
710 | } | ||
711 | |||
712 | |||
343 | /* end of getopt_helpers.c */ | 713 | /* end of getopt_helpers.c */ |
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 7ec7162f1..2beb772a9 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -223,34 +223,48 @@ run (void *cls, | |||
223 | int | 223 | int |
224 | main (int argc, char *const *argv) | 224 | main (int argc, char *const *argv) |
225 | { | 225 | { |
226 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 226 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
227 | { 'f', "filename", NULL, | 227 | GNUNET_GETOPT_OPTION_SET_ONE ('f', |
228 | gettext_noop ("obtain option of value as a filename (with $-expansion)"), | 228 | "filename", |
229 | 0, &GNUNET_GETOPT_set_one, &is_filename }, | 229 | gettext_noop ("obtain option of value as a filename (with $-expansion)"), |
230 | { 's', "section", "SECTION", | 230 | &is_filename), |
231 | gettext_noop ("name of the section to access"), | 231 | GNUNET_GETOPT_OPTION_STRING ('s', |
232 | 1, &GNUNET_GETOPT_set_string, §ion }, | 232 | "section", |
233 | { 'o', "option", "OPTION", | 233 | "SECTION", |
234 | gettext_noop ("name of the option to access"), | 234 | gettext_noop ("name of the section to access"), |
235 | 1, &GNUNET_GETOPT_set_string, &option }, | 235 | §ion), |
236 | { 'V', "value", "VALUE", | 236 | GNUNET_GETOPT_OPTION_STRING ('o', |
237 | gettext_noop ("value to set"), | 237 | "option", |
238 | 1, &GNUNET_GETOPT_set_string, &value }, | 238 | "OPTION", |
239 | { 'S', "list-sections", NULL, | 239 | gettext_noop ("name of the option to access"), |
240 | gettext_noop ("print available configuration sections"), | 240 | &option), |
241 | 0, &GNUNET_GETOPT_set_one, &list_sections }, | 241 | GNUNET_GETOPT_OPTION_STRING ('V', |
242 | { 'w', "rewrite", NULL, | 242 | "value", |
243 | gettext_noop ("write configuration file that only contains delta to defaults"), | 243 | "VALUE", |
244 | 0, &GNUNET_GETOPT_set_one, &rewrite }, | 244 | gettext_noop ("value to set"), |
245 | &value), | ||
246 | GNUNET_GETOPT_OPTION_SET_ONE ('S', | ||
247 | "list-sections", | ||
248 | gettext_noop ("print available configuration sections"), | ||
249 | &list_sections), | ||
250 | GNUNET_GETOPT_OPTION_SET_ONE ('w', | ||
251 | "rewrite", | ||
252 | gettext_noop ("write configuration file that only contains delta to defaults"), | ||
253 | &rewrite), | ||
245 | GNUNET_GETOPT_OPTION_END | 254 | GNUNET_GETOPT_OPTION_END |
246 | }; | 255 | }; |
247 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 256 | if (GNUNET_OK != |
257 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
258 | &argc, &argv)) | ||
248 | return 2; | 259 | return 2; |
249 | 260 | ||
250 | ret = (GNUNET_OK == | 261 | ret = (GNUNET_OK == |
251 | GNUNET_PROGRAM_run (argc, argv, "gnunet-config [OPTIONS]", | 262 | GNUNET_PROGRAM_run (argc, |
263 | argv, | ||
264 | "gnunet-config [OPTIONS]", | ||
252 | gettext_noop ("Manipulate GNUnet configuration files"), | 265 | gettext_noop ("Manipulate GNUnet configuration files"), |
253 | options, &run, NULL)) ? 0 : ret; | 266 | options, |
267 | &run, NULL)) ? 0 : ret; | ||
254 | GNUNET_free ((void*) argv); | 268 | GNUNET_free ((void*) argv); |
255 | return ret; | 269 | return ret; |
256 | } | 270 | } |
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index ddfd9b1c3..732228b52 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c | |||
@@ -41,7 +41,7 @@ static int list_keys; | |||
41 | /** | 41 | /** |
42 | * Flag for listing public key. | 42 | * Flag for listing public key. |
43 | */ | 43 | */ |
44 | static int list_keys_count; | 44 | static unsigned int list_keys_count; |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Flag for printing public key. | 47 | * Flag for printing public key. |
@@ -406,36 +406,50 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
406 | * @return 0 ok, 1 on error | 406 | * @return 0 ok, 1 on error |
407 | */ | 407 | */ |
408 | int | 408 | int |
409 | main (int argc, char *const *argv) | 409 | main (int argc, |
410 | char *const *argv) | ||
410 | { | 411 | { |
411 | list_keys_count = UINT32_MAX; | 412 | list_keys_count = UINT32_MAX; |
412 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 413 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
413 | { 'i', "iterate", "FILE", | 414 | GNUNET_GETOPT_OPTION_SET_ONE ('i', |
414 | gettext_noop ("list keys included in a file (for testing)"), | 415 | "iterate", |
415 | 0, &GNUNET_GETOPT_set_one, &list_keys }, | 416 | gettext_noop ("list keys included in a file (for testing)"), |
416 | { 'e', "end=", "COUNT", | 417 | &list_keys), |
417 | gettext_noop ("number of keys to list included in a file (for testing)"), | 418 | GNUNET_GETOPT_OPTION_SET_UINT ('e', |
418 | 1, &GNUNET_GETOPT_set_uint, &list_keys_count }, | 419 | "end=", |
419 | { 'g', "generate-keys", "COUNT", | 420 | "COUNT", |
420 | gettext_noop ("create COUNT public-private key pairs (for testing)"), | 421 | gettext_noop ("number of keys to list included in a file (for testing)"), |
421 | 1, &GNUNET_GETOPT_set_uint, &make_keys }, | 422 | &list_keys_count), |
422 | { 'p', "print-public-key", NULL, | 423 | GNUNET_GETOPT_OPTION_SET_UINT ('g', |
423 | gettext_noop ("print the public key in ASCII format"), | 424 | "generate-keys", |
424 | 0, &GNUNET_GETOPT_set_one, &print_public_key }, | 425 | "COUNT", |
425 | { 'E', "examples", NULL, | 426 | gettext_noop ("create COUNT public-private key pairs (for testing)"), |
426 | gettext_noop ("print examples of ECC operations (used for compatibility testing)"), | 427 | &make_keys), |
427 | 0, &GNUNET_GETOPT_set_one, &print_examples_flag }, | 428 | GNUNET_GETOPT_OPTION_SET_ONE ('p', |
429 | "print-public-key", | ||
430 | gettext_noop ("print the public key in ASCII format"), | ||
431 | &print_public_key), | ||
432 | GNUNET_GETOPT_OPTION_SET_ONE ('E', | ||
433 | "examples", | ||
434 | gettext_noop ("print examples of ECC operations (used for compatibility testing)"), | ||
435 | &print_examples_flag), | ||
428 | GNUNET_GETOPT_OPTION_END | 436 | GNUNET_GETOPT_OPTION_END |
429 | }; | 437 | }; |
430 | int ret; | 438 | int ret; |
431 | 439 | ||
432 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 440 | if (GNUNET_OK != |
441 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
442 | &argc, &argv)) | ||
433 | return 2; | 443 | return 2; |
434 | 444 | ||
435 | ret = (GNUNET_OK == | 445 | ret = (GNUNET_OK == |
436 | GNUNET_PROGRAM_run (argc, argv, "gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]", | 446 | GNUNET_PROGRAM_run (argc, |
447 | argv, | ||
448 | "gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]", | ||
437 | gettext_noop ("Manipulate GNUnet private ECC key files"), | 449 | gettext_noop ("Manipulate GNUnet private ECC key files"), |
438 | options, &run, NULL)) ? 0 : 1; | 450 | options, |
451 | &run, | ||
452 | NULL)) ? 0 : 1; | ||
439 | GNUNET_free ((void*) argv); | 453 | GNUNET_free ((void*) argv); |
440 | return ret; | 454 | return ret; |
441 | } | 455 | } |
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c index e84a2332f..563cf9fce 100644 --- a/src/util/gnunet-resolver.c +++ b/src/util/gnunet-resolver.c | |||
@@ -144,10 +144,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
144 | int | 144 | int |
145 | main (int argc, char *const *argv) | 145 | main (int argc, char *const *argv) |
146 | { | 146 | { |
147 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 147 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
148 | { 'r', "reverse", NULL, | 148 | GNUNET_GETOPT_OPTION_SET_ONE ('r', |
149 | gettext_noop ("perform a reverse lookup"), | 149 | "reverse", |
150 | 0, &GNUNET_GETOPT_set_one, &reverse }, | 150 | gettext_noop ("perform a reverse lookup"), |
151 | &reverse), | ||
151 | GNUNET_GETOPT_OPTION_END | 152 | GNUNET_GETOPT_OPTION_END |
152 | }; | 153 | }; |
153 | int ret; | 154 | int ret; |
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index ab0cf92e0..7c73cfe1e 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -307,21 +307,30 @@ run (void *cls, | |||
307 | * @return 0 ok, 1 on error | 307 | * @return 0 ok, 1 on error |
308 | */ | 308 | */ |
309 | int | 309 | int |
310 | main (int argc, char *const *argv) | 310 | main (int argc, |
311 | char *const *argv) | ||
311 | { | 312 | { |
312 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 313 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
313 | { 'b', "bits", "BITS", | 314 | GNUNET_GETOPT_OPTION_SET_ULONG ('b', |
314 | gettext_noop ("number of bits to require for the proof of work"), | 315 | "bits", |
315 | 1, &GNUNET_GETOPT_set_ulong, &nse_work_required }, | 316 | "BITS", |
316 | { 'k', "keyfile", "FILE", | 317 | gettext_noop ("number of bits to require for the proof of work"), |
317 | gettext_noop ("file with private key, otherwise default is used"), | 318 | &nse_work_required), |
318 | 1, &GNUNET_GETOPT_set_filename, &pkfn }, | 319 | GNUNET_GETOPT_OPTION_FILENAME ('k', |
319 | { 'o', "outfile", "FILE", | 320 | "keyfile", |
320 | gettext_noop ("file with proof of work, otherwise default is used"), | 321 | "FILE", |
321 | 1, &GNUNET_GETOPT_set_filename, &pwfn }, | 322 | gettext_noop ("file with private key, otherwise default is used"), |
322 | { 't', "timeout", "TIME", | 323 | &pkfn), |
323 | gettext_noop ("time to wait between calculations"), | 324 | GNUNET_GETOPT_OPTION_FILENAME ('o', |
324 | 1, &GNUNET_GETOPT_set_relative_time, &proof_find_delay }, | 325 | "outfile", |
326 | "FILE", | ||
327 | gettext_noop ("file with proof of work, otherwise default is used"), | ||
328 | &pwfn), | ||
329 | GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME ('t', | ||
330 | "timeout", | ||
331 | "TIME", | ||
332 | gettext_noop ("time to wait between calculations"), | ||
333 | &proof_find_delay), | ||
325 | GNUNET_GETOPT_OPTION_END | 334 | GNUNET_GETOPT_OPTION_END |
326 | }; | 335 | }; |
327 | int ret; | 336 | int ret; |
@@ -334,7 +343,9 @@ main (int argc, char *const *argv) | |||
334 | GNUNET_PROGRAM_run (argc, argv, | 343 | GNUNET_PROGRAM_run (argc, argv, |
335 | "gnunet-scrypt [OPTIONS] prooffile", | 344 | "gnunet-scrypt [OPTIONS] prooffile", |
336 | gettext_noop ("Manipulate GNUnet proof of work files"), | 345 | gettext_noop ("Manipulate GNUnet proof of work files"), |
337 | options, &run, NULL)) ? 0 : 1; | 346 | options, |
347 | &run, | ||
348 | NULL)) ? 0 : 1; | ||
338 | GNUNET_free ((void*) argv); | 349 | GNUNET_free ((void*) argv); |
339 | GNUNET_free_non_null (pwfn); | 350 | GNUNET_free_non_null (pwfn); |
340 | return ret; | 351 | return ret; |
diff --git a/src/util/service.c b/src/util/service.c index 496904fb1..d1dffa139 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -1402,9 +1402,10 @@ GNUNET_SERVICE_run (int argc, char *const *argv, | |||
1402 | 1402 | ||
1403 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 1403 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
1404 | GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_fn), | 1404 | GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_fn), |
1405 | {'d', "daemonize", NULL, | 1405 | GNUNET_GETOPT_OPTION_SET_ONE ('d', |
1406 | gettext_noop ("do daemonize (detach from terminal)"), 0, | 1406 | "daemonize", |
1407 | GNUNET_GETOPT_set_one, &do_daemonize}, | 1407 | gettext_noop ("do daemonize (detach from terminal)"), |
1408 | &do_daemonize), | ||
1408 | GNUNET_GETOPT_OPTION_HELP (NULL), | 1409 | GNUNET_GETOPT_OPTION_HELP (NULL), |
1409 | GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), | 1410 | GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), |
1410 | GNUNET_GETOPT_OPTION_LOGFILE (&logfile), | 1411 | GNUNET_GETOPT_OPTION_LOGFILE (&logfile), |
diff --git a/src/util/service_new.c b/src/util/service_new.c index 9c0ee539b..b4d03c17c 100644 --- a/src/util/service_new.c +++ b/src/util/service_new.c | |||
@@ -1723,9 +1723,10 @@ GNUNET_SERVICE_ruN_ (int argc, | |||
1723 | 1723 | ||
1724 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 1724 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
1725 | GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_filename), | 1725 | GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_filename), |
1726 | {'d', "daemonize", NULL, | 1726 | GNUNET_GETOPT_OPTION_SET_ONE ('d', |
1727 | gettext_noop ("do daemonize (detach from terminal)"), 0, | 1727 | "daemonize", |
1728 | GNUNET_GETOPT_set_one, &do_daemonize}, | 1728 | gettext_noop ("do daemonize (detach from terminal)"), |
1729 | &do_daemonize), | ||
1729 | GNUNET_GETOPT_OPTION_HELP (NULL), | 1730 | GNUNET_GETOPT_OPTION_HELP (NULL), |
1730 | GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), | 1731 | GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), |
1731 | GNUNET_GETOPT_OPTION_LOGFILE (&logfile), | 1732 | GNUNET_GETOPT_OPTION_LOGFILE (&logfile), |