2 This file is part of GNUnet
3 (C) 2006 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file src/util/getopt_helpers.c
23 * @brief implements command line that sets option
24 * @author Christian Grothoff
28 #include "gnunet_common.h"
29 #include "gnunet_getopt_lib.h"
33 GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext
34 *ctx, void *scls, const char *option,
37 const char *version = scls;
39 printf ("%s v%s\n", ctx->binaryName, version);
48 GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
49 *ctx, void *scls, const char *option,
52 const char *about = scls;
60 const struct GNUNET_GETOPT_CommandLineOption *opt;
62 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
64 ("Arguments mandatory for long options are also mandatory for short options.\n"));
66 opt = ctx->allOptions;
67 while (opt[i].description != NULL)
69 if (opt[i].shortName == '\0')
72 printf (" -%c, ", opt[i].shortName);
73 printf ("--%s", opt[i].name);
74 slen = 8 + strlen (opt[i].name);
75 if (opt[i].argumentHelp != NULL)
77 printf ("=%s", opt[i].argumentHelp);
78 slen += 1 + strlen (opt[i].argumentHelp);
82 printf ("\n%*s", BORDER, "");
87 printf ("%*s", (int) (BORDER - slen), "");
90 trans = gettext (opt[i].description);
94 while (ml - p > 78 - slen)
96 for (j = p + 78 - slen; j > p; j--)
98 if (isspace (trans[j]))
100 scp = GNUNET_malloc (j - p + 1);
101 memcpy (scp, &trans[p], j - p);
103 printf ("%s\n%*s", scp, BORDER + 2, "");
110 /* could not find space to break line */
111 scp = GNUNET_malloc (78 - slen + 1);
112 memcpy (scp, &trans[p], 78 - slen);
113 scp[78 - slen] = '\0';
114 printf ("%s\n%*s", scp, BORDER + 2, "");
121 printf ("%s\n", &trans[p]);
122 if (strlen (trans) == 0)
126 printf ("Report bugs to gnunet-developers@gnu.org.\n"
127 "GNUnet home page: http://www.gnu.org/software/gnunet/\n"
128 "General help using GNU software: http://www.gnu.org/gethelp/\n");
129 return GNUNET_SYSERR;
134 GNUNET_GETOPT_increment_value (struct
135 GNUNET_GETOPT_CommandLineProcessorContext *ctx,
136 void *scls, const char *cmdLineOption,
145 GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
146 void *scls, const char *option, const char *value)
154 GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext
155 *ctx, void *scls, const char *option,
160 GNUNET_assert (value != NULL);
163 *val = GNUNET_strdup (value);
168 GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext
169 *ctx, void *scls, const char *option,
172 unsigned long long *val = scls;
173 if (1 != SSCANF (value, "%llu", val))
176 _("You must pass a number to the `%s' option.\n"), "-X");
177 return GNUNET_SYSERR;
184 GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
185 void *scls, const char *option, const char *value)
187 unsigned int *val = scls;
189 if (1 != SSCANF (value, "%u", val))
192 _("You must pass a number to the `%s' option.\n"), "-X");
193 return GNUNET_SYSERR;
199 /* end of getopt_helpers.c */