xref: /openbsd/games/trek/main.c (revision 3d8817e4)
1 /*	$OpenBSD: main.c,v 1.12 2009/10/27 23:59:27 deraadt Exp $	*/
2 /*	$NetBSD: main.c,v 1.4 1995/04/22 10:59:10 cgd Exp $	*/
3 
4 /*
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.
16  * 3. Neither the name of the University nor the names of its contributors
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 
33 #include <sys/types.h>
34 #include <stdio.h>
35 #include <setjmp.h>
36 #include <termios.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <err.h>
40 #include "trek.h"
41 #include "getpar.h"
42 
43 /*
44 **	 ####  #####	#    ####	   #####  ####	 #####	#   #
45 **	#	 #     # #   #	 #	     #	  #   #	 #	#  #
46 **	 ###	 #    #####  ####	     #	  ####	 ###	###
47 **	    #	 #    #	  #  #	#	     #	  #  #	 #	#  #
48 **	####	 #    #	  #  #	 #	     #	  #   #	 #####	#   #
49 **
50 **	C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
51 **		from Jeff Poskanzer and Pete Rubinstein.
52 **
53 **	I also want to thank everyone here at Berkeley who
54 **	where crazy enough to play the undebugged game.  I want to
55 **	particularly thank Nick Whyte, who made considerable
56 **	suggestions regarding the content of the game.  Why, I'll
57 **	never forget the time he suggested the name for the
58 **	"capture" command.
59 **
60 **	Please send comments, questions, and suggestions about this
61 **		game to:
62 **			Eric P. Allman
63 **			Project INGRES
64 **			Electronics Research Laboratory
65 **			Cory Hall
66 **			University of California
67 **			Berkeley, California  94720
68 **
69 **	If you make ANY changes in the game, I sure would like to
70 **	know about them.  It is sort of an ongoing project for me,
71 **	and I very much want to put in any bug fixes and improvements
72 **	that you might come up with.
73 **
74 **	FORTRASH version by Kay R. Fisher (DEC) "and countless others".
75 **	That was adapted from the "original BASIC program" (ha!) by
76 **		Mike Mayfield (Centerline Engineering).
77 **
78 **	Additional inspiration taken from FORTRAN version by
79 **		David Matuszek and Paul Reynolds which runs on the CDC
80 **		7600 at Lawrence Berkeley Lab, maintained there by
81 **		Andy Davidson.  This version is also available at LLL
82 **		and at LMSC.  In all fairness, this version was the
83 **		major inspiration for this version of the game (trans-
84 **		lation:  I ripped off a whole lot of code).
85 **
86 **	Minor other input from the "Battelle Version 7A" by Joe Miller
87 **		(Graphics Systems Group, Battelle-Columbus Labs) and
88 **		Ross Pavlac (Systems Programmer, Battelle Memorial
89 **		Institute).  That version was written in December '74
90 **		and extensively modified June '75.  It was adapted
91 **		from the FTN version by Ron Williams of CDC Sunnyvale,
92 **		which was adapted from the Basic version distributed
93 **		by DEC.  It also had "neat stuff swiped" from T. T.
94 **		Terry and Jim Korp (University of Texas), Hicks (Penn
95 **		U.), and Rick Maus (Georgia Tech).  Unfortunately, it
96 **		was not as readable as it could have been and so the
97 **		translation effort was severely hampered.  None the
98 **		less, I got the idea of inhabited starsystems from this
99 **		version.
100 **
101 **	Permission is given for use, copying, and modification of
102 **		all or part of this program and related documentation,
103 **		provided that all reference to the authors are maintained.
104 **
105 **
106 **********************************************************************
107 **
108 **  NOTES TO THE MAINTAINER:
109 **
110 **	There is a compilation option xTRACE which must be set for any
111 **	trace information to be generated (the -t option must also be
112 **	set on the command line).  It is no longer defined by default.
113 **
114 ***********************************************************************
115 */
116 
117 jmp_buf env;
118 
119 int
120 main(argc, argv)
121 	int	argc;
122 	char	**argv;
123 {
124 	int		ac;
125 	char		**av;
126 
127 	av = argv;
128 	ac = argc;
129 	av++;
130 	srandomdev();
131 
132 #ifdef xTRACE
133 	Trace = 0;
134 	while (ac > 1 && av[0][0] == '-')
135 	{
136 		switch (av[0][1])
137 		{
138 		  case 't':	/* trace */
139 			Trace++;
140 			break;
141 
142 		  default:
143 			printf("Invalid option: %s\n", av[0]);
144 
145 		}
146 		ac--;
147 		av++;
148 	}
149 #endif
150 
151 	printf("\n   * * *   S T A R   T R E K   * * *\n\nPress return to continue.\n");
152 
153 	if (setjmp(env))
154 	{
155 		if ( !getynpar("Another game") )
156 			exit(0);
157 	}
158 	do
159 	{
160 		setup();
161 		play();
162 	} while (getynpar("Another game"));
163 
164 	fflush(stdout);
165 	return 0;
166 }
167