125993Smckusick /* 225993Smckusick * Copyright (c) 1980 Regents of the University of California. 334205Sbostic * All rights reserved. 434205Sbostic * 542606Sbostic * %sccs.include.redist.c% 625993Smckusick */ 725993Smckusick 811683Smckusick #ifndef lint 925993Smckusick char copyright[] = 1025993Smckusick "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1125993Smckusick All rights reserved.\n"; 1234205Sbostic #endif /* not lint */ 1311683Smckusick 1425993Smckusick #ifndef lint 15*46768Sbostic static char sccsid[] = "@(#)main.c 5.7 (Berkeley) 02/28/91"; 1634205Sbostic #endif /* not lint */ 1725993Smckusick 1811683Smckusick # include "trek.h" 1912738Slayer # include <stdio.h> 2012738Slayer # include <sgtty.h> 2144314Sbostic # include <setjmp.h> 2244314Sbostic 2312738Slayer # define PRIO 00 /* default priority */ 2411683Smckusick 2512738Slayer int Mother = 51 + (51 << 8); 2611683Smckusick 2711683Smckusick /* 2811683Smckusick ** #### ##### # #### ##### #### ##### # # 2911683Smckusick ** # # # # # # # # # # # # 3011683Smckusick ** ### # ##### #### # #### ### ### 3111683Smckusick ** # # # # # # # # # # # # 3211683Smckusick ** #### # # # # # # # # ##### # # 3311683Smckusick ** 3411683Smckusick ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help 3511683Smckusick ** from Jeff Poskanzer and Pete Rubinstein. 3611683Smckusick ** 3711683Smckusick ** I also want to thank everyone here at Berkeley who 3811683Smckusick ** where crazy enough to play the undebugged game. I want to 3911683Smckusick ** particularly thank Nick Whyte, who made considerable 4011683Smckusick ** suggestions regarding the content of the game. Why, I'll 4111683Smckusick ** never forget the time he suggested the name for the 4211683Smckusick ** "capture" command. 4311683Smckusick ** 4411683Smckusick ** Please send comments, questions, and suggestions about this 4511683Smckusick ** game to: 4611683Smckusick ** Eric P. Allman 4711683Smckusick ** Project INGRES 4811683Smckusick ** Electronics Research Laboratory 4911683Smckusick ** Cory Hall 5011683Smckusick ** University of California 5111683Smckusick ** Berkeley, California 94720 5211683Smckusick ** 5311683Smckusick ** If you make ANY changes in the game, I sure would like to 5411683Smckusick ** know about them. It is sort of an ongoing project for me, 5511683Smckusick ** and I very much want to put in any bug fixes and improvements 5611683Smckusick ** that you might come up with. 5711683Smckusick ** 5811683Smckusick ** FORTRASH version by Kay R. Fisher (DEC) "and countless others". 5911683Smckusick ** That was adapted from the "original BASIC program" (ha!) by 6011683Smckusick ** Mike Mayfield (Centerline Engineering). 6111683Smckusick ** 6211683Smckusick ** Additional inspiration taken from FORTRAN version by 6311683Smckusick ** David Matuszek and Paul Reynolds which runs on the CDC 6411683Smckusick ** 7600 at Lawrence Berkeley Lab, maintained there by 6511683Smckusick ** Andy Davidson. This version is also available at LLL 6611683Smckusick ** and at LMSC. In all fairness, this version was the 6711683Smckusick ** major inspiration for this version of the game (trans- 6811683Smckusick ** lation: I ripped off a whole lot of code). 6911683Smckusick ** 7011683Smckusick ** Minor other input from the "Battelle Version 7A" by Joe Miller 7111683Smckusick ** (Graphics Systems Group, Battelle-Columbus Labs) and 7211683Smckusick ** Ross Pavlac (Systems Programmer, Battelle Memorial 7311683Smckusick ** Institute). That version was written in December '74 7411683Smckusick ** and extensively modified June '75. It was adapted 7511683Smckusick ** from the FTN version by Ron Williams of CDC Sunnyvale, 7611683Smckusick ** which was adapted from the Basic version distributed 7711683Smckusick ** by DEC. It also had "neat stuff swiped" from T. T. 7811683Smckusick ** Terry and Jim Korp (University of Texas), Hicks (Penn 7911683Smckusick ** U.), and Rick Maus (Georgia Tech). Unfortunately, it 8011683Smckusick ** was not as readable as it could have been and so the 8111683Smckusick ** translation effort was severely hampered. None the 8211683Smckusick ** less, I got the idea of inhabited starsystems from this 8311683Smckusick ** version. 8411683Smckusick ** 8511683Smckusick ** Permission is given for use, copying, and modification of 8611683Smckusick ** all or part of this program and related documentation, 8711683Smckusick ** provided that all reference to the authors are maintained. 8811683Smckusick ** 8911683Smckusick ** 9011683Smckusick ********************************************************************** 9111683Smckusick ** 9211683Smckusick ** NOTES TO THE MAINTAINER: 9311683Smckusick ** 9411683Smckusick ** There is a compilation option xTRACE which must be set for any 9511683Smckusick ** trace information to be generated. It is probably defined in 9611683Smckusick ** the version that you get. It can be removed, however, if you 9711683Smckusick ** have trouble finding room in core. 9811683Smckusick ** 9911683Smckusick ** Many things in trek are not as clear as they might be, but are 10011683Smckusick ** done to reduce space. I compile with the -f and -O flags. I 10111683Smckusick ** am constrained to running with non-seperated I/D space, since 10212738Slayer ** we don't have doubleing point hardware here; even if we did, I 10311683Smckusick ** would like trek to be available to the large number of people 10411683Smckusick ** who either have an 11/40 or do not have FP hardware. I also 10511683Smckusick ** found it desirable to make the code run reentrant, so this 10611683Smckusick ** added even more space constraints. 10711683Smckusick ** 10811683Smckusick ** I use the portable C library to do my I/O. This is done be- 10911683Smckusick ** cause I wanted the game easily transportable to other C 11012738Slayer ** implementations, and because I was too lazy to do the doubleing 11111683Smckusick ** point input myself. Little did I know. The portable C library 11211683Smckusick ** released by Bell Labs has more bugs than you would believe, so 11311683Smckusick ** I ended up rewriting the whole blessed thing. Trek excercises 11411683Smckusick ** many of the bugs in it, as well as bugs in some of the section 11511683Smckusick ** III UNIX routines. We have fixed them here. One main problem 11611683Smckusick ** was a bug in alloc() that caused it to always ask for a large 11711683Smckusick ** hunk of memory, which worked fine unless you were almost out, 11811683Smckusick ** which I inevitably was. If you want the code for all of this 11911683Smckusick ** stuff, it is also available through me. 12011683Smckusick ** 12111683Smckusick *********************************************************************** 12211683Smckusick */ 12311683Smckusick 12444314Sbostic jmp_buf env; 12544314Sbostic 12611683Smckusick main(argc, argv) 12711683Smckusick int argc; 12811683Smckusick char **argv; 12911683Smckusick { 13012738Slayer long vect; 13112738Slayer /* extern FILE *f_log; */ 13211683Smckusick register char opencode; 13311683Smckusick int prio; 13411683Smckusick register int ac; 13511683Smckusick register char **av; 13612738Slayer struct sgttyb argp; 13711683Smckusick 13811683Smckusick av = argv; 13911683Smckusick ac = argc; 14011683Smckusick av++; 14112738Slayer time(&vect); 14212738Slayer srand(vect); 14311683Smckusick opencode = 'w'; 14411683Smckusick prio = PRIO; 14512738Slayer if (gtty(1, &argp) == 0) 14611683Smckusick { 14712738Slayer if ((argp.sg_ispeed ) < B1200) 14811683Smckusick Etc.fast++; 14911683Smckusick } 15011683Smckusick while (ac > 1 && av[0][0] == '-') 15111683Smckusick { 15211683Smckusick switch (av[0][1]) 15311683Smckusick { 15411683Smckusick case 'a': /* append to log file */ 15511683Smckusick opencode = 'a'; 15611683Smckusick break; 15711683Smckusick 15811683Smckusick case 'f': /* set fast mode */ 15911683Smckusick Etc.fast++; 16011683Smckusick break; 16111683Smckusick 16211683Smckusick case 's': /* set slow mode */ 16311683Smckusick Etc.fast = 0; 16411683Smckusick break; 16511683Smckusick 16611683Smckusick # ifdef xTRACE 16711683Smckusick case 't': /* trace */ 16811683Smckusick if (getuid() != Mother) 16911683Smckusick goto badflag; 17011683Smckusick Trace++; 17111683Smckusick break; 17211683Smckusick # endif 17311683Smckusick 17411683Smckusick case 'p': /* set priority */ 17511683Smckusick if (getuid() != Mother) 17611683Smckusick goto badflag; 177*46768Sbostic prio = atoi(av[0] + 2); 178*46768Sbostic break; 17911683Smckusick 18011683Smckusick default: 18111683Smckusick badflag: 18211683Smckusick printf("Invalid option: %s\n", av[0]); 18311683Smckusick 18411683Smckusick } 18511683Smckusick ac--; 18611683Smckusick av++; 18711683Smckusick } 18811683Smckusick if (ac > 2) 18911683Smckusick syserr(0, "arg count"); 19012738Slayer /* 19111683Smckusick if (ac > 1) 19212738Slayer f_log = fopen(av[0], opencode); 19312738Slayer */ 19411683Smckusick 19534591Sbostic printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n"); 19611683Smckusick 19744314Sbostic if (setjmp(env)) 19811683Smckusick { 19912738Slayer if ( !getynpar("Another game") ) 20012738Slayer exit(0); 20112738Slayer } 20212738Slayer do 20312738Slayer { 20411683Smckusick setup(); 20511683Smckusick play(); 20612738Slayer } while (getynpar("Another game")); 20712738Slayer 20812738Slayer fflush(stdout); 20911683Smckusick } 210