diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-28 11:58:08 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-28 12:06:17 -0800 |
| commit | 13df55820068f83fdbfc172c26a8e4b5b0c349fc (patch) | |
| tree | 41e94e26cbb9fff90535aa8c4dc570f8f11b94ba /src | |
| parent | 82f6c50918c3749dce7bbaa8dc560e1e8205ed1d (diff) | |
| download | tinyrad-13df55820068f83fdbfc172c26a8e4b5b0c349fc.tar.gz tinyrad-13df55820068f83fdbfc172c26a8e4b5b0c349fc.tar.bz2 tinyrad-13df55820068f83fdbfc172c26a8e4b5b0c349fc.tar.xz tinyrad-13df55820068f83fdbfc172c26a8e4b5b0c349fc.zip | |
tinyrad: cleaning up prototypes
Diffstat (limited to 'src')
| -rw-r--r-- | src/tru/tinyradutil.c | 134 | ||||
| -rw-r--r-- | 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 @@ | |||
| 80 | ////////////////// | 80 | ////////////////// |
| 81 | #pragma mark - Prototypes | 81 | #pragma mark - Prototypes |
| 82 | 82 | ||
| 83 | int | ||
| 84 | main( | ||
| 85 | int argc, | ||
| 86 | char * argv[] ); | ||
| 87 | |||
| 88 | |||
| 89 | void | ||
| 90 | tru_cleanup( | ||
| 91 | TinyRadUtilConf * cnf ); | ||
| 92 | |||
| 93 | |||
| 83 | static const TinyRadUtilWidget * | 94 | static const TinyRadUtilWidget * |
| 84 | tru_widget_lookup( | 95 | tru_widget_lookup( |
| 85 | const char * wname, | 96 | const char * wname, |
| 86 | int exact ); | 97 | int exact ); |
| 87 | 98 | ||
| 88 | 99 | ||
| 89 | ///////////////// | 100 | ///////////////// |
| @@ -146,6 +157,11 @@ const TinyRadUtilWidget tru_widget_map[] = | |||
| 146 | ///////////////// | 157 | ///////////////// |
| 147 | #pragma mark - Functions | 158 | #pragma mark - Functions |
| 148 | 159 | ||
| 160 | //---------------// | ||
| 161 | // main function // | ||
| 162 | //---------------// | ||
| 163 | #pragma mark main function | ||
| 164 | |||
| 149 | int main(int argc, char * argv[]) | 165 | int main(int argc, char * argv[]) |
| 150 | { | 166 | { |
| 151 | int c; | 167 | int c; |
| @@ -260,6 +276,11 @@ int main(int argc, char * argv[]) | |||
| 260 | } | 276 | } |
| 261 | 277 | ||
| 262 | 278 | ||
| 279 | //-------------------------// | ||
| 280 | // miscellaneous functions // | ||
| 281 | //-------------------------// | ||
| 282 | #pragma mark miscellaneous functions | ||
| 283 | |||
| 263 | void | 284 | void |
| 264 | tru_cleanup( | 285 | tru_cleanup( |
| 265 | TinyRadUtilConf * cnf ) | 286 | TinyRadUtilConf * cnf ) |
| @@ -272,6 +293,63 @@ tru_cleanup( | |||
| 272 | 293 | ||
| 273 | 294 | ||
| 274 | int | 295 | int |
| 296 | tru_load_tinyrad( | ||
| 297 | TinyRadUtilConf * cnf ) | ||
| 298 | { | ||
| 299 | int rc; | ||
| 300 | char ** errs; | ||
| 301 | size_t pos; | ||
| 302 | TinyRadDict * dict; | ||
| 303 | |||
| 304 | errs = NULL; | ||
| 305 | dict = NULL; | ||
| 306 | |||
| 307 | if ((cnf->dict_files)) | ||
| 308 | { | ||
| 309 | // initialize dictionary | ||
| 310 | if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS) | ||
| 311 | { | ||
| 312 | trutils_error(cnf->opts, NULL, "out of virtual memory"); | ||
| 313 | return(rc); | ||
| 314 | }; | ||
| 315 | |||
| 316 | // set paths | ||
| 317 | if ((cnf->dict_paths)) | ||
| 318 | { | ||
| 319 | if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS) | ||
| 320 | { | ||
| 321 | trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); | ||
| 322 | tinyrad_free(dict); | ||
| 323 | return(rc); | ||
| 324 | }; | ||
| 325 | }; | ||
| 326 | |||
| 327 | // parse dictionary files | ||
| 328 | for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++) | ||
| 329 | { | ||
| 330 | if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS) | ||
| 331 | { | ||
| 332 | trutils_error(cnf->opts, errs, NULL); | ||
| 333 | tinyrad_strsfree(errs); | ||
| 334 | tinyrad_free(dict); | ||
| 335 | return(rc); | ||
| 336 | }; | ||
| 337 | }; | ||
| 338 | }; | ||
| 339 | |||
| 340 | // initialize tinyrad handle | ||
| 341 | rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts); | ||
| 342 | tinyrad_free(dict); | ||
| 343 | return(rc); | ||
| 344 | } | ||
| 345 | |||
| 346 | |||
| 347 | //-----------------// | ||
| 348 | // usage functions // | ||
| 349 | //-----------------// | ||
| 350 | #pragma mark usage functions | ||
| 351 | |||
| 352 | int | ||
| 275 | tru_getopt( | 353 | tru_getopt( |
| 276 | TinyRadUtilConf * cnf, | 354 | TinyRadUtilConf * cnf, |
| 277 | int argc, | 355 | int argc, |
| @@ -337,58 +415,6 @@ tru_getopt( | |||
| 337 | 415 | ||
| 338 | 416 | ||
| 339 | int | 417 | int |
| 340 | tru_load_tinyrad( | ||
| 341 | TinyRadUtilConf * cnf ) | ||
| 342 | { | ||
| 343 | int rc; | ||
| 344 | char ** errs; | ||
| 345 | size_t pos; | ||
| 346 | TinyRadDict * dict; | ||
| 347 | |||
| 348 | errs = NULL; | ||
| 349 | dict = NULL; | ||
| 350 | |||
| 351 | if ((cnf->dict_files)) | ||
| 352 | { | ||
| 353 | // initialize dictionary | ||
| 354 | if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS) | ||
| 355 | { | ||
| 356 | trutils_error(cnf->opts, NULL, "out of virtual memory"); | ||
| 357 | return(rc); | ||
| 358 | }; | ||
| 359 | |||
| 360 | // set paths | ||
| 361 | if ((cnf->dict_paths)) | ||
| 362 | { | ||
| 363 | if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS) | ||
| 364 | { | ||
| 365 | trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); | ||
| 366 | tinyrad_free(dict); | ||
| 367 | return(rc); | ||
| 368 | }; | ||
| 369 | }; | ||
| 370 | |||
| 371 | // parse dictionary files | ||
| 372 | for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++) | ||
| 373 | { | ||
| 374 | if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS) | ||
| 375 | { | ||
| 376 | trutils_error(cnf->opts, errs, NULL); | ||
| 377 | tinyrad_strsfree(errs); | ||
| 378 | tinyrad_free(dict); | ||
| 379 | return(rc); | ||
| 380 | }; | ||
| 381 | }; | ||
| 382 | }; | ||
| 383 | |||
| 384 | // initialize tinyrad handle | ||
| 385 | rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts); | ||
| 386 | tinyrad_free(dict); | ||
| 387 | return(rc); | ||
| 388 | } | ||
| 389 | |||
| 390 | |||
| 391 | int | ||
| 392 | tru_usage( | 418 | tru_usage( |
| 393 | TinyRadUtilConf * cnf ) | 419 | TinyRadUtilConf * cnf ) |
| 394 | { | 420 | { |
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[]; | |||
| 160 | ////////////////// | 160 | ////////////////// |
| 161 | #pragma mark - Prototypes | 161 | #pragma mark - Prototypes |
| 162 | 162 | ||
| 163 | //--------------------------// | ||
| 164 | // miscellaneous prototypes // | ||
| 165 | //--------------------------// | ||
| 166 | #pragma mark miscellaneous prototypes | ||
| 167 | |||
| 168 | int | ||
| 169 | tru_load_tinyrad( | ||
| 170 | TinyRadUtilConf * cnf ); | ||
| 171 | |||
| 172 | |||
| 173 | //------------------// | ||
| 174 | // usage prototypes // | ||
| 175 | //------------------// | ||
| 176 | #pragma mark usage prototypes | ||
| 177 | |||
| 163 | int | 178 | int |
| 164 | main( | 179 | tru_getopt( |
| 180 | TinyRadUtilConf * cnf, | ||
| 165 | int argc, | 181 | int argc, |
| 166 | char * argv[] ); | 182 | char * const * argv, |
| 183 | const char * short_opt, | ||
| 184 | const struct option * long_opt, | ||
| 185 | int * opt_index ); | ||
| 167 | 186 | ||
| 168 | 187 | ||
| 169 | void | 188 | int |
| 170 | tru_cleanup( | 189 | tru_usage( |
| 171 | TinyRadUtilConf * cnf ); | 190 | TinyRadUtilConf * cnf ); |
| 172 | 191 | ||
| 173 | 192 | ||
| 174 | void | 193 | void |
| 175 | tru_usage_options( | 194 | tru_usage_options( |
| 176 | TinyRadUtilConf * cnf ); | 195 | TinyRadUtilConf * cnf ); |
| 177 | 196 | ||
| 178 | 197 | ||
| 179 | void | 198 | void |
| 180 | tru_usage_summary( | 199 | tru_usage_summary( |
| 181 | TinyRadUtilConf * cnf ); | 200 | TinyRadUtilConf * cnf ); |
| 182 | 201 | ||
| 183 | 202 | ||
| 203 | //-------------------// | ||
| 204 | // widget prototypes // | ||
| 205 | //-------------------// | ||
| 206 | #pragma mark widget prototypes | ||
| 207 | |||
| 184 | int | 208 | int |
| 185 | tru_widget_config( | 209 | tru_widget_config( |
| 186 | TinyRadUtilConf * cnf ); | 210 | TinyRadUtilConf * cnf ); |
| 187 | 211 | ||
| 188 | 212 | ||
| 189 | int | 213 | int |
| 190 | tru_widget_dict( | 214 | tru_widget_dict( |
| 191 | TinyRadUtilConf * cnf ); | 215 | TinyRadUtilConf * cnf ); |
| 192 | 216 | ||
| 193 | 217 | ||
| 194 | int | 218 | int |
| 195 | tru_widget_url( | 219 | tru_widget_url( |
| 196 | TinyRadUtilConf * cnf ); | 220 | TinyRadUtilConf * cnf ); |
| 197 | |||
| 198 | |||
| 199 | int | ||
| 200 | tru_getopt( | ||
| 201 | TinyRadUtilConf * cnf, | ||
| 202 | int argc, | ||
| 203 | char * const * argv, | ||
| 204 | const char * short_opt, | ||
| 205 | const struct option * long_opt, | ||
| 206 | int * opt_index ); | ||
| 207 | |||
| 208 | |||
| 209 | int | ||
| 210 | tru_load_tinyrad( | ||
| 211 | TinyRadUtilConf * cnf ); | ||
| 212 | |||
| 213 | |||
| 214 | int | ||
| 215 | tru_usage( | ||
| 216 | TinyRadUtilConf * cnf ); | ||
| 217 | 221 | ||
| 218 | 222 | ||
| 219 | #endif /* end of header */ | 223 | #endif /* end of header */ |
