xref: /csrg-svn/usr.bin/f77/libF77/main.c (revision 29974)
122925Skre /*
222925Skre  * Copyright (c) 1980 Regents of the University of California.
322925Skre  * All rights reserved.  The Berkeley software License Agreement
422925Skre  * specifies the terms and conditions for redistribution.
522925Skre  *
6*29974Smckusick  *	@(#)main.c	5.3	11/03/86
722925Skre  */
84130Sdlw #include <stdio.h>
94130Sdlw #include <signal.h>
104131Sdlw #include "../libI77/fiodefs.h"
114130Sdlw 
12*29974Smckusick extern int errno;
13*29974Smckusick char *getenv();
144130Sdlw int xargc;
154130Sdlw char **xargv;
164130Sdlw 
174130Sdlw main(argc, argv, arge)
184130Sdlw int argc;
194130Sdlw char **argv;
204130Sdlw char **arge;
214130Sdlw {
224134Sdlw int sigdie();
234130Sdlw long int (*sigf)();
244168Sdlw int signum;
254130Sdlw 
264130Sdlw xargc = argc;
274130Sdlw xargv = argv;
284130Sdlw 
294168Sdlw for (signum=1; signum<=16; signum++)
304168Sdlw {
314168Sdlw 	if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
324168Sdlw }
334168Sdlw 
344130Sdlw #ifdef pdp11
354130Sdlw 	ldfps(01200); /* detect overflow as an exception */
364130Sdlw #endif
374130Sdlw 
384130Sdlw f_init();
3912580Sfortran MAIN_();
404130Sdlw f_exit();
4120197Slibs return 0;
424130Sdlw }
434130Sdlw 
444134Sdlw struct action {
454134Sdlw 	char *mesg;
464134Sdlw 	int   core;
474134Sdlw } sig_act[16] = {
484168Sdlw 	{"Hangup", 0},			/* SIGHUP  */
494134Sdlw 	{"Interrupt!", 0},		/* SIGINT  */
504134Sdlw 	{"Quit!", 1},			/* SIGQUIT */
514170Sdlw 	{"Illegal ", 1},		/* SIGILL  */
524168Sdlw 	{"Trace Trap", 1},		/* SIGTRAP */
534134Sdlw 	{"IOT Trap", 1},		/* SIGIOT  */
544140Sdlw 	{"EMT Trap", 1},		/* SIGEMT  */
554137Sdlw 	{"Arithmetic Exception", 1},	/* SIGFPE  */
564134Sdlw 	{ 0, 0},			/* SIGKILL */
574134Sdlw 	{"Bus error", 1},		/* SIGBUS  */
584134Sdlw 	{"Segmentation violation", 1},	/* SIGSEGV */
594168Sdlw 	{"Sys arg", 1},			/* SIGSYS  */
604168Sdlw 	{"Open pipe", 0},		/* SIGPIPE */
614168Sdlw 	{"Alarm", 0},			/* SIGALRM */
624134Sdlw 	{"Terminated", 0},		/* SIGTERM */
634168Sdlw 	{"Sig 16", 0},			/* unassigned */
644134Sdlw };
654130Sdlw 
66*29974Smckusick #ifdef tahoe
67*29974Smckusick /* The following arrays are defined & used assuming that signal codes are
68*29974Smckusick    1 to 5 for SIGFPE, and 0 to 3 for SIGILL.
69*29974Smckusick    Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */
70*29974Smckusick 
71*29974Smckusick #define N_ACT_ILL 4			/* number of entries in act_ill[] */
72*29974Smckusick #define N_ACT_FPE 5			/* number of entries in act_fpe[] */
73*29974Smckusick #define ILL_ALIGN_FAULT 14
74*29974Smckusick 
754137Sdlw struct action act_fpe[] = {
764137Sdlw 	{"Integer overflow", 1},
774137Sdlw 	{"Integer divide by 0", 1},
78*29974Smckusick 	{"Floating divide by zero", 1},
79*29974Smckusick 	{"Floating point overflow", 1},
80*29974Smckusick 	{"Floating point underflow", 1},
81*29974Smckusick };
82*29974Smckusick 
83*29974Smckusick #else vax || pdp11
84*29974Smckusick 
85*29974Smckusick struct action act_fpe[] = {
86*29974Smckusick 	{"Integer overflow", 1},
87*29974Smckusick 	{"Integer divide by 0", 1},
8813232Sdlw 	{"Floating point overflow trap", 1},
8913232Sdlw 	{"Floating divide by zero trap", 1},
9013232Sdlw 	{"Floating point underflow trap", 1},
914137Sdlw 	{"Decimal overflow", 1},
924137Sdlw 	{"Subscript range", 1},
934137Sdlw 	{"Floating point overflow", 0},
944137Sdlw 	{"Floating divide by zero", 0},
954137Sdlw 	{"Floating point underflow", 0},
964137Sdlw };
97*29974Smckusick #endif vax || pdp11
984170Sdlw 
994170Sdlw struct action act_ill[] = {
1004170Sdlw 	{"addr mode", 1},
1014170Sdlw 	{"instruction", 1},
1024170Sdlw 	{"operand", 0},
103*29974Smckusick #ifdef tahoe
104*29974Smckusick 	{"alignment", 1},
105*29974Smckusick #endif tahoe
1064170Sdlw };
1074130Sdlw 
108*29974Smckusick #if (defined(vax) || defined(tahoe))
10914399Sdlw sigdie(s, t, sc)
11014399Sdlw int s; int t; struct sigcontext *sc;
11114399Sdlw 
11214399Sdlw #else	pdp11
113*29974Smckusick 
1144137Sdlw sigdie(s, t, pc)
1154137Sdlw int s; int t; long pc;
11614399Sdlw 
117*29974Smckusick #endif pdp11
1184130Sdlw {
1194131Sdlw extern unit units[];
1204134Sdlw register struct action *act = &sig_act[s-1];
1214726Sdlw /* print error message, then flush buffers */
1224726Sdlw 
12314840Sdlw if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
12414840Sdlw 	signal(s, SIG_IGN);	/* don't allow it again */
12514840Sdlw else
12614840Sdlw 	signal(s, SIG_DFL);	/* shouldn't happen again, but ... */
12714840Sdlw 
1284137Sdlw if (act->mesg)
1294137Sdlw 	{
1304173Sdlw 	fprintf(units[STDERR].ufd, "*** %s", act->mesg);
1314137Sdlw 	if (s == SIGFPE)
1324168Sdlw 		{
133*29974Smckusick #ifndef tahoe
1344168Sdlw 		if (t >= 1 && t <= 10)
135*29974Smckusick #else tahoe
136*29974Smckusick 		if ((t-1) >= 0 && t < N_ACT_FPE)
137*29974Smckusick #endif tahoe
1384168Sdlw 			fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
1394168Sdlw 		else
1404168Sdlw 			fprintf(units[STDERR].ufd, ": Type=%d?", t);
1414168Sdlw 		}
1424168Sdlw 	else if (s == SIGILL)
1434170Sdlw 		{
144*29974Smckusick #ifndef tahoe
1454170Sdlw 		if (t == 4) t = 2;	/* 4.0bsd botch */
1464170Sdlw 		if (t >= 0 && t <= 2)
147*29974Smckusick #else tahoe
148*29974Smckusick 		if (t == ILL_ALIGN_FAULT)	/* ILL_ALIGN_FAULT maps to last
149*29974Smckusick 			t = N_ACT_ILL-1;   	   entry in act_ill[] */
150*29974Smckusick 		if (t >= 0 && t < N_ACT_ILL)
151*29974Smckusick #endif tahoe
1524170Sdlw 			fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
1534170Sdlw 		else
1544170Sdlw 			fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
1554170Sdlw 		}
1564168Sdlw 	putc('\n', units[STDERR].ufd);
1574137Sdlw 	}
15820197Slibs f77_abort( s, act->core );
15920197Slibs }
160