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 * $DragonFly: src/games/sail/main.c,v 1.3 2006/09/03 17:33:13 pavalos Exp $ 33 */ 34 35 #include "externs.h" 36 37 int 38 main(int argc __unused, char **argv) 39 { 40 char *p; 41 int i; 42 43 srandomdev(); 44 issetuid = getuid() != geteuid(); 45 if ((p = rindex(*argv, '/'))) 46 p++; 47 else 48 p = *argv; 49 if (strcmp(p, "driver") == 0 || strcmp(p, "saildriver") == 0) 50 mode = MODE_DRIVER; 51 else if (strcmp(p, "sail.log") == 0) 52 mode = MODE_LOGGER; 53 else 54 mode = MODE_PLAYER; 55 while ((p = *++argv) && *p == '-') 56 switch (p[1]) { 57 case 'd': 58 mode = MODE_DRIVER; 59 break; 60 case 's': 61 mode = MODE_LOGGER; 62 break; 63 case 'D': 64 debug++; 65 break; 66 case 'x': 67 randomize++; 68 break; 69 case 'l': 70 longfmt++; 71 break; 72 case 'b': 73 nobells++; 74 break; 75 default: 76 fprintf(stderr, "SAIL: Unknown flag %s.\n", p); 77 exit(1); 78 } 79 if (*argv) 80 game = atoi(*argv); 81 else 82 game = -1; 83 84 if ((i = setjmp(restart)) != 0) 85 mode = i; 86 87 switch (mode) { 88 case MODE_PLAYER: 89 return pl_main(); 90 case MODE_DRIVER: 91 return dr_main(); 92 case MODE_LOGGER: 93 return lo_main(); 94 default: 95 fprintf(stderr, "SAIL: Unknown mode %d.\n", mode); 96 abort(); 97 } 98 /*NOTREACHED*/ 99 } 100