aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-24 00:06:12 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-24 00:10:40 -0800
commit916a4f625a1dde4fe5c4b4fb6b0bc941609c86ac (patch)
treec7af7c1190e00d2ecf405fd8f1ef5b5999849926
parent1f672ffa488dcc89b4b5517cd29d758b2ed6ccb1 (diff)
downloadtinyrad-916a4f625a1dde4fe5c4b4fb6b0bc941609c86ac.tar.gz
tinyrad-916a4f625a1dde4fe5c4b4fb6b0bc941609c86ac.tar.bz2
tinyrad-916a4f625a1dde4fe5c4b4fb6b0bc941609c86ac.tar.xz
tinyrad-916a4f625a1dde4fe5c4b4fb6b0bc941609c86ac.zip
tinyrad: starting the conversion to widgets
-rw-r--r--src/tinyrad.c84
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
97typedef struct tinyrad_config TinyRadConf;
98typedef struct tinyrad_command TinyRadCommand;
99
100
82typedef struct my_request_av 101typedef 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
108struct tinyrad_config
109{
110 unsigned opts;
111 unsigned padint;
112 TinyRadCommand * cmd;
113};
114
115
116struct 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
112void 152int
113tinyrad_usage( void ); 153tinyrad_usage(
154 TinyRadConf * cnf );
114 155
115 156
116///////////////// 157/////////////////
117// // 158// //
159// Variables //
160// //
161/////////////////
162#pragma mark - Variables
163
164static 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
343void tinyrad_usage(void) 407int
408tinyrad_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