Annotation of 43BSDReno/games/sail/pl_1.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 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: static char sccsid[] = "@(#)pl_1.c     5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include "player.h"
        !            25: #include <sys/types.h>
        !            26: #include <sys/wait.h>
        !            27: 
        !            28: /*
        !            29:  * If we get here before a ship is chosen, then ms == 0 and
        !            30:  * we don't want to update the score file, or do any Write's either.
        !            31:  * We can assume the sync file is already created and may need
        !            32:  * to be removed.
        !            33:  * Of course, we don't do any more Sync()'s if we got here
        !            34:  * because of a Sync() failure.
        !            35:  */
        !            36: leave(conditions)
        !            37: int conditions;
        !            38: {
        !            39:        (void) signal(SIGHUP, SIG_IGN);
        !            40:        (void) signal(SIGINT, SIG_IGN);
        !            41:        (void) signal(SIGQUIT, SIG_IGN);
        !            42:        (void) signal(SIGALRM, SIG_IGN);
        !            43:        (void) signal(SIGCHLD, SIG_IGN);
        !            44: 
        !            45:        if (done_curses) {
        !            46:                Signal("It looks like you've had it!",
        !            47:                        (struct ship *)0);
        !            48:                switch (conditions) {
        !            49:                case LEAVE_QUIT:
        !            50:                        break;
        !            51:                case LEAVE_CAPTURED:
        !            52:                        Signal("Your ship was captured.",
        !            53:                                (struct ship *)0);
        !            54:                        break;
        !            55:                case LEAVE_HURRICAN:
        !            56:                        Signal("Hurricane!  All ships destroyed.",
        !            57:                                (struct ship *)0);
        !            58:                        break;
        !            59:                case LEAVE_DRIVER:
        !            60:                        Signal("The driver died.", (struct ship *)0);
        !            61:                        break;
        !            62:                case LEAVE_SYNC:
        !            63:                        Signal("Synchronization error.", (struct ship *)0);
        !            64:                        break;
        !            65:                default:
        !            66:                        Signal("A funny thing happened (%d).",
        !            67:                                (struct ship *)0, conditions);
        !            68:                }
        !            69:        } else {
        !            70:                switch (conditions) {
        !            71:                case LEAVE_QUIT:
        !            72:                        break;
        !            73:                case LEAVE_DRIVER:
        !            74:                        printf("The driver died.\n");
        !            75:                        break;
        !            76:                case LEAVE_FORK:
        !            77:                        perror("fork");
        !            78:                        break;
        !            79:                case LEAVE_SYNC:
        !            80:                        printf("Synchronization error\n.");
        !            81:                        break;
        !            82:                default:
        !            83:                        printf("A funny thing happened (%d).\n",
        !            84:                                conditions);
        !            85:                }
        !            86:        }
        !            87: 
        !            88:        if (ms != 0) {
        !            89:                log(ms);
        !            90:                if (conditions != LEAVE_SYNC) {
        !            91:                        makesignal(ms, "Captain %s relinquishing.",
        !            92:                                (struct ship *)0, mf->captain);
        !            93:                        Write(W_END, ms, 0, 0, 0, 0, 0);
        !            94:                        (void) Sync();
        !            95:                }
        !            96:        }
        !            97:        sync_close(!hasdriver);
        !            98:        cleanupscreen();
        !            99:        exit(0);
        !           100: }
        !           101: 
        !           102: choke()
        !           103: {
        !           104:        leave(LEAVE_QUIT);
        !           105: }
        !           106: 
        !           107: child()
        !           108: {
        !           109:        union wait status;
        !           110:        int pid;
        !           111: 
        !           112:        (void) signal(SIGCHLD, SIG_IGN);
        !           113:        do {
        !           114:                pid = wait3(&status, WNOHANG, (struct rusage *)0);
        !           115:                if (pid < 0 || pid > 0 && !WIFSTOPPED(status))
        !           116:                        hasdriver = 0;
        !           117:        } while (pid > 0);
        !           118:        (void) signal(SIGCHLD, child);
        !           119: }

unix.superglobalmegacorp.com

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