remove Usef on clean
[unix-history] / usr / src / usr.bin / f77 / libF77 / main.c
index 5a791d5..11f40e2 100644 (file)
@@ -1,6 +1,10 @@
-/* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */
-char id_libF77[] = "@(#)main.c 2.3     %G%";
-
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)main.c      5.2     %G%
+ */
 #include <stdio.h>
 #include <signal.h>
 #include "../libI77/fiodefs.h"
 #include <stdio.h>
 #include <signal.h>
 #include "../libI77/fiodefs.h"
@@ -15,66 +19,105 @@ char **arge;
 {
 int sigdie();
 long int (*sigf)();
 {
 int sigdie();
 long int (*sigf)();
+int signum;
 
 xargc = argc;
 xargv = argv;
 
 xargc = argc;
 xargv = argv;
-signal(SIGFPE, sigdie);        /* ignore underflow, enable overflow */
-signal(SIGIOT, sigdie);
-if(sigf=signal(SIGQUIT, sigdie) != SIG_DFL) signal(SIGQUIT, sigf);
-if(sigf=signal(SIGINT,  sigdie) != SIG_DFL) signal(SIGINT,  sigf);
-if(sigf=signal(SIGTERM, sigdie) != SIG_DFL) signal(SIGTERM, sigf);
-if(sigf=signal(SIGILL,  sigdie) != SIG_DFL) signal(SIGILL,  sigf);
-if(sigf=signal(SIGEMT,  sigdie) != SIG_DFL) signal(SIGEMT,  sigf);
-if(sigf=signal(SIGBUS,  sigdie) != SIG_DFL) signal(SIGBUS,  sigf);
-if(sigf=signal(SIGSEGV, sigdie) != SIG_DFL) signal(SIGSEGV, sigf);
+
+for (signum=1; signum<=16; signum++)
+{
+       if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
+}
 
 #ifdef pdp11
        ldfps(01200); /* detect overflow as an exception */
 #endif
 
 f_init();
 
 #ifdef pdp11
        ldfps(01200); /* detect overflow as an exception */
 #endif
 
 f_init();
-MAIN__();
+MAIN_();
 f_exit();
 f_exit();
+return 0;
 }
 
 struct action {
        char *mesg;
        int   core;
 } sig_act[16] = {
 }
 
 struct action {
        char *mesg;
        int   core;
 } sig_act[16] = {
-       { 0, 0},                        /* SIGHUP  */
+       {"Hangup", 0},                  /* SIGHUP  */
        {"Interrupt!", 0},              /* SIGINT  */
        {"Quit!", 1},                   /* SIGQUIT */
        {"Interrupt!", 0},              /* SIGINT  */
        {"Quit!", 1},                   /* SIGQUIT */
-       {"Illegal instruction", 1},     /* SIGILL  */
-       { 0, 0},                        /* SIGTRAP */
+       {"Illegal ", 1},                /* SIGILL  */
+       {"Trace Trap", 1},              /* SIGTRAP */
        {"IOT Trap", 1},                /* SIGIOT  */
        {"IOT Trap", 1},                /* SIGIOT  */
-       {"EMT trap", 1},                /* SIGEMT  */
-       {"Floating Point Exception", 1},/* SIGFPE  */
+       {"EMT Trap", 1},                /* SIGEMT  */
+       {"Arithmetic Exception", 1},    /* SIGFPE  */
        { 0, 0},                        /* SIGKILL */
        {"Bus error", 1},               /* SIGBUS  */
        {"Segmentation violation", 1},  /* SIGSEGV */
        { 0, 0},                        /* SIGKILL */
        {"Bus error", 1},               /* SIGBUS  */
        {"Segmentation violation", 1},  /* SIGSEGV */
-       { 0, 0},                        /* SIGSYS  */
-       { 0, 0},                        /* SIGPIPE */
-       { 0, 0},                        /* SIGALRM */
+       {"Sys arg", 1},                 /* SIGSYS  */
+       {"Open pipe", 0},               /* SIGPIPE */
+       {"Alarm", 0},                   /* SIGALRM */
        {"Terminated", 0},              /* SIGTERM */
        {"Terminated", 0},              /* SIGTERM */
-       { 0, 0},                        /* unassigned */
+       {"Sig 16", 0},                  /* unassigned */
+};
+
+struct action act_fpe[] = {
+       {"Integer overflow", 1},
+       {"Integer divide by 0", 1},
+       {"Floating point overflow trap", 1},
+       {"Floating divide by zero trap", 1},
+       {"Floating point underflow trap", 1},
+       {"Decimal overflow", 1},
+       {"Subscript range", 1},
+       {"Floating point overflow", 0},
+       {"Floating divide by zero", 0},
+       {"Floating point underflow", 0},
 };
 
 };
 
+struct action act_ill[] = {
+       {"addr mode", 1},
+       {"instruction", 1},
+       {"operand", 0},
+};
+
+#if    vax
+sigdie(s, t, sc)
+int s; int t; struct sigcontext *sc;
+
+#else  pdp11
+sigdie(s, t, pc)
+int s; int t; long pc;
 
 
-sigdie(s)
-int s;
+#endif
 {
 extern unit units[];
 register struct action *act = &sig_act[s-1];
 {
 extern unit units[];
 register struct action *act = &sig_act[s-1];
-/* clear buffers, then print error message */
-f_exit();
-if (act->mesg) fprintf(units[STDERR].ufd, "%s\n", act->mesg);
-_cleanup();
+/* print error message, then flush buffers */
+
+if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
+       signal(s, SIG_IGN);     /* don't allow it again */
+else
+       signal(s, SIG_DFL);     /* shouldn't happen again, but ... */
 
 
-if(act->core)
+if (act->mesg)
        {
        {
-       /* now get a core */
-       signal(SIGIOT, SIG_DFL);
-       abort();
+       fprintf(units[STDERR].ufd, "*** %s", act->mesg);
+       if (s == SIGFPE)
+               {
+               if (t >= 1 && t <= 10)
+                       fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
+               else
+                       fprintf(units[STDERR].ufd, ": Type=%d?", t);
+               }
+       else if (s == SIGILL)
+               {
+               if (t == 4) t = 2;      /* 4.0bsd botch */
+               if (t >= 0 && t <= 2)
+                       fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
+               else
+                       fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
+               }
+       putc('\n', units[STDERR].ufd);
        }
        }
-exit(s);
+f77_abort( s, act->core );
 }
 }