diff options
Diffstat (limited to 'src/tru/tru.c')
| -rw-r--r-- | src/tru/tru.c | 71 |
1 files changed, 29 insertions, 42 deletions
diff --git a/src/tru/tru.c b/src/tru/tru.c index 0e86f6d..9f35096 100644 --- a/src/tru/tru.c +++ b/src/tru/tru.c | |||
| @@ -99,11 +99,8 @@ const TinyRadUtilWidget tru_widget_map[] = | |||
| 99 | { | 99 | { |
| 100 | .name = "configuration", | 100 | .name = "configuration", |
| 101 | .func = &tru_widget_config, | 101 | .func = &tru_widget_config, |
| 102 | .shortopts = TINYRAD_DICT_GETOPT_SHORT TINYRAD_GETOPT_SHORT, | 102 | .shortopts = TRU_COMMON_SHORT TRU_DICT_SHORT, |
| 103 | .longopts = (struct option []) | 103 | .longopts = (struct option []) { TRU_DICT_LONG TRU_COMMON_LONG }, |
| 104 | { TINYRAD_DICT_GETOPT_LONG | ||
| 105 | TINYRAD_GETOPT_LONG | ||
| 106 | }, | ||
| 107 | .min_arg = 0, | 104 | .min_arg = 0, |
| 108 | .max_arg = 0, | 105 | .max_arg = 0, |
| 109 | .usage = NULL, | 106 | .usage = NULL, |
| @@ -112,11 +109,8 @@ const TinyRadUtilWidget tru_widget_map[] = | |||
| 112 | { | 109 | { |
| 113 | .name = "dictionary", | 110 | .name = "dictionary", |
| 114 | .func = &tru_widget_dict, | 111 | .func = &tru_widget_dict, |
| 115 | .shortopts = TINYRAD_DICT_GETOPT_SHORT TINYRAD_GETOPT_SHORT, | 112 | .shortopts = TRU_COMMON_SHORT TRU_DICT_SHORT, |
| 116 | .longopts = (struct option []) | 113 | .longopts = (struct option []) { TRU_DICT_LONG TRU_COMMON_LONG }, |
| 117 | { TINYRAD_DICT_GETOPT_LONG | ||
| 118 | TINYRAD_GETOPT_LONG | ||
| 119 | }, | ||
| 120 | .min_arg = 0, | 114 | .min_arg = 0, |
| 121 | .max_arg = 0, | 115 | .max_arg = 0, |
| 122 | .usage = NULL, | 116 | .usage = NULL, |
| @@ -125,8 +119,8 @@ const TinyRadUtilWidget tru_widget_map[] = | |||
| 125 | { | 119 | { |
| 126 | .name = "help", | 120 | .name = "help", |
| 127 | .func = &tru_usage, | 121 | .func = &tru_usage, |
| 128 | .shortopts = TINYRAD_GETOPT_SHORT, | 122 | .shortopts = TRU_COMMON_SHORT, |
| 129 | .longopts = (struct option []) { TINYRAD_GETOPT_LONG }, | 123 | .longopts = (struct option []) { TRU_COMMON_LONG }, |
| 130 | .min_arg = 0, | 124 | .min_arg = 0, |
| 131 | .max_arg = 0, | 125 | .max_arg = 0, |
| 132 | .usage = NULL, | 126 | .usage = NULL, |
| @@ -162,8 +156,8 @@ int main(int argc, char * argv[]) | |||
| 162 | TinyRadUtilConf * cnf; | 156 | TinyRadUtilConf * cnf; |
| 163 | 157 | ||
| 164 | // getopt options | 158 | // getopt options |
| 165 | static char short_opt[] = "+" TINYRAD_GETOPT_SHORT; | 159 | static char short_opt[] = "+" TRU_COMMON_SHORT; |
| 166 | static struct option long_opt[] = { TINYRAD_GETOPT_LONG }; | 160 | static struct option long_opt[] = { TRU_COMMON_LONG }; |
| 167 | 161 | ||
| 168 | trutils_initialize(PROGRAM_NAME); | 162 | trutils_initialize(PROGRAM_NAME); |
| 169 | 163 | ||
| @@ -175,16 +169,16 @@ int main(int argc, char * argv[]) | |||
| 175 | { | 169 | { |
| 176 | switch(c) | 170 | switch(c) |
| 177 | { | 171 | { |
| 178 | case MY_GETOPT_MATCHED: /* captured by common options */ | 172 | case TRU_GETOPT_MATCHED: /* captured by common options */ |
| 179 | case -1: /* no more arguments */ | 173 | case -1: /* no more arguments */ |
| 180 | case 0: /* long options toggles */ | 174 | case 0: /* long options toggles */ |
| 181 | break; | 175 | break; |
| 182 | 176 | ||
| 183 | case MY_GETOPT_EXIT: | 177 | case TRU_GETOPT_EXIT: |
| 184 | tru_cleanup(cnf); | 178 | tru_cleanup(cnf); |
| 185 | return(0); | 179 | return(0); |
| 186 | 180 | ||
| 187 | case MY_GETOPT_ERROR: | 181 | case TRU_GETOPT_ERROR: |
| 188 | tru_cleanup(cnf); | 182 | tru_cleanup(cnf); |
| 189 | return(1); | 183 | return(1); |
| 190 | 184 | ||
| @@ -228,11 +222,11 @@ int main(int argc, char * argv[]) | |||
| 228 | case 0: /* long options toggles */ | 222 | case 0: /* long options toggles */ |
| 229 | break; | 223 | break; |
| 230 | 224 | ||
| 231 | case MY_GETOPT_EXIT: | 225 | case TRU_GETOPT_EXIT: |
| 232 | tru_cleanup(cnf); | 226 | tru_cleanup(cnf); |
| 233 | return(0); | 227 | return(0); |
| 234 | 228 | ||
| 235 | case MY_GETOPT_ERROR: | 229 | case TRU_GETOPT_ERROR: |
| 236 | tru_cleanup(cnf); | 230 | tru_cleanup(cnf); |
| 237 | return(1); | 231 | return(1); |
| 238 | 232 | ||
| @@ -293,46 +287,46 @@ tru_getopt( | |||
| 293 | { | 287 | { |
| 294 | case 'b': | 288 | case 'b': |
| 295 | cnf->tr_opts |= TRAD_BUILTIN_DICT; | 289 | cnf->tr_opts |= TRAD_BUILTIN_DICT; |
| 296 | return(MY_GETOPT_MATCHED); | 290 | return(TRU_GETOPT_MATCHED); |
| 297 | 291 | ||
| 298 | case 'D': | 292 | case 'D': |
| 299 | if (tinyrad_strsadd(&cnf->dict_files, optarg) != TRAD_SUCCESS) | 293 | if (tinyrad_strsadd(&cnf->dict_files, optarg) != TRAD_SUCCESS) |
| 300 | { | 294 | { |
| 301 | trutils_error(cnf->opts, NULL, "out of virtual memory"); | 295 | trutils_error(cnf->opts, NULL, "out of virtual memory"); |
| 302 | return(MY_GETOPT_ERROR); | 296 | return(TRU_GETOPT_ERROR); |
| 303 | }; | 297 | }; |
| 304 | return(MY_GETOPT_MATCHED); | 298 | return(TRU_GETOPT_MATCHED); |
| 305 | 299 | ||
| 306 | case 'd': | 300 | case 'd': |
| 307 | opt = ((optarg)) ? (int)strtol(optarg, NULL, 0) : TRAD_DEBUG_ANY; | 301 | opt = ((optarg)) ? (int)strtol(optarg, NULL, 0) : TRAD_DEBUG_ANY; |
| 308 | tinyrad_set_option(NULL, TRAD_OPT_DEBUG_LEVEL, &opt); | 302 | tinyrad_set_option(NULL, TRAD_OPT_DEBUG_LEVEL, &opt); |
| 309 | return(MY_GETOPT_MATCHED); | 303 | return(TRU_GETOPT_MATCHED); |
| 310 | 304 | ||
| 311 | case 'h': | 305 | case 'h': |
| 312 | tru_usage(cnf); | 306 | tru_usage(cnf); |
| 313 | return(MY_GETOPT_EXIT); | 307 | return(TRU_GETOPT_EXIT); |
| 314 | 308 | ||
| 315 | case 'I': | 309 | case 'I': |
| 316 | if (tinyrad_strsadd(&cnf->dict_paths, optarg) != TRAD_SUCCESS) | 310 | if (tinyrad_strsadd(&cnf->dict_paths, optarg) != TRAD_SUCCESS) |
| 317 | { | 311 | { |
| 318 | trutils_error(cnf->opts, NULL, "out of virtual memory"); | 312 | trutils_error(cnf->opts, NULL, "out of virtual memory"); |
| 319 | return(MY_GETOPT_ERROR); | 313 | return(TRU_GETOPT_ERROR); |
| 320 | }; | 314 | }; |
| 321 | return(MY_GETOPT_MATCHED); | 315 | return(TRU_GETOPT_MATCHED); |
| 322 | 316 | ||
| 323 | case 'q': | 317 | case 'q': |
| 324 | cnf->opts |= TRUTILS_OPT_QUIET; | 318 | cnf->opts |= TRUTILS_OPT_QUIET; |
| 325 | cnf->opts &= ~TRUTILS_OPT_VERBOSE; | 319 | cnf->opts &= ~TRUTILS_OPT_VERBOSE; |
| 326 | return(MY_GETOPT_MATCHED); | 320 | return(TRU_GETOPT_MATCHED); |
| 327 | 321 | ||
| 328 | case 'V': | 322 | case 'V': |
| 329 | trutils_version(); | 323 | trutils_version(); |
| 330 | return(MY_GETOPT_EXIT); | 324 | return(TRU_GETOPT_EXIT); |
| 331 | 325 | ||
| 332 | case 'v': | 326 | case 'v': |
| 333 | cnf->opts |= TRUTILS_OPT_VERBOSE; | 327 | cnf->opts |= TRUTILS_OPT_VERBOSE; |
| 334 | cnf->opts &= ~TRUTILS_OPT_QUIET; | 328 | cnf->opts &= ~TRUTILS_OPT_QUIET; |
| 335 | return(MY_GETOPT_MATCHED); | 329 | return(TRU_GETOPT_MATCHED); |
| 336 | 330 | ||
| 337 | default: | 331 | default: |
| 338 | break; | 332 | break; |
| @@ -403,16 +397,9 @@ tru_usage( | |||
| 403 | const char * help; | 397 | const char * help; |
| 404 | const char * s; | 398 | const char * s; |
| 405 | 399 | ||
| 406 | name = "COMMAND"; | 400 | name = (!(cnf->cmd)) ? "widget" : cnf->cmd->name; |
| 407 | help = " ..."; | 401 | help = (!(cnf->cmd)) ? " ..." : (((cnf->cmd->usage)) ? cnf->cmd->usage : ""); |
| 408 | s = TINYRAD_GETOPT_SHORT; | 402 | s = (!(cnf->cmd)) ? TRU_COMMON_SHORT : (((cnf->cmd->shortopts)) ? cnf->cmd->shortopts : TRU_COMMON_SHORT); |
| 409 | |||
| 410 | if ((cnf->cmd)) | ||
| 411 | { | ||
| 412 | name = cnf->cmd->name; | ||
| 413 | help = ((cnf->cmd->usage)) ? cnf->cmd->usage : ""; | ||
| 414 | s = ((cnf->cmd->shortopts)) ? cnf->cmd->shortopts : TINYRAD_GETOPT_SHORT; | ||
| 415 | }; | ||
| 416 | 403 | ||
| 417 | printf("Usage: %s %s [OPTIONS]%s\n", PROGRAM_NAME, name, help); | 404 | printf("Usage: %s %s [OPTIONS]%s\n", PROGRAM_NAME, name, help); |
| 418 | printf("OPTIONS:\n"); | 405 | printf("OPTIONS:\n"); |
| @@ -467,7 +454,7 @@ tru_widget_lookup( | |||
| 467 | }; | 454 | }; |
| 468 | }; | 455 | }; |
| 469 | 456 | ||
| 470 | return(NULL); | 457 | return(match); |
| 471 | } | 458 | } |
| 472 | 459 | ||
| 473 | /* end of source */ | 460 | /* end of source */ |
