main.c revision 1.3 1 /* $NetBSD: main.c,v 1.3 1995/04/22 10:37:01 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #ifndef lint
37 static char copyright[] =
38 "@(#) Copyright (c) 1983, 1993\n\
39 The Regents of the University of California. All rights reserved.\n";
40 #endif /* not lint */
41
42 #ifndef lint
43 #if 0
44 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
45 #else
46 static char rcsid[] = "$NetBSD: main.c,v 1.3 1995/04/22 10:37:01 cgd Exp $";
47 #endif
48 #endif /* not lint */
49
50 #include "externs.h"
51
52 /*ARGSUSED*/
53 main(argc, argv)
54 int argc;
55 register char **argv;
56 {
57 register char *p;
58 int i;
59
60 (void) srand(getpid());
61 issetuid = getuid() != geteuid();
62 if (p = rindex(*argv, '/'))
63 p++;
64 else
65 p = *argv;
66 if (strcmp(p, "driver") == 0 || strcmp(p, "saildriver") == 0)
67 mode = MODE_DRIVER;
68 else if (strcmp(p, "sail.log") == 0)
69 mode = MODE_LOGGER;
70 else
71 mode = MODE_PLAYER;
72 while ((p = *++argv) && *p == '-')
73 switch (p[1]) {
74 case 'd':
75 mode = MODE_DRIVER;
76 break;
77 case 's':
78 mode = MODE_LOGGER;
79 break;
80 case 'D':
81 debug++;
82 break;
83 case 'x':
84 randomize;
85 break;
86 case 'l':
87 longfmt++;
88 break;
89 case 'b':
90 nobells++;
91 break;
92 default:
93 fprintf(stderr, "SAIL: Unknown flag %s.\n", p);
94 exit(1);
95 }
96 if (*argv)
97 game = atoi(*argv);
98 else
99 game = -1;
100 if (i = setjmp(restart))
101 mode = i;
102 switch (mode) {
103 case MODE_PLAYER:
104 return pl_main();
105 case MODE_DRIVER:
106 return dr_main();
107 case MODE_LOGGER:
108 return lo_main();
109 default:
110 fprintf(stderr, "SAIL: Unknown mode %d.\n", mode);
111 abort();
112 }
113 /*NOTREACHED*/
114 }
115