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

unix.superglobalmegacorp.com

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