diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-28 11:51:37 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-28 11:51:37 -0800 |
| commit | 82f6c50918c3749dce7bbaa8dc560e1e8205ed1d (patch) | |
| tree | ed51d231147f69092824401fd863009512a20966 | |
| parent | a026948ee3f8839cb9d789493306a9b55f9cd638 (diff) | |
| download | tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.tar.gz tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.tar.bz2 tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.tar.xz tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.zip | |
tinyrad: refactoring tru_usage()
| -rw-r--r-- | src/tru/tinyradutil.c | 57 | ||||
| -rw-r--r-- | src/tru/tinyradutil.h | 10 |
2 files changed, 52 insertions, 15 deletions
diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c index 9fb8ffc..9c7c3cc 100644 --- a/src/tru/tinyradutil.c +++ b/src/tru/tinyradutil.c | |||
| @@ -393,15 +393,31 @@ tru_usage( | |||
| 393 | TinyRadUtilConf * cnf ) | 393 | TinyRadUtilConf * cnf ) |
| 394 | { | 394 | { |
| 395 | int i; | 395 | int i; |
| 396 | const char * name; | 396 | |
| 397 | const char * help; | 397 | tru_usage_summary(cnf); |
| 398 | tru_usage_options(cnf); | ||
| 399 | if (!(cnf->widget)) | ||
| 400 | { | ||
| 401 | printf("WIDGETS:\n"); | ||
| 402 | for(i = 0; tru_widget_map[i].name != NULL; i++) | ||
| 403 | if ((tru_widget_map[i].desc)) | ||
| 404 | printf(" %-25s %s\n", tru_widget_map[i].name, tru_widget_map[i].desc); | ||
| 405 | }; | ||
| 406 | printf("\n"); | ||
| 407 | return(0); | ||
| 408 | } | ||
| 409 | |||
| 410 | |||
| 411 | void | ||
| 412 | tru_usage_options( | ||
| 413 | TinyRadUtilConf * cnf ) | ||
| 414 | { | ||
| 398 | const char * s; | 415 | const char * s; |
| 399 | 416 | ||
| 400 | name = (!(cnf->widget)) ? "widget" : cnf->widget->name; | 417 | s = TRU_COMMON_SHORT; |
| 401 | help = (!(cnf->widget)) ? " ..." : (((cnf->widget->usage)) ? cnf->widget->usage : ""); | 418 | if ((cnf->widget)) |
| 402 | s = (!(cnf->widget)) ? TRU_COMMON_SHORT : (((cnf->widget->shortopts)) ? cnf->widget->shortopts : TRU_COMMON_SHORT); | 419 | s = ((cnf->widget->shortopts)) ? cnf->widget->shortopts : TRU_COMMON_SHORT; |
| 403 | 420 | ||
| 404 | printf("Usage: %s %s [OPTIONS]%s\n", PROGRAM_NAME, name, help); | ||
| 405 | printf("OPTIONS:\n"); | 421 | printf("OPTIONS:\n"); |
| 406 | if ((strchr(s, 'b'))) printf(" -b, --builtin-dict load built-in dictionary\n"); | 422 | if ((strchr(s, 'b'))) printf(" -b, --builtin-dict load built-in dictionary\n"); |
| 407 | if ((strchr(s, 'D'))) printf(" -D dictionary include dictionary\n"); | 423 | if ((strchr(s, 'D'))) printf(" -D dictionary include dictionary\n"); |
| @@ -412,15 +428,26 @@ tru_usage( | |||
| 412 | if ((strchr(s, 'q'))) printf(" -q, --quiet, --silent do not print messages\n"); | 428 | if ((strchr(s, 'q'))) printf(" -q, --quiet, --silent do not print messages\n"); |
| 413 | if ((strchr(s, 'V'))) printf(" -V, --version print version number and exit\n"); | 429 | if ((strchr(s, 'V'))) printf(" -V, --version print version number and exit\n"); |
| 414 | if ((strchr(s, 'v'))) printf(" -v, --verbose print verbose messages\n"); | 430 | if ((strchr(s, 'v'))) printf(" -v, --verbose print verbose messages\n"); |
| 415 | if (!(cnf->widget)) | 431 | |
| 416 | { | 432 | return; |
| 417 | printf("WIDGETS:\n"); | 433 | } |
| 418 | for(i = 0; tru_widget_map[i].name != NULL; i++) | 434 | |
| 419 | if ((tru_widget_map[i].desc)) | 435 | |
| 420 | printf(" %-25s %s\n", tru_widget_map[i].name, tru_widget_map[i].desc); | 436 | void |
| 421 | }; | 437 | tru_usage_summary( |
| 422 | printf("\n"); | 438 | TinyRadUtilConf * cnf ) |
| 423 | return(0); | 439 | { |
| 440 | const char * widget_name; | ||
| 441 | const char * widget_help; | ||
| 442 | |||
| 443 | widget_name = (!(cnf->widget)) ? "widget" : cnf->widget->name; | ||
| 444 | widget_help = ""; | ||
| 445 | if ((cnf->widget)) | ||
| 446 | widget_help = ((cnf->widget->usage)) ? cnf->widget->usage : ""; | ||
| 447 | |||
| 448 | printf("Usage: %s [OPTIONS] %s [WIDGETOPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help); | ||
| 449 | |||
| 450 | return; | ||
| 424 | } | 451 | } |
| 425 | 452 | ||
| 426 | 453 | ||
diff --git a/src/tru/tinyradutil.h b/src/tru/tinyradutil.h index c470257..f8f2033 100644 --- a/src/tru/tinyradutil.h +++ b/src/tru/tinyradutil.h | |||
| @@ -171,6 +171,16 @@ tru_cleanup( | |||
| 171 | TinyRadUtilConf * cnf ); | 171 | TinyRadUtilConf * cnf ); |
| 172 | 172 | ||
| 173 | 173 | ||
| 174 | void | ||
| 175 | tru_usage_options( | ||
| 176 | TinyRadUtilConf * cnf ); | ||
| 177 | |||
| 178 | |||
| 179 | void | ||
| 180 | tru_usage_summary( | ||
| 181 | TinyRadUtilConf * cnf ); | ||
| 182 | |||
| 183 | |||
| 174 | int | 184 | int |
| 175 | tru_widget_config( | 185 | tru_widget_config( |
| 176 | TinyRadUtilConf * cnf ); | 186 | TinyRadUtilConf * cnf ); |
