]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - trek/main.c
Converted from sgtty to termios api, no longer needs libcompat.
[bsdgames-darwin.git] / trek / main.c
1 /*
2 * Copyright (c) 1980 Regents of the University of California.
3 * 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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #ifndef lint
35 char copyright[] =
36 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
37 All rights reserved.\n";
38 #endif /* not lint */
39
40 #ifndef lint
41 /*static char sccsid[] = "from: @(#)main.c 5.7 (Berkeley) 2/28/91";*/
42 static char rcsid[] = "$Id: main.c,v 1.3 1994/05/24 23:54:17 jtc Exp $";
43 #endif /* not lint */
44
45 # include "trek.h"
46 # include <stdio.h>
47 # include <setjmp.h>
48 # include <termios.h>
49
50 # define PRIO 00 /* default priority */
51
52 int Mother = 51 + (51 << 8);
53
54 /*
55 ** #### ##### # #### ##### #### ##### # #
56 ** # # # # # # # # # # # #
57 ** ### # ##### #### # #### ### ###
58 ** # # # # # # # # # # # #
59 ** #### # # # # # # # # ##### # #
60 **
61 ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
62 ** from Jeff Poskanzer and Pete Rubinstein.
63 **
64 ** I also want to thank everyone here at Berkeley who
65 ** where crazy enough to play the undebugged game. I want to
66 ** particularly thank Nick Whyte, who made considerable
67 ** suggestions regarding the content of the game. Why, I'll
68 ** never forget the time he suggested the name for the
69 ** "capture" command.
70 **
71 ** Please send comments, questions, and suggestions about this
72 ** game to:
73 ** Eric P. Allman
74 ** Project INGRES
75 ** Electronics Research Laboratory
76 ** Cory Hall
77 ** University of California
78 ** Berkeley, California 94720
79 **
80 ** If you make ANY changes in the game, I sure would like to
81 ** know about them. It is sort of an ongoing project for me,
82 ** and I very much want to put in any bug fixes and improvements
83 ** that you might come up with.
84 **
85 ** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
86 ** That was adapted from the "original BASIC program" (ha!) by
87 ** Mike Mayfield (Centerline Engineering).
88 **
89 ** Additional inspiration taken from FORTRAN version by
90 ** David Matuszek and Paul Reynolds which runs on the CDC
91 ** 7600 at Lawrence Berkeley Lab, maintained there by
92 ** Andy Davidson. This version is also available at LLL
93 ** and at LMSC. In all fairness, this version was the
94 ** major inspiration for this version of the game (trans-
95 ** lation: I ripped off a whole lot of code).
96 **
97 ** Minor other input from the "Battelle Version 7A" by Joe Miller
98 ** (Graphics Systems Group, Battelle-Columbus Labs) and
99 ** Ross Pavlac (Systems Programmer, Battelle Memorial
100 ** Institute). That version was written in December '74
101 ** and extensively modified June '75. It was adapted
102 ** from the FTN version by Ron Williams of CDC Sunnyvale,
103 ** which was adapted from the Basic version distributed
104 ** by DEC. It also had "neat stuff swiped" from T. T.
105 ** Terry and Jim Korp (University of Texas), Hicks (Penn
106 ** U.), and Rick Maus (Georgia Tech). Unfortunately, it
107 ** was not as readable as it could have been and so the
108 ** translation effort was severely hampered. None the
109 ** less, I got the idea of inhabited starsystems from this
110 ** version.
111 **
112 ** Permission is given for use, copying, and modification of
113 ** all or part of this program and related documentation,
114 ** provided that all reference to the authors are maintained.
115 **
116 **
117 **********************************************************************
118 **
119 ** NOTES TO THE MAINTAINER:
120 **
121 ** There is a compilation option xTRACE which must be set for any
122 ** trace information to be generated. It is probably defined in
123 ** the version that you get. It can be removed, however, if you
124 ** have trouble finding room in core.
125 **
126 ** Many things in trek are not as clear as they might be, but are
127 ** done to reduce space. I compile with the -f and -O flags. I
128 ** am constrained to running with non-seperated I/D space, since
129 ** we don't have doubleing point hardware here; even if we did, I
130 ** would like trek to be available to the large number of people
131 ** who either have an 11/40 or do not have FP hardware. I also
132 ** found it desirable to make the code run reentrant, so this
133 ** added even more space constraints.
134 **
135 ** I use the portable C library to do my I/O. This is done be-
136 ** cause I wanted the game easily transportable to other C
137 ** implementations, and because I was too lazy to do the doubleing
138 ** point input myself. Little did I know. The portable C library
139 ** released by Bell Labs has more bugs than you would believe, so
140 ** I ended up rewriting the whole blessed thing. Trek excercises
141 ** many of the bugs in it, as well as bugs in some of the section
142 ** III UNIX routines. We have fixed them here. One main problem
143 ** was a bug in alloc() that caused it to always ask for a large
144 ** hunk of memory, which worked fine unless you were almost out,
145 ** which I inevitably was. If you want the code for all of this
146 ** stuff, it is also available through me.
147 **
148 ***********************************************************************
149 */
150
151 jmp_buf env;
152
153 main(argc, argv)
154 int argc;
155 char **argv;
156 {
157 long vect;
158 /* extern FILE *f_log; */
159 register char opencode;
160 int prio;
161 register int ac;
162 register char **av;
163 struct termios argp;
164
165 av = argv;
166 ac = argc;
167 av++;
168 time(&vect);
169 srand(vect);
170 opencode = 'w';
171 prio = PRIO;
172
173 if (tcgetattr(1, &argp) == 0)
174 {
175 if (cfgetispeed(&argp) < B1200)
176 Etc.fast++;
177 }
178
179 while (ac > 1 && av[0][0] == '-')
180 {
181 switch (av[0][1])
182 {
183 case 'a': /* append to log file */
184 opencode = 'a';
185 break;
186
187 case 'f': /* set fast mode */
188 Etc.fast++;
189 break;
190
191 case 's': /* set slow mode */
192 Etc.fast = 0;
193 break;
194
195 # ifdef xTRACE
196 case 't': /* trace */
197 if (getuid() != Mother)
198 goto badflag;
199 Trace++;
200 break;
201 # endif
202
203 case 'p': /* set priority */
204 if (getuid() != Mother)
205 goto badflag;
206 prio = atoi(av[0] + 2);
207 break;
208
209 default:
210 badflag:
211 printf("Invalid option: %s\n", av[0]);
212
213 }
214 ac--;
215 av++;
216 }
217 if (ac > 2)
218 syserr(0, "arg count");
219 /*
220 if (ac > 1)
221 f_log = fopen(av[0], opencode);
222 */
223
224 printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
225
226 if (setjmp(env))
227 {
228 if ( !getynpar("Another game") )
229 exit(0);
230 }
231 do
232 {
233 setup();
234 play();
235 } while (getynpar("Another game"));
236
237 fflush(stdout);
238 }