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

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

unix.superglobalmegacorp.com

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