Annotation of 43BSDReno/games/chess/Xchess/xchess.c, revision 1.1

1.1     ! root        1: 
        !             2: /* This file contains code for X-CHESS.
        !             3:    Copyright (C) 1986 Free Software Foundation, Inc.
        !             4: 
        !             5: This file is part of X-CHESS.
        !             6: 
        !             7: X-CHESS is distributed in the hope that it will be useful,
        !             8: but WITHOUT ANY WARRANTY.  No author or distributor
        !             9: accepts responsibility to anyone for the consequences of using it
        !            10: or for whether it serves any particular purpose or works at all,
        !            11: unless he says so in writing.  Refer to the X-CHESS General Public
        !            12: License for full details.
        !            13: 
        !            14: Everyone is granted permission to copy, modify and redistribute
        !            15: X-CHESS, but only under the conditions described in the
        !            16: X-CHESS General Public License.   A copy of this license is
        !            17: supposed to have been given to you along with X-CHESS so you
        !            18: can know your rights and responsibilities.  It should be in a
        !            19: file named COPYING.  Among other things, the copyright notice
        !            20: and this notice must be preserved on all copies.  */
        !            21: 
        !            22: 
        !            23: /* RCS Info: $Revision: 1.2 $ on $Date: 89/04/28 08:44:02 $
        !            24:  *           $Source: /usr/local/src/source/X.V11R3/contrib/games/xchess/Xchess/RCS/xchess.c,v $
        !            25:  * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
        !            26:  *     Permission is granted to do anything with this code except sell it
        !            27:  *     or remove this message.
        !            28:  */
        !            29: 
        !            30: #define USAGE  "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\
        !            31: \t[ -t moves/timeunit ] [ -c ] [ -p program ]  [ -b ] [ -bnw ] [ -s ]\n\
        !            32: \t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]"
        !            33: 
        !            34: #include <signal.h>
        !            35: #include "xchess.h"
        !            36: 
        !            37: bool debug = false;
        !            38: bool oneboard = false;
        !            39: bool bnwflag = false;
        !            40: bool progflag = false;
        !            41: bool blackflag = false;
        !            42: bool quickflag = false;
        !            43: 
        !            44: char *progname = DEF_PROGRAM;
        !            45: char *proghost = NULL;
        !            46: char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ;
        !            47: char *colornames[] = { "white", "black", "none" } ;
        !            48: char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ;
        !            49: char *dispname1 = NULL, *dispname2 = NULL;
        !            50: 
        !            51: char *black_piece_color = BLACK_PIECE_COLOR;
        !            52: char *white_piece_color = WHITE_PIECE_COLOR;
        !            53: char *black_square_color = BLACK_SQUARE_COLOR;
        !            54: char *white_square_color = WHITE_SQUARE_COLOR;
        !            55: char *border_color = BORDER_COLOR;
        !            56: char *text_color = TEXT_COLOR;
        !            57: char *text_back = TEXT_BACK;
        !            58: char *error_text = ERROR_TEXT;
        !            59: char *player_text = PLAYER_TEXT;
        !            60: char *cursor_color = CURSOR_COLOR;
        !            61: 
        !            62: int num_flashes = NUM_FLASHES;
        !            63: int flash_size = FLASH_SIZE;
        !            64: char *program;
        !            65: char *recfile = NULL;
        !            66: 
        !            67: #ifdef notdef
        !            68: /*
        !            69:  * Serves no purpose.
        !            70:  */
        !            71: die () {
        !            72: fprintf(stderr, "child proc changed status?!\n");
        !            73: }
        !            74: #endif
        !            75: 
        !            76: void
        !            77: main(ac, av)
        !            78:        char **av;
        !            79: {
        !            80:        bool randflag = false;
        !            81:        move *m;
        !            82:        char *s;
        !            83: 
        !            84:        program = av[0];
        !            85:        
        !            86: #ifdef notdef
        !            87:        signal(SIGCHLD, die);
        !            88: #endif
        !            89: 
        !            90:        /* Process args. */
        !            91:        av++; ac--;
        !            92:        while (ac > 0 && **av == '-') {
        !            93:                if (eq(*av, "-d")) {
        !            94:                        debug = true;
        !            95:                } else if (eq(*av, "-f")) {
        !            96:                        av++; ac--;
        !            97:                        if (*av)
        !            98:                                record_file = *av;
        !            99:                        else
        !           100:                                goto usage;
        !           101:                } else if (eq(*av, "-r")) {
        !           102:                        av++; ac--;
        !           103:                        if (*av)
        !           104:                                recfile = *av;
        !           105:                        else
        !           106:                                goto usage;
        !           107:                } else if (eq(*av, "-i")) {
        !           108:                        record_english = false;
        !           109:                } else if (eq(*av, "-R")) {
        !           110:                        randflag = true;
        !           111:                } else if (eq(*av, "-v")) {
        !           112:                        win_flashmove = true;
        !           113:                } else if (eq(*av, "-q")) {
        !           114:                        quickflag = true;
        !           115:                } else if (eq(*av, "-t")) {
        !           116:                        av++; ac--;
        !           117:                        if (*av) {
        !           118:                                movesperunit = atoi(*av);
        !           119:                                if (s = index(*av, '/'))
        !           120:                                        timeunit = atoi(s + 1) * 60;
        !           121:                                else
        !           122:                                        timeunit = 60;
        !           123:                        } else
        !           124:                                goto usage;
        !           125:                } else if (eq(*av, "-p")) {
        !           126:                        av++; ac--;
        !           127:                        if (*av)
        !           128:                                progname = *av;
        !           129:                        else
        !           130:                                goto usage;
        !           131:                } else if (eq(*av, "-h")) {
        !           132:                        av++; ac--;
        !           133:                        if (*av)
        !           134:                                proghost = *av;
        !           135:                        else
        !           136:                                goto usage;
        !           137:                } else if (eq(*av, "-b")) {
        !           138:                        blackflag = true;
        !           139:                } else if (eq(*av, "-c")) {
        !           140:                        progflag = true;
        !           141:                } else if (eq(*av, "-bnw")) {
        !           142:                        bnwflag = true;
        !           143:                } else if (eq(*av, "-s")) {
        !           144:                        saveflag = true;
        !           145:                } else if (eq(*av, "-n")) {
        !           146:                        noisyflag = true;
        !           147:                } else
        !           148:                        goto usage;
        !           149:                av++; ac--;
        !           150:        }
        !           151:        if (ac > 0)
        !           152:                dispname1 = av[0];
        !           153:        if (ac > 1)
        !           154:                dispname2 = av[1];
        !           155:        if (ac > 2)
        !           156:                goto usage;
        !           157: 
        !           158:        if (!dispname2)
        !           159:                oneboard = true;
        !           160:        
        !           161:        srandom(getpid());
        !           162: 
        !           163:        if (!oneboard && randflag && (random() % 2)) {
        !           164:                s = dispname1;
        !           165:                dispname1 = dispname2;
        !           166:                dispname2 = s;
        !           167:        }
        !           168:                
        !           169:        if (!dispname1)
        !           170:                dispname1 = getenv("DISPLAY");
        !           171:        
        !           172:        /* Set up the board. */
        !           173:        board_setup();
        !           174: 
        !           175:        /* Create the windows. */
        !           176:        win_setup(dispname1, dispname2);
        !           177: 
        !           178:        board_drawall();
        !           179: 
        !           180:        /* Start the program if necessary. */
        !           181:        if (progflag)
        !           182:                if (!program_init(progname))
        !           183:                        exit(1);
        !           184: 
        !           185:        if (recfile)
        !           186:                load_game(recfile);
        !           187: 
        !           188:        /* Go into a loop of prompting players alternately for moves, checking
        !           189:         * them, and updating things.
        !           190:         */
        !           191:        for (;;) {
        !           192:                win_process(false);
        !           193:                clock_update();
        !           194:                if (progflag && ((!blackflag && (nexttomove == BLACK)) ||
        !           195:                                (blackflag && (nexttomove == WHITE)))) {
        !           196:                        m = program_get();
        !           197:                        if (m)
        !           198:                                prog_move(m);
        !           199:                }
        !           200:        }
        !           201: 
        !           202: usage: fprintf(stderr, "Usage: %s\n", USAGE);
        !           203:        exit(1);
        !           204: }
        !           205: 

unix.superglobalmegacorp.com

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