From 13df55820068f83fdbfc172c26a8e4b5b0c349fc Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Mon, 28 Mar 2022 11:58:08 -0800 Subject: tinyrad: cleaning up prototypes --- src/tru/tinyradutil.c | 134 ++++++++++++++++++++++++++++++-------------------- src/tru/tinyradutil.h | 64 +++++++++++++----------- 2 files changed, 114 insertions(+), 84 deletions(-) diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c index 9c7c3cc..e4ecbf8 100644 --- a/src/tru/tinyradutil.c +++ b/src/tru/tinyradutil.c @@ -80,10 +80,21 @@ ////////////////// #pragma mark - Prototypes +int +main( + int argc, + char * argv[] ); + + +void +tru_cleanup( + TinyRadUtilConf * cnf ); + + static const TinyRadUtilWidget * tru_widget_lookup( - const char * wname, - int exact ); + const char * wname, + int exact ); ///////////////// @@ -146,6 +157,11 @@ const TinyRadUtilWidget tru_widget_map[] = ///////////////// #pragma mark - Functions +//---------------// +// main function // +//---------------// +#pragma mark main function + int main(int argc, char * argv[]) { int c; @@ -260,6 +276,11 @@ int main(int argc, char * argv[]) } +//-------------------------// +// miscellaneous functions // +//-------------------------// +#pragma mark miscellaneous functions + void tru_cleanup( TinyRadUtilConf * cnf ) @@ -271,6 +292,63 @@ tru_cleanup( } +int +tru_load_tinyrad( + TinyRadUtilConf * cnf ) +{ + int rc; + char ** errs; + size_t pos; + TinyRadDict * dict; + + errs = NULL; + dict = NULL; + + if ((cnf->dict_files)) + { + // initialize dictionary + if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS) + { + trutils_error(cnf->opts, NULL, "out of virtual memory"); + return(rc); + }; + + // set paths + if ((cnf->dict_paths)) + { + if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS) + { + trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); + tinyrad_free(dict); + return(rc); + }; + }; + + // parse dictionary files + for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++) + { + if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS) + { + trutils_error(cnf->opts, errs, NULL); + tinyrad_strsfree(errs); + tinyrad_free(dict); + return(rc); + }; + }; + }; + + // initialize tinyrad handle + rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts); + tinyrad_free(dict); + return(rc); +} + + +//-----------------// +// usage functions // +//-----------------// +#pragma mark usage functions + int tru_getopt( TinyRadUtilConf * cnf, @@ -336,58 +414,6 @@ tru_getopt( } -int -tru_load_tinyrad( - TinyRadUtilConf * cnf ) -{ - int rc; - char ** errs; - size_t pos; - TinyRadDict * dict; - - errs = NULL; - dict = NULL; - - if ((cnf->dict_files)) - { - // initialize dictionary - if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS) - { - trutils_error(cnf->opts, NULL, "out of virtual memory"); - return(rc); - }; - - // set paths - if ((cnf->dict_paths)) - { - if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS) - { - trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); - tinyrad_free(dict); - return(rc); - }; - }; - - // parse dictionary files - for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++) - { - if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS) - { - trutils_error(cnf->opts, errs, NULL); - tinyrad_strsfree(errs); - tinyrad_free(dict); - return(rc); - }; - }; - }; - - // initialize tinyrad handle - rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts); - tinyrad_free(dict); - return(rc); -} - - int tru_usage( TinyRadUtilConf * cnf ) diff --git a/src/tru/tinyradutil.h b/src/tru/tinyradutil.h index f8f2033..b2e4f92 100644 --- a/src/tru/tinyradutil.h +++ b/src/tru/tinyradutil.h @@ -160,60 +160,64 @@ extern const TinyRadUtilWidget tru_widget_map[]; ////////////////// #pragma mark - Prototypes +//--------------------------// +// miscellaneous prototypes // +//--------------------------// +#pragma mark miscellaneous prototypes + +int +tru_load_tinyrad( + TinyRadUtilConf * cnf ); + + +//------------------// +// usage prototypes // +//------------------// +#pragma mark usage prototypes + int -main( +tru_getopt( + TinyRadUtilConf * cnf, int argc, - char * argv[] ); + char * const * argv, + const char * short_opt, + const struct option * long_opt, + int * opt_index ); -void -tru_cleanup( - TinyRadUtilConf * cnf ); +int +tru_usage( + TinyRadUtilConf * cnf ); void tru_usage_options( - TinyRadUtilConf * cnf ); + TinyRadUtilConf * cnf ); void tru_usage_summary( - TinyRadUtilConf * cnf ); + TinyRadUtilConf * cnf ); +//-------------------// +// widget prototypes // +//-------------------// +#pragma mark widget prototypes + int tru_widget_config( - TinyRadUtilConf * cnf ); + TinyRadUtilConf * cnf ); int tru_widget_dict( - TinyRadUtilConf * cnf ); + TinyRadUtilConf * cnf ); int tru_widget_url( - TinyRadUtilConf * cnf ); - - -int -tru_getopt( - TinyRadUtilConf * cnf, - int argc, - char * const * argv, - const char * short_opt, - const struct option * long_opt, - int * opt_index ); - - -int -tru_load_tinyrad( - TinyRadUtilConf * cnf ); - - -int -tru_usage( - TinyRadUtilConf * cnf ); + TinyRadUtilConf * cnf ); #endif /* end of header */ -- cgit v1.2.3