2 * Copyright (c) 1994 University of Maryland
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of U.M. not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. U.M. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
15 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * Author: James da Silva, Systems Design and Analysis Group
23 * Computer Science Department
24 * University of Maryland at College Park
29 * crunched_main.c - main program for crunched binaries, it branches to a
30 * particular subprogram based on the value of argv[0]. Also included
31 * is a little program invoked when the crunched binary is called via
32 * its EXECNAME. This one prints out the list of compiled-in binaries,
33 * or calls one of them based on argv[1]. This allows the testing of
34 * the crunched binary without creating all the links.
45 extern char *__progname;
46 extern struct stub entry_points[];
48 int main(int argc, char **argv, char **envp)
50 char *slash, *basename;
53 if(argv[0] == NULL || *argv[0] == '\0')
56 slash = strrchr(argv[0], '/');
57 basename = slash? slash+1 : argv[0];
59 for(ep=entry_points; ep->name != NULL; ep++)
60 if(!strcmp(basename, ep->name)) break;
63 return ep->f(argc, argv, envp);
65 fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, basename);
71 int crunched_here(char *path)
73 char *slash, *basename;
76 slash = strrchr(path, '/');
77 basename = slash? slash+1 : path;
79 for(ep=entry_points; ep->name != NULL; ep++)
80 if(!strcmp(basename, ep->name))
86 int crunched_main(int argc, char **argv, char **envp)
95 slash = strrchr(argv[1], '/');
96 __progname = slash? slash+1 : argv[1];
98 return main(--argc, ++argv, envp);
107 fprintf(stderr, "usage: %s <prog> <args> ..., where <prog> is one of:\n",
110 for(ep=entry_points; ep->name != NULL; ep++) {
111 len = strlen(ep->name) + 1;
115 fprintf(stderr, "\n");
118 fprintf(stderr, " %s", ep->name);
120 fprintf(stderr, "\n");
124 /* end of crunched_main.c */