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