1*67c60162Sjoerg /* $NetBSD: main.c,v 1.23 2011/08/29 20:30:37 joerg Exp $ */
2887dd216Scgd
361f28255Scgd /*
4887dd216Scgd * Copyright (c) 1980, 1993
5887dd216Scgd * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
15e5aeb4eaSagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
32ef383c95Schristos #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
342fe2731dSlukem __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
352fe2731dSlukem The Regents of the University of California. All rights reserved.");
3661f28255Scgd #endif /* not lint */
3761f28255Scgd
3861f28255Scgd #ifndef lint
39887dd216Scgd #if 0
40887dd216Scgd static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
41887dd216Scgd #else
42*67c60162Sjoerg __RCSID("$NetBSD: main.c,v 1.23 2011/08/29 20:30:37 joerg Exp $");
43887dd216Scgd #endif
4461f28255Scgd #endif /* not lint */
4561f28255Scgd
4661f28255Scgd #include <stdio.h>
4761f28255Scgd #include <setjmp.h>
48ef383c95Schristos #include <stdlib.h>
49ef383c95Schristos #include <unistd.h>
50ef383c95Schristos #include <err.h>
5163b3971aScjs #include <time.h>
5220e33050Sjsm #include <sys/types.h>
53ef383c95Schristos #include "trek.h"
54ef383c95Schristos #include "getpar.h"
5561f28255Scgd
5661f28255Scgd
5761f28255Scgd /*
5861f28255Scgd ** #### ##### # #### ##### #### ##### # #
5961f28255Scgd ** # # # # # # # # # # # #
6061f28255Scgd ** ### # ##### #### # #### ### ###
6161f28255Scgd ** # # # # # # # # # # # #
6261f28255Scgd ** #### # # # # # # # # ##### # #
6361f28255Scgd **
6461f28255Scgd ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
6561f28255Scgd ** from Jeff Poskanzer and Pete Rubinstein.
6661f28255Scgd **
6761f28255Scgd ** I also want to thank everyone here at Berkeley who
6861f28255Scgd ** where crazy enough to play the undebugged game. I want to
6961f28255Scgd ** particularly thank Nick Whyte, who made considerable
7061f28255Scgd ** suggestions regarding the content of the game. Why, I'll
7161f28255Scgd ** never forget the time he suggested the name for the
7261f28255Scgd ** "capture" command.
7361f28255Scgd **
7461f28255Scgd ** Please send comments, questions, and suggestions about this
7561f28255Scgd ** game to:
7661f28255Scgd ** Eric P. Allman
7761f28255Scgd ** Project INGRES
7861f28255Scgd ** Electronics Research Laboratory
7961f28255Scgd ** Cory Hall
8061f28255Scgd ** University of California
8161f28255Scgd ** Berkeley, California 94720
8261f28255Scgd **
8361f28255Scgd ** If you make ANY changes in the game, I sure would like to
8461f28255Scgd ** know about them. It is sort of an ongoing project for me,
8561f28255Scgd ** and I very much want to put in any bug fixes and improvements
8661f28255Scgd ** that you might come up with.
8761f28255Scgd **
8861f28255Scgd ** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
8961f28255Scgd ** That was adapted from the "original BASIC program" (ha!) by
9061f28255Scgd ** Mike Mayfield (Centerline Engineering).
9161f28255Scgd **
9261f28255Scgd ** Additional inspiration taken from FORTRAN version by
9361f28255Scgd ** David Matuszek and Paul Reynolds which runs on the CDC
9461f28255Scgd ** 7600 at Lawrence Berkeley Lab, maintained there by
9561f28255Scgd ** Andy Davidson. This version is also available at LLL
9661f28255Scgd ** and at LMSC. In all fairness, this version was the
9761f28255Scgd ** major inspiration for this version of the game (trans-
9861f28255Scgd ** lation: I ripped off a whole lot of code).
9961f28255Scgd **
10061f28255Scgd ** Minor other input from the "Battelle Version 7A" by Joe Miller
10161f28255Scgd ** (Graphics Systems Group, Battelle-Columbus Labs) and
10261f28255Scgd ** Ross Pavlac (Systems Programmer, Battelle Memorial
10361f28255Scgd ** Institute). That version was written in December '74
10461f28255Scgd ** and extensively modified June '75. It was adapted
10561f28255Scgd ** from the FTN version by Ron Williams of CDC Sunnyvale,
10661f28255Scgd ** which was adapted from the Basic version distributed
10761f28255Scgd ** by DEC. It also had "neat stuff swiped" from T. T.
10861f28255Scgd ** Terry and Jim Korp (University of Texas), Hicks (Penn
10961f28255Scgd ** U.), and Rick Maus (Georgia Tech). Unfortunately, it
11061f28255Scgd ** was not as readable as it could have been and so the
11161f28255Scgd ** translation effort was severely hampered. None the
11261f28255Scgd ** less, I got the idea of inhabited starsystems from this
11361f28255Scgd ** version.
11461f28255Scgd **
11561f28255Scgd ** Permission is given for use, copying, and modification of
11661f28255Scgd ** all or part of this program and related documentation,
11761f28255Scgd ** provided that all reference to the authors are maintained.
11861f28255Scgd **
11961f28255Scgd **
12061f28255Scgd **********************************************************************
12161f28255Scgd **
12261f28255Scgd ** NOTES TO THE MAINTAINER:
12361f28255Scgd **
12461f28255Scgd ** There is a compilation option xTRACE which must be set for any
12561f28255Scgd ** trace information to be generated. It is probably defined in
12661f28255Scgd ** the version that you get. It can be removed, however, if you
12761f28255Scgd ** have trouble finding room in core.
12861f28255Scgd **
12961f28255Scgd ** Many things in trek are not as clear as they might be, but are
13061f28255Scgd ** done to reduce space. I compile with the -f and -O flags. I
131a9356936Swiz ** am constrained to running with non-separated I/D space, since
13261f28255Scgd ** we don't have doubleing point hardware here; even if we did, I
13361f28255Scgd ** would like trek to be available to the large number of people
13461f28255Scgd ** who either have an 11/40 or do not have FP hardware. I also
13561f28255Scgd ** found it desirable to make the code run reentrant, so this
13661f28255Scgd ** added even more space constraints.
13761f28255Scgd **
13861f28255Scgd ** I use the portable C library to do my I/O. This is done be-
13961f28255Scgd ** cause I wanted the game easily transportable to other C
14061f28255Scgd ** implementations, and because I was too lazy to do the doubleing
14161f28255Scgd ** point input myself. Little did I know. The portable C library
14261f28255Scgd ** released by Bell Labs has more bugs than you would believe, so
14361f28255Scgd ** I ended up rewriting the whole blessed thing. Trek excercises
14461f28255Scgd ** many of the bugs in it, as well as bugs in some of the section
14561f28255Scgd ** III UNIX routines. We have fixed them here. One main problem
14661f28255Scgd ** was a bug in alloc() that caused it to always ask for a large
14761f28255Scgd ** hunk of memory, which worked fine unless you were almost out,
14861f28255Scgd ** which I inevitably was. If you want the code for all of this
14961f28255Scgd ** stuff, it is also available through me.
15061f28255Scgd **
15161f28255Scgd ***********************************************************************
15261f28255Scgd */
15361f28255Scgd
15461f28255Scgd jmp_buf env;
15561f28255Scgd
156*67c60162Sjoerg __dead static void
usage(const char * av0)1574d0e1ebeSdholland usage(const char *av0)
1584d0e1ebeSdholland {
1594d0e1ebeSdholland errx(1, "Usage: %s [-fs]", av0);
1604d0e1ebeSdholland }
1614d0e1ebeSdholland
162ef383c95Schristos int
main(int argc,char ** argv)163bf0917b6Sdholland main(int argc, char **argv)
16461f28255Scgd {
1654d0e1ebeSdholland int ch;
16661f28255Scgd
1675367f340Sjsm /* Revoke setgid privileges */
168f9eca697Smycroft setgid(getgid());
1695367f340Sjsm
170014e646eSdholland /* Default to fast mode */
171014e646eSdholland Etc.fast = 1;
172014e646eSdholland
1733ae4e09aSdholland srandom((long) time(NULL));
17467bd328aSjtc
1754d0e1ebeSdholland while ((ch = getopt(argc, argv, "fst")) != -1) {
1764d0e1ebeSdholland switch (ch) {
17761f28255Scgd case 'f': /* set fast mode */
17861f28255Scgd Etc.fast++;
17961f28255Scgd break;
18061f28255Scgd
18161f28255Scgd case 's': /* set slow mode */
18261f28255Scgd Etc.fast = 0;
18361f28255Scgd break;
18461f28255Scgd
18561f28255Scgd #ifdef xTRACE
18661f28255Scgd case 't': /* trace */
18761f28255Scgd Trace++;
18861f28255Scgd break;
18961f28255Scgd #endif
19061f28255Scgd
19161f28255Scgd default:
1924d0e1ebeSdholland usage(argv[0]);
19361f28255Scgd }
19461f28255Scgd }
1954d0e1ebeSdholland if (optind < argc)
1964d0e1ebeSdholland usage(argv[0]);
19761f28255Scgd
19861357867Sdholland printf("\n * * * S T A R T R E K * * *\n\n"
19961357867Sdholland "Press return to continue.\n");
20061f28255Scgd
20150b862e2Sdholland if (setjmp(env)) {
20261f28255Scgd if ( !getynpar("Another game") )
20361f28255Scgd exit(0);
20461f28255Scgd }
20550b862e2Sdholland
20650b862e2Sdholland do {
20761f28255Scgd setup();
20861f28255Scgd play();
20961f28255Scgd } while (getynpar("Another game"));
21061f28255Scgd
21161f28255Scgd fflush(stdout);
212ef383c95Schristos return 0;
21361f28255Scgd }
214