2 /* Toybox infrastructure.
4 * Copyright 2006 Rob Landley <rob@landley.net>
6 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
11 // The monster fun applet list.
13 struct toy_list toy_list[] = {
14 {"toybox", toybox_main},
19 // global context for this applet.
21 struct toy_context toys;
29 usage (short long example info)
44 struct toy_list *find_toy_by_name(char *name)
46 int top, bottom, middle;
48 // If the name starts with "toybox", accept that as a match. Otherwise
49 // skip the first entry, which is out of order.
51 if (!strncmp(name,"toybox",6)) return toy_list;
54 // Binary search to find this applet.
56 top=(sizeof(toy_list)/sizeof(struct toy_list))-1;
60 middle=(top+bottom)/2;
61 if(middle<bottom || middle>top) return NULL;
62 result = strcmp(name,toy_list[middle].name);
63 if(!result) return toy_list+middle;
64 if(result<0) top=--middle;
69 int main(int argc, char *argv[])
73 // Record command line arguments.
77 // Figure out which applet got called.
78 name = rindex(argv[0],'/');
79 if (!name) name = argv[0];
81 toys.which = find_toy_by_name(name);
84 dprintf(2,"No behavior for %s\n",name);
87 return toys.which->toy_main();