aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-28 11:51:37 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-28 11:51:37 -0800
commit82f6c50918c3749dce7bbaa8dc560e1e8205ed1d (patch)
treeed51d231147f69092824401fd863009512a20966 /src
parenta026948ee3f8839cb9d789493306a9b55f9cd638 (diff)
downloadtinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.tar.gz
tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.tar.bz2
tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.tar.xz
tinyrad-82f6c50918c3749dce7bbaa8dc560e1e8205ed1d.zip
tinyrad: refactoring tru_usage()
Diffstat (limited to 'src')
-rw-r--r--src/tru/tinyradutil.c57
-rw-r--r--src/tru/tinyradutil.h10
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
411void
412tru_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); 436void
421 }; 437tru_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
174void
175tru_usage_options(
176 TinyRadUtilConf * cnf );
177
178
179void
180tru_usage_summary(
181 TinyRadUtilConf * cnf );
182
183
174int 184int
175tru_widget_config( 185tru_widget_config(
176 TinyRadUtilConf * cnf ); 186 TinyRadUtilConf * cnf );