Annotation of 43BSD/games/trek/main.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.