diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/tinyrad.c | 84 |
1 files changed, 79 insertions, 5 deletions
diff --git a/src/tinyrad.c b/src/tinyrad.c index 8c644ff..6e530e5 100644 --- a/src/tinyrad.c +++ b/src/tinyrad.c | |||
| @@ -72,6 +72,21 @@ | |||
| 72 | #define MY_OPT_CONFIG_PRINT 0x0008UL | 72 | #define MY_OPT_CONFIG_PRINT 0x0008UL |
| 73 | 73 | ||
| 74 | 74 | ||
| 75 | #define TINYRAD_GETOPT_SHORT "h" | ||
| 76 | #define TINYRAD_GETOPT_LONG \ | ||
| 77 | { "debug", optional_argument, NULL, 'd' }, \ | ||
| 78 | { "file", optional_argument, NULL, 'f' }, \ | ||
| 79 | { "help", no_argument, NULL, 'h' }, \ | ||
| 80 | { "quiet", no_argument, NULL, 'q' }, \ | ||
| 81 | { "silent", no_argument, NULL, 'q' }, \ | ||
| 82 | { "version", no_argument, NULL, 'V' }, \ | ||
| 83 | { "verbose", no_argument, NULL, 'v' }, \ | ||
| 84 | { "configuration", no_argument, NULL, 3 }, \ | ||
| 85 | { "defaults", no_argument, NULL, 2 }, \ | ||
| 86 | { "dictionary-dump", no_argument, NULL, 1 }, \ | ||
| 87 | { NULL, 0, NULL, 0 } | ||
| 88 | |||
| 89 | |||
| 75 | ////////////////// | 90 | ////////////////// |
| 76 | // // | 91 | // // |
| 77 | // Data Types // | 92 | // Data Types // |
| @@ -79,6 +94,10 @@ | |||
| 79 | ////////////////// | 94 | ////////////////// |
| 80 | #pragma mark - Data Types | 95 | #pragma mark - Data Types |
| 81 | 96 | ||
| 97 | typedef struct tinyrad_config TinyRadConf; | ||
| 98 | typedef struct tinyrad_command TinyRadCommand; | ||
| 99 | |||
| 100 | |||
| 82 | typedef struct my_request_av | 101 | typedef struct my_request_av |
| 83 | { | 102 | { |
| 84 | char * attr_name; | 103 | char * attr_name; |
| @@ -86,6 +105,27 @@ typedef struct my_request_av | |||
| 86 | } MyRequestAV; | 105 | } MyRequestAV; |
| 87 | 106 | ||
| 88 | 107 | ||
| 108 | struct tinyrad_config | ||
| 109 | { | ||
| 110 | unsigned opts; | ||
| 111 | unsigned padint; | ||
| 112 | TinyRadCommand * cmd; | ||
| 113 | }; | ||
| 114 | |||
| 115 | |||
| 116 | struct tinyrad_command | ||
| 117 | { | ||
| 118 | const char * cmd_name; | ||
| 119 | int (*cmd_func)(TinyRadConf * cnf); | ||
| 120 | const char * cmd_shortopts; | ||
| 121 | struct option * cmd_longopts; | ||
| 122 | int cmd_min_arg; | ||
| 123 | int cmd_max_arg; | ||
| 124 | const char * cmd_help; | ||
| 125 | const char * cmd_desc; | ||
| 126 | }; | ||
| 127 | |||
| 128 | |||
| 89 | ////////////////// | 129 | ////////////////// |
| 90 | // // | 130 | // // |
| 91 | // Prototypes // | 131 | // Prototypes // |
| @@ -109,12 +149,34 @@ tinyrad_load_dict( | |||
| 109 | char ** dict_paths ); | 149 | char ** dict_paths ); |
| 110 | 150 | ||
| 111 | 151 | ||
| 112 | void | 152 | int |
| 113 | tinyrad_usage( void ); | 153 | tinyrad_usage( |
| 154 | TinyRadConf * cnf ); | ||
| 114 | 155 | ||
| 115 | 156 | ||
| 116 | ///////////////// | 157 | ///////////////// |
| 117 | // // | 158 | // // |
| 159 | // Variables // | ||
| 160 | // // | ||
| 161 | ///////////////// | ||
| 162 | #pragma mark - Variables | ||
| 163 | |||
| 164 | static const TinyRadCommand tinyrad_cmdmap[] = | ||
| 165 | { | ||
| 166 | { | ||
| 167 | "help", // command name | ||
| 168 | &tinyrad_usage, // entry function | ||
| 169 | TINYRAD_GETOPT_SHORT, // getopt short options | ||
| 170 | (struct option []) { TINYRAD_GETOPT_LONG }, // getopt long options | ||
| 171 | 0, 0, // min/max arguments | ||
| 172 | NULL, // extra cli usage | ||
| 173 | "print command usage" // command description | ||
| 174 | }, | ||
| 175 | { NULL, NULL, NULL, NULL, -1, -1, NULL, NULL } | ||
| 176 | }; | ||
| 177 | |||
| 178 | ///////////////// | ||
| 179 | // // | ||
| 118 | // Functions // | 180 | // Functions // |
| 119 | // // | 181 | // // |
| 120 | ///////////////// | 182 | ///////////////// |
| @@ -133,6 +195,7 @@ int main(int argc, char * argv[]) | |||
| 133 | char ** dict_files; | 195 | char ** dict_files; |
| 134 | char ** dict_paths; | 196 | char ** dict_paths; |
| 135 | unsigned opts; | 197 | unsigned opts; |
| 198 | TinyRadConf cnf; | ||
| 136 | 199 | ||
| 137 | // getopt options | 200 | // getopt options |
| 138 | static char short_opt[] = "D:d:f:hI:qVv"; | 201 | static char short_opt[] = "D:d:f:hI:qVv"; |
| @@ -153,6 +216,7 @@ int main(int argc, char * argv[]) | |||
| 153 | 216 | ||
| 154 | trutils_initialize(PROGRAM_NAME); | 217 | trutils_initialize(PROGRAM_NAME); |
| 155 | 218 | ||
| 219 | memset(&cnf, 0, sizeof(cnf)); | ||
| 156 | opts = 0; | 220 | opts = 0; |
| 157 | tr_opts = 0; | 221 | tr_opts = 0; |
| 158 | url = NULL; | 222 | url = NULL; |
| @@ -196,7 +260,7 @@ int main(int argc, char * argv[]) | |||
| 196 | break; | 260 | break; |
| 197 | 261 | ||
| 198 | case 'h': | 262 | case 'h': |
| 199 | tinyrad_usage(); | 263 | tinyrad_usage(&cnf); |
| 200 | return(0); | 264 | return(0); |
| 201 | 265 | ||
| 202 | case 'I': | 266 | case 'I': |
| @@ -340,8 +404,11 @@ tinyrad_load_dict( | |||
| 340 | } | 404 | } |
| 341 | 405 | ||
| 342 | 406 | ||
| 343 | void tinyrad_usage(void) | 407 | int |
| 408 | tinyrad_usage( | ||
| 409 | TinyRadConf * cnf ) | ||
| 344 | { | 410 | { |
| 411 | int i; | ||
| 345 | printf("Usage: %s [OPTIONS] [url]\n", PROGRAM_NAME); | 412 | printf("Usage: %s [OPTIONS] [url]\n", PROGRAM_NAME); |
| 346 | printf("OPTIONS:\n"); | 413 | printf("OPTIONS:\n"); |
| 347 | printf(" -D dictionary include dictionary\n"); | 414 | printf(" -D dictionary include dictionary\n"); |
| @@ -355,8 +422,15 @@ void tinyrad_usage(void) | |||
| 355 | printf(" --defaults load default dictionaries\n"); | 422 | printf(" --defaults load default dictionaries\n"); |
| 356 | printf(" --dictionary-dump print imported dictionaries\n"); | 423 | printf(" --dictionary-dump print imported dictionaries\n"); |
| 357 | printf(" --configuration print configuration\n"); | 424 | printf(" --configuration print configuration\n"); |
| 425 | if (!(cnf->cmd)) | ||
| 426 | { | ||
| 427 | printf("COMMANDS:\n"); | ||
| 428 | for(i = 0; tinyrad_cmdmap[i].cmd_name != NULL; i++) | ||
| 429 | if ((tinyrad_cmdmap[i].cmd_desc)) | ||
| 430 | printf(" %-25s %s\n", tinyrad_cmdmap[i].cmd_name, tinyrad_cmdmap[i].cmd_desc); | ||
| 431 | }; | ||
| 358 | printf("\n"); | 432 | printf("\n"); |
| 359 | return; | 433 | return(0); |
| 360 | } | 434 | } |
| 361 | 435 | ||
| 362 | 436 | ||
