Annotation of 43BSDReno/games/larn/signal.c, revision 1.1

1.1     ! root        1: #include <signal.h>
        !             2: #include "header.h"                    /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
        !             3: #define BIT(a) (1<<((a)-1))
        !             4: extern char savefilename[],wizard,predostuff,nosignal;
        !             5: static s2choose()      /* text to be displayed if ^C during intro screen */
        !             6:        {
        !             7:        cursor(1,24); lprcat("Press "); setbold(); lprcat("return"); resetbold();
        !             8:        lprcat(" to continue: ");   lflush(); 
        !             9:        }
        !            10: 
        !            11: static cntlc() /* what to do for a ^C */
        !            12:        {
        !            13:        if (nosignal) return;   /* don't do anything if inhibited */
        !            14:        signal(SIGQUIT,SIG_IGN);        signal(SIGINT,SIG_IGN);
        !            15:        quit(); if (predostuff==1) s2choose(); else showplayer();
        !            16:        lflush();
        !            17:        signal(SIGQUIT,cntlc);  signal(SIGINT,cntlc);
        !            18:        }
        !            19: 
        !            20: /*
        !            21:  *     subroutine to save the game if a hangup signal
        !            22:  */
        !            23: static sgam()
        !            24:        {
        !            25:        savegame(savefilename);  wizard=1;  died(-257); /* hangup signal */
        !            26:        }
        !            27: 
        !            28: #ifdef SIGTSTP
        !            29: static tstop() /* control Y    */
        !            30:        {
        !            31:        if (nosignal)   return;  /* nothing if inhibited */
        !            32:        lcreat((char*)0);  clearvt100();        lflush();         signal(SIGTSTP,SIG_DFL);
        !            33: #ifdef SIGVTALRM
        !            34:        /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/
        !            35:        sigsetmask(sigblock(0)& ~BIT(SIGTSTP));
        !            36: #endif
        !            37:        kill(getpid(),SIGTSTP);
        !            38: 
        !            39:        setupvt100();  signal(SIGTSTP,tstop);
        !            40:        if (predostuff==1) s2choose(); else drawscreen();
        !            41:        showplayer();   lflush();
        !            42:        }
        !            43: #endif SIGTSTP
        !            44: 
        !            45: /*
        !            46:  *     subroutine to issue the needed signal traps  called from main()
        !            47:  */
        !            48: static sigill()  { sigpanic(SIGILL); }  static sigtrap() { sigpanic(SIGTRAP); }
        !            49: static sigiot()  { sigpanic(SIGIOT); }   static sigemt()  { sigpanic(SIGEMT); }
        !            50: static sigfpe()  { sigpanic(SIGFPE); }   static sigbus()  { sigpanic(SIGBUS); }
        !            51: static sigsegv() { sigpanic(SIGSEGV); }  static sigsys()  { sigpanic(SIGSYS); }
        !            52: static sigpipe() { sigpanic(SIGPIPE); }  static sigterm() { sigpanic(SIGTERM); }
        !            53: sigsetup()
        !            54:        {
        !            55:        signal(SIGQUIT, cntlc);                 signal(SIGINT,  cntlc); 
        !            56:        signal(SIGKILL, SIG_IGN);               signal(SIGHUP,  sgam);
        !            57:        signal(SIGILL,  sigill);                signal(SIGTRAP, sigtrap);
        !            58:        signal(SIGIOT,  sigiot);                signal(SIGEMT,  sigemt);
        !            59:        signal(SIGFPE,  sigfpe);                signal(SIGBUS,  sigbus);
        !            60:        signal(SIGSEGV, sigsegv);               signal(SIGSYS,  sigsys);
        !            61:        signal(SIGPIPE, sigpipe);               signal(SIGTERM, sigterm);
        !            62: #ifdef SIGTSTP
        !            63:        signal(SIGTSTP,tstop);          signal(SIGSTOP,tstop);
        !            64: #endif SIGTSTP
        !            65:        }
        !            66: 
        !            67: #ifdef BSD     /* for BSD UNIX? */
        !            68: 
        !            69: static char *signame[NSIG] = { "",
        !            70: "SIGHUP",  /*  1        hangup */
        !            71: "SIGINT",  /*  2        interrupt */
        !            72: "SIGQUIT", /*  3        quit */
        !            73: "SIGILL",  /*  4        illegal instruction (not reset when caught) */
        !            74: "SIGTRAP", /*  5        trace trap (not reset when caught) */
        !            75: "SIGIOT",  /*  6        IOT instruction */
        !            76: "SIGEMT",  /*  7        EMT instruction */
        !            77: "SIGFPE",  /*  8        floating point exception */
        !            78: "SIGKILL", /*  9        kill (cannot be caught or ignored) */
        !            79: "SIGBUS",  /*  10       bus error */
        !            80: "SIGSEGV", /*  11       segmentation violation */
        !            81: "SIGSYS",  /*  12       bad argument to system call */
        !            82: "SIGPIPE", /*  13       write on a pipe with no one to read it */
        !            83: "SIGALRM", /*  14       alarm clock */
        !            84: "SIGTERM", /*  15       software termination signal from kill */
        !            85: "SIGURG",  /*  16       urgent condition on IO channel */
        !            86: "SIGSTOP", /*  17       sendable stop signal not from tty */
        !            87: "SIGTSTP", /*  18       stop signal from tty */
        !            88: "SIGCONT", /*  19       continue a stopped process */
        !            89: "SIGCHLD", /*  20       to parent on child stop or exit */
        !            90: "SIGTTIN", /*  21       to readers pgrp upon background tty read */
        !            91: "SIGTTOU", /*  22       like TTIN for output if (tp->t_local&LTOSTOP) */
        !            92: "SIGIO",   /*  23       input/output possible signal */
        !            93: "SIGXCPU", /*  24       exceeded CPU time limit */
        !            94: "SIGXFSZ", /*  25       exceeded file size limit */
        !            95: "SIGVTALRM",/*  26      virtual time alarm */
        !            96: "SIGPROF", /*  27       profiling time alarm */
        !            97: "","","","" };
        !            98: 
        !            99: #else BSD      /* for system V? */
        !           100: 
        !           101: static char *signame[NSIG] = { "",
        !           102: "SIGHUP",  /*  1        hangup */
        !           103: "SIGINT",  /*  2        interrupt */
        !           104: "SIGQUIT", /*  3        quit */
        !           105: "SIGILL",  /*  4        illegal instruction (not reset when caught) */
        !           106: "SIGTRAP", /*  5        trace trap (not reset when caught) */
        !           107: "SIGIOT",  /*  6        IOT instruction */
        !           108: "SIGEMT",  /*  7        EMT instruction */
        !           109: "SIGFPE",  /*  8        floating point exception */
        !           110: "SIGKILL", /*  9        kill (cannot be caught or ignored) */
        !           111: "SIGBUS",  /*  10       bus error */
        !           112: "SIGSEGV", /*  11       segmentation violation */
        !           113: "SIGSYS",  /*  12       bad argument to system call */
        !           114: "SIGPIPE", /*  13       write on a pipe with no one to read it */
        !           115: "SIGALRM", /*  14       alarm clock */
        !           116: "SIGTERM", /*  15       software termination signal from kill */
        !           117: "SIGUSR1",  /* 16       user defines signal 1 */
        !           118: "SIGUSR2", /*  17       user defines signal 2 */
        !           119: "SIGCLD",  /*  18       child death */
        !           120: "SIGPWR",  /*  19       power fail */
        !           121: "","","","","","","","","","","","" };
        !           122: 
        !           123: #endif BSD
        !           124: 
        !           125: /*
        !           126:  *     routine to process a fatal error signal
        !           127:  */
        !           128: static sigpanic(sig)
        !           129:        int sig;
        !           130:        {
        !           131:        char buf[128];
        !           132:        signal(sig,SIG_DFL);
        !           133:        sprintf(buf,"\nLarn - Panic! Signal %d received [%s]",sig,signame[sig]);
        !           134:        write(2,buf,strlen(buf));  sleep(2);
        !           135:        sncbr();
        !           136:        savegame(savefilename); 
        !           137:        kill(getpid(),sig); /* this will terminate us */
        !           138:        }

unix.superglobalmegacorp.com

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