xref: /original-bsd/usr.bin/f77/f77.tahoe/f77.c (revision 780aea47)
1*780aea47Sbostic /*-
2*780aea47Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*780aea47Sbostic  * All rights reserved.
4*780aea47Sbostic  *
5*780aea47Sbostic  * %sccs.include.proprietary.c%
6*780aea47Sbostic  */
7*780aea47Sbostic 
8*780aea47Sbostic #ifndef lint
9*780aea47Sbostic char copyright[] =
10*780aea47Sbostic "@(#) Copyright (c) 1991 The Regents of the University of California.\n\
11*780aea47Sbostic  All rights reserved.\n";
12*780aea47Sbostic #endif /* not lint */
13*780aea47Sbostic 
14*780aea47Sbostic #ifndef lint
15*780aea47Sbostic static char sccsid[] = "@(#)f77.c	5.5 (Berkeley) 04/12/91";
16*780aea47Sbostic #endif /* not lint */
17*780aea47Sbostic 
184b5db810Sbostic /*
194b5db810Sbostic  * f77.c
204b5db810Sbostic  *
214b5db810Sbostic  * Driver program for the 4.2 BSD f77 compiler.
224b5db810Sbostic  *
234b5db810Sbostic  * University of Utah CS Dept modification history:
244b5db810Sbostic  *
254b5db810Sbostic  * $Log:	f77.c,v $
264b5db810Sbostic  * Revision 1.14  85/03/01  00:07:57  donn
274b5db810Sbostic  * Portability fix from Ralph Campbell.
284b5db810Sbostic  *
294b5db810Sbostic  * Revision 1.13  85/02/12  19:31:47  donn
304b5db810Sbostic  * Use CATNAME to get the name of a concatenation command instead of
314b5db810Sbostic  * explicitly running 'cat' -- you can get the wrong 'cat' the old way!
324b5db810Sbostic  *
334b5db810Sbostic  * Revision 1.12  85/01/14  06:42:30  donn
344b5db810Sbostic  * Changed to call the peephole optimizer with the '-f' flag, so that
354b5db810Sbostic  * floating point moves are translated to integer moves.
364b5db810Sbostic  *
374b5db810Sbostic  * Revision 1.11  85/01/14  04:38:59  donn
384b5db810Sbostic  * Jerry's change to pass -O to f1 so it knows whether the peephole optimizer
394b5db810Sbostic  * will be run.  This is necessary in order to handle movf/movl translation.
404b5db810Sbostic  *
414b5db810Sbostic  * Revision 1.10  85/01/14  03:59:12  donn
424b5db810Sbostic  * Added Jerry Berkman's fix for the '-q' flag.
434b5db810Sbostic  *
444b5db810Sbostic  * Revision 1.9  84/11/09  01:51:26  donn
454b5db810Sbostic  * Cosmetic change to stupid() suggested by John McCarthy at Memorial
464b5db810Sbostic  * University, St. Johns.
474b5db810Sbostic  *
484b5db810Sbostic  * Revision 1.8  84/09/14  16:02:34  donn
494b5db810Sbostic  * Added changes to notice when people do 'f77 -c foo.f -o bar.o' and tell
504b5db810Sbostic  * them why it doesn't do what they think it does.
514b5db810Sbostic  *
524b5db810Sbostic  * Revision 1.7  84/08/24  21:08:31  donn
534b5db810Sbostic  * Added call to setrlimit() to prevent core dumps when not debugging.
544b5db810Sbostic  * Reorganized the include file arrangment somewhat.
554b5db810Sbostic  *
564b5db810Sbostic  * Revision 1.6  84/08/24  20:20:24  donn
574b5db810Sbostic  * Changed stupidity check on Jerry Berkman's suggestion -- now it balks if
584b5db810Sbostic  * the load file exists and has a sensitive suffix.
594b5db810Sbostic  *
604b5db810Sbostic  * Revision 1.5  84/08/15  18:56:44  donn
614b5db810Sbostic  * Added test for -O combined with -g, suggested by Raleigh Romine.  To keep
624b5db810Sbostic  * things simple, if both are specified then the second in the list is thrown
634b5db810Sbostic  * out and the user is warned.
644b5db810Sbostic  *
654b5db810Sbostic  * Revision 1.4  84/08/05  21:33:15  donn
664b5db810Sbostic  * Added stupidity check -- f77 won't load on a file that it's asked to
674b5db810Sbostic  * compile as well.
684b5db810Sbostic  *
694b5db810Sbostic  * Revision 1.3  84/08/04  22:58:24  donn
704b5db810Sbostic  * Improved error reporting -- we now explain why we died and what we did.
714b5db810Sbostic  * Only works on 4.2.  Added at the instigation of Jerry Berkman.
724b5db810Sbostic  *
734b5db810Sbostic  * Revision 1.2  84/07/28  13:11:24  donn
744b5db810Sbostic  * Added Ralph Campbell's changes to reduce offsets to data.
754b5db810Sbostic  *
764b5db810Sbostic  */
774b5db810Sbostic 
784b5db810Sbostic char *xxxvers[] = "\n@(#) F77 DRIVER, VERSION 4.2,   1984 JULY 28\n";
794b5db810Sbostic #include <stdio.h>
804b5db810Sbostic #include <sys/types.h>
814b5db810Sbostic #include <sys/stat.h>
824b5db810Sbostic #include <ctype.h>
834b5db810Sbostic #include <signal.h>
844b5db810Sbostic 
854b5db810Sbostic #ifdef	SIGPROF
864b5db810Sbostic /*
874b5db810Sbostic  * Some 4.2 BSD capabilities.
884b5db810Sbostic  */
894b5db810Sbostic #include <sys/time.h>
904b5db810Sbostic #include <sys/resource.h>
914b5db810Sbostic #define	NOCORE		1
924b5db810Sbostic #include <sys/wait.h>
934b5db810Sbostic #define PSIGNAL		1
944b5db810Sbostic #define INLINE		1
954b5db810Sbostic #endif
964b5db810Sbostic 
974b5db810Sbostic #include "defines.h"
984b5db810Sbostic #include "machdefs.h"
996b951ba4Sbostic #include "pathnames.h"
1004b5db810Sbostic #include "version.h"
1014b5db810Sbostic 
1024b5db810Sbostic static FILEP diagfile	= {stderr} ;
1034b5db810Sbostic static int pid;
1044b5db810Sbostic static int sigivalue	= 0;
1054b5db810Sbostic static int sigqvalue	= 0;
1064b5db810Sbostic static int sighvalue	= 0;
1074b5db810Sbostic static int sigtvalue	= 0;
1084b5db810Sbostic 
1094b5db810Sbostic static char *pass1name	= PASS1NAME ;
1104b5db810Sbostic static char *pass2name	= PASS2NAME ;
1114b5db810Sbostic static char *pass2opt	= PASS2OPT ;
1124b5db810Sbostic static char *asmname	= ASMNAME ;
1134b5db810Sbostic static char *ldname	= LDNAME ;
1144b5db810Sbostic static char *footname	= FOOTNAME;
1154b5db810Sbostic static char *proffoot	= PROFFOOT;
1164b5db810Sbostic static char *macroname	= "m4";
1176b951ba4Sbostic static char *shellname	= _PATH_BSHELL;
1186b951ba4Sbostic static char *cppname	= _PATH_CPP;
1194b5db810Sbostic static char *aoutname	= "a.out" ;
1204b5db810Sbostic static char *temppref	= TEMPPREF;
1214b5db810Sbostic 
1224b5db810Sbostic static char *infname;
1234b5db810Sbostic static char textfname[44];
1244b5db810Sbostic static char asmfname[44];
1254b5db810Sbostic static char asmpass2[44];
1264b5db810Sbostic static char initfname[44];
1274b5db810Sbostic static char sortfname[44];
1284b5db810Sbostic static char prepfname[44];
1294b5db810Sbostic static char objfdefault[44];
1304b5db810Sbostic static char optzfname[44];
1314b5db810Sbostic static char setfname[44];
1324b5db810Sbostic 
1334b5db810Sbostic static char fflags[50]	= "-";
1344b5db810Sbostic static char f2flags[50];
1354b5db810Sbostic static char cflags[50]	= "-c";
1364b5db810Sbostic #if TARGET == GCOS
1374b5db810Sbostic 	static char eflags[30]	= "system=gcos ";
1384b5db810Sbostic #else
1394b5db810Sbostic 	static char eflags[30]	= "system=unix ";
1404b5db810Sbostic #endif
1414b5db810Sbostic static char rflags[30]	= "";
1424b5db810Sbostic static char lflag[3]	= "-x";
1434b5db810Sbostic static char *fflagp	= fflags+1;
1444b5db810Sbostic static char *f2flagp	= f2flags;
1454b5db810Sbostic static char *cflagp	= cflags+2;
1464b5db810Sbostic static char *eflagp	= eflags+12;
1474b5db810Sbostic static char *rflagp	= rflags;
1484b5db810Sbostic static char *cppflags	= "";
1494b5db810Sbostic static char **cppargs;
1504b5db810Sbostic static char **loadargs;
1514b5db810Sbostic static char **loadp;
1524b5db810Sbostic 
1534b5db810Sbostic static flag erred	= NO;
1544b5db810Sbostic static flag loadflag	= YES;
1554b5db810Sbostic static flag saveasmflag	= NO;
1564b5db810Sbostic static flag profileflag	= NO;
1574b5db810Sbostic static flag optimflag	= NO;
1584b5db810Sbostic static flag debugflag	= NO;
1594b5db810Sbostic static flag verbose	= NO;
1604b5db810Sbostic static flag nofloating	= NO;
1614b5db810Sbostic static flag fortonly	= NO;
1624b5db810Sbostic static flag macroflag	= NO;
1634b5db810Sbostic static flag sdbflag	= NO;
1644b5db810Sbostic static flag namesflag	= YES;
1654b5db810Sbostic 
1664b5db810Sbostic static int ncpp;
1674b5db810Sbostic 
1684b5db810Sbostic 
main(argc,argv)1694b5db810Sbostic main(argc, argv)
1704b5db810Sbostic int argc;
1714b5db810Sbostic char **argv;
1724b5db810Sbostic {
1734b5db810Sbostic int i, c, status;
1744b5db810Sbostic char *setdoto(), *lastchar(), *lastfield(), *copys(), *argvtos();
1754b5db810Sbostic ptr ckalloc();
1764b5db810Sbostic register char *s;
1774b5db810Sbostic char fortfile[20], *t;
1784b5db810Sbostic char buff[100];
1794b5db810Sbostic int intrupt();
1804b5db810Sbostic int new_aoutname = NO;
1814b5db810Sbostic 
1824b5db810Sbostic sigivalue = signal(SIGINT, SIG_IGN) == SIG_IGN;
1834b5db810Sbostic sigqvalue = signal(SIGQUIT,SIG_IGN) == SIG_IGN;
1844b5db810Sbostic sighvalue = signal(SIGHUP, SIG_IGN) == SIG_IGN;
1854b5db810Sbostic sigtvalue = signal(SIGTERM,SIG_IGN) == SIG_IGN;
1864b5db810Sbostic enbint(intrupt);
1874b5db810Sbostic 
1884b5db810Sbostic pid = getpid();
1894b5db810Sbostic crfnames();
1904b5db810Sbostic 
1914b5db810Sbostic cppargs  = (char **) ckalloc( argc * sizeof(*cppargs) );
1924b5db810Sbostic loadargs = (char **) ckalloc( (argc+20) * sizeof(*loadargs) );
1934b5db810Sbostic loadargs[1] = "-X";
1944b5db810Sbostic loadargs[2] = "-u";
1954b5db810Sbostic #if HERE==PDP11 || HERE==VAX || HERE==TAHOE
1964b5db810Sbostic 	loadargs[3] = "_MAIN_";
1974b5db810Sbostic #endif
1984b5db810Sbostic #if HERE == INTERDATA
1994b5db810Sbostic 	loadargs[3] = "main";
2004b5db810Sbostic #endif
2014b5db810Sbostic loadp = loadargs + 4;
2024b5db810Sbostic 
2034b5db810Sbostic --argc;
2044b5db810Sbostic ++argv;
2054b5db810Sbostic 
2064b5db810Sbostic while(argc>0 && argv[0][0]=='-' && argv[0][1]!='\0')
2074b5db810Sbostic 	{
2084b5db810Sbostic 	for(s = argv[0]+1 ; *s ; ++s) switch(*s)
2094b5db810Sbostic 		{
2104b5db810Sbostic 		case 'T':  /* use special passes */
2114b5db810Sbostic 			switch(*++s)
2124b5db810Sbostic 				{
2134b5db810Sbostic 				case '1':
2144b5db810Sbostic 					pass1name = s+1; goto endfor;
2154b5db810Sbostic 				case '2':
2164b5db810Sbostic 					pass2name = s+1; goto endfor;
2174b5db810Sbostic 				case 'p':
2184b5db810Sbostic 					pass2opt = s+1; goto endfor;
2194b5db810Sbostic 				case 'a':
2204b5db810Sbostic 					asmname = s+1; goto endfor;
2214b5db810Sbostic 				case 'l':
2224b5db810Sbostic 					ldname = s+1; goto endfor;
2234b5db810Sbostic 				case 'F':
2244b5db810Sbostic 					footname = s+1; goto endfor;
2254b5db810Sbostic 				case 'm':
2264b5db810Sbostic 					macroname = s+1; goto endfor;
2274b5db810Sbostic 				case 't':
2284b5db810Sbostic 					temppref = s+1; goto endfor;
2294b5db810Sbostic 				default:
2304b5db810Sbostic 					fatali("bad option -T%c", *s);
2314b5db810Sbostic 				}
2324b5db810Sbostic 			break;
2334b5db810Sbostic 
2344b5db810Sbostic 		case '6':
2354b5db810Sbostic 			if(s[1]=='6')
2364b5db810Sbostic 				{
2374b5db810Sbostic 				*fflagp++ = *s++;
2384b5db810Sbostic 				goto copyfflag;
2394b5db810Sbostic 				}
2404b5db810Sbostic 			else	{
2414b5db810Sbostic 				fprintf(diagfile, "invalid flag 6%c\n", s[1]);
2424b5db810Sbostic 				done(1);
2434b5db810Sbostic 				}
2444b5db810Sbostic 
2454b5db810Sbostic 		case 'w':
2464b5db810Sbostic 			if(s[1]=='6' && s[2]=='6')
2474b5db810Sbostic 				{
2484b5db810Sbostic 				*fflagp++ = *s++;
2494b5db810Sbostic 				*fflagp++ = *s++;
2504b5db810Sbostic 				}
2514b5db810Sbostic 
2524b5db810Sbostic 		copyfflag:
2534b5db810Sbostic 		case 'u':
2544b5db810Sbostic 		case 'U':
2554b5db810Sbostic 		case '1':
2564b5db810Sbostic 		case 'C':
2574b5db810Sbostic 			*fflagp++ = *s;
2584b5db810Sbostic 			break;
2594b5db810Sbostic 
2604b5db810Sbostic 		case 'O':
2614b5db810Sbostic 			if(sdbflag)
2624b5db810Sbostic 				{
2634b5db810Sbostic 				fprintf(diagfile, "-O and -g are incompatible; -O ignored\n");
2644b5db810Sbostic 				break;
2654b5db810Sbostic 				}
2664b5db810Sbostic 			optimflag = YES;
2674b5db810Sbostic #if TARGET == INTERDATA
2684b5db810Sbostic 				*loadp++ = "-r";
2694b5db810Sbostic 				*loadp++ = "-d";
2704b5db810Sbostic #endif
2714b5db810Sbostic 			*fflagp++ = 'O';
2724b5db810Sbostic 			break;
2734b5db810Sbostic 
2744b5db810Sbostic 		case 'N':
2754b5db810Sbostic 			*fflagp++ = 'N';
2764b5db810Sbostic 			if( oneof(*++s, "qxscn") )
2774b5db810Sbostic 				*fflagp++ = *s++;
2784b5db810Sbostic 			else	{
2794b5db810Sbostic 				fprintf(diagfile, "invalid flag -N%c\n", *s);
2804b5db810Sbostic 				done(1);
2814b5db810Sbostic 				}
2824b5db810Sbostic 			while( isdigit(*s) )
2834b5db810Sbostic 				*fflagp++ = *s++;
2844b5db810Sbostic 			*fflagp++ = 'X';
2854b5db810Sbostic 			goto endfor;
2864b5db810Sbostic 
2874b5db810Sbostic 		case 'm':
2884b5db810Sbostic 			if(s[1] == '4')
2894b5db810Sbostic 				++s;
2904b5db810Sbostic 			macroflag = YES;
2914b5db810Sbostic 			break;
2924b5db810Sbostic 
2934b5db810Sbostic 		case 'S':
2944b5db810Sbostic 			strcat(cflags, " -S");
2954b5db810Sbostic 			saveasmflag = YES;
2964b5db810Sbostic 
2974b5db810Sbostic 		case 'c':
2984b5db810Sbostic 			if( new_aoutname == YES ){
2994b5db810Sbostic 				fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname);
3004b5db810Sbostic 				new_aoutname = NO;
3014b5db810Sbostic 				}
3024b5db810Sbostic 			loadflag = NO;
3034b5db810Sbostic 			break;
3044b5db810Sbostic 
3054b5db810Sbostic 		case 'v':
3064b5db810Sbostic 			verbose = YES;
3074b5db810Sbostic 			fprintf(diagfile,"\nBerkeley F77, version %s\n",
3084b5db810Sbostic 				VERSIONNUMBER);
3094b5db810Sbostic 			break;
3104b5db810Sbostic 
3114b5db810Sbostic 		case 'd':
3124b5db810Sbostic 			debugflag = YES;
3134b5db810Sbostic 			*fflagp++ = 'd';
3144b5db810Sbostic 			s++;
3154b5db810Sbostic 			while( isdigit(*s) || *s == ',' )
3164b5db810Sbostic 				*fflagp++ = *s++;
3174b5db810Sbostic 			*fflagp++ = 'X';
3184b5db810Sbostic 			goto endfor;
3194b5db810Sbostic 
3204b5db810Sbostic 		case 'M':
3214b5db810Sbostic 			*loadp++ = "-M";
3224b5db810Sbostic 			break;
3234b5db810Sbostic 
3244b5db810Sbostic 		case 'g':
3254b5db810Sbostic 			if(optimflag)
3264b5db810Sbostic 				{
3274b5db810Sbostic 				fprintf(diagfile, "-g and -O are incompatible; -g ignored\n");
3284b5db810Sbostic 				break;
3294b5db810Sbostic 				}
3304b5db810Sbostic 			strcat(cflags," -g");
3314b5db810Sbostic 			sdbflag = YES;
3324b5db810Sbostic 			goto copyfflag;
3334b5db810Sbostic 
3344b5db810Sbostic 		case 'p':
3354b5db810Sbostic 			profileflag = YES;
3364b5db810Sbostic 			strcat(cflags," -p");
3374b5db810Sbostic 			*fflagp++ = 'p';
3384b5db810Sbostic 			if(s[1] == 'g')
3394b5db810Sbostic 				{
3404b5db810Sbostic 				proffoot = GPRFFOOT;
3414b5db810Sbostic 				s++;
3424b5db810Sbostic 				}
3434b5db810Sbostic 			break;
3444b5db810Sbostic 
3454b5db810Sbostic 		case 'q':
3464b5db810Sbostic 			namesflag = NO;
3474b5db810Sbostic 			*fflagp++ = *s;
3484b5db810Sbostic 			break;
3494b5db810Sbostic 
3504b5db810Sbostic 		case 'o':
3514b5db810Sbostic 			if( ! strcmp(s, "onetrip") )
3524b5db810Sbostic 				{
3534b5db810Sbostic 				*fflagp++ = '1';
3544b5db810Sbostic 				goto endfor;
3554b5db810Sbostic 				}
3564b5db810Sbostic 			new_aoutname = YES;
3574b5db810Sbostic 			aoutname = *++argv;
3584b5db810Sbostic 			--argc;
3594b5db810Sbostic 			if( loadflag == NO ){
3604b5db810Sbostic 				fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname);
3614b5db810Sbostic 				new_aoutname = NO;
3624b5db810Sbostic 				}
3634b5db810Sbostic 			break;
3644b5db810Sbostic 
3654b5db810Sbostic #if TARGET == PDP11
3664b5db810Sbostic 		case 'f':
3674b5db810Sbostic 			nofloating = YES;
3684b5db810Sbostic 			pass2name = NOFLPASS2;
3694b5db810Sbostic 		break;
3704b5db810Sbostic #endif
3714b5db810Sbostic 
3724b5db810Sbostic 		case 'F':
3734b5db810Sbostic 			fortonly = YES;
3744b5db810Sbostic 			loadflag = NO;
3754b5db810Sbostic 			break;
3764b5db810Sbostic 		case 'D':
3774b5db810Sbostic 		case 'I':
3784b5db810Sbostic 			cppargs[ncpp++] = *argv;
3794b5db810Sbostic 			goto endfor;
3804b5db810Sbostic 
3814b5db810Sbostic 		case 'i':
3824b5db810Sbostic 			if((s[1]=='2' || s[1]=='4') && s[2] == '\0')
3834b5db810Sbostic 				{
3844b5db810Sbostic 				*fflagp++ = *s++;
3854b5db810Sbostic 				goto copyfflag;
3864b5db810Sbostic 				}
3874b5db810Sbostic #ifdef INLINE
3884b5db810Sbostic 			*f2flagp++ = '-';
3894b5db810Sbostic 			while(*f2flagp++ = *s++)
3904b5db810Sbostic 				;
3914b5db810Sbostic 			*f2flagp = ' ';
3924b5db810Sbostic 			if(strcmp(pass2name, PASS2NAME) == 0)
3934b5db810Sbostic 				pass2name = PASS2INAME;
3944b5db810Sbostic 			goto endfor;
3954b5db810Sbostic #else
3964b5db810Sbostic 			fprintf(diagfile, "invalid flag -i%c\n", s[1]);
3974b5db810Sbostic 			done(1);
3984b5db810Sbostic #endif
3994b5db810Sbostic 
4004b5db810Sbostic 		case 'l':	/* letter ell--library */
4014b5db810Sbostic 			s[-1] = '-';
4024b5db810Sbostic 			*loadp++ = s-1;
4034b5db810Sbostic 			goto endfor;
4044b5db810Sbostic 
4054b5db810Sbostic 		case 'E':	/* EFL flag argument */
4064b5db810Sbostic 			while( *eflagp++ = *++s)
4074b5db810Sbostic 				;
4084b5db810Sbostic 			*eflagp++ = ' ';
4094b5db810Sbostic 			goto endfor;
4104b5db810Sbostic 		case 'R':
4114b5db810Sbostic 			while( *rflagp++ = *++s )
4124b5db810Sbostic 				;
4134b5db810Sbostic 			*rflagp++ = ' ';
4144b5db810Sbostic 			goto endfor;
4154b5db810Sbostic 		default:
4164b5db810Sbostic 			lflag[1] = *s;
4174b5db810Sbostic 			*loadp++ = copys(lflag);
4184b5db810Sbostic 			break;
4194b5db810Sbostic 		}
4204b5db810Sbostic endfor:
4214b5db810Sbostic 	--argc;
4224b5db810Sbostic 	++argv;
4234b5db810Sbostic 	}
4244b5db810Sbostic 
4254b5db810Sbostic #ifdef	NOCORE
4264b5db810Sbostic if(!debugflag)
4274b5db810Sbostic 	{
4284b5db810Sbostic 	struct rlimit r;
4294b5db810Sbostic 
4304b5db810Sbostic 	r.rlim_cur = r.rlim_max = 0;
4314b5db810Sbostic 	setrlimit(RLIMIT_CORE, &r);
4324b5db810Sbostic 	}
4334b5db810Sbostic #endif	NOCORE
4344b5db810Sbostic 
4354b5db810Sbostic *fflagp = '\0';
4364b5db810Sbostic 
4374b5db810Sbostic if (ncpp > 0)
4384b5db810Sbostic 	cppflags = argvtos (ncpp,cppargs);
4394b5db810Sbostic 
4404b5db810Sbostic loadargs[0] = ldname;
4414b5db810Sbostic #if TARGET == PDP11
4424b5db810Sbostic 	if(nofloating)
4434b5db810Sbostic 		*loadp++ = (profileflag ? NOFLPROF : NOFLFOOT);
4444b5db810Sbostic 	else
4454b5db810Sbostic #endif
4464b5db810Sbostic *loadp++ = (profileflag ? proffoot : footname);
4474b5db810Sbostic 
4484b5db810Sbostic for(i = 0 ; i<argc ; ++i)
4494b5db810Sbostic 	switch(c =  dotchar(infname = argv[i]) )
4504b5db810Sbostic 		{
4514b5db810Sbostic 		case 'r':	/* Ratfor file */
4524b5db810Sbostic 		case 'e':	/* EFL file */
4534b5db810Sbostic 			if( unreadable(argv[i]) )
4544b5db810Sbostic 				{
4554b5db810Sbostic 				erred = YES;
4564b5db810Sbostic 				break;
4574b5db810Sbostic 				}
4584b5db810Sbostic 			s = fortfile;
4594b5db810Sbostic 			t = lastfield(argv[i]);
4604b5db810Sbostic 			while( *s++ = *t++)
4614b5db810Sbostic 				;
4624b5db810Sbostic 			s[-2] = 'f';
4634b5db810Sbostic 
4644b5db810Sbostic 			if(macroflag)
4654b5db810Sbostic 				{
4664b5db810Sbostic 				sprintf(buff, "%s %s >%s", macroname, infname, prepfname);
4674b5db810Sbostic 				if( sys(buff) )
4684b5db810Sbostic 					{
4694b5db810Sbostic 					rmf(prepfname);
4704b5db810Sbostic 					erred = YES;
4714b5db810Sbostic 					break;
4724b5db810Sbostic 					}
4734b5db810Sbostic 				infname = prepfname;
4744b5db810Sbostic 				}
4754b5db810Sbostic 
4764b5db810Sbostic 			if(c == 'e')
4774b5db810Sbostic 				sprintf(buff, "efl %s %s >%s", eflags, infname, fortfile);
4784b5db810Sbostic 			else
4794b5db810Sbostic 				sprintf(buff, "ratfor %s %s >%s", rflags, infname, fortfile);
4804b5db810Sbostic 			status = sys(buff);
4814b5db810Sbostic 			if(macroflag)
4824b5db810Sbostic 				rmf(infname);
4834b5db810Sbostic 			if(status)
4844b5db810Sbostic 				{
4854b5db810Sbostic 				erred = YES;
4864b5db810Sbostic 				rmf(fortfile);
4874b5db810Sbostic 				break;
4884b5db810Sbostic 				}
4894b5db810Sbostic 
4904b5db810Sbostic 			if( ! fortonly )
4914b5db810Sbostic 				{
4924b5db810Sbostic 				infname = argv[i] = lastfield(argv[i]);
4934b5db810Sbostic 				*lastchar(infname) = 'f';
4944b5db810Sbostic 
4954b5db810Sbostic 				if( dofort(argv[i]) )
4964b5db810Sbostic 					erred = YES;
4974b5db810Sbostic 				else	{
4984b5db810Sbostic 					if( nodup(t = setdoto(argv[i])) )
4994b5db810Sbostic 						*loadp++ = t;
5004b5db810Sbostic 					rmf(fortfile);
5014b5db810Sbostic 					}
5024b5db810Sbostic 				}
5034b5db810Sbostic 			break;
5044b5db810Sbostic 
5054b5db810Sbostic 		case 'F':	/* C preprocessor -> Fortran file */
5064b5db810Sbostic 			if( unreadable(argv[i]) )
5074b5db810Sbostic 				{
5084b5db810Sbostic 				erred = YES;
5094b5db810Sbostic 				break;
5104b5db810Sbostic 				}
5114b5db810Sbostic 			s = fortfile;
5124b5db810Sbostic 			t = lastfield(argv[i]);
5134b5db810Sbostic 			while( *s++ = *t++)
5144b5db810Sbostic 				;
5154b5db810Sbostic 			s[-2] = 'f';
5164b5db810Sbostic 			sprintf(buff,"%s %s %s >%s", cppname, cppflags, infname, fortfile);
5174b5db810Sbostic 			status = sys(buff);
5184b5db810Sbostic 			if(status)
5194b5db810Sbostic 				{
5204b5db810Sbostic 				erred = YES;
5214b5db810Sbostic 				rmf(fortfile);
5224b5db810Sbostic 				break;
5234b5db810Sbostic 				}
5244b5db810Sbostic 
5254b5db810Sbostic 			if( ! fortonly )
5264b5db810Sbostic 				{
5274b5db810Sbostic 				infname = argv[i] = lastfield(argv[i]);
5284b5db810Sbostic 				*lastchar(infname) = 'f';
5294b5db810Sbostic 
5304b5db810Sbostic 				if ( dofort(argv[i]) )
5314b5db810Sbostic 					erred = YES;
5324b5db810Sbostic 				else	{
5334b5db810Sbostic 					if (nodup(t = setdoto(argv[i])) )
5344b5db810Sbostic 						*loadp++ = t;
5354b5db810Sbostic 						rmf(fortfile);
5364b5db810Sbostic 						}
5374b5db810Sbostic 				}
5384b5db810Sbostic 			break;
5394b5db810Sbostic 
5404b5db810Sbostic 		case 'f':	/* Fortran file */
5414b5db810Sbostic 			if( unreadable(argv[i]) )
5424b5db810Sbostic 				erred = YES;
5434b5db810Sbostic 			else if( dofort(argv[i]) )
5444b5db810Sbostic 				erred = YES;
5454b5db810Sbostic 			else if( nodup(t=setdoto(argv[i])) )
5464b5db810Sbostic 				*loadp++ = t;
5474b5db810Sbostic 			break;
5484b5db810Sbostic 
5494b5db810Sbostic 		case 'c':	/* C file */
5504b5db810Sbostic 		case 's':	/* Assembler file */
5514b5db810Sbostic 			if( unreadable(argv[i]) )
5524b5db810Sbostic 				{
5534b5db810Sbostic 				erred = YES;
5544b5db810Sbostic 				break;
5554b5db810Sbostic 				}
5564b5db810Sbostic #if HERE==PDP11 || HERE==VAX || HERE==TAHOE
5574b5db810Sbostic 			if( namesflag == YES )
5584b5db810Sbostic 				fprintf(diagfile, "%s:\n", argv[i]);
5594b5db810Sbostic #endif
5604b5db810Sbostic 			sprintf(buff, "cc %s %s", cflags, argv[i] );
5614b5db810Sbostic 			if( sys(buff) )
5624b5db810Sbostic 				erred = YES;
5634b5db810Sbostic 			else
5644b5db810Sbostic 				if( nodup(t = setdoto(argv[i])) )
5654b5db810Sbostic 					*loadp++ = t;
5664b5db810Sbostic 			break;
5674b5db810Sbostic 
5684b5db810Sbostic 		case 'o':
5694b5db810Sbostic 			if( nodup(argv[i]) )
5704b5db810Sbostic 				*loadp++ = argv[i];
5714b5db810Sbostic 			break;
5724b5db810Sbostic 
5734b5db810Sbostic 		default:
5744b5db810Sbostic 			if( ! strcmp(argv[i], "-o") ) {
5754b5db810Sbostic 				aoutname = argv[++i];
5764b5db810Sbostic 				new_aoutname = YES;
5774b5db810Sbostic 				if( loadflag == NO ){
5784b5db810Sbostic 					fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname);
5794b5db810Sbostic 					new_aoutname = NO;
5804b5db810Sbostic 					}
5814b5db810Sbostic 			} else
5824b5db810Sbostic 				*loadp++ = argv[i];
5834b5db810Sbostic 			break;
5844b5db810Sbostic 		}
5854b5db810Sbostic 
5864b5db810Sbostic if( loadflag && stupid(aoutname) )
5874b5db810Sbostic 	erred = YES;
5884b5db810Sbostic if(loadflag && !erred)
5894b5db810Sbostic 	doload(loadargs, loadp);
5904b5db810Sbostic done(erred);
5914b5db810Sbostic }
5924b5db810Sbostic 
5934b5db810Sbostic 
5944b5db810Sbostic 
5954b5db810Sbostic /*
5964b5db810Sbostic  * argvtos() copies a list of arguments contained in an array of character
5974b5db810Sbostic  * strings to a single dynamically allocated string. Each argument is
5984b5db810Sbostic  * separated by one blank space. Returns a pointer to the string or null
5994b5db810Sbostic  * if out of memory.
6004b5db810Sbostic  */
6014b5db810Sbostic #define SBUFINCR	1024
6024b5db810Sbostic #define SBUFMAX		10240
6034b5db810Sbostic 
6044b5db810Sbostic char *
argvtos(argc,argv)6054b5db810Sbostic argvtos(argc, argv)
6064b5db810Sbostic 	char **argv;
6074b5db810Sbostic 	int  argc;
6084b5db810Sbostic {
6094b5db810Sbostic 	register char *s;		/* string pointer */
6104b5db810Sbostic 	register int  i;		/* string buffer pointer */
6114b5db810Sbostic 	char *malloc();			/* memory allocator */
6124b5db810Sbostic 	char *realloc();		/* increase size of storage */
6134b5db810Sbostic 	char *sbuf;			/* string buffer */
6144b5db810Sbostic 	int nbytes;			/* bytes of memory required */
6154b5db810Sbostic 	int nu;				/* no. of SBUFINCR units required */
6164b5db810Sbostic 	int sbufsize;			/* current size of sbuf */
6174b5db810Sbostic 	int strlen();			/* string length */
6184b5db810Sbostic 
6194b5db810Sbostic 	sbufsize = SBUFINCR;
6204b5db810Sbostic 	if ((sbuf = malloc((unsigned)sbufsize)) == NULL)
6214b5db810Sbostic 		{
6224b5db810Sbostic 		fatal("out of memory (argvtos)");
6234b5db810Sbostic 		/* NOTREACHED */
6244b5db810Sbostic 		}
6254b5db810Sbostic 
6264b5db810Sbostic 	for (i = 0; argc-- > 0; ++argv)
6274b5db810Sbostic 		{
6284b5db810Sbostic 		if ((nbytes = (i+strlen(*argv)+1-sbufsize)) > 0)
6294b5db810Sbostic 			{
6304b5db810Sbostic 			nu = (nbytes+SBUFINCR-1)/SBUFINCR;
6314b5db810Sbostic 			sbufsize += nu * SBUFINCR;
6324b5db810Sbostic 			if (sbufsize > SBUFMAX)
6334b5db810Sbostic 				{
6344b5db810Sbostic 				fatal("argument length exceeded (argvtos)");
6354b5db810Sbostic 				/* NOTREACHED */
6364b5db810Sbostic 				}
6374b5db810Sbostic 			if ((sbuf = realloc(sbuf, (unsigned)sbufsize)) == NULL)
6384b5db810Sbostic 				{
6394b5db810Sbostic 				fatal("out of memory (argvtos)");
6404b5db810Sbostic 				/* NOTREACHED */
6414b5db810Sbostic 				}
6424b5db810Sbostic 			}
6434b5db810Sbostic 		for (s = *argv; *s != '\0'; i++, s++)
6444b5db810Sbostic 			sbuf[i] = *s;
6454b5db810Sbostic 		sbuf[i++] = ' ';
6464b5db810Sbostic 		}
6474b5db810Sbostic 	sbuf[--i] = '\0';
6484b5db810Sbostic 	return(sbuf);
6494b5db810Sbostic }
6504b5db810Sbostic 
dofort(s)6514b5db810Sbostic dofort(s)
6524b5db810Sbostic char *s;
6534b5db810Sbostic {
6544b5db810Sbostic int retcode;
6554b5db810Sbostic char buff[200];
6564b5db810Sbostic 
6574b5db810Sbostic infname = s;
6584b5db810Sbostic sprintf(buff, "%s %s %s %s %s %s",
6594b5db810Sbostic 	pass1name, fflags, s, asmfname, initfname, textfname);
6604b5db810Sbostic switch( sys(buff) )
6614b5db810Sbostic 	{
6624b5db810Sbostic 	case 1:
6634b5db810Sbostic 		goto error;
6644b5db810Sbostic 	case 0:
6654b5db810Sbostic 		break;
6664b5db810Sbostic 	default:
6674b5db810Sbostic 		goto comperror;
6684b5db810Sbostic 	}
6694b5db810Sbostic 
6704b5db810Sbostic if( dopass2() )
6714b5db810Sbostic 	goto comperror;
6724b5db810Sbostic doasm(s);
6734b5db810Sbostic retcode = 0;
6744b5db810Sbostic 
6754b5db810Sbostic ret:
6764b5db810Sbostic 	rmf(asmfname);
6774b5db810Sbostic 	rmf(initfname);
6784b5db810Sbostic 	rmf(textfname);
6794b5db810Sbostic 	return(retcode);
6804b5db810Sbostic 
6814b5db810Sbostic error:
6824b5db810Sbostic 	fprintf(diagfile, "\nError.  No assembly.\n");
6834b5db810Sbostic 	retcode = 1;
6844b5db810Sbostic 	goto ret;
6854b5db810Sbostic 
6864b5db810Sbostic comperror:
6874b5db810Sbostic 	fprintf(diagfile, "\ncompiler error.\n");
6884b5db810Sbostic 	retcode = 2;
6894b5db810Sbostic 	goto ret;
6904b5db810Sbostic }
6914b5db810Sbostic 
6924b5db810Sbostic 
6934b5db810Sbostic 
6944b5db810Sbostic 
dopass2()6954b5db810Sbostic dopass2()
6964b5db810Sbostic {
6974b5db810Sbostic char buff[100];
6984b5db810Sbostic 
6994b5db810Sbostic if(verbose)
7004b5db810Sbostic 	fprintf(diagfile, "PASS2.");
7014b5db810Sbostic 
7024b5db810Sbostic #if FAMILY==DMR
7034b5db810Sbostic 	sprintf(buff, "%s %s - %s", pass2name, textfname, asmpass2);
7044b5db810Sbostic 	return( sys(buff) );
7054b5db810Sbostic #endif
7064b5db810Sbostic 
7074b5db810Sbostic 
7084b5db810Sbostic #if FAMILY == PCC
7094b5db810Sbostic #	if TARGET==INTERDATA
7104b5db810Sbostic 	sprintf(buff, "%s -A%s <%s >%s", pass2name, setfname, textfname, asmpass2);
7114b5db810Sbostic #	else
7124b5db810Sbostic 	sprintf(buff, "%s %s %s >%s",
7134b5db810Sbostic 		pass2name, f2flags, textfname, asmpass2);
7144b5db810Sbostic #	endif
7154b5db810Sbostic 	return( sys(buff) );
7164b5db810Sbostic #endif
7174b5db810Sbostic }
7184b5db810Sbostic 
7194b5db810Sbostic 
7204b5db810Sbostic 
7214b5db810Sbostic 
doasm(s)7224b5db810Sbostic doasm(s)
7234b5db810Sbostic char *s;
7244b5db810Sbostic {
7254b5db810Sbostic register char *lastc;
7264b5db810Sbostic char *obj;
7274b5db810Sbostic char buff[200];
7284b5db810Sbostic char *lastchar(), *setdoto();
7294b5db810Sbostic 
7304b5db810Sbostic if(*s == '\0')
7314b5db810Sbostic 	s = objfdefault;
7324b5db810Sbostic lastc = lastchar(s);
7334b5db810Sbostic obj = setdoto(s);
7344b5db810Sbostic 
7354b5db810Sbostic #if TARGET==PDP11 || TARGET==VAX || TARGET==TAHOE
7364b5db810Sbostic #	ifdef PASS2OPT
7374b5db810Sbostic 	if(optimflag)
7384b5db810Sbostic 		{
7394b5db810Sbostic #if TARGET==TAHOE
7404b5db810Sbostic 		sprintf(buff, "%s -f %s %s",
7414b5db810Sbostic #else
7424b5db810Sbostic 		sprintf(buff, "%s %s %s",
7434b5db810Sbostic #endif
7444b5db810Sbostic 		 pass2opt, asmpass2, optzfname);
7454b5db810Sbostic 		if( sys(buff) )
7464b5db810Sbostic 			rmf(optzfname);
7474b5db810Sbostic 		else
748086b6a4eSbostic 			(void)rename(optzfname, asmpass2);
7494b5db810Sbostic 		}
7504b5db810Sbostic #	endif
7514b5db810Sbostic #endif
7524b5db810Sbostic 
7534b5db810Sbostic if(saveasmflag)
7544b5db810Sbostic 	{
7554b5db810Sbostic 	*lastc = 's';
7564b5db810Sbostic #if TARGET == INTERDATA
7574b5db810Sbostic 	sprintf(buff, "%s %s %s %s %s >%s", CATNAME, asmfname, initfname,
7584b5db810Sbostic 		setfname, asmpass2, obj);
7594b5db810Sbostic #else
7604b5db810Sbostic #if TARGET == VAX || TARGET == TAHOE
7614b5db810Sbostic 		sprintf(buff, "%s %s %s %s >%s",
7624b5db810Sbostic 		CATNAME, asmfname, asmpass2, initfname, obj);
7634b5db810Sbostic #else
7644b5db810Sbostic 	sprintf(buff, "%s %s %s %s >%s",
7654b5db810Sbostic 		CATNAME, asmfname, initfname, asmpass2, obj);
7664b5db810Sbostic #endif
7674b5db810Sbostic #endif
7684b5db810Sbostic 	sys(buff);
7694b5db810Sbostic 	*lastc = 'o';
7704b5db810Sbostic 	}
7714b5db810Sbostic else
7724b5db810Sbostic 	{
7734b5db810Sbostic 	if(verbose)
7744b5db810Sbostic 		fprintf(diagfile, "  ASM.");
7754b5db810Sbostic #if TARGET == INTERDATA
7764b5db810Sbostic 	sprintf(buff, "%s -o %s %s %s %s %s", asmname, obj, asmfname,
7774b5db810Sbostic 		initfname, setfname, asmpass2);
7784b5db810Sbostic #endif
7794b5db810Sbostic 
7804b5db810Sbostic #if TARGET == VAX || TARGET == TAHOE
7814b5db810Sbostic 	/* vax assembler currently accepts only one input file */
7824b5db810Sbostic 
7834b5db810Sbostic 	sprintf(buff, "%s %s %s >>%s",
7844b5db810Sbostic 	CATNAME, asmpass2, initfname, asmfname);
7854b5db810Sbostic 	sys(buff);
7864b5db810Sbostic #ifdef UCBVAXASM
7874b5db810Sbostic 	sprintf(buff, "%s -J -o %s %s", asmname, obj, asmfname);
7884b5db810Sbostic #else
7894b5db810Sbostic 	sprintf(buff, "%s -o %s %s", asmname, obj, asmfname);
7904b5db810Sbostic #endif
7914b5db810Sbostic #endif
7924b5db810Sbostic 
7934b5db810Sbostic #if TARGET == PDP11
7944b5db810Sbostic 	sprintf(buff, "%s -u -o %s %s %s", asmname, obj, asmfname, asmpass2);
7954b5db810Sbostic #endif
7964b5db810Sbostic 
7974b5db810Sbostic #if TARGET!=INTERDATA && TARGET!=PDP11 && TARGET!=VAX && TARGET!=TAHOE
7984b5db810Sbostic 	sprintf(buff, "%s -o %s %s %s", asmname, obj, asmfname, asmpass2);
7994b5db810Sbostic #endif
8004b5db810Sbostic 
8014b5db810Sbostic 	if( sys(buff) )
8024b5db810Sbostic 		fatal("assembler error");
8034b5db810Sbostic 	if(verbose)
8044b5db810Sbostic 		fprintf(diagfile, "\n");
8054b5db810Sbostic #if HERE==PDP11 && TARGET!=PDP11
8064b5db810Sbostic 	rmf(obj);
8074b5db810Sbostic #endif
8084b5db810Sbostic 	}
8094b5db810Sbostic 
8104b5db810Sbostic rmf(asmpass2);
8114b5db810Sbostic }
8124b5db810Sbostic 
8134b5db810Sbostic 
8144b5db810Sbostic 
doload(v0,v)8154b5db810Sbostic doload(v0, v)
8164b5db810Sbostic register char *v0[], *v[];
8174b5db810Sbostic {
8184b5db810Sbostic char **p;
8194b5db810Sbostic int waitpid;
8204b5db810Sbostic 
8214b5db810Sbostic if (profileflag)
8224b5db810Sbostic 	{
8234b5db810Sbostic 	for(p = p_liblist ; *p ; *v++ = *p++)
8244b5db810Sbostic 		;
8254b5db810Sbostic 	}
8264b5db810Sbostic else	{
8274b5db810Sbostic 	for(p = liblist ; *p ; *v++ = *p++)
8284b5db810Sbostic 		;
8294b5db810Sbostic 	}
8304b5db810Sbostic 
8314b5db810Sbostic *v++ = "-o";
8324b5db810Sbostic *v++ = aoutname;
8334b5db810Sbostic *v = NULL;
8344b5db810Sbostic 
8354b5db810Sbostic if(verbose)
8364b5db810Sbostic 	fprintf(diagfile, "LOAD.");
8374b5db810Sbostic if(debugflag)
8384b5db810Sbostic 	{
8394b5db810Sbostic 	for(p = v0 ; p<v ; ++p)
8404b5db810Sbostic 		fprintf(diagfile, "%s ", *p);
8414b5db810Sbostic 	fprintf(diagfile, "\n");
8424b5db810Sbostic 	}
8434b5db810Sbostic 
8444b5db810Sbostic #if HERE==PDP11 || HERE==INTERDATA || HERE==VAX || HERE==TAHOE
8454b5db810Sbostic 	if( (waitpid = fork()) == 0)
8464b5db810Sbostic 		{
8474b5db810Sbostic 		enbint(SIG_DFL);
8484b5db810Sbostic 		execv(ldname, v0);
8494b5db810Sbostic 		fatalstr("couldn't load %s", ldname);
8504b5db810Sbostic 		}
8514b5db810Sbostic 	await(waitpid);
8524b5db810Sbostic #endif
8534b5db810Sbostic 
8544b5db810Sbostic #if HERE==INTERDATA
8554b5db810Sbostic 	if(optimflag)
8564b5db810Sbostic 		{
8574b5db810Sbostic 		char buff1[100], buff2[100];
8584b5db810Sbostic 		sprintf(buff1, "nopt %s -o junk.%d", aoutname, pid);
8594b5db810Sbostic 		sprintf(buff2, "mv junk.%d %s", pid, aoutname);
8604b5db810Sbostic 		if( sys(buff1) || sys(buff2) )
8614b5db810Sbostic 			err("bad optimization");
8624b5db810Sbostic 		}
8634b5db810Sbostic #endif
8644b5db810Sbostic 
8654b5db810Sbostic if(verbose)
8664b5db810Sbostic 	fprintf(diagfile, "\n");
8674b5db810Sbostic }
8684b5db810Sbostic 
8694b5db810Sbostic /* Process control and Shell-simulating routines */
8704b5db810Sbostic 
sys(str)8714b5db810Sbostic sys(str)
8724b5db810Sbostic char *str;
8734b5db810Sbostic {
8744b5db810Sbostic register char *s, *t;
8756b951ba4Sbostic char *argv[100];
8764b5db810Sbostic char *inname, *outname;
8774b5db810Sbostic int append;
8784b5db810Sbostic int waitpid;
8794b5db810Sbostic int argc;
8804b5db810Sbostic 
8814b5db810Sbostic 
8824b5db810Sbostic if(debugflag)
8834b5db810Sbostic 	fprintf(diagfile, "%s\n", str);
8844b5db810Sbostic inname  = NULL;
8854b5db810Sbostic outname = NULL;
8864b5db810Sbostic argv[0] = shellname;
8874b5db810Sbostic argc = 1;
8884b5db810Sbostic 
8894b5db810Sbostic t = str;
8904b5db810Sbostic while( isspace(*t) )
8914b5db810Sbostic 	++t;
8924b5db810Sbostic while(*t)
8934b5db810Sbostic 	{
8944b5db810Sbostic 	if(*t == '<')
8954b5db810Sbostic 		inname = t+1;
8964b5db810Sbostic 	else if(*t == '>')
8974b5db810Sbostic 		{
8984b5db810Sbostic 		if(t[1] == '>')
8994b5db810Sbostic 			{
9004b5db810Sbostic 			append = YES;
9014b5db810Sbostic 			outname = t+2;
9024b5db810Sbostic 			}
9034b5db810Sbostic 		else	{
9044b5db810Sbostic 			append = NO;
9054b5db810Sbostic 			outname = t+1;
9064b5db810Sbostic 			}
9074b5db810Sbostic 		}
9084b5db810Sbostic 	else
9094b5db810Sbostic 		argv[argc++] = t;
9104b5db810Sbostic 	while( !isspace(*t) && *t!='\0' )
9114b5db810Sbostic 		++t;
9124b5db810Sbostic 	if(*t)
9134b5db810Sbostic 		{
9144b5db810Sbostic 		*t++ = '\0';
9154b5db810Sbostic 		while( isspace(*t) )
9164b5db810Sbostic 			++t;
9174b5db810Sbostic 		}
9184b5db810Sbostic 	}
9194b5db810Sbostic 
9204b5db810Sbostic if(argc == 1)   /* no command */
9214b5db810Sbostic 	return(-1);
9224b5db810Sbostic argv[argc] = 0;
9234b5db810Sbostic 
9244b5db810Sbostic if((waitpid = fork()) == 0)
9254b5db810Sbostic 	{
9264b5db810Sbostic 	if(inname)
9274b5db810Sbostic 		freopen(inname, "r", stdin);
9284b5db810Sbostic 	if(outname)
9294b5db810Sbostic 		freopen(outname, (append ? "a" : "w"), stdout);
9304b5db810Sbostic 	enbint(SIG_DFL);
9314b5db810Sbostic 
9326b951ba4Sbostic 	texec(argv[1]  , argv);
9334b5db810Sbostic 
9346b951ba4Sbostic 	fatalstr("Cannot load %s", argv[1]);
9354b5db810Sbostic 	}
9364b5db810Sbostic 
9374b5db810Sbostic return( await(waitpid) );
9384b5db810Sbostic }
9394b5db810Sbostic 
9404b5db810Sbostic 
9414b5db810Sbostic 
9424b5db810Sbostic 
9434b5db810Sbostic 
9444b5db810Sbostic #include "errno.h"
9454b5db810Sbostic 
9464b5db810Sbostic /* modified version from the Shell */
texec(f,av)9474b5db810Sbostic texec(f, av)
9484b5db810Sbostic char *f;
9494b5db810Sbostic char **av;
9504b5db810Sbostic {
9514b5db810Sbostic extern int errno;
9524b5db810Sbostic 
9534b5db810Sbostic execv(f, av+1);
9544b5db810Sbostic 
9554b5db810Sbostic if (errno==ENOEXEC)
9564b5db810Sbostic 	{
9574b5db810Sbostic 	av[1] = f;
9584b5db810Sbostic 	execv(shellname, av);
9594b5db810Sbostic 	fatal("No shell!");
9604b5db810Sbostic 	}
9614b5db810Sbostic if (errno==ENOMEM)
9624b5db810Sbostic 	fatalstr("%s: too large", f);
9634b5db810Sbostic }
9644b5db810Sbostic 
9654b5db810Sbostic 
9664b5db810Sbostic 
9674b5db810Sbostic 
9684b5db810Sbostic 
9694b5db810Sbostic 
done(k)9704b5db810Sbostic done(k)
9714b5db810Sbostic int k;
9724b5db810Sbostic {
9734b5db810Sbostic static int recurs	= NO;
9744b5db810Sbostic 
9754b5db810Sbostic if(recurs == NO)
9764b5db810Sbostic 	{
9774b5db810Sbostic 	recurs = YES;
9784b5db810Sbostic 	rmfiles();
9794b5db810Sbostic 	}
9804b5db810Sbostic exit(k);
9814b5db810Sbostic }
9824b5db810Sbostic 
9834b5db810Sbostic 
9844b5db810Sbostic 
9854b5db810Sbostic 
9864b5db810Sbostic 
9874b5db810Sbostic 
9884b5db810Sbostic enbint(k)
9894b5db810Sbostic int (*k)();
9904b5db810Sbostic {
9914b5db810Sbostic if(sigivalue == 0)
9924b5db810Sbostic 	signal(SIGINT,k);
9934b5db810Sbostic if(sigqvalue == 0)
9944b5db810Sbostic 	signal(SIGQUIT,k);
9954b5db810Sbostic if(sighvalue == 0)
9964b5db810Sbostic 	signal(SIGHUP,k);
9974b5db810Sbostic if(sigtvalue == 0)
9984b5db810Sbostic 	signal(SIGTERM,k);
9994b5db810Sbostic }
10004b5db810Sbostic 
10014b5db810Sbostic 
10024b5db810Sbostic 
10034b5db810Sbostic 
intrupt()10044b5db810Sbostic intrupt()
10054b5db810Sbostic {
10064b5db810Sbostic done(2);
10074b5db810Sbostic }
10084b5db810Sbostic 
10094b5db810Sbostic 
10104b5db810Sbostic #ifdef PSIGNAL
10114b5db810Sbostic /*
10124b5db810Sbostic  * Fancy 4.2 BSD signal printing stuff.
10134b5db810Sbostic  */
10144b5db810Sbostic char harmless[NSIG] = { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 };
10154b5db810Sbostic #endif
10164b5db810Sbostic 
10174b5db810Sbostic 
await(waitpid)10184b5db810Sbostic await(waitpid)
10194b5db810Sbostic int waitpid;
10204b5db810Sbostic {
10214b5db810Sbostic 
10224b5db810Sbostic #ifdef PSIGNAL
10234b5db810Sbostic extern char *sys_siglist[];
10244b5db810Sbostic union wait status;
10254b5db810Sbostic #else PSIGNAL
10264b5db810Sbostic int status;
10274b5db810Sbostic #endif PSIGNAL
10284b5db810Sbostic 
10294b5db810Sbostic int w;
10304b5db810Sbostic 
10314b5db810Sbostic enbint(SIG_IGN);
10324b5db810Sbostic while ( (w = wait(&status)) != waitpid)
10334b5db810Sbostic 	if(w == -1)
10344b5db810Sbostic 		fatal("bad wait code");
10354b5db810Sbostic enbint(intrupt);
10364b5db810Sbostic 
10374b5db810Sbostic #ifdef PSIGNAL
10384b5db810Sbostic if(status.w_termsig)
10394b5db810Sbostic 	{
10404b5db810Sbostic 	debugflag = 0;	/* Prevent us from dumping core ourselves */
10414b5db810Sbostic 	if(status.w_termsig != SIGINT && status.w_termsig < NSIG)
10424b5db810Sbostic 		fprintf(diagfile, "%s%s\n", sys_siglist[status.w_termsig],
10434b5db810Sbostic 			status.w_coredump ? " -- core dumped" : "");
10444b5db810Sbostic 	if(status.w_termsig < NSIG && ! harmless[status.w_termsig])
10454b5db810Sbostic 		fatal("see a system manager");
10464b5db810Sbostic 	else
10474b5db810Sbostic 		done(3);
10484b5db810Sbostic 	}
10494b5db810Sbostic return(status.w_retcode);
10504b5db810Sbostic #else PSIGNAL
10514b5db810Sbostic if(status & 0377)
10524b5db810Sbostic 	{
10534b5db810Sbostic 	if(status != SIGINT)
10544b5db810Sbostic 		fprintf(diagfile, "Termination code %d\n", status);
10554b5db810Sbostic 	done(3);
10564b5db810Sbostic 	}
10574b5db810Sbostic return(status>>8);
10584b5db810Sbostic #endif PSIGNAL
10594b5db810Sbostic }
10604b5db810Sbostic 
10614b5db810Sbostic /* File Name and File Manipulation Routines */
10624b5db810Sbostic 
unreadable(s)10634b5db810Sbostic unreadable(s)
10644b5db810Sbostic register char *s;
10654b5db810Sbostic {
10664b5db810Sbostic register FILE *fp;
10674b5db810Sbostic 
10684b5db810Sbostic if(fp = fopen(s, "r"))
10694b5db810Sbostic 	{
10704b5db810Sbostic 	fclose(fp);
10714b5db810Sbostic 	return(NO);
10724b5db810Sbostic 	}
10734b5db810Sbostic 
10744b5db810Sbostic else
10754b5db810Sbostic 	{
10764b5db810Sbostic 	fprintf(diagfile, "Error: Cannot read file %s\n", s);
10774b5db810Sbostic 	return(YES);
10784b5db810Sbostic 	}
10794b5db810Sbostic }
10804b5db810Sbostic 
10814b5db810Sbostic 
10824b5db810Sbostic 
stupid(s)10834b5db810Sbostic stupid(s)
10844b5db810Sbostic char *s;
10854b5db810Sbostic {
10864b5db810Sbostic char c;
10874b5db810Sbostic 
10884b5db810Sbostic if( (c = dotchar(s))
10894b5db810Sbostic   && index("focsreF", c)
10904b5db810Sbostic   && access(s, 0) == 0 )
10914b5db810Sbostic 	{
10924b5db810Sbostic 	fprintf(diagfile, "Loading on %s would destroy it\n", s);
10934b5db810Sbostic 	return(YES);
10944b5db810Sbostic 	}
10954b5db810Sbostic return(NO);
10964b5db810Sbostic }
10974b5db810Sbostic 
10984b5db810Sbostic 
10994b5db810Sbostic 
clf(p)11004b5db810Sbostic clf(p)
11014b5db810Sbostic FILEP *p;
11024b5db810Sbostic {
11034b5db810Sbostic if(p!=NULL && *p!=NULL && *p!=stdout)
11044b5db810Sbostic 	{
11054b5db810Sbostic 	if(ferror(*p))
11064b5db810Sbostic 		fatal("writing error");
11074b5db810Sbostic 	fclose(*p);
11084b5db810Sbostic 	}
11094b5db810Sbostic *p = NULL;
11104b5db810Sbostic }
11114b5db810Sbostic 
rmfiles()11124b5db810Sbostic rmfiles()
11134b5db810Sbostic {
11144b5db810Sbostic rmf(textfname);
11154b5db810Sbostic rmf(asmfname);
11164b5db810Sbostic rmf(initfname);
11174b5db810Sbostic rmf(asmpass2);
11184b5db810Sbostic #if TARGET == INTERDATA
11194b5db810Sbostic 	rmf(setfname);
11204b5db810Sbostic #endif
11214b5db810Sbostic }
11224b5db810Sbostic 
11234b5db810Sbostic 
11244b5db810Sbostic 
11254b5db810Sbostic 
11264b5db810Sbostic 
11274b5db810Sbostic 
11284b5db810Sbostic 
11294b5db810Sbostic 
11304b5db810Sbostic /* return -1 if file does not exist, 0 if it is of zero length
11314b5db810Sbostic    and 1 if of positive length
11324b5db810Sbostic */
content(filename)11334b5db810Sbostic content(filename)
11344b5db810Sbostic char *filename;
11354b5db810Sbostic {
11364b5db810Sbostic #ifdef VERSION6
11374b5db810Sbostic 	struct stat
11384b5db810Sbostic 		{
11394b5db810Sbostic 		char cjunk[9];
11404b5db810Sbostic 		char size0;
11414b5db810Sbostic 		int size1;
11424b5db810Sbostic 		int ijunk[12];
11434b5db810Sbostic 		} buf;
11444b5db810Sbostic #else
11454b5db810Sbostic 	struct stat buf;
11464b5db810Sbostic #endif
11474b5db810Sbostic 
11484b5db810Sbostic if(stat(filename,&buf) < 0)
11494b5db810Sbostic 	return(-1);
11504b5db810Sbostic #ifdef VERSION6
11514b5db810Sbostic 	return(buf.size0 || buf.size1);
11524b5db810Sbostic #else
11534b5db810Sbostic 	return( buf.st_size > 0 );
11544b5db810Sbostic #endif
11554b5db810Sbostic }
11564b5db810Sbostic 
11574b5db810Sbostic 
11584b5db810Sbostic 
11594b5db810Sbostic 
crfnames()11604b5db810Sbostic crfnames()
11614b5db810Sbostic {
11624b5db810Sbostic fname(textfname, "x");
11634b5db810Sbostic fname(asmfname, "s");
11644b5db810Sbostic fname(asmpass2, "a");
11654b5db810Sbostic fname(initfname, "d");
11664b5db810Sbostic fname(sortfname, "S");
11674b5db810Sbostic fname(objfdefault, "o");
11684b5db810Sbostic fname(prepfname, "p");
11694b5db810Sbostic fname(optzfname, "z");
11704b5db810Sbostic fname(setfname, "A");
11714b5db810Sbostic }
11724b5db810Sbostic 
11734b5db810Sbostic 
11744b5db810Sbostic 
11754b5db810Sbostic 
rmf(fn)11764b5db810Sbostic rmf(fn)
11774b5db810Sbostic register char *fn;
11784b5db810Sbostic {
11794b5db810Sbostic /* if(!debugflag && fn!=NULL && *fn!='\0') */
11804b5db810Sbostic 
11814b5db810Sbostic if(fn!=NULL && *fn!='\0')
11824b5db810Sbostic 	unlink(fn);
11834b5db810Sbostic }
11844b5db810Sbostic 
11854b5db810Sbostic 
11864b5db810Sbostic 
11874b5db810Sbostic 
11884b5db810Sbostic 
fname(name,suff)11894b5db810Sbostic LOCAL fname(name, suff)
11904b5db810Sbostic char *name, *suff;
11914b5db810Sbostic {
11926b951ba4Sbostic sprintf(name, "%s/%s%d.%s", _PATH_TMP, temppref, pid, suff);
11934b5db810Sbostic }
11944b5db810Sbostic 
11954b5db810Sbostic 
11964b5db810Sbostic 
11974b5db810Sbostic 
dotchar(s)11984b5db810Sbostic dotchar(s)
11994b5db810Sbostic register char *s;
12004b5db810Sbostic {
12014b5db810Sbostic for( ; *s ; ++s)
12024b5db810Sbostic 	if(s[0]=='.' && s[1]!='\0' && s[2]=='\0')
12034b5db810Sbostic 		return( s[1] );
12044b5db810Sbostic return(NO);
12054b5db810Sbostic }
12064b5db810Sbostic 
12074b5db810Sbostic 
12084b5db810Sbostic 
lastfield(s)12094b5db810Sbostic char *lastfield(s)
12104b5db810Sbostic register char *s;
12114b5db810Sbostic {
12124b5db810Sbostic register char *t;
12134b5db810Sbostic for(t = s; *s ; ++s)
12144b5db810Sbostic 	if(*s == '/')
12154b5db810Sbostic 		t = s+1;
12164b5db810Sbostic return(t);
12174b5db810Sbostic }
12184b5db810Sbostic 
12194b5db810Sbostic 
12204b5db810Sbostic 
lastchar(s)12214b5db810Sbostic char *lastchar(s)
12224b5db810Sbostic register char *s;
12234b5db810Sbostic {
12244b5db810Sbostic while(*s)
12254b5db810Sbostic 	++s;
12264b5db810Sbostic return(s-1);
12274b5db810Sbostic }
12284b5db810Sbostic 
setdoto(s)12294b5db810Sbostic char *setdoto(s)
12304b5db810Sbostic register char *s;
12314b5db810Sbostic {
12324b5db810Sbostic *lastchar(s) = 'o';
12334b5db810Sbostic return( lastfield(s) );
12344b5db810Sbostic }
12354b5db810Sbostic 
12364b5db810Sbostic 
12374b5db810Sbostic 
badfile(s)12384b5db810Sbostic badfile(s)
12394b5db810Sbostic char *s;
12404b5db810Sbostic {
12414b5db810Sbostic fatalstr("cannot open intermediate file %s", s);
12424b5db810Sbostic }
12434b5db810Sbostic 
12444b5db810Sbostic 
12454b5db810Sbostic 
ckalloc(n)12464b5db810Sbostic ptr ckalloc(n)
12474b5db810Sbostic int n;
12484b5db810Sbostic {
12494b5db810Sbostic ptr p, calloc();
12504b5db810Sbostic 
12514b5db810Sbostic if( p = calloc(1, (unsigned) n) )
12524b5db810Sbostic 	return(p);
12534b5db810Sbostic 
12544b5db810Sbostic fatal("out of memory");
12554b5db810Sbostic /* NOTREACHED */
12564b5db810Sbostic }
12574b5db810Sbostic 
12584b5db810Sbostic 
12594b5db810Sbostic 
12604b5db810Sbostic 
12614b5db810Sbostic 
copyn(n,s)12624b5db810Sbostic char *copyn(n, s)
12634b5db810Sbostic register int n;
12644b5db810Sbostic register char *s;
12654b5db810Sbostic {
12664b5db810Sbostic register char *p, *q;
12674b5db810Sbostic 
12684b5db810Sbostic p = q = (char *) ckalloc(n);
12694b5db810Sbostic while(n-- > 0)
12704b5db810Sbostic 	*q++ = *s++;
12714b5db810Sbostic return(p);
12724b5db810Sbostic }
12734b5db810Sbostic 
12744b5db810Sbostic 
12754b5db810Sbostic 
copys(s)12764b5db810Sbostic char *copys(s)
12774b5db810Sbostic char *s;
12784b5db810Sbostic {
12794b5db810Sbostic return( copyn( strlen(s)+1 , s) );
12804b5db810Sbostic }
12814b5db810Sbostic 
12824b5db810Sbostic 
12834b5db810Sbostic 
12844b5db810Sbostic 
12854b5db810Sbostic 
oneof(c,s)12864b5db810Sbostic oneof(c,s)
12874b5db810Sbostic register c;
12884b5db810Sbostic register char *s;
12894b5db810Sbostic {
12904b5db810Sbostic while( *s )
12914b5db810Sbostic 	if(*s++ == c)
12924b5db810Sbostic 		return(YES);
12934b5db810Sbostic return(NO);
12944b5db810Sbostic }
12954b5db810Sbostic 
12964b5db810Sbostic 
12974b5db810Sbostic 
nodup(s)12984b5db810Sbostic nodup(s)
12994b5db810Sbostic char *s;
13004b5db810Sbostic {
13014b5db810Sbostic register char **p;
13024b5db810Sbostic 
13034b5db810Sbostic for(p = loadargs ; p < loadp ; ++p)
13044b5db810Sbostic 	if( !strcmp(*p, s) )
13054b5db810Sbostic 		return(NO);
13064b5db810Sbostic 
13074b5db810Sbostic return(YES);
13084b5db810Sbostic }
13094b5db810Sbostic 
13104b5db810Sbostic 
13114b5db810Sbostic 
fatal(t)13124b5db810Sbostic static fatal(t)
13134b5db810Sbostic char *t;
13144b5db810Sbostic {
13154b5db810Sbostic fprintf(diagfile, "Compiler error in file %s: %s\n", infname, t);
13164b5db810Sbostic if(debugflag)
13174b5db810Sbostic 	abort();
13184b5db810Sbostic done(1);
13194b5db810Sbostic exit(1);
13204b5db810Sbostic }
13214b5db810Sbostic 
13224b5db810Sbostic 
13234b5db810Sbostic 
13244b5db810Sbostic 
fatali(t,d)13254b5db810Sbostic static fatali(t,d)
13264b5db810Sbostic char *t;
13274b5db810Sbostic int d;
13284b5db810Sbostic {
13294b5db810Sbostic char buff[100];
13304b5db810Sbostic sprintf(buff, t, d);
13314b5db810Sbostic fatal(buff);
13324b5db810Sbostic }
13334b5db810Sbostic 
13344b5db810Sbostic 
13354b5db810Sbostic 
13364b5db810Sbostic 
fatalstr(t,s)13374b5db810Sbostic static fatalstr(t, s)
13384b5db810Sbostic char *t, *s;
13394b5db810Sbostic {
13404b5db810Sbostic char buff[100];
13414b5db810Sbostic sprintf(buff, t, s);
13424b5db810Sbostic fatal(buff);
13434b5db810Sbostic }
err(s)13444b5db810Sbostic err(s)
13454b5db810Sbostic char *s;
13464b5db810Sbostic {
13474b5db810Sbostic fprintf(diagfile, "Error in file %s: %s\n", infname, s);
13484b5db810Sbostic }
13494b5db810Sbostic 
1350