xref: /original-bsd/games/sail/main.c (revision 5d3a6356)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 char copyright[] =
15 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
16  All rights reserved.\n";
17 #endif /* not lint */
18 
19 #ifndef lint
20 static char sccsid[] = "@(#)main.c	5.3 (Berkeley) 04/04/88";
21 #endif /* not lint */
22 
23 #include "externs.h"
24 
25 /*ARGSUSED*/
26 main(argc, argv)
27 	int argc;
28 	register char **argv;
29 {
30 	register char *p;
31 	int i;
32 
33 	(void) srand(getpid());
34 	issetuid = getuid() != geteuid();
35 	if (p = rindex(*argv, '/'))
36 		p++;
37 	else
38 		p = *argv;
39 	if (strcmp(p, "driver") == 0 || strcmp(p, "saildriver") == 0)
40 		mode = MODE_DRIVER;
41 	else if (strcmp(p, "sail.log") == 0)
42 		mode = MODE_LOGGER;
43 	else
44 		mode = MODE_PLAYER;
45 	while ((p = *++argv) && *p == '-')
46 		switch (p[1]) {
47 		case 'd':
48 			mode = MODE_DRIVER;
49 			break;
50 		case 's':
51 			mode = MODE_LOGGER;
52 			break;
53 		case 'D':
54 			debug++;
55 			break;
56 		case 'x':
57 			randomize;
58 			break;
59 		case 'l':
60 			longfmt++;
61 			break;
62 		case 'b':
63 			nobells++;
64 			break;
65 		default:
66 			fprintf(stderr, "SAIL: Unknown flag %s.\n", p);
67 			exit(1);
68 		}
69 	if (*argv)
70 		game = atoi(*argv);
71 	else
72 		game = -1;
73 	if (i = setjmp(restart))
74 		mode = i;
75 	switch (mode) {
76 	case MODE_PLAYER:
77 		return pl_main();
78 	case MODE_DRIVER:
79 		return dr_main();
80 	case MODE_LOGGER:
81 		return lo_main();
82 	default:
83 		fprintf(stderr, "SAIL: Unknown mode %d.\n", mode);
84 		abort();
85 	}
86 	/*NOTREACHED*/
87 }
88