main.c revision 1.5 1 /* $NetBSD: main.c,v 1.5 1997/10/12 21:25:01 christos Exp $ */
2
3 /*
4 * Copyright (c) 1980, 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 #include <sys/cdefs.h>
37 #ifndef lint
38 __COPYRIGHT("@(#) Copyright (c) 1980, 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 __RCSID("$NetBSD: main.c,v 1.5 1997/10/12 21:25:01 christos Exp $");
47 #endif
48 #endif /* not lint */
49
50 #include <stdio.h>
51 #include <setjmp.h>
52 #include <termios.h>
53 #include <stdlib.h>
54 #include <unistd.h>
55 #include <err.h>
56 #include "trek.h"
57 #include "getpar.h"
58
59 # define PRIO 00 /* default priority */
60
61 int Mother = 51 + (51 << 8);
62
63 /*
64 ** #### ##### # #### ##### #### ##### # #
65 ** # # # # # # # # # # # #
66 ** ### # ##### #### # #### ### ###
67 ** # # # # # # # # # # # #
68 ** #### # # # # # # # # ##### # #
69 **
70 ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
71 ** from Jeff Poskanzer and Pete Rubinstein.
72 **
73 ** I also want to thank everyone here at Berkeley who
74 ** where crazy enough to play the undebugged game. I want to
75 ** particularly thank Nick Whyte, who made considerable
76 ** suggestions regarding the content of the game. Why, I'll
77 ** never forget the time he suggested the name for the
78 ** "capture" command.
79 **
80 ** Please send comments, questions, and suggestions about this
81 ** game to:
82 ** Eric P. Allman
83 ** Project INGRES
84 ** Electronics Research Laboratory
85 ** Cory Hall
86 ** University of California
87 ** Berkeley, California 94720
88 **
89 ** If you make ANY changes in the game, I sure would like to
90 ** know about them. It is sort of an ongoing project for me,
91 ** and I very much want to put in any bug fixes and improvements
92 ** that you might come up with.
93 **
94 ** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
95 ** That was adapted from the "original BASIC program" (ha!) by
96 ** Mike Mayfield (Centerline Engineering).
97 **
98 ** Additional inspiration taken from FORTRAN version by
99 ** David Matuszek and Paul Reynolds which runs on the CDC
100 ** 7600 at Lawrence Berkeley Lab, maintained there by
101 ** Andy Davidson. This version is also available at LLL
102 ** and at LMSC. In all fairness, this version was the
103 ** major inspiration for this version of the game (trans-
104 ** lation: I ripped off a whole lot of code).
105 **
106 ** Minor other input from the "Battelle Version 7A" by Joe Miller
107 ** (Graphics Systems Group, Battelle-Columbus Labs) and
108 ** Ross Pavlac (Systems Programmer, Battelle Memorial
109 ** Institute). That version was written in December '74
110 ** and extensively modified June '75. It was adapted
111 ** from the FTN version by Ron Williams of CDC Sunnyvale,
112 ** which was adapted from the Basic version distributed
113 ** by DEC. It also had "neat stuff swiped" from T. T.
114 ** Terry and Jim Korp (University of Texas), Hicks (Penn
115 ** U.), and Rick Maus (Georgia Tech). Unfortunately, it
116 ** was not as readable as it could have been and so the
117 ** translation effort was severely hampered. None the
118 ** less, I got the idea of inhabited starsystems from this
119 ** version.
120 **
121 ** Permission is given for use, copying, and modification of
122 ** all or part of this program and related documentation,
123 ** provided that all reference to the authors are maintained.
124 **
125 **
126 **********************************************************************
127 **
128 ** NOTES TO THE MAINTAINER:
129 **
130 ** There is a compilation option xTRACE which must be set for any
131 ** trace information to be generated. It is probably defined in
132 ** the version that you get. It can be removed, however, if you
133 ** have trouble finding room in core.
134 **
135 ** Many things in trek are not as clear as they might be, but are
136 ** done to reduce space. I compile with the -f and -O flags. I
137 ** am constrained to running with non-seperated I/D space, since
138 ** we don't have doubleing point hardware here; even if we did, I
139 ** would like trek to be available to the large number of people
140 ** who either have an 11/40 or do not have FP hardware. I also
141 ** found it desirable to make the code run reentrant, so this
142 ** added even more space constraints.
143 **
144 ** I use the portable C library to do my I/O. This is done be-
145 ** cause I wanted the game easily transportable to other C
146 ** implementations, and because I was too lazy to do the doubleing
147 ** point input myself. Little did I know. The portable C library
148 ** released by Bell Labs has more bugs than you would believe, so
149 ** I ended up rewriting the whole blessed thing. Trek excercises
150 ** many of the bugs in it, as well as bugs in some of the section
151 ** III UNIX routines. We have fixed them here. One main problem
152 ** was a bug in alloc() that caused it to always ask for a large
153 ** hunk of memory, which worked fine unless you were almost out,
154 ** which I inevitably was. If you want the code for all of this
155 ** stuff, it is also available through me.
156 **
157 ***********************************************************************
158 */
159
160 jmp_buf env;
161
162 int main __P((int, char **));
163
164 int
165 main(argc, argv)
166 int argc;
167 char **argv;
168 {
169 long vect;
170 char opencode;
171 int prio;
172 int ac;
173 char **av;
174 struct termios argp;
175
176 av = argv;
177 ac = argc;
178 av++;
179 time(&vect);
180 srand(vect);
181 opencode = 'w';
182 prio = PRIO;
183
184 if (tcgetattr(1, &argp) == 0)
185 {
186 if (cfgetispeed(&argp) < B1200)
187 Etc.fast++;
188 }
189
190 while (ac > 1 && av[0][0] == '-')
191 {
192 switch (av[0][1])
193 {
194 case 'a': /* append to log file */
195 opencode = 'a';
196 break;
197
198 case 'f': /* set fast mode */
199 Etc.fast++;
200 break;
201
202 case 's': /* set slow mode */
203 Etc.fast = 0;
204 break;
205
206 # ifdef xTRACE
207 case 't': /* trace */
208 if (getuid() != Mother)
209 goto badflag;
210 Trace++;
211 break;
212 # endif
213
214 case 'p': /* set priority */
215 if (getuid() != Mother)
216 goto badflag;
217 prio = atoi(av[0] + 2);
218 break;
219
220 default:
221 badflag:
222 printf("Invalid option: %s\n", av[0]);
223
224 }
225 ac--;
226 av++;
227 }
228 if (ac > 2)
229 errx(1, "arg count");
230 /*
231 if (ac > 1)
232 f_log = fopen(av[0], opencode);
233 */
234
235 printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
236
237 if (setjmp(env))
238 {
239 if ( !getynpar("Another game") )
240 exit(0);
241 }
242 do
243 {
244 setup();
245 play();
246 } while (getynpar("Another game"));
247
248 fflush(stdout);
249 return 0;
250 }
251