summaryrefslogtreecommitdiff
path: root/applets/busybox.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-10-25 19:00:51 +0000
committerMatt Kraai <kraai@debian.org>2000-10-25 19:00:51 +0000
commita0428eee9e0e5422fae9572d9dbafe7a9f81f485 (patch)
treed12dc08cf6173f358cf039fdcbc8c2bbb93e0445 /applets/busybox.c
parentef5529b27865adc79cd4d48f932d477b1d79b94e (diff)
downloadbusybox-w32-a0428eee9e0e5422fae9572d9dbafe7a9f81f485.tar.gz
busybox-w32-a0428eee9e0e5422fae9572d9dbafe7a9f81f485.tar.bz2
busybox-w32-a0428eee9e0e5422fae9572d9dbafe7a9f81f485.zip
Avoid reinventing the wheel (and thus save some space).
Diffstat (limited to 'applets/busybox.c')
-rw-r--r--applets/busybox.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/applets/busybox.c b/applets/busybox.c
index 696dd4262..985798ed6 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -81,11 +81,18 @@ static void install_links(const char *busybox, int use_symbolic_links)
81 81
82#endif /* BB_FEATURE_INSTALLER */ 82#endif /* BB_FEATURE_INSTALLER */
83 83
84static int applet_name_compare(const void *x, const void *y)
85{
86 const struct BB_applet *applet1 = x;
87 const struct BB_applet *applet2 = y;
88
89 return strcmp(applet1->name, applet2->name);
90}
84 91
85int main(int argc, char **argv) 92int main(int argc, char **argv)
86{ 93{
94 struct BB_applet search_applet, *applet;
87 const char *s; 95 const char *s;
88 int u, l; /* Lower and upper bounds for the binary search. */
89 applet_name = "busybox"; 96 applet_name = "busybox";
90 97
91#ifdef BB_FEATURE_INSTALLER 98#ifdef BB_FEATURE_INSTALLER
@@ -134,31 +141,11 @@ int main(int argc, char **argv)
134#endif 141#endif
135 142
136 /* Do a binary search to find the applet entry given the name. */ 143 /* Do a binary search to find the applet entry given the name. */
137 144 search_applet.name = applet_name;
138 u = NUM_APPLETS - 1; 145 applet = bsearch(&search_applet, applets, NUM_APPLETS,
139 l = 0; 146 sizeof(struct BB_applet), applet_name_compare);
140 147 if (applet != NULL)
141 for (;;) { 148 exit((*(applet->main)) (argc, argv));
142 int i = l + (u - l) / 2;
143 int j = strcmp(applet_name, applets[i].name);
144
145 if (j == 0) {
146 if (applets[i].usage && argv[1] && strcmp(argv[1], "--help") == 0)
147 usage(applets[i].usage);
148 exit(((*(applets[i].main)) (argc, argv)));
149 }
150
151 if (u == l)
152 break;
153
154 if (j < 0)
155 u = i - 1;
156 else
157 l = i + 1;
158
159 if (u < l)
160 break;
161 }
162 149
163 return(busybox_main(argc, argv)); 150 return(busybox_main(argc, argv));
164} 151}