Annotation of 43BSDReno/games/robots/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
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF 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.4 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: # include      "robots.h"
        !            31: # include      <signal.h>
        !            32: # include      <ctype.h>
        !            33: 
        !            34: main(ac, av)
        !            35: int    ac;
        !            36: char   **av;
        !            37: {
        !            38:        register char   *sp;
        !            39:        register bool   bad_arg;
        !            40:        register bool   show_only;
        !            41:        extern char     *Scorefile;
        !            42:        extern int      Max_per_uid;
        !            43:        extern char     *rindex();
        !            44: 
        !            45:        show_only = FALSE;
        !            46:        if (ac > 1) {
        !            47:                bad_arg = FALSE;
        !            48:                for (++av; ac > 1 && *av[0]; av++, ac--)
        !            49:                        if (av[0][0] != '-')
        !            50:                                if (isdigit(av[0][0]))
        !            51:                                        Max_per_uid = atoi(av[0]);
        !            52:                                else {
        !            53:                                        setuid(getuid());
        !            54:                                        setgid(getgid());
        !            55:                                        Scorefile = av[0];
        !            56: # ifdef        FANCY
        !            57:                                        sp = rindex(Scorefile, '/');
        !            58:                                        if (sp == NULL)
        !            59:                                                sp = Scorefile;
        !            60:                                        if (strcmp(sp, "pattern_roll") == 0)
        !            61:                                                Pattern_roll = TRUE;
        !            62:                                        else if (strcmp(sp, "stand_still") == 0)
        !            63:                                                Stand_still = TRUE;
        !            64:                                        if (Pattern_roll || Stand_still)
        !            65:                                                Teleport = TRUE;
        !            66: # endif
        !            67:                                }
        !            68:                        else
        !            69:                                for (sp = &av[0][1]; *sp; sp++)
        !            70:                                        switch (*sp) {
        !            71:                                          case 's':
        !            72:                                                show_only = TRUE;
        !            73:                                                break;
        !            74:                                          case 'r':
        !            75:                                                Real_time = TRUE;
        !            76:                                                break;
        !            77:                                          case 'a':
        !            78:                                                Start_level = 4;
        !            79:                                                break;
        !            80:                                          case 'j':
        !            81:                                                Jump = TRUE;
        !            82:                                                break;
        !            83:                                          case 't':
        !            84:                                                Teleport = TRUE;
        !            85:                                                break;
        !            86:                                          default:
        !            87:                                                fprintf(stderr, "robots: uknown option: %c\n", *sp);
        !            88:                                                bad_arg = TRUE;
        !            89:                                                break;
        !            90:                                        }
        !            91:                if (bad_arg) {
        !            92:                        exit(1);
        !            93:                        /* NOTREACHED */
        !            94:                }
        !            95:        }
        !            96: 
        !            97:        if (show_only) {
        !            98:                show_score();
        !            99:                exit(0);
        !           100:                /* NOTREACHED */
        !           101:        }
        !           102: 
        !           103:        initscr();
        !           104:        signal(SIGINT, quit);
        !           105:        crmode();
        !           106:        noecho();
        !           107:        nonl();
        !           108:        if (LINES != Y_SIZE || COLS != X_SIZE) {
        !           109:                if (LINES < Y_SIZE || COLS < X_SIZE) {
        !           110:                        endwin();
        !           111:                        printf("Need at least a %dx%d screen\n", Y_SIZE, X_SIZE);
        !           112:                        exit(1);
        !           113:                }
        !           114:                delwin(stdscr);
        !           115:                stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
        !           116:        }
        !           117: 
        !           118:        srand(getpid());
        !           119:        if (Real_time)
        !           120:                signal(SIGALRM, move_robots);
        !           121:        do {
        !           122:                init_field();
        !           123:                for (Level = Start_level; !Dead; Level++) {
        !           124:                        make_level();
        !           125:                        play_level();
        !           126:                }
        !           127:                move(My_pos.y, My_pos.x);
        !           128:                printw("AARRrrgghhhh....");
        !           129:                refresh();
        !           130:                score();
        !           131:        } while (another());
        !           132:        quit();
        !           133: }
        !           134: 
        !           135: /*
        !           136:  * quit:
        !           137:  *     Leave the program elegantly.
        !           138:  */
        !           139: quit()
        !           140: {
        !           141:        extern int      _putchar();
        !           142: 
        !           143:        mvcur(0, COLS - 1, LINES - 1, 0);
        !           144:        if (CE) {
        !           145:                tputs(CE, 1, _putchar);
        !           146:                endwin();
        !           147:        }
        !           148:        else {
        !           149:                endwin();
        !           150:                putchar('\n');
        !           151:        }
        !           152:        exit(0);
        !           153:        /* NOTREACHED */
        !           154: }
        !           155: 
        !           156: /*
        !           157:  * another:
        !           158:  *     See if another game is desired
        !           159:  */
        !           160: another()
        !           161: {
        !           162:        register int    y;
        !           163: 
        !           164: #ifdef FANCY
        !           165:        if ((Stand_still || Pattern_roll) && !Newscore)
        !           166:                return TRUE;
        !           167: #endif
        !           168: 
        !           169:        if (query("Another game?")) {
        !           170:                if (Full_clear) {
        !           171:                        for (y = 1; y <= Num_scores; y++) {
        !           172:                                move(y, 1);
        !           173:                                clrtoeol();
        !           174:                        }
        !           175:                        refresh();
        !           176:                }
        !           177:                return TRUE;
        !           178:        }
        !           179:        return FALSE;
        !           180: }

unix.superglobalmegacorp.com

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