nrelease - fix/improve livecd
[dragonfly.git] / games / trek / main.c
CommitLineData
4318c66e
SW
1/* @(#)main.c 8.1 (Berkeley) 5/31/93 */
2/* $NetBSD: main.c,v 1.23 2011/08/29 20:30:37 joerg Exp $ */
3
4/*
984263bc
MD
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
6693db17 16 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
4318c66e
SW
33#include <stdio.h>
34#include <setjmp.h>
35#include <stdlib.h>
36#include <unistd.h>
37#include <err.h>
38#include <time.h>
39#include <sys/types.h>
6693db17
SW
40#include "trek.h"
41#include "getpar.h"
984263bc 42
984263bc
MD
43
44/*
45** #### ##### # #### ##### #### ##### # #
46** # # # # # # # # # # # #
47** ### # ##### #### # #### ### ###
48** # # # # # # # # # # # #
49** #### # # # # # # # # ##### # #
50**
51** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
52** from Jeff Poskanzer and Pete Rubinstein.
53**
54** I also want to thank everyone here at Berkeley who
55** where crazy enough to play the undebugged game. I want to
56** particularly thank Nick Whyte, who made considerable
57** suggestions regarding the content of the game. Why, I'll
58** never forget the time he suggested the name for the
59** "capture" command.
60**
61** Please send comments, questions, and suggestions about this
62** game to:
63** Eric P. Allman
64** Project INGRES
65** Electronics Research Laboratory
66** Cory Hall
67** University of California
68** Berkeley, California 94720
69**
70** If you make ANY changes in the game, I sure would like to
71** know about them. It is sort of an ongoing project for me,
72** and I very much want to put in any bug fixes and improvements
73** that you might come up with.
74**
75** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
76** That was adapted from the "original BASIC program" (ha!) by
77** Mike Mayfield (Centerline Engineering).
78**
79** Additional inspiration taken from FORTRAN version by
80** David Matuszek and Paul Reynolds which runs on the CDC
81** 7600 at Lawrence Berkeley Lab, maintained there by
82** Andy Davidson. This version is also available at LLL
83** and at LMSC. In all fairness, this version was the
84** major inspiration for this version of the game (trans-
85** lation: I ripped off a whole lot of code).
86**
87** Minor other input from the "Battelle Version 7A" by Joe Miller
88** (Graphics Systems Group, Battelle-Columbus Labs) and
89** Ross Pavlac (Systems Programmer, Battelle Memorial
90** Institute). That version was written in December '74
91** and extensively modified June '75. It was adapted
92** from the FTN version by Ron Williams of CDC Sunnyvale,
93** which was adapted from the Basic version distributed
94** by DEC. It also had "neat stuff swiped" from T. T.
95** Terry and Jim Korp (University of Texas), Hicks (Penn
96** U.), and Rick Maus (Georgia Tech). Unfortunately, it
97** was not as readable as it could have been and so the
98** translation effort was severely hampered. None the
99** less, I got the idea of inhabited starsystems from this
100** version.
101**
102** Permission is given for use, copying, and modification of
103** all or part of this program and related documentation,
104** provided that all reference to the authors are maintained.
105**
106**
107**********************************************************************
108**
109** NOTES TO THE MAINTAINER:
110**
111** There is a compilation option xTRACE which must be set for any
112** trace information to be generated. It is probably defined in
113** the version that you get. It can be removed, however, if you
114** have trouble finding room in core.
115**
116** Many things in trek are not as clear as they might be, but are
117** done to reduce space. I compile with the -f and -O flags. I
118** am constrained to running with non-separated I/D space, since
119** we don't have doubleing point hardware here; even if we did, I
120** would like trek to be available to the large number of people
121** who either have an 11/40 or do not have FP hardware. I also
122** found it desirable to make the code run reentrant, so this
123** added even more space constraints.
124**
125** I use the portable C library to do my I/O. This is done be-
126** cause I wanted the game easily transportable to other C
127** implementations, and because I was too lazy to do the doubleing
128** point input myself. Little did I know. The portable C library
129** released by Bell Labs has more bugs than you would believe, so
4318c66e 130** I ended up rewriting the whole blessed thing. Trek excercises
984263bc
MD
131** many of the bugs in it, as well as bugs in some of the section
132** III UNIX routines. We have fixed them here. One main problem
133** was a bug in alloc() that caused it to always ask for a large
134** hunk of memory, which worked fine unless you were almost out,
135** which I inevitably was. If you want the code for all of this
136** stuff, it is also available through me.
137**
138***********************************************************************
139*/
140
141jmp_buf env;
142
4318c66e
SW
143__dead2 static void
144usage(const char *av0)
145{
146 errx(1, "Usage: %s [-fs]", av0);
147}
148
ac79378f
PA
149int
150main(int argc, char **argv)
984263bc 151{
4318c66e 152 int ch;
984263bc 153
6693db17 154 /* Revoke setgid privileges */
984263bc
MD
155 setgid(getgid());
156
4318c66e
SW
157 /* Default to fast mode */
158 Etc.fast = 1;
159
160 srandom((long) time(NULL));
161
162 while ((ch = getopt(argc, argv, "fst")) != -1) {
163 switch (ch) {
164 case 'f': /* set fast mode */
165 Etc.fast++;
166 break;
167
168 case 's': /* set slow mode */
169 Etc.fast = 0;
170 break;
171
6693db17 172#ifdef xTRACE
984263bc 173 case 't': /* trace */
984263bc
MD
174 Trace++;
175 break;
6693db17 176#endif
984263bc 177
4318c66e
SW
178 default:
179 usage(argv[0]);
984263bc 180 }
984263bc 181 }
4318c66e
SW
182 if (optind < argc)
183 usage(argv[0]);
984263bc 184
4318c66e
SW
185 printf("\n * * * S T A R T R E K * * *\n\n"
186 "Press return to continue.\n");
984263bc 187
6693db17 188 if (setjmp(env)) {
984263bc
MD
189 if ( !getynpar("Another game") )
190 exit(0);
191 }
4318c66e 192
6693db17 193 do {
984263bc
MD
194 setup();
195 play();
196 } while (getynpar("Another game"));
197
198 fflush(stdout);
4318c66e 199 return 0;
984263bc 200}