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