Annotation of cci/usr/src/usr.lib/libF77/main.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     @(#)main.c      2.1
                      3:  */
                      4: #include <stdio.h>
                      5: #include <signal.h>
                      6: #include "../libI77/fiodefs.h"
                      7: 
                      8: #define ILL_ALIGN_FAULT 14
                      9: 
                     10: extern int errno;
                     11: char *getenv();
                     12: 
                     13: int xargc;
                     14: char **xargv;
                     15: 
                     16: main(argc, argv, arge)
                     17: int argc;
                     18: char **argv;
                     19: char **arge;
                     20: {
                     21: int sigdie();
                     22: long int (*sigf)();
                     23: int signum;
                     24: 
                     25: xargc = argc;
                     26: xargv = argv;
                     27: 
                     28: for (signum=1; signum<=16; signum++)
                     29: {
                     30:        if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
                     31: }
                     32: 
                     33: f_init();
                     34: MAIN_();
                     35: f_exit();
                     36: return 0;
                     37: }
                     38: 
                     39: struct action {
                     40:        char *mesg;
                     41:        int   core;
                     42: } sig_act[16] = {
                     43:        {"Hangup", 0},                  /* SIGHUP  */
                     44:        {"Interrupt!", 0},              /* SIGINT  */
                     45:        {"Quit!", 1},                   /* SIGQUIT */
                     46:        {"Illegal ", 1},                /* SIGILL  */
                     47:        {"Trace Trap", 1},              /* SIGTRAP */
                     48:        {"IOT Trap", 1},                /* SIGIOT  */
                     49:        {"EMT Trap", 1},                /* SIGEMT  */
                     50:        {"Arithmetic Exception", 1},    /* SIGFPE  */
                     51:        { 0, 0},                        /* SIGKILL */
                     52:        {"Bus error", 1},               /* SIGBUS  */
                     53:        {"Segmentation violation", 1},  /* SIGSEGV */
                     54:        {"Sys arg", 1},                 /* SIGSYS  */
                     55:        {"Open pipe", 0},               /* SIGPIPE */
                     56:        {"Alarm", 0},                   /* SIGALRM */
                     57:        {"Terminated", 0},              /* SIGTERM */
                     58:        {"Sig 16", 0},                  /* unassigned */
                     59: };
                     60: 
                     61: /* The following arrays are defined & used assuming that signal codes are 
                     62:    1 to 5 for SIGFPE, and 0 to 3 for SIGILL. 
                     63:    Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */
                     64: 
                     65: #define N_ACT_FPE 5                    /* number of entries in act_fpe[] */
                     66: 
                     67: struct action act_fpe[] = {
                     68:        {"Integer overflow", 1},
                     69:        {"Integer divide by 0", 1},
                     70:        {"Floating divide by zero", 1},
                     71:        {"Floating point overflow", 1},
                     72:        {"Floating point underflow", 1},
                     73: };
                     74: 
                     75: #define N_ACT_ILL 4                    /* number of entries in act_ill[] */
                     76: 
                     77: struct action act_ill[] = {
                     78:        {"addr mode", 1},
                     79:        {"instruction", 1},
                     80:        {"operand", 0},
                     81:        {"alignment", 1},
                     82: };
                     83: 
                     84: 
                     85: sigdie(s, t, sc)
                     86: int s; int t; struct sigcontext *sc;
                     87: {
                     88: extern unit units[];
                     89: register struct action *act = &sig_act[s-1];
                     90: /* print error message, then flush buffers */
                     91: 
                     92: if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
                     93:        signal(s, SIG_IGN);     /* don't allow it again */
                     94: else
                     95:        signal(s, SIG_DFL);     /* shouldn't happen again, but ... */
                     96: 
                     97: if (act->mesg)
                     98:        {
                     99:        fprintf(units[STDERR].ufd, "*** %s", act->mesg);
                    100:        if (s == SIGFPE)
                    101:                {
                    102:                if ((t-1) >= 0 && t < N_ACT_FPE)
                    103:                        fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
                    104:                else
                    105:                        fprintf(units[STDERR].ufd, ": Type=%d?", t);
                    106:                }
                    107:        else if (s == SIGILL)
                    108:                {
                    109:                if (t == ILL_ALIGN_FAULT)       /* ILL_ALIGN_FAULT maps to last
                    110:                        t = N_ACT_ILL-1;           entry in act_ill[] */
                    111:                if (t >= 0 && t < N_ACT_ILL)
                    112:                        fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
                    113:                else
                    114:                        fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
                    115:                }
                    116:        putc('\n', units[STDERR].ufd);
                    117:        }
                    118: f77_abort( s, act->core );
                    119: }
                    120: 
                    121: extern int _dbsubc;    /* dbsubc is non-zero if -lg was specified to ld */
                    122: f77_abort( err_val, act_core )
                    123: {
                    124:        char first_char, *env_var;
                    125:        int core_dump;
                    126: 
                    127:        env_var = getenv("f77_dump_flag");
                    128:        first_char = (env_var == NULL) ? 0 : *env_var;
                    129: 
                    130:        signal(SIGILL, SIG_DFL);
                    131:        sigsetmask(0);                  /* don't block */
                    132: 
                    133:        /* see if we want a core dump:
                    134:                first line checks for signals like hangup - don't dump then.
                    135:                second line checks if -lg specified to ld (e.g. by saying
                    136:                        -g to f77) and checks the f77_dump_flag var. */
                    137:        core_dump = ((nargs() != 2) || act_core) &&
                    138:            ( (_dbsubc && (first_char != 'n')) || first_char == 'y');
                    139: 
                    140:        if( !core_dump )
                    141:                fprintf(units[STDERR].ufd,"*** Execution terminated\n");
                    142: 
                    143:        f_exit();
                    144:        _cleanup();
                    145:        if( nargs() ) errno = err_val;
                    146:        else errno = -2;   /* prior value will be meaningless,
                    147:                                so set it to undefined value */
                    148: 
                    149:        if( core_dump ) abort();
                    150:        else  exit( errno );
                    151: }

unix.superglobalmegacorp.com

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