xref: /csrg-svn/usr.bin/f77/libF77/main.c (revision 51684)
147940Sbostic /*-
247940Sbostic  * Copyright (c) 1980 The Regents of the University of California.
347940Sbostic  * All rights reserved.
422925Skre  *
547940Sbostic  * %sccs.include.proprietary.c%
622925Skre  */
747940Sbostic 
8*51684Sbostic /*
9*51684Sbostic  * Don't split the copyright notice over two lines, it makes mkvers
10*51684Sbostic  * unhappy.
11*51684Sbostic  */
1247940Sbostic #ifndef lint
1347940Sbostic char copyright[] =
14*51684Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n All rights reserved.\n";
1547940Sbostic #endif /* not lint */
1647940Sbostic 
1747940Sbostic #ifndef lint
18*51684Sbostic static char sccsid[] = "@(#)main.c	5.7 (Berkeley) 11/13/91";
1947940Sbostic #endif /* not lint */
2047940Sbostic 
214130Sdlw #include <stdio.h>
224130Sdlw #include <signal.h>
234131Sdlw #include "../libI77/fiodefs.h"
244130Sdlw 
2529974Smckusick extern int errno;
2629974Smckusick char *getenv();
274130Sdlw int xargc;
284130Sdlw char **xargv;
294130Sdlw 
main(argc,argv,arge)304130Sdlw main(argc, argv, arge)
314130Sdlw int argc;
324130Sdlw char **argv;
334130Sdlw char **arge;
344130Sdlw {
3542454Sbostic void sigdie();
3639139Sbostic sig_t sigf;
374168Sdlw int signum;
384130Sdlw 
394130Sdlw xargc = argc;
404130Sdlw xargv = argv;
414130Sdlw 
424168Sdlw for (signum=1; signum<=16; signum++)
434168Sdlw {
444168Sdlw 	if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
454168Sdlw }
464168Sdlw 
474130Sdlw #ifdef pdp11
484130Sdlw 	ldfps(01200); /* detect overflow as an exception */
494130Sdlw #endif
504130Sdlw 
514130Sdlw f_init();
5212580Sfortran MAIN_();
534130Sdlw f_exit();
5420197Slibs return 0;
554130Sdlw }
564130Sdlw 
574134Sdlw struct action {
584134Sdlw 	char *mesg;
594134Sdlw 	int   core;
604134Sdlw } sig_act[16] = {
614168Sdlw 	{"Hangup", 0},			/* SIGHUP  */
624134Sdlw 	{"Interrupt!", 0},		/* SIGINT  */
634134Sdlw 	{"Quit!", 1},			/* SIGQUIT */
644170Sdlw 	{"Illegal ", 1},		/* SIGILL  */
654168Sdlw 	{"Trace Trap", 1},		/* SIGTRAP */
664134Sdlw 	{"IOT Trap", 1},		/* SIGIOT  */
674140Sdlw 	{"EMT Trap", 1},		/* SIGEMT  */
684137Sdlw 	{"Arithmetic Exception", 1},	/* SIGFPE  */
694134Sdlw 	{ 0, 0},			/* SIGKILL */
704134Sdlw 	{"Bus error", 1},		/* SIGBUS  */
714134Sdlw 	{"Segmentation violation", 1},	/* SIGSEGV */
724168Sdlw 	{"Sys arg", 1},			/* SIGSYS  */
734168Sdlw 	{"Open pipe", 0},		/* SIGPIPE */
744168Sdlw 	{"Alarm", 0},			/* SIGALRM */
754134Sdlw 	{"Terminated", 0},		/* SIGTERM */
764168Sdlw 	{"Sig 16", 0},			/* unassigned */
774134Sdlw };
784130Sdlw 
7929974Smckusick #ifdef tahoe
8029974Smckusick /* The following arrays are defined & used assuming that signal codes are
8129974Smckusick    1 to 5 for SIGFPE, and 0 to 3 for SIGILL.
8229974Smckusick    Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */
8329974Smckusick 
8429974Smckusick #define N_ACT_ILL 4			/* number of entries in act_ill[] */
8529974Smckusick #define N_ACT_FPE 5			/* number of entries in act_fpe[] */
8629974Smckusick #define ILL_ALIGN_FAULT 14
8729974Smckusick 
884137Sdlw struct action act_fpe[] = {
894137Sdlw 	{"Integer overflow", 1},
904137Sdlw 	{"Integer divide by 0", 1},
9129974Smckusick 	{"Floating divide by zero", 1},
9229974Smckusick 	{"Floating point overflow", 1},
9329974Smckusick 	{"Floating point underflow", 1},
9429974Smckusick };
9529974Smckusick 
9629974Smckusick #else vax || pdp11
9729974Smckusick 
9829974Smckusick struct action act_fpe[] = {
9929974Smckusick 	{"Integer overflow", 1},
10029974Smckusick 	{"Integer divide by 0", 1},
10113232Sdlw 	{"Floating point overflow trap", 1},
10213232Sdlw 	{"Floating divide by zero trap", 1},
10313232Sdlw 	{"Floating point underflow trap", 1},
1044137Sdlw 	{"Decimal overflow", 1},
1054137Sdlw 	{"Subscript range", 1},
1064137Sdlw 	{"Floating point overflow", 0},
1074137Sdlw 	{"Floating divide by zero", 0},
1084137Sdlw 	{"Floating point underflow", 0},
1094137Sdlw };
11029974Smckusick #endif vax || pdp11
1114170Sdlw 
1124170Sdlw struct action act_ill[] = {
1134170Sdlw 	{"addr mode", 1},
1144170Sdlw 	{"instruction", 1},
1154170Sdlw 	{"operand", 0},
11629974Smckusick #ifdef tahoe
11729974Smckusick 	{"alignment", 1},
11829974Smckusick #endif tahoe
1194170Sdlw };
1204130Sdlw 
12129974Smckusick #if (defined(vax) || defined(tahoe))
12242454Sbostic void
sigdie(s,t,sc)12314399Sdlw sigdie(s, t, sc)
12414399Sdlw int s; int t; struct sigcontext *sc;
12514399Sdlw 
12614399Sdlw #else	pdp11
12729974Smckusick 
12842454Sbostic void
1294137Sdlw sigdie(s, t, pc)
1304137Sdlw int s; int t; long pc;
13114399Sdlw 
13229974Smckusick #endif pdp11
1334130Sdlw {
1344131Sdlw extern unit units[];
1354134Sdlw register struct action *act = &sig_act[s-1];
1364726Sdlw /* print error message, then flush buffers */
1374726Sdlw 
13814840Sdlw if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
13914840Sdlw 	signal(s, SIG_IGN);	/* don't allow it again */
14014840Sdlw else
14114840Sdlw 	signal(s, SIG_DFL);	/* shouldn't happen again, but ... */
14214840Sdlw 
1434137Sdlw if (act->mesg)
1444137Sdlw 	{
1454173Sdlw 	fprintf(units[STDERR].ufd, "*** %s", act->mesg);
1464137Sdlw 	if (s == SIGFPE)
1474168Sdlw 		{
14829974Smckusick #ifndef tahoe
1494168Sdlw 		if (t >= 1 && t <= 10)
15029974Smckusick #else tahoe
15129974Smckusick 		if ((t-1) >= 0 && t < N_ACT_FPE)
15229974Smckusick #endif tahoe
1534168Sdlw 			fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
1544168Sdlw 		else
1554168Sdlw 			fprintf(units[STDERR].ufd, ": Type=%d?", t);
1564168Sdlw 		}
1574168Sdlw 	else if (s == SIGILL)
1584170Sdlw 		{
15929974Smckusick #ifndef tahoe
1604170Sdlw 		if (t == 4) t = 2;	/* 4.0bsd botch */
1614170Sdlw 		if (t >= 0 && t <= 2)
16229974Smckusick #else tahoe
16329974Smckusick 		if (t == ILL_ALIGN_FAULT)	/* ILL_ALIGN_FAULT maps to last
16429974Smckusick 			t = N_ACT_ILL-1;   	   entry in act_ill[] */
16529974Smckusick 		if (t >= 0 && t < N_ACT_ILL)
16629974Smckusick #endif tahoe
1674170Sdlw 			fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
1684170Sdlw 		else
1694170Sdlw 			fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
1704170Sdlw 		}
1714168Sdlw 	putc('\n', units[STDERR].ufd);
1724137Sdlw 	}
17320197Slibs f77_abort( s, act->core );
17420197Slibs }
175