diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-28 13:09:54 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-28 13:09:54 -0800 |
| commit | 78d3dd29179b1da6df63b35e28a9702df6690f49 (patch) | |
| tree | c6e51df90e1c3f5fa37791aaffd7d62bd08129f2 /src/tru | |
| parent | b0d4dbe3d8abc9776e26a9531d2024f1090d0f5a (diff) | |
| download | tinyrad-78d3dd29179b1da6df63b35e28a9702df6690f49.tar.gz tinyrad-78d3dd29179b1da6df63b35e28a9702df6690f49.tar.bz2 tinyrad-78d3dd29179b1da6df63b35e28a9702df6690f49.tar.xz tinyrad-78d3dd29179b1da6df63b35e28a9702df6690f49.zip | |
tinyrad: refactoring members of TinyRadUtilWidget
Diffstat (limited to 'src/tru')
| -rw-r--r-- | src/tru/tinyradutil.c | 35 | ||||
| -rw-r--r-- | src/tru/tinyradutil.h | 16 |
2 files changed, 19 insertions, 32 deletions
diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c index e857282..9f4ab4f 100644 --- a/src/tru/tinyradutil.c +++ b/src/tru/tinyradutil.c | |||
| @@ -109,31 +109,21 @@ const TinyRadUtilWidget tru_widget_map[] = | |||
| 109 | { | 109 | { |
| 110 | { | 110 | { |
| 111 | .name = "configuration", | 111 | .name = "configuration", |
| 112 | .func = &tru_widget_config, | 112 | .desc = "print configuration", |
| 113 | .shortopts = TRU_COMMON_SHORT TRU_DICT_SHORT, | ||
| 114 | .longopts = (struct option []) { TRU_DICT_LONG TRU_COMMON_LONG }, | ||
| 115 | .min_arg = 0, | ||
| 116 | .max_arg = 0, | ||
| 117 | .usage = NULL, | 113 | .usage = NULL, |
| 118 | .desc = "print configuration" | 114 | .aliases = NULL, |
| 115 | .func = &tru_widget_config | ||
| 119 | }, | 116 | }, |
| 120 | { | 117 | { |
| 121 | .name = "dictionary", | 118 | .name = "dictionary", |
| 122 | .func = &tru_widget_dict, | 119 | .desc = "print processed dictionary", |
| 123 | .shortopts = TRU_COMMON_SHORT TRU_DICT_SHORT, | ||
| 124 | .longopts = (struct option []) { TRU_DICT_LONG TRU_COMMON_LONG }, | ||
| 125 | .min_arg = 0, | ||
| 126 | .max_arg = 0, | ||
| 127 | .usage = NULL, | 120 | .usage = NULL, |
| 128 | .desc = "print processed dictionary" | 121 | .aliases = NULL, |
| 122 | .func = &tru_widget_dict | ||
| 129 | }, | 123 | }, |
| 130 | { | 124 | { |
| 131 | .name = NULL, | 125 | .name = NULL, |
| 132 | .func = NULL, | 126 | .func = NULL, |
| 133 | .shortopts = NULL, | ||
| 134 | .longopts = NULL, | ||
| 135 | .min_arg = -1, | ||
| 136 | .max_arg = -1, | ||
| 137 | .usage = NULL, | 127 | .usage = NULL, |
| 138 | .desc = NULL | 128 | .desc = NULL |
| 139 | } | 129 | } |
| @@ -303,7 +293,7 @@ tru_cli_parse( | |||
| 303 | return(TRU_GETOPT_ERROR); | 293 | return(TRU_GETOPT_ERROR); |
| 304 | 294 | ||
| 305 | case 'h': | 295 | case 'h': |
| 306 | tru_usage(cnf); | 296 | tru_usage(cnf, short_opt); |
| 307 | return(TRU_GETOPT_EXIT); | 297 | return(TRU_GETOPT_EXIT); |
| 308 | 298 | ||
| 309 | case '?': | 299 | case '?': |
| @@ -384,12 +374,13 @@ tru_getopt( | |||
| 384 | 374 | ||
| 385 | int | 375 | int |
| 386 | tru_usage( | 376 | tru_usage( |
| 387 | TinyRadUtilConf * cnf ) | 377 | TinyRadUtilConf * cnf, |
| 378 | const char * short_opt ) | ||
| 388 | { | 379 | { |
| 389 | int i; | 380 | int i; |
| 390 | 381 | ||
| 391 | tru_usage_summary(cnf); | 382 | tru_usage_summary(cnf); |
| 392 | tru_usage_options(cnf); | 383 | tru_usage_options(short_opt); |
| 393 | if (!(cnf->widget)) | 384 | if (!(cnf->widget)) |
| 394 | { | 385 | { |
| 395 | printf("WIDGETS:\n"); | 386 | printf("WIDGETS:\n"); |
| @@ -404,13 +395,11 @@ tru_usage( | |||
| 404 | 395 | ||
| 405 | void | 396 | void |
| 406 | tru_usage_options( | 397 | tru_usage_options( |
| 407 | TinyRadUtilConf * cnf ) | 398 | const char * short_opt ) |
| 408 | { | 399 | { |
| 409 | const char * s; | 400 | const char * s; |
| 410 | 401 | ||
| 411 | s = TRU_COMMON_SHORT; | 402 | s = short_opt; |
| 412 | if ((cnf->widget)) | ||
| 413 | s = ((cnf->widget->shortopts)) ? cnf->widget->shortopts : TRU_COMMON_SHORT; | ||
| 414 | 403 | ||
| 415 | printf("OPTIONS:\n"); | 404 | printf("OPTIONS:\n"); |
| 416 | if ((strchr(s, 'b'))) printf(" -b, --builtin-dict load built-in dictionary\n"); | 405 | if ((strchr(s, 'b'))) printf(" -b, --builtin-dict load built-in dictionary\n"); |
diff --git a/src/tru/tinyradutil.h b/src/tru/tinyradutil.h index 5ebd650..3871c21 100644 --- a/src/tru/tinyradutil.h +++ b/src/tru/tinyradutil.h | |||
| @@ -131,14 +131,11 @@ struct tinyrad_util_config | |||
| 131 | 131 | ||
| 132 | struct tinyrad_util_widget | 132 | struct tinyrad_util_widget |
| 133 | { | 133 | { |
| 134 | const char * name; | 134 | const char * name; |
| 135 | const char * desc; | ||
| 136 | const char * usage; | ||
| 137 | const char * const * aliases; | ||
| 135 | int (*func)(TinyRadUtilConf * cnf); | 138 | int (*func)(TinyRadUtilConf * cnf); |
| 136 | const char * shortopts; | ||
| 137 | struct option * longopts; | ||
| 138 | int min_arg; | ||
| 139 | int max_arg; | ||
| 140 | const char * usage; | ||
| 141 | const char * desc; | ||
| 142 | }; | 139 | }; |
| 143 | 140 | ||
| 144 | 141 | ||
| @@ -196,12 +193,13 @@ tru_getopt( | |||
| 196 | 193 | ||
| 197 | int | 194 | int |
| 198 | tru_usage( | 195 | tru_usage( |
| 199 | TinyRadUtilConf * cnf ); | 196 | TinyRadUtilConf * cnf, |
| 197 | const char * short_opt ); | ||
| 200 | 198 | ||
| 201 | 199 | ||
| 202 | void | 200 | void |
| 203 | tru_usage_options( | 201 | tru_usage_options( |
| 204 | TinyRadUtilConf * cnf ); | 202 | const char * short_opt ); |
| 205 | 203 | ||
| 206 | 204 | ||
| 207 | void | 205 | void |
