aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt_helpers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/util/getopt_helpers.c
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r--src/util/getopt_helpers.c171
1 files changed, 83 insertions, 88 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index 8564d591f..8b49c5907 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -42,8 +42,8 @@
42 */ 42 */
43int 43int
44GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext 44GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext
45 *ctx, void *scls, const char *option, 45 *ctx, void *scls, const char *option,
46 const char *value) 46 const char *value)
47{ 47{
48 const char *version = scls; 48 const char *version = scls;
49 49
@@ -66,8 +66,8 @@ GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext
66 */ 66 */
67int 67int
68GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext 68GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
69 *ctx, void *scls, const char *option, 69 *ctx, void *scls, const char *option,
70 const char *value) 70 const char *value)
71{ 71{
72 const char *about = scls; 72 const char *about = scls;
73 size_t slen; 73 size_t slen;
@@ -81,74 +81,74 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
81 81
82 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); 82 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
83 printf (_ 83 printf (_
84 ("Arguments mandatory for long options are also mandatory for short options.\n")); 84 ("Arguments mandatory for long options are also mandatory for short options.\n"));
85 i = 0; 85 i = 0;
86 opt = ctx->allOptions; 86 opt = ctx->allOptions;
87 while (opt[i].description != NULL) 87 while (opt[i].description != NULL)
88 {
89 if (opt[i].shortName == '\0')
90 printf (" ");
91 else
92 printf (" -%c, ", opt[i].shortName);
93 printf ("--%s", opt[i].name);
94 slen = 8 + strlen (opt[i].name);
95 if (opt[i].argumentHelp != NULL)
88 { 96 {
89 if (opt[i].shortName == '\0') 97 printf ("=%s", opt[i].argumentHelp);
90 printf (" "); 98 slen += 1 + strlen (opt[i].argumentHelp);
91 else
92 printf (" -%c, ", opt[i].shortName);
93 printf ("--%s", opt[i].name);
94 slen = 8 + strlen (opt[i].name);
95 if (opt[i].argumentHelp != NULL)
96 {
97 printf ("=%s", opt[i].argumentHelp);
98 slen += 1 + strlen (opt[i].argumentHelp);
99 }
100 if (slen > BORDER)
101 {
102 printf ("\n%*s", BORDER, "");
103 slen = BORDER;
104 }
105 if (slen < BORDER)
106 {
107 printf ("%*s", (int) (BORDER - slen), "");
108 slen = BORDER;
109 }
110 if (0 < strlen (opt[i].description))
111 trans = gettext (opt[i].description);
112 else
113 trans = "";
114 ml = strlen (trans);
115 p = 0;
116 OUTER:
117 while (ml - p > 78 - slen)
118 {
119 for (j = p + 78 - slen; j > p; j--)
120 {
121 if (isspace ((unsigned char) trans[j]))
122 {
123 scp = GNUNET_malloc (j - p + 1);
124 memcpy (scp, &trans[p], j - p);
125 scp[j - p] = '\0';
126 printf ("%s\n%*s", scp, BORDER + 2, "");
127 GNUNET_free (scp);
128 p = j + 1;
129 slen = BORDER + 2;
130 goto OUTER;
131 }
132 }
133 /* could not find space to break line */
134 scp = GNUNET_malloc (78 - slen + 1);
135 memcpy (scp, &trans[p], 78 - slen);
136 scp[78 - slen] = '\0';
137 printf ("%s\n%*s", scp, BORDER + 2, "");
138 GNUNET_free (scp);
139 slen = BORDER + 2;
140 p = p + 78 - slen;
141 }
142 /* print rest */
143 if (p < ml)
144 printf ("%s\n", &trans[p]);
145 if (strlen (trans) == 0)
146 printf ("\n");
147 i++;
148 } 99 }
100 if (slen > BORDER)
101 {
102 printf ("\n%*s", BORDER, "");
103 slen = BORDER;
104 }
105 if (slen < BORDER)
106 {
107 printf ("%*s", (int) (BORDER - slen), "");
108 slen = BORDER;
109 }
110 if (0 < strlen (opt[i].description))
111 trans = gettext (opt[i].description);
112 else
113 trans = "";
114 ml = strlen (trans);
115 p = 0;
116OUTER:
117 while (ml - p > 78 - slen)
118 {
119 for (j = p + 78 - slen; j > p; j--)
120 {
121 if (isspace ((unsigned char) trans[j]))
122 {
123 scp = GNUNET_malloc (j - p + 1);
124 memcpy (scp, &trans[p], j - p);
125 scp[j - p] = '\0';
126 printf ("%s\n%*s", scp, BORDER + 2, "");
127 GNUNET_free (scp);
128 p = j + 1;
129 slen = BORDER + 2;
130 goto OUTER;
131 }
132 }
133 /* could not find space to break line */
134 scp = GNUNET_malloc (78 - slen + 1);
135 memcpy (scp, &trans[p], 78 - slen);
136 scp[78 - slen] = '\0';
137 printf ("%s\n%*s", scp, BORDER + 2, "");
138 GNUNET_free (scp);
139 slen = BORDER + 2;
140 p = p + 78 - slen;
141 }
142 /* print rest */
143 if (p < ml)
144 printf ("%s\n", &trans[p]);
145 if (strlen (trans) == 0)
146 printf ("\n");
147 i++;
148 }
149 printf ("Report bugs to gnunet-developers@gnu.org.\n" 149 printf ("Report bugs to gnunet-developers@gnu.org.\n"
150 "GNUnet home page: http://www.gnu.org/software/gnunet/\n" 150 "GNUnet home page: http://www.gnu.org/software/gnunet/\n"
151 "General help using GNU software: http://www.gnu.org/gethelp/\n"); 151 "General help using GNU software: http://www.gnu.org/gethelp/\n");
152 return GNUNET_SYSERR; 152 return GNUNET_SYSERR;
153} 153}
154 154
@@ -168,10 +168,9 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
168 * @return GNUNET_OK 168 * @return GNUNET_OK
169 */ 169 */
170int 170int
171GNUNET_GETOPT_increment_value (struct 171GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext
172 GNUNET_GETOPT_CommandLineProcessorContext *ctx, 172 *ctx, void *scls, const char *option,
173 void *scls, const char *option, 173 const char *value)
174 const char *value)
175{ 174{
176 int *val = scls; 175 int *val = scls;
177 176
@@ -196,7 +195,7 @@ GNUNET_GETOPT_increment_value (struct
196 */ 195 */
197int 196int
198GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 197GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
199 void *scls, const char *option, const char *value) 198 void *scls, const char *option, const char *value)
200{ 199{
201 int *val = scls; 200 int *val = scls;
202 201
@@ -220,9 +219,8 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
220 * @return GNUNET_OK 219 * @return GNUNET_OK
221 */ 220 */
222int 221int
223GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext 222GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
224 *ctx, void *scls, const char *option, 223 void *scls, const char *option, const char *value)
225 const char *value)
226{ 224{
227 char **val = scls; 225 char **val = scls;
228 226
@@ -247,18 +245,16 @@ GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext
247 * @return GNUNET_OK if parsing the value worked 245 * @return GNUNET_OK if parsing the value worked
248 */ 246 */
249int 247int
250GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext 248GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
251 *ctx, void *scls, const char *option, 249 void *scls, const char *option, const char *value)
252 const char *value)
253{ 250{
254 unsigned long long *val = scls; 251 unsigned long long *val = scls;
255 252
256 if (1 != SSCANF (value, "%llu", val)) 253 if (1 != SSCANF (value, "%llu", val))
257 { 254 {
258 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), 255 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option);
259 option); 256 return GNUNET_SYSERR;
260 return GNUNET_SYSERR; 257 }
261 }
262 return GNUNET_OK; 258 return GNUNET_OK;
263} 259}
264 260
@@ -278,16 +274,15 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext
278 */ 274 */
279int 275int
280GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 276GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
281 void *scls, const char *option, const char *value) 277 void *scls, const char *option, const char *value)
282{ 278{
283 unsigned int *val = scls; 279 unsigned int *val = scls;
284 280
285 if (1 != SSCANF (value, "%u", val)) 281 if (1 != SSCANF (value, "%u", val))
286 { 282 {
287 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), 283 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option);
288 option); 284 return GNUNET_SYSERR;
289 return GNUNET_SYSERR; 285 }
290 }
291 return GNUNET_OK; 286 return GNUNET_OK;
292} 287}
293 288