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