Annotation of 43BSDReno/games/trek/main.c, revision 1.1

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

unix.superglobalmegacorp.com

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