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