Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / crunch / crunchgen / crunched_main.c
1 /*
2  * Copyright (c) 1994 University of Maryland
3  * All Rights Reserved.
4  *
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.
14  *
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.
21  *
22  * Author: James da Silva, Systems Design and Analysis Group
23  *                         Computer Science Department
24  *                         University of Maryland at College Park
25  *
26  * $FreeBSD: src/usr.sbin/crunch/crunchgen/crunched_main.c,v 1.6.6.2 2002/08/09 02:42:02 gshapiro Exp $
27  * $DragonFly: src/usr.sbin/crunch/crunchgen/crunched_main.c,v 1.2 2003/06/17 04:29:53 dillon Exp $
28  */
29 /*
30  * crunched_main.c - main program for crunched binaries, it branches to a
31  *      particular subprogram based on the value of argv[0].  Also included
32  *      is a little program invoked when the crunched binary is called via
33  *      its EXECNAME.  This one prints out the list of compiled-in binaries,
34  *      or calls one of them based on argv[1].   This allows the testing of
35  *      the crunched binary without creating all the links.
36  */
37 #include <stdio.h>
38 #include <string.h>
39
40 struct stub {
41     char *name;
42     int (*f)();
43 };
44
45 extern struct stub entry_points[];
46
47 int main(int argc, char **argv, char **envp)
48 {
49     char *slash, *basename;
50     struct stub *ep;
51
52     if(argv[0] == NULL || *argv[0] == '\0')
53         crunched_usage();
54
55     slash = strrchr(argv[0], '/');
56     basename = slash? slash+1 : argv[0];
57
58     for(ep=entry_points; ep->name != NULL; ep++)
59         if(!strcmp(basename, ep->name)) break;
60
61     if(ep->name)
62         return ep->f(argc, argv, envp);
63     else {
64         fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, basename);
65         crunched_usage();
66     }
67 }
68
69
70 int crunched_here(char *path)
71 {
72     char *slash, *basename;
73     struct stub *ep;
74
75     slash = strrchr(path, '/');
76     basename = slash? slash+1 : path;
77
78     for(ep=entry_points; ep->name != NULL; ep++)
79         if(!strcmp(basename, ep->name))
80             return 1;
81     return 0;
82 }
83
84
85 int crunched_main(int argc, char **argv, char **envp)
86 {
87     struct stub *ep;
88     int columns, len;
89
90     if(argc <= 1)
91         crunched_usage();
92
93     return main(--argc, ++argv, envp);
94 }
95
96
97 int crunched_usage()
98 {
99     int columns, len;
100     struct stub *ep;
101
102     fprintf(stderr, "usage: %s <prog> <args> ..., where <prog> is one of:\n",
103             EXECNAME);
104     columns = 0;
105     for(ep=entry_points; ep->name != NULL; ep++) {
106         len = strlen(ep->name) + 1;
107         if(columns+len < 80)
108             columns += len;
109         else {
110             fprintf(stderr, "\n");
111             columns = len;
112         }
113         fprintf(stderr, " %s", ep->name);
114     }
115     fprintf(stderr, "\n");
116     exit(1);
117 }
118
119 /* end of crunched_main.c */
120