diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
commit | d9d94d0e53d26af75ec8241383d166544ebd79f3 (patch) | |
tree | 9080b73624389403a198257fe0547bb4634e64d2 /src/util/getopt_helpers.c | |
parent | 2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff) | |
download | gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip |
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r-- | src/util/getopt_helpers.c | 173 |
1 files changed, 90 insertions, 83 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index f00c27f29..8564d591f 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | #include "gnunet_getopt_lib.h" | 29 | #include "gnunet_getopt_lib.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
32 | |||
31 | 33 | ||
32 | /** | 34 | /** |
33 | * Print out program version (implements --version). | 35 | * Print out program version (implements --version). |
@@ -40,8 +42,8 @@ | |||
40 | */ | 42 | */ |
41 | int | 43 | int |
42 | GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext | 44 | GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext |
43 | *ctx, void *scls, const char *option, | 45 | *ctx, void *scls, const char *option, |
44 | const char *value) | 46 | const char *value) |
45 | { | 47 | { |
46 | const char *version = scls; | 48 | const char *version = scls; |
47 | 49 | ||
@@ -64,8 +66,8 @@ GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
64 | */ | 66 | */ |
65 | int | 67 | int |
66 | GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext | 68 | GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext |
67 | *ctx, void *scls, const char *option, | 69 | *ctx, void *scls, const char *option, |
68 | const char *value) | 70 | const char *value) |
69 | { | 71 | { |
70 | const char *about = scls; | 72 | const char *about = scls; |
71 | size_t slen; | 73 | size_t slen; |
@@ -79,74 +81,74 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
79 | 81 | ||
80 | printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); | 82 | printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); |
81 | printf (_ | 83 | printf (_ |
82 | ("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")); |
83 | i = 0; | 85 | i = 0; |
84 | opt = ctx->allOptions; | 86 | opt = ctx->allOptions; |
85 | while (opt[i].description != NULL) | 87 | while (opt[i].description != NULL) |
86 | { | ||
87 | if (opt[i].shortName == '\0') | ||
88 | printf (" "); | ||
89 | else | ||
90 | printf (" -%c, ", opt[i].shortName); | ||
91 | printf ("--%s", opt[i].name); | ||
92 | slen = 8 + strlen (opt[i].name); | ||
93 | if (opt[i].argumentHelp != NULL) | ||
94 | { | ||
95 | printf ("=%s", opt[i].argumentHelp); | ||
96 | slen += 1 + strlen (opt[i].argumentHelp); | ||
97 | } | ||
98 | if (slen > BORDER) | ||
99 | { | 88 | { |
100 | printf ("\n%*s", BORDER, ""); | 89 | if (opt[i].shortName == '\0') |
101 | slen = BORDER; | 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) | ||
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++; | ||
102 | } | 148 | } |
103 | if (slen < BORDER) | ||
104 | { | ||
105 | printf ("%*s", (int) (BORDER - slen), ""); | ||
106 | slen = BORDER; | ||
107 | } | ||
108 | if (0 < strlen (opt[i].description)) | ||
109 | trans = gettext (opt[i].description); | ||
110 | else | ||
111 | trans = ""; | ||
112 | ml = strlen (trans); | ||
113 | p = 0; | ||
114 | OUTER: | ||
115 | while (ml - p > 78 - slen) | ||
116 | { | ||
117 | for (j = p + 78 - slen; j > p; j--) | ||
118 | { | ||
119 | if (isspace ((unsigned char) trans[j])) | ||
120 | { | ||
121 | scp = GNUNET_malloc (j - p + 1); | ||
122 | memcpy (scp, &trans[p], j - p); | ||
123 | scp[j - p] = '\0'; | ||
124 | printf ("%s\n%*s", scp, BORDER + 2, ""); | ||
125 | GNUNET_free (scp); | ||
126 | p = j + 1; | ||
127 | slen = BORDER + 2; | ||
128 | goto OUTER; | ||
129 | } | ||
130 | } | ||
131 | /* could not find space to break line */ | ||
132 | scp = GNUNET_malloc (78 - slen + 1); | ||
133 | memcpy (scp, &trans[p], 78 - slen); | ||
134 | scp[78 - slen] = '\0'; | ||
135 | printf ("%s\n%*s", scp, BORDER + 2, ""); | ||
136 | GNUNET_free (scp); | ||
137 | slen = BORDER + 2; | ||
138 | p = p + 78 - slen; | ||
139 | } | ||
140 | /* print rest */ | ||
141 | if (p < ml) | ||
142 | printf ("%s\n", &trans[p]); | ||
143 | if (strlen (trans) == 0) | ||
144 | printf ("\n"); | ||
145 | i++; | ||
146 | } | ||
147 | printf ("Report bugs to gnunet-developers@gnu.org.\n" | 149 | printf ("Report bugs to gnunet-developers@gnu.org.\n" |
148 | "GNUnet home page: http://www.gnu.org/software/gnunet/\n" | 150 | "GNUnet home page: http://www.gnu.org/software/gnunet/\n" |
149 | "General help using GNU software: http://www.gnu.org/gethelp/\n"); | 151 | "General help using GNU software: http://www.gnu.org/gethelp/\n"); |
150 | return GNUNET_SYSERR; | 152 | return GNUNET_SYSERR; |
151 | } | 153 | } |
152 | 154 | ||
@@ -166,9 +168,10 @@ OUTER: | |||
166 | * @return GNUNET_OK | 168 | * @return GNUNET_OK |
167 | */ | 169 | */ |
168 | int | 170 | int |
169 | GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext | 171 | GNUNET_GETOPT_increment_value (struct |
170 | *ctx, void *scls, const char *option, | 172 | GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
171 | const char *value) | 173 | void *scls, const char *option, |
174 | const char *value) | ||
172 | { | 175 | { |
173 | int *val = scls; | 176 | int *val = scls; |
174 | 177 | ||
@@ -193,7 +196,7 @@ GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
193 | */ | 196 | */ |
194 | int | 197 | int |
195 | GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 198 | GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
196 | void *scls, const char *option, const char *value) | 199 | void *scls, const char *option, const char *value) |
197 | { | 200 | { |
198 | int *val = scls; | 201 | int *val = scls; |
199 | 202 | ||
@@ -217,8 +220,9 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
217 | * @return GNUNET_OK | 220 | * @return GNUNET_OK |
218 | */ | 221 | */ |
219 | int | 222 | int |
220 | GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 223 | GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext |
221 | void *scls, const char *option, const char *value) | 224 | *ctx, void *scls, const char *option, |
225 | const char *value) | ||
222 | { | 226 | { |
223 | char **val = scls; | 227 | char **val = scls; |
224 | 228 | ||
@@ -243,16 +247,18 @@ GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
243 | * @return GNUNET_OK if parsing the value worked | 247 | * @return GNUNET_OK if parsing the value worked |
244 | */ | 248 | */ |
245 | int | 249 | int |
246 | GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 250 | GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext |
247 | void *scls, const char *option, const char *value) | 251 | *ctx, void *scls, const char *option, |
252 | const char *value) | ||
248 | { | 253 | { |
249 | unsigned long long *val = scls; | 254 | unsigned long long *val = scls; |
250 | 255 | ||
251 | if (1 != SSCANF (value, "%llu", val)) | 256 | if (1 != SSCANF (value, "%llu", val)) |
252 | { | 257 | { |
253 | fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option); | 258 | fprintf (stderr, _("You must pass a number to the `%s' option.\n"), |
254 | return GNUNET_SYSERR; | 259 | option); |
255 | } | 260 | return GNUNET_SYSERR; |
261 | } | ||
256 | return GNUNET_OK; | 262 | return GNUNET_OK; |
257 | } | 263 | } |
258 | 264 | ||
@@ -272,15 +278,16 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
272 | */ | 278 | */ |
273 | int | 279 | int |
274 | GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 280 | GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
275 | void *scls, const char *option, const char *value) | 281 | void *scls, const char *option, const char *value) |
276 | { | 282 | { |
277 | unsigned int *val = scls; | 283 | unsigned int *val = scls; |
278 | 284 | ||
279 | if (1 != SSCANF (value, "%u", val)) | 285 | if (1 != SSCANF (value, "%u", val)) |
280 | { | 286 | { |
281 | fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option); | 287 | fprintf (stderr, _("You must pass a number to the `%s' option.\n"), |
282 | return GNUNET_SYSERR; | 288 | option); |
283 | } | 289 | return GNUNET_SYSERR; |
290 | } | ||
284 | return GNUNET_OK; | 291 | return GNUNET_OK; |
285 | } | 292 | } |
286 | 293 | ||