xref: /original-bsd/usr.bin/f77/libF77/main.c (revision 90bde559)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)main.c	5.5	05/29/90
7  */
8 #include <stdio.h>
9 #include <signal.h>
10 #include "../libI77/fiodefs.h"
11 
12 extern int errno;
13 char *getenv();
14 int xargc;
15 char **xargv;
16 
17 main(argc, argv, arge)
18 int argc;
19 char **argv;
20 char **arge;
21 {
22 void sigdie();
23 sig_t sigf;
24 int signum;
25 
26 xargc = argc;
27 xargv = argv;
28 
29 for (signum=1; signum<=16; signum++)
30 {
31 	if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
32 }
33 
34 #ifdef pdp11
35 	ldfps(01200); /* detect overflow as an exception */
36 #endif
37 
38 f_init();
39 MAIN_();
40 f_exit();
41 return 0;
42 }
43 
44 struct action {
45 	char *mesg;
46 	int   core;
47 } sig_act[16] = {
48 	{"Hangup", 0},			/* SIGHUP  */
49 	{"Interrupt!", 0},		/* SIGINT  */
50 	{"Quit!", 1},			/* SIGQUIT */
51 	{"Illegal ", 1},		/* SIGILL  */
52 	{"Trace Trap", 1},		/* SIGTRAP */
53 	{"IOT Trap", 1},		/* SIGIOT  */
54 	{"EMT Trap", 1},		/* SIGEMT  */
55 	{"Arithmetic Exception", 1},	/* SIGFPE  */
56 	{ 0, 0},			/* SIGKILL */
57 	{"Bus error", 1},		/* SIGBUS  */
58 	{"Segmentation violation", 1},	/* SIGSEGV */
59 	{"Sys arg", 1},			/* SIGSYS  */
60 	{"Open pipe", 0},		/* SIGPIPE */
61 	{"Alarm", 0},			/* SIGALRM */
62 	{"Terminated", 0},		/* SIGTERM */
63 	{"Sig 16", 0},			/* unassigned */
64 };
65 
66 #ifdef tahoe
67 /* The following arrays are defined & used assuming that signal codes are
68    1 to 5 for SIGFPE, and 0 to 3 for SIGILL.
69    Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */
70 
71 #define N_ACT_ILL 4			/* number of entries in act_ill[] */
72 #define N_ACT_FPE 5			/* number of entries in act_fpe[] */
73 #define ILL_ALIGN_FAULT 14
74 
75 struct action act_fpe[] = {
76 	{"Integer overflow", 1},
77 	{"Integer divide by 0", 1},
78 	{"Floating divide by zero", 1},
79 	{"Floating point overflow", 1},
80 	{"Floating point underflow", 1},
81 };
82 
83 #else vax || pdp11
84 
85 struct action act_fpe[] = {
86 	{"Integer overflow", 1},
87 	{"Integer divide by 0", 1},
88 	{"Floating point overflow trap", 1},
89 	{"Floating divide by zero trap", 1},
90 	{"Floating point underflow trap", 1},
91 	{"Decimal overflow", 1},
92 	{"Subscript range", 1},
93 	{"Floating point overflow", 0},
94 	{"Floating divide by zero", 0},
95 	{"Floating point underflow", 0},
96 };
97 #endif vax || pdp11
98 
99 struct action act_ill[] = {
100 	{"addr mode", 1},
101 	{"instruction", 1},
102 	{"operand", 0},
103 #ifdef tahoe
104 	{"alignment", 1},
105 #endif tahoe
106 };
107 
108 #if (defined(vax) || defined(tahoe))
109 void
110 sigdie(s, t, sc)
111 int s; int t; struct sigcontext *sc;
112 
113 #else	pdp11
114 
115 void
116 sigdie(s, t, pc)
117 int s; int t; long pc;
118 
119 #endif pdp11
120 {
121 extern unit units[];
122 register struct action *act = &sig_act[s-1];
123 /* print error message, then flush buffers */
124 
125 if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
126 	signal(s, SIG_IGN);	/* don't allow it again */
127 else
128 	signal(s, SIG_DFL);	/* shouldn't happen again, but ... */
129 
130 if (act->mesg)
131 	{
132 	fprintf(units[STDERR].ufd, "*** %s", act->mesg);
133 	if (s == SIGFPE)
134 		{
135 #ifndef tahoe
136 		if (t >= 1 && t <= 10)
137 #else tahoe
138 		if ((t-1) >= 0 && t < N_ACT_FPE)
139 #endif tahoe
140 			fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
141 		else
142 			fprintf(units[STDERR].ufd, ": Type=%d?", t);
143 		}
144 	else if (s == SIGILL)
145 		{
146 #ifndef tahoe
147 		if (t == 4) t = 2;	/* 4.0bsd botch */
148 		if (t >= 0 && t <= 2)
149 #else tahoe
150 		if (t == ILL_ALIGN_FAULT)	/* ILL_ALIGN_FAULT maps to last
151 			t = N_ACT_ILL-1;   	   entry in act_ill[] */
152 		if (t >= 0 && t < N_ACT_ILL)
153 #endif tahoe
154 			fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
155 		else
156 			fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
157 		}
158 	putc('\n', units[STDERR].ufd);
159 	}
160 f77_abort( s, act->core );
161 }
162