1 /* $NetBSD: crunched_main.c,v 1.3 2002/07/03 12:45:06 pooka Exp $ */
3 * Copyright (c) 1994 University of Maryland
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * crunched_main.c - main program for crunched binaries, it branches to a
29 * particular subprogram based on the value of argv[0]. Also included
30 * is a little program invoked when the crunched binary is called via
31 * its EXECNAME. This one prints out the list of compiled-in binaries,
32 * or calls one of them based on argv[1]. This allows the testing of
33 * the crunched binary without creating all the links.
35 #include <sys/cdefs.h>
37 __RCSID("$NetBSD: crunched_main.c,v 1.3 2002/07/03 12:45:06 pooka Exp $");
49 extern struct stub entry_points
[];
51 int main(int argc
, char **argv
, char **envp
)
53 char *slash
, *basename
;
56 if(argv
[0] == NULL
|| *argv
[0] == '\0')
59 slash
= strrchr(argv
[0], '/');
60 basename
= slash
? slash
+1 : argv
[0];
62 for(ep
=entry_points
; ep
->name
!= NULL
; ep
++)
63 if(!strcmp(basename
, ep
->name
)) break;
66 return ep
->f(argc
, argv
, envp
);
68 fprintf(stderr
, "%s: %s not compiled in\n", EXECNAME
, basename
);
74 int crunched_main(int argc
, char **argv
, char **envp
)
82 return main(--argc
, ++argv
, envp
);
91 fprintf(stderr
, "Usage: %s <prog> <args> ..., where <prog> is one of:\n",
94 for(ep
=entry_points
; ep
->name
!= NULL
; ep
++) {
95 len
= strlen(ep
->name
) + 1;
99 fprintf(stderr
, "\n");
102 fprintf(stderr
, " %s", ep
->name
);
104 fprintf(stderr
, "\n");
108 /* end of crunched_main.c */