Sync usage with man page.
[netbsd-mini2440.git] / usr.bin / crunch / crunchgen / crunched_main.c
blobab5fabbd2626dbec3b10ff4680b86ee930a48f0d
1 /* $NetBSD: crunched_main.c,v 1.3 2002/07/03 12:45:06 pooka Exp $ */
2 /*
3 * Copyright (c) 1994 University of Maryland
4 * All Rights Reserved.
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>
36 #ifndef lint
37 __RCSID("$NetBSD: crunched_main.c,v 1.3 2002/07/03 12:45:06 pooka Exp $");
38 #endif
40 #include <stdio.h>
41 #include <string.h>
42 #include <stdlib.h>
44 struct stub {
45 char *name;
46 int (*f)();
49 extern struct stub entry_points[];
51 int main(int argc, char **argv, char **envp)
53 char *slash, *basename;
54 struct stub *ep;
56 if(argv[0] == NULL || *argv[0] == '\0')
57 crunched_usage();
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;
65 if(ep->name)
66 return ep->f(argc, argv, envp);
67 else {
68 fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, basename);
69 crunched_usage();
74 int crunched_main(int argc, char **argv, char **envp)
76 struct stub *ep;
77 int columns, len;
79 if(argc <= 1)
80 crunched_usage();
82 return main(--argc, ++argv, envp);
86 int crunched_usage()
88 int columns, len;
89 struct stub *ep;
91 fprintf(stderr, "Usage: %s <prog> <args> ..., where <prog> is one of:\n",
92 EXECNAME);
93 columns = 0;
94 for(ep=entry_points; ep->name != NULL; ep++) {
95 len = strlen(ep->name) + 1;
96 if(columns+len < 80)
97 columns += len;
98 else {
99 fprintf(stderr, "\n");
100 columns = len;
102 fprintf(stderr, " %s", ep->name);
104 fprintf(stderr, "\n");
105 exit(1);
108 /* end of crunched_main.c */