diff options
Diffstat (limited to 'src/util/program.c')
-rw-r--r-- | src/util/program.c | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/src/util/program.c b/src/util/program.c index b91d0f59e..cccb7db73 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -95,9 +95,12 @@ cmd_sorter (__const void *a1, __const void *a2) | |||
95 | { | 95 | { |
96 | __const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; | 96 | __const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; |
97 | __const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; | 97 | __const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; |
98 | if (toupper ( (unsigned char) c1->shortName) > toupper ( (unsigned char) c2->shortName)) | 98 | |
99 | if (toupper ((unsigned char) c1->shortName) > | ||
100 | toupper ((unsigned char) c2->shortName)) | ||
99 | return 1; | 101 | return 1; |
100 | if (toupper ( (unsigned char) c1->shortName) < toupper ( (unsigned char) c2->shortName)) | 102 | if (toupper ((unsigned char) c1->shortName) < |
103 | toupper ((unsigned char) c2->shortName)) | ||
101 | return -1; | 104 | return -1; |
102 | if (c1->shortName > c2->shortName) | 105 | if (c1->shortName > c2->shortName) |
103 | return 1; | 106 | return 1; |
@@ -138,6 +141,7 @@ GNUNET_PROGRAM_run (int argc, | |||
138 | unsigned long long skew_variance; | 141 | unsigned long long skew_variance; |
139 | long long clock_offset; | 142 | long long clock_offset; |
140 | struct GNUNET_CONFIGURATION_Handle *cfg; | 143 | struct GNUNET_CONFIGURATION_Handle *cfg; |
144 | |||
141 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { | 145 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { |
142 | GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), | 146 | GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), |
143 | GNUNET_GETOPT_OPTION_HELP (binaryHelp), | 147 | GNUNET_GETOPT_OPTION_HELP (binaryHelp), |
@@ -153,29 +157,29 @@ GNUNET_PROGRAM_run (int argc, | |||
153 | logfile = NULL; | 157 | logfile = NULL; |
154 | gargs = getenv ("GNUNET_ARGS"); | 158 | gargs = getenv ("GNUNET_ARGS"); |
155 | if (gargs != NULL) | 159 | if (gargs != NULL) |
160 | { | ||
161 | char **gargv; | ||
162 | unsigned int gargc; | ||
163 | int i; | ||
164 | char *tok; | ||
165 | char *cargs; | ||
166 | |||
167 | gargv = NULL; | ||
168 | gargc = 0; | ||
169 | for (i = 0; i < argc; i++) | ||
170 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); | ||
171 | cargs = GNUNET_strdup (gargs); | ||
172 | tok = strtok (cargs, " "); | ||
173 | while (NULL != tok) | ||
156 | { | 174 | { |
157 | char **gargv; | 175 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); |
158 | unsigned int gargc; | 176 | tok = strtok (NULL, " "); |
159 | int i; | ||
160 | char *tok; | ||
161 | char *cargs; | ||
162 | |||
163 | gargv = NULL; | ||
164 | gargc = 0; | ||
165 | for (i=0;i<argc;i++) | ||
166 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); | ||
167 | cargs = GNUNET_strdup (gargs); | ||
168 | tok = strtok (cargs, " "); | ||
169 | while (NULL != tok) | ||
170 | { | ||
171 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); | ||
172 | tok = strtok (NULL, " "); | ||
173 | } | ||
174 | GNUNET_free (cargs); | ||
175 | GNUNET_array_append (gargv, gargc, NULL); | ||
176 | argv = (char *const *) gargv; | ||
177 | argc = gargc - 1; | ||
178 | } | 177 | } |
178 | GNUNET_free (cargs); | ||
179 | GNUNET_array_append (gargv, gargc, NULL); | ||
180 | argv = (char *const *) gargv; | ||
181 | argc = gargc - 1; | ||
182 | } | ||
179 | memset (&cc, 0, sizeof (cc)); | 183 | memset (&cc, 0, sizeof (cc)); |
180 | loglev = NULL; | 184 | loglev = NULL; |
181 | cc.task = task; | 185 | cc.task = task; |
@@ -187,26 +191,25 @@ GNUNET_PROGRAM_run (int argc, | |||
187 | setlocale (LC_ALL, ""); | 191 | setlocale (LC_ALL, ""); |
188 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); | 192 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
189 | if (path != NULL) | 193 | if (path != NULL) |
190 | { | 194 | { |
191 | BINDTEXTDOMAIN ("GNUnet", path); | 195 | BINDTEXTDOMAIN ("GNUnet", path); |
192 | GNUNET_free (path); | 196 | GNUNET_free (path); |
193 | } | 197 | } |
194 | textdomain ("GNUnet"); | 198 | textdomain ("GNUnet"); |
195 | #endif | 199 | #endif |
196 | cnt = 0; | 200 | cnt = 0; |
197 | while (options[cnt].name != NULL) | 201 | while (options[cnt].name != NULL) |
198 | cnt++; | 202 | cnt++; |
199 | allopts = | 203 | allopts = |
200 | GNUNET_malloc ((cnt + | 204 | GNUNET_malloc ((cnt + |
201 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + | 205 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + |
202 | sizeof (defoptions)); | 206 | sizeof (defoptions)); |
203 | memcpy (allopts, defoptions, sizeof (defoptions)); | 207 | memcpy (allopts, defoptions, sizeof (defoptions)); |
204 | memcpy (&allopts | 208 | memcpy (&allopts |
205 | [sizeof (defoptions) / | 209 | [sizeof (defoptions) / |
206 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, | 210 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, |
207 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); | 211 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); |
208 | cnt += | 212 | cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); |
209 | sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); | ||
210 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), | 213 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), |
211 | &cmd_sorter); | 214 | &cmd_sorter); |
212 | loglev = GNUNET_strdup ("WARNING"); | 215 | loglev = GNUNET_strdup ("WARNING"); |
@@ -222,22 +225,26 @@ GNUNET_PROGRAM_run (int argc, | |||
222 | loglev, | 225 | loglev, |
223 | logfile)) || | 226 | logfile)) || |
224 | (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)))) | 227 | (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)))) |
225 | { | 228 | { |
226 | GNUNET_CONFIGURATION_destroy (cfg); | 229 | GNUNET_CONFIGURATION_destroy (cfg); |
227 | GNUNET_free_non_null (cc.cfgfile); | 230 | GNUNET_free_non_null (cc.cfgfile); |
228 | GNUNET_free (loglev); | 231 | GNUNET_free (loglev); |
229 | GNUNET_free (allopts); | 232 | GNUNET_free (allopts); |
230 | GNUNET_free (lpfx); | 233 | GNUNET_free (lpfx); |
231 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
232 | } | 235 | } |
233 | GNUNET_free (allopts); | 236 | GNUNET_free (allopts); |
234 | GNUNET_free (lpfx); | 237 | GNUNET_free (lpfx); |
235 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_offset", &skew_offset) && | 238 | if (GNUNET_OK == |
236 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_variance", &skew_variance))) | 239 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", |
237 | { | 240 | &skew_offset) && |
238 | clock_offset = skew_offset - skew_variance; | 241 | (GNUNET_OK == |
239 | GNUNET_TIME_set_offset(clock_offset); | 242 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", |
240 | } | 243 | "skew_variance", &skew_variance))) |
244 | { | ||
245 | clock_offset = skew_offset - skew_variance; | ||
246 | GNUNET_TIME_set_offset (clock_offset); | ||
247 | } | ||
241 | /* run */ | 248 | /* run */ |
242 | cc.args = &argv[ret]; | 249 | cc.args = &argv[ret]; |
243 | GNUNET_SCHEDULER_run (&program_main, &cc); | 250 | GNUNET_SCHEDULER_run (&program_main, &cc); |