1 /*- 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved. 30 * @(#)main.c 8.1 (Berkeley) 5/31/93 31 * $FreeBSD: src/games/sail/main.c,v 1.5 1999/11/30 03:49:34 billf Exp $ 32 */ 33 34 #include "externs.h" 35 36 int 37 main(int argc __unused, char **argv) 38 { 39 char *p; 40 int i; 41 42 srandomdev(); 43 issetuid = getuid() != geteuid(); 44 if ((p = rindex(*argv, '/'))) 45 p++; 46 else 47 p = *argv; 48 if (strcmp(p, "driver") == 0 || strcmp(p, "saildriver") == 0) 49 mode = MODE_DRIVER; 50 else if (strcmp(p, "sail.log") == 0) 51 mode = MODE_LOGGER; 52 else 53 mode = MODE_PLAYER; 54 while ((p = *++argv) && *p == '-') 55 switch (p[1]) { 56 case 'd': 57 mode = MODE_DRIVER; 58 break; 59 case 's': 60 mode = MODE_LOGGER; 61 break; 62 case 'D': 63 debug++; 64 break; 65 case 'x': 66 randomize++; 67 break; 68 case 'l': 69 longfmt++; 70 break; 71 case 'b': 72 nobells++; 73 break; 74 default: 75 fprintf(stderr, "SAIL: Unknown flag %s.\n", p); 76 exit(1); 77 } 78 if (*argv) 79 game = atoi(*argv); 80 else 81 game = -1; 82 83 if ((i = setjmp(restart)) != 0) 84 mode = i; 85 86 switch (mode) { 87 case MODE_PLAYER: 88 pl_main(); 89 case MODE_DRIVER: 90 return dr_main(); 91 case MODE_LOGGER: 92 return lo_main(); 93 default: 94 fprintf(stderr, "SAIL: Unknown mode %d.\n", mode); 95 abort(); 96 } 97 /*NOTREACHED*/ 98 } 99