aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r--src/util/getopt_helpers.c583
1 files changed, 293 insertions, 290 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index a5e752546..68da423b8 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28 28
29#define LOG(kind, ...) GNUNET_log_from(kind, "util-getopt", __VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
30 30
31 31
32/** 32/**
@@ -39,16 +39,16 @@
39 * @return #GNUNET_NO (do not continue, not an error) 39 * @return #GNUNET_NO (do not continue, not an error)
40 */ 40 */
41static int 41static int
42print_version(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 42print_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
49 (void)option; 49 (void) option;
50 (void)value; 50 (void) value;
51 printf("%s v%s\n", ctx->binaryName, version); 51 printf ("%s v%s\n", ctx->binaryName, version);
52 return GNUNET_NO; 52 return GNUNET_NO;
53} 53}
54 54
@@ -60,15 +60,15 @@ print_version(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
60 * @param version string with the version number 60 * @param version string with the version number
61 */ 61 */
62struct GNUNET_GETOPT_CommandLineOption 62struct GNUNET_GETOPT_CommandLineOption
63GNUNET_GETOPT_option_version(const char *version) 63GNUNET_GETOPT_option_version (const char *version)
64{ 64{
65 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = 'v', 65 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = 'v',
66 .name = "version", 66 .name = "version",
67 .description = gettext_noop( 67 .description = gettext_noop (
68 "print the version number"), 68 "print the version number"),
69 .option_exclusive = 1, 69 .option_exclusive = 1,
70 .processor = &print_version, 70 .processor = &print_version,
71 .scls = (void *)version }; 71 .scls = (void *) version };
72 72
73 return clo; 73 return clo;
74} 74}
@@ -89,10 +89,10 @@ GNUNET_GETOPT_option_version(const char *version)
89 * @return #GNUNET_NO (do not continue, not an error) 89 * @return #GNUNET_NO (do not continue, not an error)
90 */ 90 */
91static int 91static int
92format_help(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 92format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
93 void *scls, 93 void *scls,
94 const char *option, 94 const char *option,
95 const char *value) 95 const char *value)
96{ 96{
97 const char *about = scls; 97 const char *about = scls;
98 size_t slen; 98 size_t slen;
@@ -105,86 +105,86 @@ format_help(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
105 const struct GNUNET_GETOPT_CommandLineOption *opt; 105 const struct GNUNET_GETOPT_CommandLineOption *opt;
106 const struct GNUNET_OS_ProjectData *pd; 106 const struct GNUNET_OS_ProjectData *pd;
107 107
108 (void)option; 108 (void) option;
109 (void)value; 109 (void) value;
110 if (NULL != about) 110 if (NULL != about)
111 { 111 {
112 printf("%s\n%s\n", ctx->binaryOptions, gettext(about)); 112 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
113 printf(_( 113 printf (_ (
114 "Arguments mandatory for long options are also mandatory for short options.\n")); 114 "Arguments mandatory for long options are also mandatory for short options.\n"));
115 } 115 }
116 i = 0; 116 i = 0;
117 opt = ctx->allOptions; 117 opt = ctx->allOptions;
118 while (NULL != opt[i].description) 118 while (NULL != opt[i].description)
119 {
120 if (opt[i].shortName == '\0')
121 printf (" ");
122 else
123 printf (" -%c, ", opt[i].shortName);
124 printf ("--%s", opt[i].name);
125 slen = 8 + strlen (opt[i].name);
126 if (NULL != opt[i].argumentHelp)
119 { 127 {
120 if (opt[i].shortName == '\0') 128 printf ("=%s", opt[i].argumentHelp);
121 printf(" "); 129 slen += 1 + strlen (opt[i].argumentHelp);
122 else 130 }
123 printf(" -%c, ", opt[i].shortName); 131 if (slen > BORDER)
124 printf("--%s", opt[i].name); 132 {
125 slen = 8 + strlen(opt[i].name); 133 printf ("\n%*s", BORDER, "");
126 if (NULL != opt[i].argumentHelp) 134 slen = BORDER;
127 { 135 }
128 printf("=%s", opt[i].argumentHelp); 136 if (slen < BORDER)
129 slen += 1 + strlen(opt[i].argumentHelp); 137 {
130 } 138 printf ("%*s", (int) (BORDER - slen), "");
131 if (slen > BORDER) 139 slen = BORDER;
132 { 140 }
133 printf("\n%*s", BORDER, ""); 141 if (0 < strlen (opt[i].description))
134 slen = BORDER; 142 trans = gettext (opt[i].description);
135 } 143 else
136 if (slen < BORDER) 144 trans = "";
137 { 145 ml = strlen (trans);
138 printf("%*s", (int)(BORDER - slen), ""); 146 p = 0;
139 slen = BORDER;
140 }
141 if (0 < strlen(opt[i].description))
142 trans = gettext(opt[i].description);
143 else
144 trans = "";
145 ml = strlen(trans);
146 p = 0;
147OUTER: 147OUTER:
148 while (ml - p > 78 - slen) 148 while (ml - p > 78 - slen)
149 {
150 for (j = p + 78 - slen; j > (int) p; j--)
151 {
152 if (isspace ((unsigned char) trans[j]))
149 { 153 {
150 for (j = p + 78 - slen; j > (int)p; j--) 154 scp = GNUNET_malloc (j - p + 1);
151 { 155 GNUNET_memcpy (scp, &trans[p], j - p);
152 if (isspace((unsigned char)trans[j])) 156 scp[j - p] = '\0';
153 { 157 printf ("%s\n%*s", scp, BORDER + 2, "");
154 scp = GNUNET_malloc(j - p + 1); 158 GNUNET_free (scp);
155 GNUNET_memcpy(scp, &trans[p], j - p); 159 p = j + 1;
156 scp[j - p] = '\0';
157 printf("%s\n%*s", scp, BORDER + 2, "");
158 GNUNET_free(scp);
159 p = j + 1;
160 slen = BORDER + 2;
161 goto OUTER;
162 }
163 }
164 /* could not find space to break line */
165 scp = GNUNET_malloc(78 - slen + 1);
166 GNUNET_memcpy(scp, &trans[p], 78 - slen);
167 scp[78 - slen] = '\0';
168 printf("%s\n%*s", scp, BORDER + 2, "");
169 GNUNET_free(scp);
170 slen = BORDER + 2; 160 slen = BORDER + 2;
171 p = p + 78 - slen; 161 goto OUTER;
172 } 162 }
173 /* print rest */ 163 }
174 if (p < ml) 164 /* could not find space to break line */
175 printf("%s\n", &trans[p]); 165 scp = GNUNET_malloc (78 - slen + 1);
176 if (strlen(trans) == 0) 166 GNUNET_memcpy (scp, &trans[p], 78 - slen);
177 printf("\n"); 167 scp[78 - slen] = '\0';
178 i++; 168 printf ("%s\n%*s", scp, BORDER + 2, "");
169 GNUNET_free (scp);
170 slen = BORDER + 2;
171 p = p + 78 - slen;
179 } 172 }
180 pd = GNUNET_OS_project_data_get(); 173 /* print rest */
181 printf("Report bugs to %s.\n" 174 if (p < ml)
182 "Home page: %s\n", 175 printf ("%s\n", &trans[p]);
183 pd->bug_email, 176 if (strlen (trans) == 0)
184 pd->homepage); 177 printf ("\n");
178 i++;
179 }
180 pd = GNUNET_OS_project_data_get ();
181 printf ("Report bugs to %s.\n"
182 "Home page: %s\n",
183 pd->bug_email,
184 pd->homepage);
185 185
186 if (0 != pd->is_gnu) 186 if (0 != pd->is_gnu)
187 printf("General help using GNU software: http://www.gnu.org/gethelp/\n"); 187 printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
188 188
189 return GNUNET_NO; 189 return GNUNET_NO;
190} 190}
@@ -197,15 +197,15 @@ OUTER:
197 * @param about string with brief description of the application 197 * @param about string with brief description of the application
198 */ 198 */
199struct GNUNET_GETOPT_CommandLineOption 199struct GNUNET_GETOPT_CommandLineOption
200GNUNET_GETOPT_option_help(const char *about) 200GNUNET_GETOPT_option_help (const char *about)
201{ 201{
202 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = 'h', 202 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = 'h',
203 .name = "help", 203 .name = "help",
204 .description = gettext_noop( 204 .description = gettext_noop (
205 "print this help"), 205 "print this help"),
206 .option_exclusive = 1, 206 .option_exclusive = 1,
207 .processor = format_help, 207 .processor = format_help,
208 .scls = (void *)about }; 208 .scls = (void *) about };
209 209
210 return clo; 210 return clo;
211} 211}
@@ -226,16 +226,16 @@ GNUNET_GETOPT_option_help(const char *about)
226 * @return #GNUNET_OK 226 * @return #GNUNET_OK
227 */ 227 */
228static int 228static int
229increment_value(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 229increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
230 void *scls, 230 void *scls,
231 const char *option, 231 const char *option,
232 const char *value) 232 const char *value)
233{ 233{
234 unsigned int *val = scls; 234 unsigned int *val = scls;
235 235
236 (void)ctx; 236 (void) ctx;
237 (void)option; 237 (void) option;
238 (void)value; 238 (void) value;
239 (*val)++; 239 (*val)++;
240 return GNUNET_OK; 240 return GNUNET_OK;
241} 241}
@@ -251,16 +251,16 @@ increment_value(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
251 * @param[out] val increment by 1 each time the option is present 251 * @param[out] val increment by 1 each time the option is present
252 */ 252 */
253struct GNUNET_GETOPT_CommandLineOption 253struct GNUNET_GETOPT_CommandLineOption
254GNUNET_GETOPT_option_increment_uint(char shortName, 254GNUNET_GETOPT_option_increment_uint (char shortName,
255 const char *name, 255 const char *name,
256 const char *description, 256 const char *description,
257 unsigned int *val) 257 unsigned int *val)
258{ 258{
259 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 259 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
260 .name = name, 260 .name = name,
261 .description = description, 261 .description = description,
262 .processor = &increment_value, 262 .processor = &increment_value,
263 .scls = (void *)val }; 263 .scls = (void *) val };
264 264
265 return clo; 265 return clo;
266} 266}
@@ -273,14 +273,14 @@ GNUNET_GETOPT_option_increment_uint(char shortName,
273 * @param[out] level set to the verbosity level 273 * @param[out] level set to the verbosity level
274 */ 274 */
275struct GNUNET_GETOPT_CommandLineOption 275struct GNUNET_GETOPT_CommandLineOption
276GNUNET_GETOPT_option_verbose(unsigned int *level) 276GNUNET_GETOPT_option_verbose (unsigned int *level)
277{ 277{
278 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = 'V', 278 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = 'V',
279 .name = "verbose", 279 .name = "verbose",
280 .description = 280 .description =
281 gettext_noop("be verbose"), 281 gettext_noop ("be verbose"),
282 .processor = &increment_value, 282 .processor = &increment_value,
283 .scls = (void *)level }; 283 .scls = (void *) level };
284 284
285 return clo; 285 return clo;
286} 286}
@@ -301,16 +301,16 @@ GNUNET_GETOPT_option_verbose(unsigned int *level)
301 * @return #GNUNET_OK 301 * @return #GNUNET_OK
302 */ 302 */
303static int 303static int
304set_one(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 304set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
305 void *scls, 305 void *scls,
306 const char *option, 306 const char *option,
307 const char *value) 307 const char *value)
308{ 308{
309 int *val = scls; 309 int *val = scls;
310 310
311 (void)ctx; 311 (void) ctx;
312 (void)option; 312 (void) option;
313 (void)value; 313 (void) value;
314 *val = 1; 314 *val = 1;
315 return GNUNET_OK; 315 return GNUNET_OK;
316} 316}
@@ -327,16 +327,16 @@ set_one(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
327 * @param[out] val set to 1 if the option is present 327 * @param[out] val set to 1 if the option is present
328 */ 328 */
329struct GNUNET_GETOPT_CommandLineOption 329struct GNUNET_GETOPT_CommandLineOption
330GNUNET_GETOPT_option_flag(char shortName, 330GNUNET_GETOPT_option_flag (char shortName,
331 const char *name, 331 const char *name,
332 const char *description, 332 const char *description,
333 int *val) 333 int *val)
334{ 334{
335 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 335 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
336 .name = name, 336 .name = name,
337 .description = description, 337 .description = description,
338 .processor = &set_one, 338 .processor = &set_one,
339 .scls = (void *)val }; 339 .scls = (void *) val };
340 340
341 return clo; 341 return clo;
342} 342}
@@ -357,18 +357,18 @@ GNUNET_GETOPT_option_flag(char shortName,
357 * @return #GNUNET_OK 357 * @return #GNUNET_OK
358 */ 358 */
359static int 359static int
360set_string(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 360set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
361 void *scls, 361 void *scls,
362 const char *option, 362 const char *option,
363 const char *value) 363 const char *value)
364{ 364{
365 char **val = scls; 365 char **val = scls;
366 366
367 (void)ctx; 367 (void) ctx;
368 (void)option; 368 (void) option;
369 GNUNET_assert(NULL != value); 369 GNUNET_assert (NULL != value);
370 GNUNET_free_non_null(*val); 370 GNUNET_free_non_null (*val);
371 *val = GNUNET_strdup(value); 371 *val = GNUNET_strdup (value);
372 return GNUNET_OK; 372 return GNUNET_OK;
373} 373}
374 374
@@ -383,11 +383,11 @@ set_string(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
383 * @param[out] str set to the string 383 * @param[out] str set to the string
384 */ 384 */
385struct GNUNET_GETOPT_CommandLineOption 385struct GNUNET_GETOPT_CommandLineOption
386GNUNET_GETOPT_option_string(char shortName, 386GNUNET_GETOPT_option_string (char shortName,
387 const char *name, 387 const char *name,
388 const char *argumentHelp, 388 const char *argumentHelp,
389 const char *description, 389 const char *description,
390 char **str) 390 char **str)
391{ 391{
392 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 392 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
393 .name = name, 393 .name = name,
@@ -395,7 +395,7 @@ GNUNET_GETOPT_option_string(char shortName,
395 .description = description, 395 .description = description,
396 .require_argument = 1, 396 .require_argument = 1,
397 .processor = &set_string, 397 .processor = &set_string,
398 .scls = (void *)str }; 398 .scls = (void *) str };
399 399
400 return clo; 400 return clo;
401} 401}
@@ -408,16 +408,16 @@ GNUNET_GETOPT_option_string(char shortName,
408 * @param[out] level set to the log level 408 * @param[out] level set to the log level
409 */ 409 */
410struct GNUNET_GETOPT_CommandLineOption 410struct GNUNET_GETOPT_CommandLineOption
411GNUNET_GETOPT_option_loglevel(char **level) 411GNUNET_GETOPT_option_loglevel (char **level)
412{ 412{
413 struct GNUNET_GETOPT_CommandLineOption clo = 413 struct GNUNET_GETOPT_CommandLineOption clo =
414 { .shortName = 'L', 414 { .shortName = 'L',
415 .name = "log", 415 .name = "log",
416 .argumentHelp = "LOGLEVEL", 416 .argumentHelp = "LOGLEVEL",
417 .description = gettext_noop("configure logging to use LOGLEVEL"), 417 .description = gettext_noop ("configure logging to use LOGLEVEL"),
418 .require_argument = 1, 418 .require_argument = 1,
419 .processor = &set_string, 419 .processor = &set_string,
420 .scls = (void *)level }; 420 .scls = (void *) level };
421 421
422 return clo; 422 return clo;
423} 423}
@@ -435,18 +435,18 @@ GNUNET_GETOPT_option_loglevel(char **level)
435 * @return #GNUNET_OK 435 * @return #GNUNET_OK
436 */ 436 */
437static int 437static int
438set_filename(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 438set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
439 void *scls, 439 void *scls,
440 const char *option, 440 const char *option,
441 const char *value) 441 const char *value)
442{ 442{
443 char **val = scls; 443 char **val = scls;
444 444
445 (void)ctx; 445 (void) ctx;
446 (void)option; 446 (void) option;
447 GNUNET_assert(NULL != value); 447 GNUNET_assert (NULL != value);
448 GNUNET_free_non_null(*val); 448 GNUNET_free_non_null (*val);
449 *val = GNUNET_STRINGS_filename_expand(value); 449 *val = GNUNET_STRINGS_filename_expand (value);
450 return GNUNET_OK; 450 return GNUNET_OK;
451} 451}
452 452
@@ -461,11 +461,11 @@ set_filename(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
461 * @param[out] str set to the string 461 * @param[out] str set to the string
462 */ 462 */
463struct GNUNET_GETOPT_CommandLineOption 463struct GNUNET_GETOPT_CommandLineOption
464GNUNET_GETOPT_option_filename(char shortName, 464GNUNET_GETOPT_option_filename (char shortName,
465 const char *name, 465 const char *name,
466 const char *argumentHelp, 466 const char *argumentHelp,
467 const char *description, 467 const char *description,
468 char **str) 468 char **str)
469{ 469{
470 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 470 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
471 .name = name, 471 .name = name,
@@ -473,7 +473,7 @@ GNUNET_GETOPT_option_filename(char shortName,
473 .description = description, 473 .description = description,
474 .require_argument = 1, 474 .require_argument = 1,
475 .processor = &set_filename, 475 .processor = &set_filename,
476 .scls = (void *)str }; 476 .scls = (void *) str };
477 477
478 return clo; 478 return clo;
479} 479}
@@ -485,17 +485,17 @@ GNUNET_GETOPT_option_filename(char shortName,
485 * @param[out] logfn set to the name of the logfile 485 * @param[out] logfn set to the name of the logfile
486 */ 486 */
487struct GNUNET_GETOPT_CommandLineOption 487struct GNUNET_GETOPT_CommandLineOption
488GNUNET_GETOPT_option_logfile(char **logfn) 488GNUNET_GETOPT_option_logfile (char **logfn)
489{ 489{
490 struct GNUNET_GETOPT_CommandLineOption clo = 490 struct GNUNET_GETOPT_CommandLineOption clo =
491 { .shortName = 'l', 491 { .shortName = 'l',
492 .name = "logfile", 492 .name = "logfile",
493 .argumentHelp = "FILENAME", 493 .argumentHelp = "FILENAME",
494 .description = 494 .description =
495 gettext_noop("configure logging to write logs to FILENAME"), 495 gettext_noop ("configure logging to write logs to FILENAME"),
496 .require_argument = 1, 496 .require_argument = 1,
497 .processor = &set_filename, 497 .processor = &set_filename,
498 .scls = (void *)logfn }; 498 .scls = (void *) logfn };
499 499
500 return clo; 500 return clo;
501} 501}
@@ -507,16 +507,16 @@ GNUNET_GETOPT_option_logfile(char **logfn)
507 * @param[out] fn set to the name of the configuration file 507 * @param[out] fn set to the name of the configuration file
508 */ 508 */
509struct GNUNET_GETOPT_CommandLineOption 509struct GNUNET_GETOPT_CommandLineOption
510GNUNET_GETOPT_option_cfgfile(char **fn) 510GNUNET_GETOPT_option_cfgfile (char **fn)
511{ 511{
512 struct GNUNET_GETOPT_CommandLineOption clo = 512 struct GNUNET_GETOPT_CommandLineOption clo =
513 { .shortName = 'c', 513 { .shortName = 'c',
514 .name = "config", 514 .name = "config",
515 .argumentHelp = "FILENAME", 515 .argumentHelp = "FILENAME",
516 .description = gettext_noop("use configuration file FILENAME"), 516 .description = gettext_noop ("use configuration file FILENAME"),
517 .require_argument = 1, 517 .require_argument = 1,
518 .processor = &set_filename, 518 .processor = &set_filename,
519 .scls = (void *)fn }; 519 .scls = (void *) fn };
520 520
521 return clo; 521 return clo;
522} 522}
@@ -536,22 +536,22 @@ GNUNET_GETOPT_option_cfgfile(char **fn)
536 * @return #GNUNET_OK if parsing the value worked 536 * @return #GNUNET_OK if parsing the value worked
537 */ 537 */
538static int 538static int
539set_ulong(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 539set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
540 void *scls, 540 void *scls,
541 const char *option, 541 const char *option,
542 const char *value) 542 const char *value)
543{ 543{
544 unsigned long long *val = scls; 544 unsigned long long *val = scls;
545 char dummy[2]; 545 char dummy[2];
546 546
547 (void)ctx; 547 (void) ctx;
548 if (1 != sscanf(value, "%llu%1s", val, dummy)) 548 if (1 != sscanf (value, "%llu%1s", val, dummy))
549 { 549 {
550 fprintf(stderr, 550 fprintf (stderr,
551 _("You must pass a number to the `%s' option.\n"), 551 _ ("You must pass a number to the `%s' option.\n"),
552 option); 552 option);
553 return GNUNET_SYSERR; 553 return GNUNET_SYSERR;
554 } 554 }
555 return GNUNET_OK; 555 return GNUNET_OK;
556} 556}
557 557
@@ -566,11 +566,11 @@ set_ulong(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
566 * @param[out] val set to the value specified at the command line 566 * @param[out] val set to the value specified at the command line
567 */ 567 */
568struct GNUNET_GETOPT_CommandLineOption 568struct GNUNET_GETOPT_CommandLineOption
569GNUNET_GETOPT_option_ulong(char shortName, 569GNUNET_GETOPT_option_ulong (char shortName,
570 const char *name, 570 const char *name,
571 const char *argumentHelp, 571 const char *argumentHelp,
572 const char *description, 572 const char *description,
573 unsigned long long *val) 573 unsigned long long *val)
574{ 574{
575 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 575 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
576 .name = name, 576 .name = name,
@@ -578,7 +578,7 @@ GNUNET_GETOPT_option_ulong(char shortName,
578 .description = description, 578 .description = description,
579 .require_argument = 1, 579 .require_argument = 1,
580 .processor = &set_ulong, 580 .processor = &set_ulong,
581 .scls = (void *)val }; 581 .scls = (void *) val };
582 582
583 return clo; 583 return clo;
584} 584}
@@ -598,21 +598,21 @@ GNUNET_GETOPT_option_ulong(char shortName,
598 * @return #GNUNET_OK if parsing the value worked 598 * @return #GNUNET_OK if parsing the value worked
599 */ 599 */
600static int 600static int
601set_relative_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 601set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
602 void *scls, 602 void *scls,
603 const char *option, 603 const char *option,
604 const char *value) 604 const char *value)
605{ 605{
606 struct GNUNET_TIME_Relative *val = scls; 606 struct GNUNET_TIME_Relative *val = scls;
607 607
608 (void)ctx; 608 (void) ctx;
609 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(value, val)) 609 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val))
610 { 610 {
611 fprintf(stderr, 611 fprintf (stderr,
612 _("You must pass relative time to the `%s' option.\n"), 612 _ ("You must pass relative time to the `%s' option.\n"),
613 option); 613 option);
614 return GNUNET_SYSERR; 614 return GNUNET_SYSERR;
615 } 615 }
616 return GNUNET_OK; 616 return GNUNET_OK;
617} 617}
618 618
@@ -628,19 +628,20 @@ set_relative_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
628 * @param[out] val set to the time specified at the command line 628 * @param[out] val set to the time specified at the command line
629 */ 629 */
630struct GNUNET_GETOPT_CommandLineOption 630struct GNUNET_GETOPT_CommandLineOption
631GNUNET_GETOPT_option_relative_time(char shortName, 631GNUNET_GETOPT_option_relative_time (char shortName,
632 const char *name, 632 const char *name,
633 const char *argumentHelp, 633 const char *argumentHelp,
634 const char *description, 634 const char *description,
635 struct GNUNET_TIME_Relative *val) 635 struct GNUNET_TIME_Relative *val)
636{ 636{
637 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 637 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
638 .name = name, 638 .name = name,
639 .argumentHelp = argumentHelp, 639 .argumentHelp = argumentHelp,
640 .description = description, 640 .description = description,
641 .require_argument = 1, 641 .require_argument = 1,
642 .processor = &set_relative_time, 642 .processor =
643 .scls = (void *)val }; 643 &set_relative_time,
644 .scls = (void *) val };
644 645
645 return clo; 646 return clo;
646} 647}
@@ -660,21 +661,21 @@ GNUNET_GETOPT_option_relative_time(char shortName,
660 * @return #GNUNET_OK if parsing the value worked 661 * @return #GNUNET_OK if parsing the value worked
661 */ 662 */
662static int 663static int
663set_absolute_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 664set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
664 void *scls, 665 void *scls,
665 const char *option, 666 const char *option,
666 const char *value) 667 const char *value)
667{ 668{
668 struct GNUNET_TIME_Absolute *val = scls; 669 struct GNUNET_TIME_Absolute *val = scls;
669 670
670 (void)ctx; 671 (void) ctx;
671 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute(value, val)) 672 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val))
672 { 673 {
673 fprintf(stderr, 674 fprintf (stderr,
674 _("You must pass absolute time to the `%s' option.\n"), 675 _ ("You must pass absolute time to the `%s' option.\n"),
675 option); 676 option);
676 return GNUNET_SYSERR; 677 return GNUNET_SYSERR;
677 } 678 }
678 return GNUNET_OK; 679 return GNUNET_OK;
679} 680}
680 681
@@ -690,19 +691,20 @@ set_absolute_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
690 * @param[out] val set to the time specified at the command line 691 * @param[out] val set to the time specified at the command line
691 */ 692 */
692struct GNUNET_GETOPT_CommandLineOption 693struct GNUNET_GETOPT_CommandLineOption
693GNUNET_GETOPT_option_absolute_time(char shortName, 694GNUNET_GETOPT_option_absolute_time (char shortName,
694 const char *name, 695 const char *name,
695 const char *argumentHelp, 696 const char *argumentHelp,
696 const char *description, 697 const char *description,
697 struct GNUNET_TIME_Absolute *val) 698 struct GNUNET_TIME_Absolute *val)
698{ 699{
699 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 700 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
700 .name = name, 701 .name = name,
701 .argumentHelp = argumentHelp, 702 .argumentHelp = argumentHelp,
702 .description = description, 703 .description = description,
703 .require_argument = 1, 704 .require_argument = 1,
704 .processor = &set_absolute_time, 705 .processor =
705 .scls = (void *)val }; 706 &set_absolute_time,
707 .scls = (void *) val };
706 708
707 return clo; 709 return clo;
708} 710}
@@ -722,30 +724,30 @@ GNUNET_GETOPT_option_absolute_time(char shortName,
722 * @return #GNUNET_OK if parsing the value worked 724 * @return #GNUNET_OK if parsing the value worked
723 */ 725 */
724static int 726static int
725set_uint(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 727set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
726 void *scls, 728 void *scls,
727 const char *option, 729 const char *option,
728 const char *value) 730 const char *value)
729{ 731{
730 unsigned int *val = scls; 732 unsigned int *val = scls;
731 char dummy[2]; 733 char dummy[2];
732 734
733 (void)ctx; 735 (void) ctx;
734 if ('-' == *value) 736 if ('-' == *value)
735 { 737 {
736 fprintf(stderr, 738 fprintf (stderr,
737 _( 739 _ (
738 "Your input for the '%s' option has to be a non negative number \n"), 740 "Your input for the '%s' option has to be a non negative number \n"),
739 option); 741 option);
740 return GNUNET_SYSERR; 742 return GNUNET_SYSERR;
741 } 743 }
742 if (1 != sscanf(value, "%u%1s", val, dummy)) 744 if (1 != sscanf (value, "%u%1s", val, dummy))
743 { 745 {
744 fprintf(stderr, 746 fprintf (stderr,
745 _("You must pass a number to the `%s' option.\n"), 747 _ ("You must pass a number to the `%s' option.\n"),
746 option); 748 option);
747 return GNUNET_SYSERR; 749 return GNUNET_SYSERR;
748 } 750 }
749 return GNUNET_OK; 751 return GNUNET_OK;
750} 752}
751 753
@@ -760,11 +762,11 @@ set_uint(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
760 * @param[out] val set to the value specified at the command line 762 * @param[out] val set to the value specified at the command line
761 */ 763 */
762struct GNUNET_GETOPT_CommandLineOption 764struct GNUNET_GETOPT_CommandLineOption
763GNUNET_GETOPT_option_uint(char shortName, 765GNUNET_GETOPT_option_uint (char shortName,
764 const char *name, 766 const char *name,
765 const char *argumentHelp, 767 const char *argumentHelp,
766 const char *description, 768 const char *description,
767 unsigned int *val) 769 unsigned int *val)
768{ 770{
769 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 771 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
770 .name = name, 772 .name = name,
@@ -772,7 +774,7 @@ GNUNET_GETOPT_option_uint(char shortName,
772 .description = description, 774 .description = description,
773 .require_argument = 1, 775 .require_argument = 1,
774 .processor = &set_uint, 776 .processor = &set_uint,
775 .scls = (void *)val }; 777 .scls = (void *) val };
776 778
777 return clo; 779 return clo;
778} 780}
@@ -792,32 +794,32 @@ GNUNET_GETOPT_option_uint(char shortName,
792 * @return #GNUNET_OK if parsing the value worked 794 * @return #GNUNET_OK if parsing the value worked
793 */ 795 */
794static int 796static int
795set_uint16(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 797set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
796 void *scls, 798 void *scls,
797 const char *option, 799 const char *option,
798 const char *value) 800 const char *value)
799{ 801{
800 uint16_t *val = scls; 802 uint16_t *val = scls;
801 unsigned int v; 803 unsigned int v;
802 char dummy[2]; 804 char dummy[2];
803 805
804 (void)ctx; 806 (void) ctx;
805 if (1 != sscanf(value, "%u%1s", &v, dummy)) 807 if (1 != sscanf (value, "%u%1s", &v, dummy))
806 { 808 {
807 fprintf(stderr, 809 fprintf (stderr,
808 _("You must pass a number to the `%s' option.\n"), 810 _ ("You must pass a number to the `%s' option.\n"),
809 option); 811 option);
810 return GNUNET_SYSERR; 812 return GNUNET_SYSERR;
811 } 813 }
812 if (v > UINT16_MAX) 814 if (v > UINT16_MAX)
813 { 815 {
814 fprintf(stderr, 816 fprintf (stderr,
815 _("You must pass a number below %u to the `%s' option.\n"), 817 _ ("You must pass a number below %u to the `%s' option.\n"),
816 (unsigned int)UINT16_MAX, 818 (unsigned int) UINT16_MAX,
817 option); 819 option);
818 return GNUNET_SYSERR; 820 return GNUNET_SYSERR;
819 } 821 }
820 *val = (uint16_t)v; 822 *val = (uint16_t) v;
821 return GNUNET_OK; 823 return GNUNET_OK;
822} 824}
823 825
@@ -832,11 +834,11 @@ set_uint16(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
832 * @param[out] val set to the value specified at the command line 834 * @param[out] val set to the value specified at the command line
833 */ 835 */
834struct GNUNET_GETOPT_CommandLineOption 836struct GNUNET_GETOPT_CommandLineOption
835GNUNET_GETOPT_option_uint16(char shortName, 837GNUNET_GETOPT_option_uint16 (char shortName,
836 const char *name, 838 const char *name,
837 const char *argumentHelp, 839 const char *argumentHelp,
838 const char *description, 840 const char *description,
839 uint16_t *val) 841 uint16_t *val)
840{ 842{
841 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 843 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
842 .name = name, 844 .name = name,
@@ -844,7 +846,7 @@ GNUNET_GETOPT_option_uint16(char shortName,
844 .description = description, 846 .description = description,
845 .require_argument = 1, 847 .require_argument = 1,
846 .processor = &set_uint16, 848 .processor = &set_uint16,
847 .scls = (void *)val }; 849 .scls = (void *) val };
848 850
849 return clo; 851 return clo;
850} 852}
@@ -853,7 +855,8 @@ GNUNET_GETOPT_option_uint16(char shortName,
853/** 855/**
854 * Closure for #set_base32(). 856 * Closure for #set_base32().
855 */ 857 */
856struct Base32Context { 858struct Base32Context
859{
857 /** 860 /**
858 * Value to initialize (already allocated) 861 * Value to initialize (already allocated)
859 */ 862 */
@@ -880,26 +883,26 @@ struct Base32Context {
880 * @return #GNUNET_OK if parsing the value worked 883 * @return #GNUNET_OK if parsing the value worked
881 */ 884 */
882static int 885static int
883set_base32(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 886set_base32 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
884 void *scls, 887 void *scls,
885 const char *option, 888 const char *option,
886 const char *value) 889 const char *value)
887{ 890{
888 struct Base32Context *bc = scls; 891 struct Base32Context *bc = scls;
889 892
890 (void)ctx; 893 (void) ctx;
891 if (GNUNET_OK != GNUNET_STRINGS_string_to_data(value, 894 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (value,
892 strlen(value), 895 strlen (value),
893 bc->val, 896 bc->val,
894 bc->val_size)) 897 bc->val_size))
895 { 898 {
896 fprintf( 899 fprintf (
897 stderr, 900 stderr,
898 _( 901 _ (
899 "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"), 902 "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
900 option); 903 option);
901 return GNUNET_SYSERR; 904 return GNUNET_SYSERR;
902 } 905 }
903 return GNUNET_OK; 906 return GNUNET_OK;
904} 907}
905 908
@@ -911,9 +914,9 @@ set_base32(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
911 * @param cls value to GNUNET_free() 914 * @param cls value to GNUNET_free()
912 */ 915 */
913static void 916static void
914free_bc(void *cls) 917free_bc (void *cls)
915{ 918{
916 GNUNET_free(cls); 919 GNUNET_free (cls);
917} 920}
918 921
919 922
@@ -929,14 +932,14 @@ free_bc(void *cls)
929 * @param val_size size of @a val in bytes 932 * @param val_size size of @a val in bytes
930 */ 933 */
931struct GNUNET_GETOPT_CommandLineOption 934struct GNUNET_GETOPT_CommandLineOption
932GNUNET_GETOPT_option_base32_fixed_size(char shortName, 935GNUNET_GETOPT_option_base32_fixed_size (char shortName,
933 const char *name, 936 const char *name,
934 const char *argumentHelp, 937 const char *argumentHelp,
935 const char *description, 938 const char *description,
936 void *val, 939 void *val,
937 size_t val_size) 940 size_t val_size)
938{ 941{
939 struct Base32Context *bc = GNUNET_new(struct Base32Context); 942 struct Base32Context *bc = GNUNET_new (struct Base32Context);
940 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, 943 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
941 .name = name, 944 .name = name,
942 .argumentHelp = argumentHelp, 945 .argumentHelp = argumentHelp,
@@ -944,7 +947,7 @@ GNUNET_GETOPT_option_base32_fixed_size(char shortName,
944 .require_argument = 1, 947 .require_argument = 1,
945 .processor = &set_base32, 948 .processor = &set_base32,
946 .cleaner = &free_bc, 949 .cleaner = &free_bc,
947 .scls = (void *)bc }; 950 .scls = (void *) bc };
948 951
949 bc->val = val; 952 bc->val = val;
950 bc->val_size = val_size; 953 bc->val_size = val_size;
@@ -959,7 +962,7 @@ GNUNET_GETOPT_option_base32_fixed_size(char shortName,
959 * @return @a opt with the mandatory flag set. 962 * @return @a opt with the mandatory flag set.
960 */ 963 */
961struct GNUNET_GETOPT_CommandLineOption 964struct GNUNET_GETOPT_CommandLineOption
962GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt) 965GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt)
963{ 966{
964 opt.option_mandatory = 1; 967 opt.option_mandatory = 1;
965 return opt; 968 return opt;
@@ -973,7 +976,7 @@ GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
973 * @return @a opt with the exclusive flag set. 976 * @return @a opt with the exclusive flag set.
974 */ 977 */
975struct GNUNET_GETOPT_CommandLineOption 978struct GNUNET_GETOPT_CommandLineOption
976GNUNET_GETOPT_option_exclusive(struct GNUNET_GETOPT_CommandLineOption opt) 979GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt)
977{ 980{
978 opt.option_exclusive = 1; 981 opt.option_exclusive = 1;
979 return opt; 982 return opt;