diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-24 16:07:21 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-24 16:07:21 -0800 |
| commit | 31289f54265963005bd1efcbd0c9b40715fdc814 (patch) | |
| tree | c1ed6f7bbdfdf7445d468f76509e7092bbc2bea7 | |
| parent | 6aea0f9407291a4e9954ccf7730b74fa425e6407 (diff) | |
| download | tinyrad-31289f54265963005bd1efcbd0c9b40715fdc814.tar.gz tinyrad-31289f54265963005bd1efcbd0c9b40715fdc814.tar.bz2 tinyrad-31289f54265963005bd1efcbd0c9b40715fdc814.tar.xz tinyrad-31289f54265963005bd1efcbd0c9b40715fdc814.zip | |
tinyrad: changing namespace from 'tinyrad_' to 'tru_'
| -rw-r--r-- | src/tinyrad.c | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/src/tinyrad.c b/src/tinyrad.c index ecad466..a8c319e 100644 --- a/src/tinyrad.c +++ b/src/tinyrad.c | |||
| @@ -105,8 +105,8 @@ | |||
| 105 | ////////////////// | 105 | ////////////////// |
| 106 | #pragma mark - Data Types | 106 | #pragma mark - Data Types |
| 107 | 107 | ||
| 108 | typedef struct tinyrad_config TinyRadConf; | 108 | typedef struct tinyrad_util_config TinyRadUtilConf; |
| 109 | typedef struct tinyrad_command TinyRadCommand; | 109 | typedef struct tinyrad_util_widget TinyRadUtilWidget; |
| 110 | 110 | ||
| 111 | 111 | ||
| 112 | typedef struct my_request_av | 112 | typedef struct my_request_av |
| @@ -116,28 +116,28 @@ typedef struct my_request_av | |||
| 116 | } MyRequestAV; | 116 | } MyRequestAV; |
| 117 | 117 | ||
| 118 | 118 | ||
| 119 | struct tinyrad_config | 119 | struct tinyrad_util_config |
| 120 | { | 120 | { |
| 121 | unsigned opts; | 121 | unsigned opts; |
| 122 | unsigned tr_opts; | 122 | unsigned tr_opts; |
| 123 | int padint; | 123 | int padint; |
| 124 | int cmd_argc; | 124 | int cmd_argc; |
| 125 | char ** cmd_argv; | 125 | char ** cmd_argv; |
| 126 | const char * cmd_name; | 126 | const char * cmd_name; |
| 127 | size_t cmd_len; | 127 | size_t cmd_len; |
| 128 | void * padptr; | 128 | void * padptr; |
| 129 | const TinyRadCommand * cmd; | 129 | const TinyRadUtilWidget * cmd; |
| 130 | TinyRad * tr; | 130 | TinyRad * tr; |
| 131 | const char * url; | 131 | const char * url; |
| 132 | char ** dict_files; | 132 | char ** dict_files; |
| 133 | char ** dict_paths; | 133 | char ** dict_paths; |
| 134 | }; | 134 | }; |
| 135 | 135 | ||
| 136 | 136 | ||
| 137 | struct tinyrad_command | 137 | struct tinyrad_util_widget |
| 138 | { | 138 | { |
| 139 | const char * cmd_name; | 139 | const char * cmd_name; |
| 140 | int (*cmd_func)(TinyRadConf * cnf); | 140 | int (*cmd_func)(TinyRadUtilConf * cnf); |
| 141 | const char * cmd_shortopts; | 141 | const char * cmd_shortopts; |
| 142 | struct option * cmd_longopts; | 142 | struct option * cmd_longopts; |
| 143 | int cmd_min_arg; | 143 | int cmd_min_arg; |
| @@ -161,23 +161,23 @@ main( | |||
| 161 | 161 | ||
| 162 | 162 | ||
| 163 | void | 163 | void |
| 164 | tinyrad_cleanup( | 164 | tru_cleanup( |
| 165 | TinyRadConf * cnf ); | 165 | TinyRadUtilConf * cnf ); |
| 166 | 166 | ||
| 167 | 167 | ||
| 168 | int | 168 | int |
| 169 | tinyrad_cmd_config( | 169 | tru_widget_config( |
| 170 | TinyRadConf * cnf ); | 170 | TinyRadUtilConf * cnf ); |
| 171 | 171 | ||
| 172 | 172 | ||
| 173 | int | 173 | int |
| 174 | tinyrad_cmd_dict( | 174 | tru_widget_dict( |
| 175 | TinyRadConf * cnf ); | 175 | TinyRadUtilConf * cnf ); |
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | int | 178 | int |
| 179 | tinyrad_getopt( | 179 | tru_getopt( |
| 180 | TinyRadConf * cnf, | 180 | TinyRadUtilConf * cnf, |
| 181 | int argc, | 181 | int argc, |
| 182 | char * const * argv, | 182 | char * const * argv, |
| 183 | const char * short_opt, | 183 | const char * short_opt, |
| @@ -186,13 +186,13 @@ tinyrad_getopt( | |||
| 186 | 186 | ||
| 187 | 187 | ||
| 188 | int | 188 | int |
| 189 | tinyrad_load_dict( | 189 | tru_load_tinyrad( |
| 190 | TinyRadConf * cnf ); | 190 | TinyRadUtilConf * cnf ); |
| 191 | 191 | ||
| 192 | 192 | ||
| 193 | int | 193 | int |
| 194 | tinyrad_usage( | 194 | tru_usage( |
| 195 | TinyRadConf * cnf ); | 195 | TinyRadUtilConf * cnf ); |
| 196 | 196 | ||
| 197 | 197 | ||
| 198 | ///////////////// | 198 | ///////////////// |
| @@ -203,11 +203,11 @@ tinyrad_usage( | |||
| 203 | #pragma mark - Variables | 203 | #pragma mark - Variables |
| 204 | 204 | ||
| 205 | #pragma mark tinyrad_cmdmap[] | 205 | #pragma mark tinyrad_cmdmap[] |
| 206 | static const TinyRadCommand tinyrad_cmdmap[] = | 206 | static const TinyRadUtilWidget tru_widget_map[] = |
| 207 | { | 207 | { |
| 208 | { | 208 | { |
| 209 | "configuration", // command name | 209 | "configuration", // command name |
| 210 | &tinyrad_cmd_config, // entry function | 210 | &tru_widget_config, // entry function |
| 211 | TINYRAD_DICT_GETOPT_SHORT | 211 | TINYRAD_DICT_GETOPT_SHORT |
| 212 | TINYRAD_GETOPT_SHORT, // getopt short options | 212 | TINYRAD_GETOPT_SHORT, // getopt short options |
| 213 | (struct option []) | 213 | (struct option []) |
| @@ -220,7 +220,7 @@ static const TinyRadCommand tinyrad_cmdmap[] = | |||
| 220 | }, | 220 | }, |
| 221 | { | 221 | { |
| 222 | "dictionary", // command name | 222 | "dictionary", // command name |
| 223 | &tinyrad_cmd_dict, // entry function | 223 | &tru_widget_dict, // entry function |
| 224 | TINYRAD_DICT_GETOPT_SHORT | 224 | TINYRAD_DICT_GETOPT_SHORT |
| 225 | TINYRAD_GETOPT_SHORT, // getopt short options | 225 | TINYRAD_GETOPT_SHORT, // getopt short options |
| 226 | (struct option []) | 226 | (struct option []) |
| @@ -233,7 +233,7 @@ static const TinyRadCommand tinyrad_cmdmap[] = | |||
| 233 | }, | 233 | }, |
| 234 | { | 234 | { |
| 235 | "help", // command name | 235 | "help", // command name |
| 236 | &tinyrad_usage, // entry function | 236 | &tru_usage, // entry function |
| 237 | TINYRAD_GETOPT_SHORT, // getopt short options | 237 | TINYRAD_GETOPT_SHORT, // getopt short options |
| 238 | (struct option []) { TINYRAD_GETOPT_LONG }, // getopt long options | 238 | (struct option []) { TINYRAD_GETOPT_LONG }, // getopt long options |
| 239 | 0, 0, // min/max arguments | 239 | 0, 0, // min/max arguments |
| @@ -258,8 +258,8 @@ int main(int argc, char * argv[]) | |||
| 258 | int rc; | 258 | int rc; |
| 259 | size_t pos; | 259 | size_t pos; |
| 260 | TinyRadDict * dict; | 260 | TinyRadDict * dict; |
| 261 | TinyRadConf cnfdata; | 261 | TinyRadUtilConf cnfdata; |
| 262 | TinyRadConf * cnf; | 262 | TinyRadUtilConf * cnf; |
| 263 | 263 | ||
| 264 | // getopt options | 264 | // getopt options |
| 265 | static char short_opt[] = "+" TINYRAD_GETOPT_SHORT; | 265 | static char short_opt[] = "+" TINYRAD_GETOPT_SHORT; |
| @@ -271,7 +271,7 @@ int main(int argc, char * argv[]) | |||
| 271 | cnf = &cnfdata; | 271 | cnf = &cnfdata; |
| 272 | dict = NULL; | 272 | dict = NULL; |
| 273 | 273 | ||
| 274 | while((c = tinyrad_getopt(cnf, argc, argv, short_opt, long_opt, &opt_index)) != -1) | 274 | while((c = tru_getopt(cnf, argc, argv, short_opt, long_opt, &opt_index)) != -1) |
| 275 | { | 275 | { |
| 276 | switch(c) | 276 | switch(c) |
| 277 | { | 277 | { |
| @@ -281,11 +281,11 @@ int main(int argc, char * argv[]) | |||
| 281 | break; | 281 | break; |
| 282 | 282 | ||
| 283 | case MY_GETOPT_EXIT: | 283 | case MY_GETOPT_EXIT: |
| 284 | tinyrad_cleanup(cnf); | 284 | tru_cleanup(cnf); |
| 285 | return(0); | 285 | return(0); |
| 286 | 286 | ||
| 287 | case MY_GETOPT_ERROR: | 287 | case MY_GETOPT_ERROR: |
| 288 | tinyrad_cleanup(cnf); | 288 | tru_cleanup(cnf); |
| 289 | return(1); | 289 | return(1); |
| 290 | 290 | ||
| 291 | case '?': | 291 | case '?': |
| @@ -310,9 +310,9 @@ int main(int argc, char * argv[]) | |||
| 310 | cnf->cmd_len = strlen(cnf->cmd_name); | 310 | cnf->cmd_len = strlen(cnf->cmd_name); |
| 311 | 311 | ||
| 312 | // looks up widget | 312 | // looks up widget |
| 313 | for(pos = 0; (tinyrad_cmdmap[pos].cmd_name != NULL); pos++) | 313 | for(pos = 0; (tru_widget_map[pos].cmd_name != NULL); pos++) |
| 314 | { | 314 | { |
| 315 | if ((strncmp(cnf->cmd_name, tinyrad_cmdmap[pos].cmd_name, cnf->cmd_len))) | 315 | if ((strncmp(cnf->cmd_name, tru_widget_map[pos].cmd_name, cnf->cmd_len))) |
| 316 | continue; | 316 | continue; |
| 317 | if ((cnf->cmd)) | 317 | if ((cnf->cmd)) |
| 318 | { | 318 | { |
| @@ -320,7 +320,7 @@ int main(int argc, char * argv[]) | |||
| 320 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | 320 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); |
| 321 | return(1); | 321 | return(1); |
| 322 | }; | 322 | }; |
| 323 | cnf->cmd = &tinyrad_cmdmap[pos]; | 323 | cnf->cmd = &tru_widget_map[pos]; |
| 324 | }; | 324 | }; |
| 325 | if (!(cnf->cmd)) | 325 | if (!(cnf->cmd)) |
| 326 | { | 326 | { |
| @@ -338,7 +338,7 @@ int main(int argc, char * argv[]) | |||
| 338 | // process widget cli options | 338 | // process widget cli options |
| 339 | optind = 1; | 339 | optind = 1; |
| 340 | opt_index = 0; | 340 | opt_index = 0; |
| 341 | while((c = tinyrad_getopt(cnf, cnf->cmd_argc, cnf->cmd_argv, cnf->cmd->cmd_shortopts, cnf->cmd->cmd_longopts, &opt_index)) != -1) | 341 | while((c = tru_getopt(cnf, cnf->cmd_argc, cnf->cmd_argv, cnf->cmd->cmd_shortopts, cnf->cmd->cmd_longopts, &opt_index)) != -1) |
| 342 | { | 342 | { |
| 343 | switch(c) | 343 | switch(c) |
| 344 | { | 344 | { |
| @@ -348,11 +348,11 @@ int main(int argc, char * argv[]) | |||
| 348 | break; | 348 | break; |
| 349 | 349 | ||
| 350 | case MY_GETOPT_EXIT: | 350 | case MY_GETOPT_EXIT: |
| 351 | tinyrad_cleanup(cnf); | 351 | tru_cleanup(cnf); |
| 352 | return(0); | 352 | return(0); |
| 353 | 353 | ||
| 354 | case MY_GETOPT_ERROR: | 354 | case MY_GETOPT_ERROR: |
| 355 | tinyrad_cleanup(cnf); | 355 | tru_cleanup(cnf); |
| 356 | return(1); | 356 | return(1); |
| 357 | 357 | ||
| 358 | case '?': | 358 | case '?': |
| @@ -380,14 +380,14 @@ int main(int argc, char * argv[]) | |||
| 380 | 380 | ||
| 381 | // call widget | 381 | // call widget |
| 382 | rc = cnf->cmd->cmd_func(cnf); | 382 | rc = cnf->cmd->cmd_func(cnf); |
| 383 | tinyrad_cleanup(cnf); | 383 | tru_cleanup(cnf); |
| 384 | return(trutils_exit_code(rc)); | 384 | return(trutils_exit_code(rc)); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | 387 | ||
| 388 | void | 388 | void |
| 389 | tinyrad_cleanup( | 389 | tru_cleanup( |
| 390 | TinyRadConf * cnf ) | 390 | TinyRadUtilConf * cnf ) |
| 391 | { | 391 | { |
| 392 | tinyrad_free(cnf->tr); | 392 | tinyrad_free(cnf->tr); |
| 393 | tinyrad_strsfree(cnf->dict_files); | 393 | tinyrad_strsfree(cnf->dict_files); |
| @@ -397,12 +397,12 @@ tinyrad_cleanup( | |||
| 397 | 397 | ||
| 398 | 398 | ||
| 399 | int | 399 | int |
| 400 | tinyrad_cmd_config( | 400 | tru_widget_config( |
| 401 | TinyRadConf * cnf ) | 401 | TinyRadUtilConf * cnf ) |
| 402 | { | 402 | { |
| 403 | int rc; | 403 | int rc; |
| 404 | TinyRadDict * dict; | 404 | TinyRadDict * dict; |
| 405 | if ((rc = tinyrad_load_dict(cnf)) != TRAD_SUCCESS) | 405 | if ((rc = tru_load_tinyrad(cnf)) != TRAD_SUCCESS) |
| 406 | return(rc); | 406 | return(rc); |
| 407 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); | 407 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); |
| 408 | tinyrad_conf_print(cnf->tr, dict); | 408 | tinyrad_conf_print(cnf->tr, dict); |
| @@ -412,12 +412,12 @@ tinyrad_cmd_config( | |||
| 412 | 412 | ||
| 413 | 413 | ||
| 414 | int | 414 | int |
| 415 | tinyrad_cmd_dict( | 415 | tru_widget_dict( |
| 416 | TinyRadConf * cnf ) | 416 | TinyRadUtilConf * cnf ) |
| 417 | { | 417 | { |
| 418 | int rc; | 418 | int rc; |
| 419 | TinyRadDict * dict; | 419 | TinyRadDict * dict; |
| 420 | if ((rc = tinyrad_load_dict(cnf)) != TRAD_SUCCESS) | 420 | if ((rc = tru_load_tinyrad(cnf)) != TRAD_SUCCESS) |
| 421 | return(rc); | 421 | return(rc); |
| 422 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); | 422 | tinyrad_get_option(cnf->tr, TRAD_OPT_DICTIONARY, &dict); |
| 423 | tinyrad_dict_print(dict, 0xffff); | 423 | tinyrad_dict_print(dict, 0xffff); |
| @@ -427,8 +427,8 @@ tinyrad_cmd_dict( | |||
| 427 | 427 | ||
| 428 | 428 | ||
| 429 | int | 429 | int |
| 430 | tinyrad_getopt( | 430 | tru_getopt( |
| 431 | TinyRadConf * cnf, | 431 | TinyRadUtilConf * cnf, |
| 432 | int argc, | 432 | int argc, |
| 433 | char * const * argv, | 433 | char * const * argv, |
| 434 | const char * short_opt, | 434 | const char * short_opt, |
| @@ -458,7 +458,7 @@ tinyrad_getopt( | |||
| 458 | return(MY_GETOPT_MATCHED); | 458 | return(MY_GETOPT_MATCHED); |
| 459 | 459 | ||
| 460 | case 'h': | 460 | case 'h': |
| 461 | tinyrad_usage(cnf); | 461 | tru_usage(cnf); |
| 462 | return(MY_GETOPT_EXIT); | 462 | return(MY_GETOPT_EXIT); |
| 463 | 463 | ||
| 464 | case 'I': | 464 | case 'I': |
| @@ -492,8 +492,8 @@ tinyrad_getopt( | |||
| 492 | 492 | ||
| 493 | 493 | ||
| 494 | int | 494 | int |
| 495 | tinyrad_load_dict( | 495 | tru_load_tinyrad( |
| 496 | TinyRadConf * cnf ) | 496 | TinyRadUtilConf * cnf ) |
| 497 | { | 497 | { |
| 498 | int rc; | 498 | int rc; |
| 499 | char ** errs; | 499 | char ** errs; |
| @@ -544,8 +544,8 @@ tinyrad_load_dict( | |||
| 544 | 544 | ||
| 545 | 545 | ||
| 546 | int | 546 | int |
| 547 | tinyrad_usage( | 547 | tru_usage( |
| 548 | TinyRadConf * cnf ) | 548 | TinyRadUtilConf * cnf ) |
| 549 | { | 549 | { |
| 550 | int i; | 550 | int i; |
| 551 | const char * name; | 551 | const char * name; |
| @@ -577,9 +577,9 @@ tinyrad_usage( | |||
| 577 | if (!(cnf->cmd)) | 577 | if (!(cnf->cmd)) |
| 578 | { | 578 | { |
| 579 | printf("COMMANDS:\n"); | 579 | printf("COMMANDS:\n"); |
| 580 | for(i = 0; tinyrad_cmdmap[i].cmd_name != NULL; i++) | 580 | for(i = 0; tru_widget_map[i].cmd_name != NULL; i++) |
| 581 | if ((tinyrad_cmdmap[i].cmd_desc)) | 581 | if ((tru_widget_map[i].cmd_desc)) |
| 582 | printf(" %-25s %s\n", tinyrad_cmdmap[i].cmd_name, tinyrad_cmdmap[i].cmd_desc); | 582 | printf(" %-25s %s\n", tru_widget_map[i].cmd_name, tru_widget_map[i].cmd_desc); |
| 583 | }; | 583 | }; |
| 584 | printf("\n"); | 584 | printf("\n"); |
| 585 | return(0); | 585 | return(0); |
