Annotation of src/usr.bin/tcfs/tcfsuse.c, Revision 1.4
1.4 ! fgsch 1: /* $OpenBSD$ */
! 2:
1.1 provos 3: /*
4: * Copyright 2000 Niels Provos <provos@citi.umich.edu>
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. The name of the author may not be used to endorse or promote products
16: * derived from this software without specific prior written permission.
17: *
18: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: */
29:
30: #include <stdio.h>
31: #include <stdlib.h>
32:
33: extern int putkey_main(int argc, char **argv);
34: extern int run_main(int argc, char **argv);
35: extern int rmkey_main(int argc, char **argv);
36: extern int genkey_main(int argc, char **argv);
37: extern int stat_main(int argc, char **argv);
38: extern int flags_main(int argc, char **argv);
39:
40: struct subprg {
41: char *name;
42: int (*function)(int, char **);
43: };
44:
45: struct subprg subcmds[] = {
46: {"putkey", putkey_main},
47: {"run", run_main},
48: {"rmkey", rmkey_main},
49: {"genkey", genkey_main},
50: {"stat", stat_main},
51: {"flags", flags_main}
52: };
53:
54: void
55: usage(char *name)
56: {
57: int i;
58: fprintf(stderr, "Usage: %s <subcmd> [arguments]\n", name);
59:
60: fprintf(stderr, "Possible sub commands:");
1.2 aaron 61:
1.3 aaron 62: for (i = sizeof(subcmds) / sizeof(struct subprg) - 1; i >= 0; i--)
1.1 provos 63: fprintf(stderr, " %s", subcmds[i].name);
1.2 aaron 64:
1.1 provos 65: fprintf(stderr, "\n");
66: }
67:
68:
69: int
70: main (int argc, char **argv)
71: {
72: int i;
73:
74: if (argc < 2) {
75: usage(argv[0]);
76: exit(1);
77: }
78:
1.3 aaron 79: for (i = sizeof(subcmds) / sizeof(struct subprg) - 1; i >= 0; i--) {
1.1 provos 80: if (!strcmp(argv[1], subcmds[i].name))
81: return (*subcmds[i].function)(argc - 1, argv + 1);
82: }
83:
84: fprintf(stderr, "%s: unknown command %s\n\n", argv[0], argv[1]);
85: usage(argv[0]);
1.2 aaron 86: exit(1);
1.1 provos 87: }