xref: /original-bsd/usr.bin/f77/libF77/main.c (revision e9696cc1)
18d528b7aSbostic /*-
28d528b7aSbostic  * Copyright (c) 1980 The Regents of the University of California.
38d528b7aSbostic  * All rights reserved.
4e778201eSkre  *
58d528b7aSbostic  * %sccs.include.proprietary.c%
6e778201eSkre  */
78d528b7aSbostic 
8*e9696cc1Sbostic /*
9*e9696cc1Sbostic  * Don't split the copyright notice over two lines, it makes mkvers
10*e9696cc1Sbostic  * unhappy.
11*e9696cc1Sbostic  */
128d528b7aSbostic #ifndef lint
138d528b7aSbostic char copyright[] =
14*e9696cc1Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n All rights reserved.\n";
158d528b7aSbostic #endif /* not lint */
168d528b7aSbostic 
178d528b7aSbostic #ifndef lint
18*e9696cc1Sbostic static char sccsid[] = "@(#)main.c	5.7 (Berkeley) 11/13/91";
198d528b7aSbostic #endif /* not lint */
208d528b7aSbostic 
21f6a36eabSdlw #include <stdio.h>
22f6a36eabSdlw #include <signal.h>
23ea4435f8Sdlw #include "../libI77/fiodefs.h"
24f6a36eabSdlw 
250ff5cf41Smckusick extern int errno;
260ff5cf41Smckusick char *getenv();
27f6a36eabSdlw int xargc;
28f6a36eabSdlw char **xargv;
29f6a36eabSdlw 
main(argc,argv,arge)30f6a36eabSdlw main(argc, argv, arge)
31f6a36eabSdlw int argc;
32f6a36eabSdlw char **argv;
33f6a36eabSdlw char **arge;
34f6a36eabSdlw {
354847e0f7Sbostic void sigdie();
36cf6d160eSbostic sig_t sigf;
370bd11cf3Sdlw int signum;
38f6a36eabSdlw 
39f6a36eabSdlw xargc = argc;
40f6a36eabSdlw xargv = argv;
410bd11cf3Sdlw 
420bd11cf3Sdlw for (signum=1; signum<=16; signum++)
430bd11cf3Sdlw {
440bd11cf3Sdlw 	if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
450bd11cf3Sdlw }
46f6a36eabSdlw 
47f6a36eabSdlw #ifdef pdp11
48f6a36eabSdlw 	ldfps(01200); /* detect overflow as an exception */
49f6a36eabSdlw #endif
50f6a36eabSdlw 
51f6a36eabSdlw f_init();
52a1c68f5dSfortran MAIN_();
53f6a36eabSdlw f_exit();
54edb0e733Slibs return 0;
55f6a36eabSdlw }
56f6a36eabSdlw 
57743fa628Sdlw struct action {
58743fa628Sdlw 	char *mesg;
59ea4435f8Sdlw 	int   core;
60743fa628Sdlw } sig_act[16] = {
610bd11cf3Sdlw 	{"Hangup", 0},			/* SIGHUP  */
62743fa628Sdlw 	{"Interrupt!", 0},		/* SIGINT  */
63743fa628Sdlw 	{"Quit!", 1},			/* SIGQUIT */
642a4a0a24Sdlw 	{"Illegal ", 1},		/* SIGILL  */
650bd11cf3Sdlw 	{"Trace Trap", 1},		/* SIGTRAP */
66743fa628Sdlw 	{"IOT Trap", 1},		/* SIGIOT  */
67731a835bSdlw 	{"EMT Trap", 1},		/* SIGEMT  */
68bc2756f6Sdlw 	{"Arithmetic Exception", 1},	/* SIGFPE  */
69743fa628Sdlw 	{ 0, 0},			/* SIGKILL */
70743fa628Sdlw 	{"Bus error", 1},		/* SIGBUS  */
71743fa628Sdlw 	{"Segmentation violation", 1},	/* SIGSEGV */
720bd11cf3Sdlw 	{"Sys arg", 1},			/* SIGSYS  */
730bd11cf3Sdlw 	{"Open pipe", 0},		/* SIGPIPE */
740bd11cf3Sdlw 	{"Alarm", 0},			/* SIGALRM */
75743fa628Sdlw 	{"Terminated", 0},		/* SIGTERM */
760bd11cf3Sdlw 	{"Sig 16", 0},			/* unassigned */
77743fa628Sdlw };
78743fa628Sdlw 
790ff5cf41Smckusick #ifdef tahoe
800ff5cf41Smckusick /* The following arrays are defined & used assuming that signal codes are
810ff5cf41Smckusick    1 to 5 for SIGFPE, and 0 to 3 for SIGILL.
820ff5cf41Smckusick    Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */
830ff5cf41Smckusick 
840ff5cf41Smckusick #define N_ACT_ILL 4			/* number of entries in act_ill[] */
850ff5cf41Smckusick #define N_ACT_FPE 5			/* number of entries in act_fpe[] */
860ff5cf41Smckusick #define ILL_ALIGN_FAULT 14
870ff5cf41Smckusick 
880ff5cf41Smckusick struct action act_fpe[] = {
890ff5cf41Smckusick 	{"Integer overflow", 1},
900ff5cf41Smckusick 	{"Integer divide by 0", 1},
910ff5cf41Smckusick 	{"Floating divide by zero", 1},
920ff5cf41Smckusick 	{"Floating point overflow", 1},
930ff5cf41Smckusick 	{"Floating point underflow", 1},
940ff5cf41Smckusick };
950ff5cf41Smckusick 
960ff5cf41Smckusick #else vax || pdp11
970ff5cf41Smckusick 
98bc2756f6Sdlw struct action act_fpe[] = {
99bc2756f6Sdlw 	{"Integer overflow", 1},
100bc2756f6Sdlw 	{"Integer divide by 0", 1},
10162b8e8a3Sdlw 	{"Floating point overflow trap", 1},
10262b8e8a3Sdlw 	{"Floating divide by zero trap", 1},
10362b8e8a3Sdlw 	{"Floating point underflow trap", 1},
104bc2756f6Sdlw 	{"Decimal overflow", 1},
105bc2756f6Sdlw 	{"Subscript range", 1},
106bc2756f6Sdlw 	{"Floating point overflow", 0},
107bc2756f6Sdlw 	{"Floating divide by zero", 0},
108bc2756f6Sdlw 	{"Floating point underflow", 0},
109bc2756f6Sdlw };
1100ff5cf41Smckusick #endif vax || pdp11
1112a4a0a24Sdlw 
1122a4a0a24Sdlw struct action act_ill[] = {
1132a4a0a24Sdlw 	{"addr mode", 1},
1142a4a0a24Sdlw 	{"instruction", 1},
1152a4a0a24Sdlw 	{"operand", 0},
1160ff5cf41Smckusick #ifdef tahoe
1170ff5cf41Smckusick 	{"alignment", 1},
1180ff5cf41Smckusick #endif tahoe
1192a4a0a24Sdlw };
120743fa628Sdlw 
1210ff5cf41Smckusick #if (defined(vax) || defined(tahoe))
1224847e0f7Sbostic void
sigdie(s,t,sc)12339a0928aSdlw sigdie(s, t, sc)
12439a0928aSdlw int s; int t; struct sigcontext *sc;
12539a0928aSdlw 
12639a0928aSdlw #else	pdp11
1270ff5cf41Smckusick 
1284847e0f7Sbostic void
129bc2756f6Sdlw sigdie(s, t, pc)
130bc2756f6Sdlw int s; int t; long pc;
13139a0928aSdlw 
1320ff5cf41Smckusick #endif pdp11
133ea4435f8Sdlw {
134ea4435f8Sdlw extern unit units[];
135743fa628Sdlw register struct action *act = &sig_act[s-1];
136712d3d7aSdlw /* print error message, then flush buffers */
137712d3d7aSdlw 
138a4712720Sdlw if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
139a4712720Sdlw 	signal(s, SIG_IGN);	/* don't allow it again */
140a4712720Sdlw else
141a4712720Sdlw 	signal(s, SIG_DFL);	/* shouldn't happen again, but ... */
142a4712720Sdlw 
143bc2756f6Sdlw if (act->mesg)
144bc2756f6Sdlw 	{
145a0bf07c1Sdlw 	fprintf(units[STDERR].ufd, "*** %s", act->mesg);
146bc2756f6Sdlw 	if (s == SIGFPE)
1470bd11cf3Sdlw 		{
1480ff5cf41Smckusick #ifndef tahoe
1490bd11cf3Sdlw 		if (t >= 1 && t <= 10)
1500ff5cf41Smckusick #else tahoe
1510ff5cf41Smckusick 		if ((t-1) >= 0 && t < N_ACT_FPE)
1520ff5cf41Smckusick #endif tahoe
1530bd11cf3Sdlw 			fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
154bc2756f6Sdlw 		else
1550bd11cf3Sdlw 			fprintf(units[STDERR].ufd, ": Type=%d?", t);
1560bd11cf3Sdlw 		}
1570bd11cf3Sdlw 	else if (s == SIGILL)
1582a4a0a24Sdlw 		{
1590ff5cf41Smckusick #ifndef tahoe
1602a4a0a24Sdlw 		if (t == 4) t = 2;	/* 4.0bsd botch */
1612a4a0a24Sdlw 		if (t >= 0 && t <= 2)
1620ff5cf41Smckusick #else tahoe
1630ff5cf41Smckusick 		if (t == ILL_ALIGN_FAULT)	/* ILL_ALIGN_FAULT maps to last
1640ff5cf41Smckusick 			t = N_ACT_ILL-1;   	   entry in act_ill[] */
1650ff5cf41Smckusick 		if (t >= 0 && t < N_ACT_ILL)
1660ff5cf41Smckusick #endif tahoe
1672a4a0a24Sdlw 			fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
1682a4a0a24Sdlw 		else
1692a4a0a24Sdlw 			fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
1702a4a0a24Sdlw 		}
171bc2756f6Sdlw 	putc('\n', units[STDERR].ufd);
172bc2756f6Sdlw 	}
173edb0e733Slibs f77_abort( s, act->core );
174edb0e733Slibs }
175