aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/tru/tinyrad.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/src/tru/tinyrad.c b/src/tru/tinyrad.c
index 155f09a..0e86f6d 100644
--- a/src/tru/tinyrad.c
+++ b/src/tru/tinyrad.c
@@ -80,6 +80,11 @@
80////////////////// 80//////////////////
81#pragma mark - Prototypes 81#pragma mark - Prototypes
82 82
83static const TinyRadUtilWidget *
84tru_widget_lookup(
85 const char * wname,
86 int exact );
87
83 88
84///////////////// 89/////////////////
85// // 90// //
@@ -152,7 +157,6 @@ int main(int argc, char * argv[])
152 int c; 157 int c;
153 int opt_index; 158 int opt_index;
154 int rc; 159 int rc;
155 size_t pos;
156 TinyRadDict * dict; 160 TinyRadDict * dict;
157 TinyRadUtilConf cnfdata; 161 TinyRadUtilConf cnfdata;
158 TinyRadUtilConf * cnf; 162 TinyRadUtilConf * cnf;
@@ -203,30 +207,11 @@ int main(int argc, char * argv[])
203 cnf->cmd_argc = (argc - optind); 207 cnf->cmd_argc = (argc - optind);
204 cnf->cmd_argv = &argv[optind]; 208 cnf->cmd_argv = &argv[optind];
205 cnf->cmd_name = cnf->cmd_argv[0]; 209 cnf->cmd_name = cnf->cmd_argv[0];
206 cnf->cmd_len = strlen(cnf->cmd_name);
207 210
208 // looks up widget 211 // looks up widget
209 for(pos = 0; (tru_widget_map[pos].name != NULL); pos++) 212 if ((cnf->cmd = tru_widget_lookup(cnf->cmd_argv[0], TRAD_NO)) == NULL)
210 {
211 if ((strncmp(cnf->cmd_name, tru_widget_map[pos].name, cnf->cmd_len)))
212 continue;
213 if ((cnf->cmd))
214 {
215 fprintf(stderr, "%s: ambiguous command -- \"%s\"\n", PROGRAM_NAME, cnf->cmd_name);
216 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
217 return(1);
218 };
219 cnf->cmd = &tru_widget_map[pos];
220 };
221 if (!(cnf->cmd))
222 {
223 fprintf(stderr, "%s: unknown command -- \"%s\"\n", PROGRAM_NAME, cnf->cmd_name);
224 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
225 return(1);
226 };
227 if (!(cnf->cmd->func))
228 { 213 {
229 fprintf(stderr, "%s: command not implemented -- \"%s\"\n", PROGRAM_NAME, cnf->cmd->name); 214 fprintf(stderr, "%s: unknown or ambiguous widget -- \"%s\"\n", PROGRAM_NAME, cnf->cmd_argv[0]);
230 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); 215 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
231 return(1); 216 return(1);
232 }; 217 };
@@ -452,4 +437,37 @@ tru_usage(
452} 437}
453 438
454 439
440static const TinyRadUtilWidget *
441tru_widget_lookup(
442 const char * wname,
443 int exact )
444{
445 size_t wname_len;
446 size_t x;
447 const TinyRadUtilWidget * widget;
448 const TinyRadUtilWidget * match;
449
450 match = NULL;
451 wname_len = strlen(wname);
452
453 for(x = 0; ((tru_widget_map[x].name)); x++)
454 {
455 widget = &tru_widget_map[x];
456 if (widget->func == NULL)
457 continue;
458
459 if (!(strncmp(widget->name, wname, wname_len)))
460 {
461 if (widget->name[wname_len] == '\0')
462 return(widget);
463 if ((match))
464 return(NULL);
465 if (exact == TRAD_NO)
466 match = widget;
467 };
468 };
469
470 return(NULL);
471}
472
455/* end of source */ 473/* end of source */