Annotation of 43BSDTahoe/games/mille/mille.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: char copyright[] =
                     20: "@(#) Copyright (c) 1982 Regents of the University of California.\n\
                     21:  All rights reserved.\n";
                     22: #endif /* not lint */
                     23: 
                     24: #ifndef lint
                     25: static char sccsid[] = "@(#)mille.c    5.3 (Berkeley) 6/18/88";
                     26: #endif /* not lint */
                     27: 
                     28: # include      "mille.h"
                     29: # include      <signal.h>
                     30: # ifdef attron
                     31: #      include <term.h>
                     32: # endif        attron
                     33: 
                     34: /*
                     35:  * @(#)mille.c 1.3 (Berkeley) 5/10/83
                     36:  */
                     37: 
                     38: int    rub();
                     39: 
                     40: main(ac, av)
                     41: reg int                ac;
                     42: reg char       *av[]; {
                     43: 
                     44:        reg bool        restore;
                     45: 
                     46:        /* run as the user */
                     47:        setuid(getuid());
                     48: 
                     49:        if (strcmp(av[0], "a.out") == 0) {
                     50:                outf = fopen("q", "w");
                     51:                setbuf(outf, (char *)NULL);
                     52:                Debug = TRUE;
                     53:        }
                     54:        restore = FALSE;
                     55:        switch (ac) {
                     56:          case 2:
                     57:                rest_f(av[1]);
                     58:                restore = TRUE;
                     59:          case 1:
                     60:                break;
                     61:          default:
                     62:                printf("usage: milles [ restore_file ]\n");
                     63:                exit(-1);
                     64:                /* NOTREACHED */
                     65:        }
                     66:        Play = PLAYER;
                     67:        initscr();
                     68: # ifdef attron
                     69: #      define  CA      cursor_address
                     70: # endif
                     71:        if (!CA) {
                     72:                printf("Sorry.  Need cursor addressing to play mille\n");
                     73:                exit(-1);
                     74:        }
                     75:        delwin(stdscr);
                     76:        stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0);
                     77:        Score = newwin(SCORE_Y, SCORE_X, 0, 40);
                     78:        Miles = newwin(MILES_Y, MILES_X, 17, 0);
                     79: #ifdef attron
                     80:        idlok(Board, TRUE);
                     81:        idlok(Score, TRUE);
                     82:        idlok(Miles, TRUE);
                     83: #endif
                     84:        leaveok(Score, TRUE);
                     85:        leaveok(Miles, TRUE);
                     86:        clearok(curscr, TRUE);
                     87: # ifndef PROF
                     88:        srandom(getpid());
                     89: # else
                     90:        srandom(0);
                     91: # endif
                     92:        crmode();
                     93:        noecho();
                     94:        signal(SIGINT, rub);
                     95:        for (;;) {
                     96:                if (!restore || (Player[PLAYER].total >= 5000
                     97:                    || Player[COMP].total >= 5000)) {
                     98:                        if (Player[COMP].total < Player[PLAYER].total)
                     99:                                Player[PLAYER].games++;
                    100:                        else if (Player[COMP].total > Player[PLAYER].total)
                    101:                                Player[COMP].games++;
                    102:                        Player[COMP].total = 0;
                    103:                        Player[PLAYER].total = 0;
                    104:                }
                    105:                do {
                    106:                        if (!restore)
                    107:                                Handstart = Play = other(Handstart);
                    108:                        if (!restore || On_exit) {
                    109:                                shuffle();
                    110:                                init();
                    111:                        }
                    112:                        newboard();
                    113:                        if (restore)
                    114:                                mvwaddstr(Score, ERR_Y, ERR_X, Initstr);
                    115:                        prboard();
                    116:                        do {
                    117:                                domove();
                    118:                                if (Finished)
                    119:                                        newscore();
                    120:                                prboard();
                    121:                        } while (!Finished);
                    122:                        check_more();
                    123:                        restore = On_exit = FALSE;
                    124:                } while (Player[COMP].total < 5000
                    125:                    && Player[PLAYER].total < 5000);
                    126:        }
                    127: }
                    128: 
                    129: /*
                    130:  *     Routine to trap rubouts, and make sure they really want to
                    131:  * quit.
                    132:  */
                    133: rub() {
                    134: 
                    135:        (void)signal(SIGINT, SIG_IGN);
                    136:        if (getyn(REALLYPROMPT))
                    137:                die();
                    138:        (void)signal(SIGINT, rub);
                    139: }
                    140: 
                    141: /*
                    142:  *     Time to go beddy-by
                    143:  */
                    144: die() {
                    145: 
                    146:        (void)signal(SIGINT, SIG_IGN);
                    147:        if (outf)
                    148:                fflush(outf);
                    149:        mvcur(0, COLS - 1, LINES - 1, 0);
                    150:        endwin();
                    151:        exit(1);
                    152: }
                    153: 

unix.superglobalmegacorp.com

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