diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-28 12:59:51 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-28 12:59:51 -0800 |
| commit | 5ce66a3ce8c8628e57556a5ae9dae4462f77253d (patch) | |
| tree | d3022d881aa1304f7941719eb239e13393b8c069 | |
| parent | 7178491e0be9aef9f1862f1453d74472118ad297 (diff) | |
| download | tinyrad-5ce66a3ce8c8628e57556a5ae9dae4462f77253d.tar.gz tinyrad-5ce66a3ce8c8628e57556a5ae9dae4462f77253d.tar.bz2 tinyrad-5ce66a3ce8c8628e57556a5ae9dae4462f77253d.tar.xz tinyrad-5ce66a3ce8c8628e57556a5ae9dae4462f77253d.zip | |
tinyrad: moving widget CLI parsing to widget
| -rw-r--r-- | src/tru/tinyradutil.c | 19 | ||||
| -rw-r--r-- | src/tru/widget-config.c | 18 | ||||
| -rw-r--r-- | src/tru/widget-dict.c | 18 |
3 files changed, 36 insertions, 19 deletions
diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c index 2b5956d..0e1bef7 100644 --- a/src/tru/tinyradutil.c +++ b/src/tru/tinyradutil.c | |||
| @@ -203,25 +203,6 @@ int main(int argc, char * argv[]) | |||
| 203 | return(1); | 203 | return(1); |
| 204 | }; | 204 | }; |
| 205 | 205 | ||
| 206 | // process widget cli options | ||
| 207 | if ((rc = tru_cli_parse(cnf, cnf->argc, cnf->argv, cnf->widget->shortopts, cnf->widget->longopts)) != 0) | ||
| 208 | { | ||
| 209 | tru_cleanup(cnf); | ||
| 210 | return((rc == 0) ? 0 : 1); | ||
| 211 | }; | ||
| 212 | if ((cnf->argc - optind) < cnf->widget->min_arg) | ||
| 213 | { | ||
| 214 | fprintf(stderr, "%s: missing required argument\n", PROGRAM_NAME); | ||
| 215 | fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); | ||
| 216 | return(1); | ||
| 217 | }; | ||
| 218 | if ((optind+cnf->widget->max_arg) > cnf->argc) | ||
| 219 | { | ||
| 220 | fprintf(stderr, "%s: unrecognized argument `-- %s'\n", PROGRAM_NAME, cnf->argv[optind+1]); | ||
| 221 | fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); | ||
| 222 | return(1); | ||
| 223 | }; | ||
| 224 | |||
| 225 | // call widget | 206 | // call widget |
| 226 | rc = cnf->widget->func(cnf); | 207 | rc = cnf->widget->func(cnf); |
| 227 | tru_cleanup(cnf); | 208 | tru_cleanup(cnf); |
diff --git a/src/tru/widget-config.c b/src/tru/widget-config.c index 0f2e643..e1eaa68 100644 --- a/src/tru/widget-config.c +++ b/src/tru/widget-config.c | |||
| @@ -56,11 +56,29 @@ tru_widget_config( | |||
| 56 | { | 56 | { |
| 57 | int rc; | 57 | int rc; |
| 58 | TinyRadDict * dict; | 58 | TinyRadDict * dict; |
| 59 | |||
| 60 | // getopt options | ||
| 61 | static char short_opt[] = TRU_COMMON_SHORT TRU_DICT_SHORT; | ||
| 62 | static struct option long_opt[] = { TRU_DICT_LONG TRU_COMMON_LONG }; | ||
| 63 | |||
| 64 | // process widget cli options | ||
| 65 | if ((rc = tru_cli_parse(cnf, cnf->argc, cnf->argv, short_opt, long_opt)) != 0) | ||
| 66 | { | ||
| 67 | return((rc == 0) ? 0 : 1); | ||
| 68 | }; | ||
| 69 | if (optind < cnf->argc) | ||
| 70 | { | ||
| 71 | fprintf(stderr, "%s: unrecognized argument `-- %s'\n", PROGRAM_NAME, cnf->argv[optind+1]); | ||
| 72 | fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); | ||
| 73 | return(1); | ||
| 74 | }; | ||
| 75 | |||
| 59 | if ((rc = tru_load_tinyrad(cnf)) != TRAD_SUCCESS) | 76 | if ((rc = tru_load_tinyrad(cnf)) != TRAD_SUCCESS) |
| 60 | return(rc); | 77 | return(rc); |
| 61 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); | 78 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); |
| 62 | tinyrad_conf_print(cnf->tr, dict); | 79 | tinyrad_conf_print(cnf->tr, dict); |
| 63 | tinyrad_free(dict); | 80 | tinyrad_free(dict); |
| 81 | |||
| 64 | return(TRAD_SUCCESS); | 82 | return(TRAD_SUCCESS); |
| 65 | } | 83 | } |
| 66 | 84 | ||
diff --git a/src/tru/widget-dict.c b/src/tru/widget-dict.c index 793f308..8318af4 100644 --- a/src/tru/widget-dict.c +++ b/src/tru/widget-dict.c | |||
| @@ -56,11 +56,29 @@ tru_widget_dict( | |||
| 56 | { | 56 | { |
| 57 | int rc; | 57 | int rc; |
| 58 | TinyRadDict * dict; | 58 | TinyRadDict * dict; |
| 59 | |||
| 60 | // getopt options | ||
| 61 | static char short_opt[] = TRU_COMMON_SHORT TRU_DICT_SHORT; | ||
| 62 | static struct option long_opt[] = { TRU_DICT_LONG TRU_COMMON_LONG }; | ||
| 63 | |||
| 64 | // process widget cli options | ||
| 65 | if ((rc = tru_cli_parse(cnf, cnf->argc, cnf->argv, short_opt, long_opt)) != 0) | ||
| 66 | { | ||
| 67 | return((rc == 0) ? 0 : 1); | ||
| 68 | }; | ||
| 69 | if (optind < cnf->argc) | ||
| 70 | { | ||
| 71 | fprintf(stderr, "%s: unrecognized argument `-- %s'\n", PROGRAM_NAME, cnf->argv[optind+1]); | ||
| 72 | fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); | ||
| 73 | return(1); | ||
| 74 | }; | ||
| 75 | |||
| 59 | if ((rc = tru_load_tinyrad(cnf)) != TRAD_SUCCESS) | 76 | if ((rc = tru_load_tinyrad(cnf)) != TRAD_SUCCESS) |
| 60 | return(rc); | 77 | return(rc); |
| 61 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); | 78 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); |
| 62 | tinyrad_dict_print(dict, 0xffff); | 79 | tinyrad_dict_print(dict, 0xffff); |
| 63 | tinyrad_free(dict); | 80 | tinyrad_free(dict); |
| 81 | |||
| 64 | return(TRAD_SUCCESS); | 82 | return(TRAD_SUCCESS); |
| 65 | } | 83 | } |
| 66 | 84 | ||
