Annotation of researchv10no/cmd/sh/error.c, revision 1.1.1.1

1.1       root        1: /*     @(#)error.c     1.4     */
                      2: /*
                      3:  * UNIX shell
                      4:  *
                      5:  * Bell Telephone Laboratories
                      6:  *
                      7:  */
                      8: 
                      9: #include       "defs.h"
                     10: 
                     11: 
                     12: /* ========    error handling  ======== */
                     13: 
                     14: failed(s1, s2, per)
                     15: char   *s1, *s2;
                     16: {
                     17:        extern int sys_nerr;
                     18:        extern char *sys_errlist[];
                     19:        extern int errno;
                     20: 
                     21:        prp();
                     22:        prs_cntl(s1);
                     23:        if (s2)
                     24:        {
                     25:                prs(colon);
                     26:                prs(s2);
                     27:        }
                     28:        if (per)
                     29:        {
                     30:                if (errno >= 0 && errno < sys_nerr) {
                     31:                        prs(colon);
                     32:                        prs(sys_errlist[errno]);
                     33:                } else {
                     34: #if NOTDEF             /* prn gets negative numbers wrong */
                     35:                        prs(": error ");
                     36:                        prn(errno);
                     37: #else
                     38:                        prs(": Unknown error");
                     39: #endif
                     40:                }
                     41:        }
                     42:        newline();
                     43:        exitsh(ERROR);
                     44: }
                     45: 
                     46: error(s)
                     47: char   *s;
                     48: {
                     49:        failed(s, NIL, 0);
                     50: }
                     51: 
                     52: exitsh(xno)
                     53: int    xno;
                     54: {
                     55:        /*
                     56:         * Arrive here from `FATAL' errors
                     57:         *  a) exit command,
                     58:         *  b) default trap,
                     59:         *  c) fault with no trap set.
                     60:         *
                     61:         * Action is to return to command level or exit.
                     62:         */
                     63:        exitval = xno;
                     64:        flags |= eflag;
                     65:        if ((flags & (forked | errflg | ttyflg)) != ttyflg)
                     66:                done();
                     67:        else
                     68:        {
                     69:                clearup();
                     70:                restore(0);
                     71:                clear_buff();
                     72:                execbrk = breakcnt = funcnt = 0;
                     73:                longjmp(errshell, 1);
                     74:        }
                     75: }
                     76: 
                     77: done()
                     78: {
                     79:        register char   *t;
                     80: 
                     81:        if (t = trapcom[0])
                     82:        {
                     83:                trapcom[0] = 0;
                     84:                execexp(t, 0);
                     85:                shfree(t);
                     86:        }
                     87:        else
                     88:                chktrap();
                     89: 
                     90:        rmtemp(0);
                     91:        rmfunctmp();
                     92: 
                     93: #ifdef ACCT
                     94:        doacct();
                     95: #endif
                     96:        exit(exitval);
                     97: }
                     98: 
                     99: rmtemp(base)
                    100: struct ionod   *base;
                    101: {
                    102:        while (iotemp > base)
                    103:        {
                    104:                unlink(iotemp->ioname);
                    105:                shfree(iotemp->iolink);
                    106:                iotemp = iotemp->iolst;
                    107:        }
                    108: }
                    109: 
                    110: rmfunctmp()
                    111: {
                    112:        while (fiotemp)
                    113:        {
                    114:                unlink(fiotemp->ioname);
                    115:                fiotemp = fiotemp->iolst;
                    116:        }
                    117: }

unix.superglobalmegacorp.com

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