137414Sbostic /* 237414Sbostic * f77.c 337414Sbostic * 437414Sbostic * Driver program for the 4.2 BSD f77 compiler. 537414Sbostic * 637414Sbostic * University of Utah CS Dept modification history: 737414Sbostic * 837414Sbostic * $Log: f77.c,v $ 937414Sbostic * Revision 1.14 85/03/01 00:07:57 donn 1037414Sbostic * Portability fix from Ralph Campbell. 1137414Sbostic * 1237414Sbostic * Revision 1.13 85/02/12 19:31:47 donn 1337414Sbostic * Use CATNAME to get the name of a concatenation command instead of 1437414Sbostic * explicitly running 'cat' -- you can get the wrong 'cat' the old way! 1537414Sbostic * 1637414Sbostic * Revision 1.12 85/01/14 06:42:30 donn 1737414Sbostic * Changed to call the peephole optimizer with the '-f' flag, so that 1837414Sbostic * floating point moves are translated to integer moves. 1937414Sbostic * 2037414Sbostic * Revision 1.11 85/01/14 04:38:59 donn 2137414Sbostic * Jerry's change to pass -O to f1 so it knows whether the peephole optimizer 2237414Sbostic * will be run. This is necessary in order to handle movf/movl translation. 2337414Sbostic * 2437414Sbostic * Revision 1.10 85/01/14 03:59:12 donn 2537414Sbostic * Added Jerry Berkman's fix for the '-q' flag. 2637414Sbostic * 2737414Sbostic * Revision 1.9 84/11/09 01:51:26 donn 2837414Sbostic * Cosmetic change to stupid() suggested by John McCarthy at Memorial 2937414Sbostic * University, St. Johns. 3037414Sbostic * 3137414Sbostic * Revision 1.8 84/09/14 16:02:34 donn 3237414Sbostic * Added changes to notice when people do 'f77 -c foo.f -o bar.o' and tell 3337414Sbostic * them why it doesn't do what they think it does. 3437414Sbostic * 3537414Sbostic * Revision 1.7 84/08/24 21:08:31 donn 3637414Sbostic * Added call to setrlimit() to prevent core dumps when not debugging. 3737414Sbostic * Reorganized the include file arrangment somewhat. 3837414Sbostic * 3937414Sbostic * Revision 1.6 84/08/24 20:20:24 donn 4037414Sbostic * Changed stupidity check on Jerry Berkman's suggestion -- now it balks if 4137414Sbostic * the load file exists and has a sensitive suffix. 4237414Sbostic * 4337414Sbostic * Revision 1.5 84/08/15 18:56:44 donn 4437414Sbostic * Added test for -O combined with -g, suggested by Raleigh Romine. To keep 4537414Sbostic * things simple, if both are specified then the second in the list is thrown 4637414Sbostic * out and the user is warned. 4737414Sbostic * 4837414Sbostic * Revision 1.4 84/08/05 21:33:15 donn 4937414Sbostic * Added stupidity check -- f77 won't load on a file that it's asked to 5037414Sbostic * compile as well. 5137414Sbostic * 5237414Sbostic * Revision 1.3 84/08/04 22:58:24 donn 5337414Sbostic * Improved error reporting -- we now explain why we died and what we did. 5437414Sbostic * Only works on 4.2. Added at the instigation of Jerry Berkman. 5537414Sbostic * 5637414Sbostic * Revision 1.2 84/07/28 13:11:24 donn 5737414Sbostic * Added Ralph Campbell's changes to reduce offsets to data. 5837414Sbostic * 5937414Sbostic */ 6037414Sbostic 6137414Sbostic char *xxxvers[] = "\n@(#) F77 DRIVER, VERSION 4.2, 1984 JULY 28\n"; 6237414Sbostic #include <stdio.h> 6337414Sbostic #include <sys/types.h> 6437414Sbostic #include <sys/stat.h> 6537414Sbostic #include <ctype.h> 6637414Sbostic #include <signal.h> 6737414Sbostic 6837414Sbostic #ifdef SIGPROF 6937414Sbostic /* 7037414Sbostic * Some 4.2 BSD capabilities. 7137414Sbostic */ 7237414Sbostic #include <sys/time.h> 7337414Sbostic #include <sys/resource.h> 7437414Sbostic #define NOCORE 1 7537414Sbostic #include <sys/wait.h> 7637414Sbostic #define PSIGNAL 1 7737414Sbostic #define INLINE 1 7837414Sbostic #endif 7937414Sbostic 8037414Sbostic #include "defines.h" 8137414Sbostic #include "machdefs.h" 8237792Sbostic #include "pathnames.h" 8337414Sbostic #include "version.h" 8437414Sbostic 8537414Sbostic static FILEP diagfile = {stderr} ; 8637414Sbostic static int pid; 8737414Sbostic static int sigivalue = 0; 8837414Sbostic static int sigqvalue = 0; 8937414Sbostic static int sighvalue = 0; 9037414Sbostic static int sigtvalue = 0; 9137414Sbostic 9237414Sbostic static char *pass1name = PASS1NAME ; 9337414Sbostic static char *pass2name = PASS2NAME ; 9437414Sbostic static char *pass2opt = PASS2OPT ; 9537414Sbostic static char *asmname = ASMNAME ; 9637414Sbostic static char *ldname = LDNAME ; 9737414Sbostic static char *footname = FOOTNAME; 9837414Sbostic static char *proffoot = PROFFOOT; 9937414Sbostic static char *macroname = "m4"; 10037792Sbostic static char *shellname = _PATH_BSHELL; 10137792Sbostic static char *cppname = _PATH_CPP; 10237414Sbostic static char *aoutname = "a.out" ; 10337414Sbostic static char *temppref = TEMPPREF; 10437414Sbostic 10537414Sbostic static char *infname; 10637414Sbostic static char textfname[44]; 10737414Sbostic static char asmfname[44]; 10837414Sbostic static char asmpass2[44]; 10937414Sbostic static char initfname[44]; 11037414Sbostic static char sortfname[44]; 11137414Sbostic static char prepfname[44]; 11237414Sbostic static char objfdefault[44]; 11337414Sbostic static char optzfname[44]; 11437414Sbostic static char setfname[44]; 11537414Sbostic 11637414Sbostic static char fflags[50] = "-"; 11737414Sbostic static char f2flags[50]; 11837414Sbostic static char cflags[50] = "-c"; 11937414Sbostic #if TARGET == GCOS 12037414Sbostic static char eflags[30] = "system=gcos "; 12137414Sbostic #else 12237414Sbostic static char eflags[30] = "system=unix "; 12337414Sbostic #endif 12437414Sbostic static char rflags[30] = ""; 12537414Sbostic static char lflag[3] = "-x"; 12637414Sbostic static char *fflagp = fflags+1; 12737414Sbostic static char *f2flagp = f2flags; 12837414Sbostic static char *cflagp = cflags+2; 12937414Sbostic static char *eflagp = eflags+12; 13037414Sbostic static char *rflagp = rflags; 13137414Sbostic static char *cppflags = ""; 13237414Sbostic static char **cppargs; 13337414Sbostic static char **loadargs; 13437414Sbostic static char **loadp; 13537414Sbostic 13637414Sbostic static flag erred = NO; 13737414Sbostic static flag loadflag = YES; 13837414Sbostic static flag saveasmflag = NO; 13937414Sbostic static flag profileflag = NO; 14037414Sbostic static flag optimflag = NO; 14137414Sbostic static flag debugflag = NO; 14237414Sbostic static flag verbose = NO; 14337414Sbostic static flag nofloating = NO; 14437414Sbostic static flag fortonly = NO; 14537414Sbostic static flag macroflag = NO; 14637414Sbostic static flag sdbflag = NO; 14737414Sbostic static flag namesflag = YES; 14837414Sbostic 14937414Sbostic static int ncpp; 15037414Sbostic 15137414Sbostic 15237414Sbostic main(argc, argv) 15337414Sbostic int argc; 15437414Sbostic char **argv; 15537414Sbostic { 15637414Sbostic int i, c, status; 15737414Sbostic char *setdoto(), *lastchar(), *lastfield(), *copys(), *argvtos(); 15837414Sbostic ptr ckalloc(); 15937414Sbostic register char *s; 16037414Sbostic char fortfile[20], *t; 16137414Sbostic char buff[100]; 16237414Sbostic int intrupt(); 16337414Sbostic int new_aoutname = NO; 16437414Sbostic 16537414Sbostic sigivalue = signal(SIGINT, SIG_IGN) == SIG_IGN; 16637414Sbostic sigqvalue = signal(SIGQUIT,SIG_IGN) == SIG_IGN; 16737414Sbostic sighvalue = signal(SIGHUP, SIG_IGN) == SIG_IGN; 16837414Sbostic sigtvalue = signal(SIGTERM,SIG_IGN) == SIG_IGN; 16937414Sbostic enbint(intrupt); 17037414Sbostic 17137414Sbostic pid = getpid(); 17237414Sbostic crfnames(); 17337414Sbostic 17437414Sbostic cppargs = (char **) ckalloc( argc * sizeof(*cppargs) ); 17537414Sbostic loadargs = (char **) ckalloc( (argc+20) * sizeof(*loadargs) ); 17637414Sbostic loadargs[1] = "-X"; 17737414Sbostic loadargs[2] = "-u"; 17837414Sbostic #if HERE==PDP11 || HERE==VAX || HERE==TAHOE 17937414Sbostic loadargs[3] = "_MAIN_"; 18037414Sbostic #endif 18137414Sbostic #if HERE == INTERDATA 18237414Sbostic loadargs[3] = "main"; 18337414Sbostic #endif 18437414Sbostic loadp = loadargs + 4; 18537414Sbostic 18637414Sbostic --argc; 18737414Sbostic ++argv; 18837414Sbostic 18937414Sbostic while(argc>0 && argv[0][0]=='-' && argv[0][1]!='\0') 19037414Sbostic { 19137414Sbostic for(s = argv[0]+1 ; *s ; ++s) switch(*s) 19237414Sbostic { 19337414Sbostic case 'T': /* use special passes */ 19437414Sbostic switch(*++s) 19537414Sbostic { 19637414Sbostic case '1': 19737414Sbostic pass1name = s+1; goto endfor; 19837414Sbostic case '2': 19937414Sbostic pass2name = s+1; goto endfor; 20037414Sbostic case 'p': 20137414Sbostic pass2opt = s+1; goto endfor; 20237414Sbostic case 'a': 20337414Sbostic asmname = s+1; goto endfor; 20437414Sbostic case 'l': 20537414Sbostic ldname = s+1; goto endfor; 20637414Sbostic case 'F': 20737414Sbostic footname = s+1; goto endfor; 20837414Sbostic case 'm': 20937414Sbostic macroname = s+1; goto endfor; 21037414Sbostic case 't': 21137414Sbostic temppref = s+1; goto endfor; 21237414Sbostic default: 21337414Sbostic fatali("bad option -T%c", *s); 21437414Sbostic } 21537414Sbostic break; 21637414Sbostic 21737414Sbostic case '6': 21837414Sbostic if(s[1]=='6') 21937414Sbostic { 22037414Sbostic *fflagp++ = *s++; 22137414Sbostic goto copyfflag; 22237414Sbostic } 22337414Sbostic else { 22437414Sbostic fprintf(diagfile, "invalid flag 6%c\n", s[1]); 22537414Sbostic done(1); 22637414Sbostic } 22737414Sbostic 22837414Sbostic case 'w': 22937414Sbostic if(s[1]=='6' && s[2]=='6') 23037414Sbostic { 23137414Sbostic *fflagp++ = *s++; 23237414Sbostic *fflagp++ = *s++; 23337414Sbostic } 23437414Sbostic 23537414Sbostic copyfflag: 23637414Sbostic case 'u': 23737414Sbostic case 'U': 23837414Sbostic case '1': 23937414Sbostic case 'C': 24037414Sbostic *fflagp++ = *s; 24137414Sbostic break; 24237414Sbostic 24337414Sbostic case 'O': 24437414Sbostic if(sdbflag) 24537414Sbostic { 24637414Sbostic fprintf(diagfile, "-O and -g are incompatible; -O ignored\n"); 24737414Sbostic break; 24837414Sbostic } 24937414Sbostic optimflag = YES; 25037414Sbostic #if TARGET == INTERDATA 25137414Sbostic *loadp++ = "-r"; 25237414Sbostic *loadp++ = "-d"; 25337414Sbostic #endif 25437414Sbostic *fflagp++ = 'O'; 25537414Sbostic break; 25637414Sbostic 25737414Sbostic case 'N': 25837414Sbostic *fflagp++ = 'N'; 25937414Sbostic if( oneof(*++s, "qxscn") ) 26037414Sbostic *fflagp++ = *s++; 26137414Sbostic else { 26237414Sbostic fprintf(diagfile, "invalid flag -N%c\n", *s); 26337414Sbostic done(1); 26437414Sbostic } 26537414Sbostic while( isdigit(*s) ) 26637414Sbostic *fflagp++ = *s++; 26737414Sbostic *fflagp++ = 'X'; 26837414Sbostic goto endfor; 26937414Sbostic 27037414Sbostic case 'm': 27137414Sbostic if(s[1] == '4') 27237414Sbostic ++s; 27337414Sbostic macroflag = YES; 27437414Sbostic break; 27537414Sbostic 27637414Sbostic case 'S': 27737414Sbostic strcat(cflags, " -S"); 27837414Sbostic saveasmflag = YES; 27937414Sbostic 28037414Sbostic case 'c': 28137414Sbostic if( new_aoutname == YES ){ 28237414Sbostic fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname); 28337414Sbostic new_aoutname = NO; 28437414Sbostic } 28537414Sbostic loadflag = NO; 28637414Sbostic break; 28737414Sbostic 28837414Sbostic case 'v': 28937414Sbostic verbose = YES; 29037414Sbostic fprintf(diagfile,"\nBerkeley F77, version %s\n", 29137414Sbostic VERSIONNUMBER); 29237414Sbostic break; 29337414Sbostic 29437414Sbostic case 'd': 29537414Sbostic debugflag = YES; 29637414Sbostic *fflagp++ = 'd'; 29737414Sbostic s++; 29837414Sbostic while( isdigit(*s) || *s == ',' ) 29937414Sbostic *fflagp++ = *s++; 30037414Sbostic *fflagp++ = 'X'; 30137414Sbostic goto endfor; 30237414Sbostic 30337414Sbostic case 'M': 30437414Sbostic *loadp++ = "-M"; 30537414Sbostic break; 30637414Sbostic 30737414Sbostic case 'g': 30837414Sbostic if(optimflag) 30937414Sbostic { 31037414Sbostic fprintf(diagfile, "-g and -O are incompatible; -g ignored\n"); 31137414Sbostic break; 31237414Sbostic } 31337414Sbostic strcat(cflags," -g"); 31437414Sbostic sdbflag = YES; 31537414Sbostic goto copyfflag; 31637414Sbostic 31737414Sbostic case 'p': 31837414Sbostic profileflag = YES; 31937414Sbostic strcat(cflags," -p"); 32037414Sbostic *fflagp++ = 'p'; 32137414Sbostic if(s[1] == 'g') 32237414Sbostic { 32337414Sbostic proffoot = GPRFFOOT; 32437414Sbostic s++; 32537414Sbostic } 32637414Sbostic break; 32737414Sbostic 32837414Sbostic case 'q': 32937414Sbostic namesflag = NO; 33037414Sbostic *fflagp++ = *s; 33137414Sbostic break; 33237414Sbostic 33337414Sbostic case 'o': 33437414Sbostic if( ! strcmp(s, "onetrip") ) 33537414Sbostic { 33637414Sbostic *fflagp++ = '1'; 33737414Sbostic goto endfor; 33837414Sbostic } 33937414Sbostic new_aoutname = YES; 34037414Sbostic aoutname = *++argv; 34137414Sbostic --argc; 34237414Sbostic if( loadflag == NO ){ 34337414Sbostic fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname); 34437414Sbostic new_aoutname = NO; 34537414Sbostic } 34637414Sbostic break; 34737414Sbostic 34837414Sbostic #if TARGET == PDP11 34937414Sbostic case 'f': 35037414Sbostic nofloating = YES; 35137414Sbostic pass2name = NOFLPASS2; 35237414Sbostic break; 35337414Sbostic #endif 35437414Sbostic 35537414Sbostic case 'F': 35637414Sbostic fortonly = YES; 35737414Sbostic loadflag = NO; 35837414Sbostic break; 35937414Sbostic case 'D': 36037414Sbostic case 'I': 36137414Sbostic cppargs[ncpp++] = *argv; 36237414Sbostic goto endfor; 36337414Sbostic 36437414Sbostic case 'i': 36537414Sbostic if((s[1]=='2' || s[1]=='4') && s[2] == '\0') 36637414Sbostic { 36737414Sbostic *fflagp++ = *s++; 36837414Sbostic goto copyfflag; 36937414Sbostic } 37037414Sbostic #ifdef INLINE 37137414Sbostic *f2flagp++ = '-'; 37237414Sbostic while(*f2flagp++ = *s++) 37337414Sbostic ; 37437414Sbostic *f2flagp = ' '; 37537414Sbostic if(strcmp(pass2name, PASS2NAME) == 0) 37637414Sbostic pass2name = PASS2INAME; 37737414Sbostic goto endfor; 37837414Sbostic #else 37937414Sbostic fprintf(diagfile, "invalid flag -i%c\n", s[1]); 38037414Sbostic done(1); 38137414Sbostic #endif 38237414Sbostic 38337414Sbostic case 'l': /* letter ell--library */ 38437414Sbostic s[-1] = '-'; 38537414Sbostic *loadp++ = s-1; 38637414Sbostic goto endfor; 38737414Sbostic 38837414Sbostic case 'E': /* EFL flag argument */ 38937414Sbostic while( *eflagp++ = *++s) 39037414Sbostic ; 39137414Sbostic *eflagp++ = ' '; 39237414Sbostic goto endfor; 39337414Sbostic case 'R': 39437414Sbostic while( *rflagp++ = *++s ) 39537414Sbostic ; 39637414Sbostic *rflagp++ = ' '; 39737414Sbostic goto endfor; 39837414Sbostic default: 39937414Sbostic lflag[1] = *s; 40037414Sbostic *loadp++ = copys(lflag); 40137414Sbostic break; 40237414Sbostic } 40337414Sbostic endfor: 40437414Sbostic --argc; 40537414Sbostic ++argv; 40637414Sbostic } 40737414Sbostic 40837414Sbostic #ifdef NOCORE 40937414Sbostic if(!debugflag) 41037414Sbostic { 41137414Sbostic struct rlimit r; 41237414Sbostic 41337414Sbostic r.rlim_cur = r.rlim_max = 0; 41437414Sbostic setrlimit(RLIMIT_CORE, &r); 41537414Sbostic } 41637414Sbostic #endif NOCORE 41737414Sbostic 41837414Sbostic *fflagp = '\0'; 41937414Sbostic 42037414Sbostic if (ncpp > 0) 42137414Sbostic cppflags = argvtos (ncpp,cppargs); 42237414Sbostic 42337414Sbostic loadargs[0] = ldname; 42437414Sbostic #if TARGET == PDP11 42537414Sbostic if(nofloating) 42637414Sbostic *loadp++ = (profileflag ? NOFLPROF : NOFLFOOT); 42737414Sbostic else 42837414Sbostic #endif 42937414Sbostic *loadp++ = (profileflag ? proffoot : footname); 43037414Sbostic 43137414Sbostic for(i = 0 ; i<argc ; ++i) 43237414Sbostic switch(c = dotchar(infname = argv[i]) ) 43337414Sbostic { 43437414Sbostic case 'r': /* Ratfor file */ 43537414Sbostic case 'e': /* EFL file */ 43637414Sbostic if( unreadable(argv[i]) ) 43737414Sbostic { 43837414Sbostic erred = YES; 43937414Sbostic break; 44037414Sbostic } 44137414Sbostic s = fortfile; 44237414Sbostic t = lastfield(argv[i]); 44337414Sbostic while( *s++ = *t++) 44437414Sbostic ; 44537414Sbostic s[-2] = 'f'; 44637414Sbostic 44737414Sbostic if(macroflag) 44837414Sbostic { 44937414Sbostic sprintf(buff, "%s %s >%s", macroname, infname, prepfname); 45037414Sbostic if( sys(buff) ) 45137414Sbostic { 45237414Sbostic rmf(prepfname); 45337414Sbostic erred = YES; 45437414Sbostic break; 45537414Sbostic } 45637414Sbostic infname = prepfname; 45737414Sbostic } 45837414Sbostic 45937414Sbostic if(c == 'e') 46037414Sbostic sprintf(buff, "efl %s %s >%s", eflags, infname, fortfile); 46137414Sbostic else 46237414Sbostic sprintf(buff, "ratfor %s %s >%s", rflags, infname, fortfile); 46337414Sbostic status = sys(buff); 46437414Sbostic if(macroflag) 46537414Sbostic rmf(infname); 46637414Sbostic if(status) 46737414Sbostic { 46837414Sbostic erred = YES; 46937414Sbostic rmf(fortfile); 47037414Sbostic break; 47137414Sbostic } 47237414Sbostic 47337414Sbostic if( ! fortonly ) 47437414Sbostic { 47537414Sbostic infname = argv[i] = lastfield(argv[i]); 47637414Sbostic *lastchar(infname) = 'f'; 47737414Sbostic 47837414Sbostic if( dofort(argv[i]) ) 47937414Sbostic erred = YES; 48037414Sbostic else { 48137414Sbostic if( nodup(t = setdoto(argv[i])) ) 48237414Sbostic *loadp++ = t; 48337414Sbostic rmf(fortfile); 48437414Sbostic } 48537414Sbostic } 48637414Sbostic break; 48737414Sbostic 48837414Sbostic case 'F': /* C preprocessor -> Fortran file */ 48937414Sbostic if( unreadable(argv[i]) ) 49037414Sbostic { 49137414Sbostic erred = YES; 49237414Sbostic break; 49337414Sbostic } 49437414Sbostic s = fortfile; 49537414Sbostic t = lastfield(argv[i]); 49637414Sbostic while( *s++ = *t++) 49737414Sbostic ; 49837414Sbostic s[-2] = 'f'; 49937414Sbostic sprintf(buff,"%s %s %s >%s", cppname, cppflags, infname, fortfile); 50037414Sbostic status = sys(buff); 50137414Sbostic if(status) 50237414Sbostic { 50337414Sbostic erred = YES; 50437414Sbostic rmf(fortfile); 50537414Sbostic break; 50637414Sbostic } 50737414Sbostic 50837414Sbostic if( ! fortonly ) 50937414Sbostic { 51037414Sbostic infname = argv[i] = lastfield(argv[i]); 51137414Sbostic *lastchar(infname) = 'f'; 51237414Sbostic 51337414Sbostic if ( dofort(argv[i]) ) 51437414Sbostic erred = YES; 51537414Sbostic else { 51637414Sbostic if (nodup(t = setdoto(argv[i])) ) 51737414Sbostic *loadp++ = t; 51837414Sbostic rmf(fortfile); 51937414Sbostic } 52037414Sbostic } 52137414Sbostic break; 52237414Sbostic 52337414Sbostic case 'f': /* Fortran file */ 52437414Sbostic if( unreadable(argv[i]) ) 52537414Sbostic erred = YES; 52637414Sbostic else if( dofort(argv[i]) ) 52737414Sbostic erred = YES; 52837414Sbostic else if( nodup(t=setdoto(argv[i])) ) 52937414Sbostic *loadp++ = t; 53037414Sbostic break; 53137414Sbostic 53237414Sbostic case 'c': /* C file */ 53337414Sbostic case 's': /* Assembler file */ 53437414Sbostic if( unreadable(argv[i]) ) 53537414Sbostic { 53637414Sbostic erred = YES; 53737414Sbostic break; 53837414Sbostic } 53937414Sbostic #if HERE==PDP11 || HERE==VAX || HERE==TAHOE 54037414Sbostic if( namesflag == YES ) 54137414Sbostic fprintf(diagfile, "%s:\n", argv[i]); 54237414Sbostic #endif 54337414Sbostic sprintf(buff, "cc %s %s", cflags, argv[i] ); 54437414Sbostic if( sys(buff) ) 54537414Sbostic erred = YES; 54637414Sbostic else 54737414Sbostic if( nodup(t = setdoto(argv[i])) ) 54837414Sbostic *loadp++ = t; 54937414Sbostic break; 55037414Sbostic 55137414Sbostic case 'o': 55237414Sbostic if( nodup(argv[i]) ) 55337414Sbostic *loadp++ = argv[i]; 55437414Sbostic break; 55537414Sbostic 55637414Sbostic default: 55737414Sbostic if( ! strcmp(argv[i], "-o") ) { 55837414Sbostic aoutname = argv[++i]; 55937414Sbostic new_aoutname = YES; 56037414Sbostic if( loadflag == NO ){ 56137414Sbostic fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname); 56237414Sbostic new_aoutname = NO; 56337414Sbostic } 56437414Sbostic } else 56537414Sbostic *loadp++ = argv[i]; 56637414Sbostic break; 56737414Sbostic } 56837414Sbostic 56937414Sbostic if( loadflag && stupid(aoutname) ) 57037414Sbostic erred = YES; 57137414Sbostic if(loadflag && !erred) 57237414Sbostic doload(loadargs, loadp); 57337414Sbostic done(erred); 57437414Sbostic } 57537414Sbostic 57637414Sbostic 57737414Sbostic 57837414Sbostic /* 57937414Sbostic * argvtos() copies a list of arguments contained in an array of character 58037414Sbostic * strings to a single dynamically allocated string. Each argument is 58137414Sbostic * separated by one blank space. Returns a pointer to the string or null 58237414Sbostic * if out of memory. 58337414Sbostic */ 58437414Sbostic #define SBUFINCR 1024 58537414Sbostic #define SBUFMAX 10240 58637414Sbostic 58737414Sbostic char * 58837414Sbostic argvtos(argc, argv) 58937414Sbostic char **argv; 59037414Sbostic int argc; 59137414Sbostic { 59237414Sbostic register char *s; /* string pointer */ 59337414Sbostic register int i; /* string buffer pointer */ 59437414Sbostic char *malloc(); /* memory allocator */ 59537414Sbostic char *realloc(); /* increase size of storage */ 59637414Sbostic char *sbuf; /* string buffer */ 59737414Sbostic int nbytes; /* bytes of memory required */ 59837414Sbostic int nu; /* no. of SBUFINCR units required */ 59937414Sbostic int sbufsize; /* current size of sbuf */ 60037414Sbostic int strlen(); /* string length */ 60137414Sbostic 60237414Sbostic sbufsize = SBUFINCR; 60337414Sbostic if ((sbuf = malloc((unsigned)sbufsize)) == NULL) 60437414Sbostic { 60537414Sbostic fatal("out of memory (argvtos)"); 60637414Sbostic /* NOTREACHED */ 60737414Sbostic } 60837414Sbostic 60937414Sbostic for (i = 0; argc-- > 0; ++argv) 61037414Sbostic { 61137414Sbostic if ((nbytes = (i+strlen(*argv)+1-sbufsize)) > 0) 61237414Sbostic { 61337414Sbostic nu = (nbytes+SBUFINCR-1)/SBUFINCR; 61437414Sbostic sbufsize += nu * SBUFINCR; 61537414Sbostic if (sbufsize > SBUFMAX) 61637414Sbostic { 61737414Sbostic fatal("argument length exceeded (argvtos)"); 61837414Sbostic /* NOTREACHED */ 61937414Sbostic } 62037414Sbostic if ((sbuf = realloc(sbuf, (unsigned)sbufsize)) == NULL) 62137414Sbostic { 62237414Sbostic fatal("out of memory (argvtos)"); 62337414Sbostic /* NOTREACHED */ 62437414Sbostic } 62537414Sbostic } 62637414Sbostic for (s = *argv; *s != '\0'; i++, s++) 62737414Sbostic sbuf[i] = *s; 62837414Sbostic sbuf[i++] = ' '; 62937414Sbostic } 63037414Sbostic sbuf[--i] = '\0'; 63137414Sbostic return(sbuf); 63237414Sbostic } 63337414Sbostic 63437414Sbostic dofort(s) 63537414Sbostic char *s; 63637414Sbostic { 63737414Sbostic int retcode; 63837414Sbostic char buff[200]; 63937414Sbostic 64037414Sbostic infname = s; 64137414Sbostic sprintf(buff, "%s %s %s %s %s %s", 64237414Sbostic pass1name, fflags, s, asmfname, initfname, textfname); 64337414Sbostic switch( sys(buff) ) 64437414Sbostic { 64537414Sbostic case 1: 64637414Sbostic goto error; 64737414Sbostic case 0: 64837414Sbostic break; 64937414Sbostic default: 65037414Sbostic goto comperror; 65137414Sbostic } 65237414Sbostic 65337414Sbostic if( dopass2() ) 65437414Sbostic goto comperror; 65537414Sbostic doasm(s); 65637414Sbostic retcode = 0; 65737414Sbostic 65837414Sbostic ret: 65937414Sbostic rmf(asmfname); 66037414Sbostic rmf(initfname); 66137414Sbostic rmf(textfname); 66237414Sbostic return(retcode); 66337414Sbostic 66437414Sbostic error: 66537414Sbostic fprintf(diagfile, "\nError. No assembly.\n"); 66637414Sbostic retcode = 1; 66737414Sbostic goto ret; 66837414Sbostic 66937414Sbostic comperror: 67037414Sbostic fprintf(diagfile, "\ncompiler error.\n"); 67137414Sbostic retcode = 2; 67237414Sbostic goto ret; 67337414Sbostic } 67437414Sbostic 67537414Sbostic 67637414Sbostic 67737414Sbostic 67837414Sbostic dopass2() 67937414Sbostic { 68037414Sbostic char buff[100]; 68137414Sbostic 68237414Sbostic if(verbose) 68337414Sbostic fprintf(diagfile, "PASS2."); 68437414Sbostic 68537414Sbostic #if FAMILY==DMR 68637414Sbostic sprintf(buff, "%s %s - %s", pass2name, textfname, asmpass2); 68737414Sbostic return( sys(buff) ); 68837414Sbostic #endif 68937414Sbostic 69037414Sbostic 69137414Sbostic #if FAMILY == PCC 69237414Sbostic # if TARGET==INTERDATA 69337414Sbostic sprintf(buff, "%s -A%s <%s >%s", pass2name, setfname, textfname, asmpass2); 69437414Sbostic # else 69537414Sbostic sprintf(buff, "%s %s %s >%s", 69637414Sbostic pass2name, f2flags, textfname, asmpass2); 69737414Sbostic # endif 69837414Sbostic return( sys(buff) ); 69937414Sbostic #endif 70037414Sbostic } 70137414Sbostic 70237414Sbostic 70337414Sbostic 70437414Sbostic 70537414Sbostic doasm(s) 70637414Sbostic char *s; 70737414Sbostic { 70837414Sbostic register char *lastc; 70937414Sbostic char *obj; 71037414Sbostic char buff[200]; 71137414Sbostic char *lastchar(), *setdoto(); 71237414Sbostic 71337414Sbostic if(*s == '\0') 71437414Sbostic s = objfdefault; 71537414Sbostic lastc = lastchar(s); 71637414Sbostic obj = setdoto(s); 71737414Sbostic 71837414Sbostic #if TARGET==PDP11 || TARGET==VAX || TARGET==TAHOE 71937414Sbostic # ifdef PASS2OPT 72037414Sbostic if(optimflag) 72137414Sbostic { 72237414Sbostic #if TARGET==TAHOE 72337414Sbostic sprintf(buff, "%s -f %s %s", 72437414Sbostic #else 72537414Sbostic sprintf(buff, "%s %s %s", 72637414Sbostic #endif 72737414Sbostic pass2opt, asmpass2, optzfname); 72837414Sbostic if( sys(buff) ) 72937414Sbostic rmf(optzfname); 73037414Sbostic else 731*39250Sbostic (void)rename(optzfname, asmpass2); 73237414Sbostic } 73337414Sbostic # endif 73437414Sbostic #endif 73537414Sbostic 73637414Sbostic if(saveasmflag) 73737414Sbostic { 73837414Sbostic *lastc = 's'; 73937414Sbostic #if TARGET == INTERDATA 74037414Sbostic sprintf(buff, "%s %s %s %s %s >%s", CATNAME, asmfname, initfname, 74137414Sbostic setfname, asmpass2, obj); 74237414Sbostic #else 74337414Sbostic #if TARGET == VAX || TARGET == TAHOE 74437414Sbostic sprintf(buff, "%s %s %s %s >%s", 74537414Sbostic CATNAME, asmfname, asmpass2, initfname, obj); 74637414Sbostic #else 74737414Sbostic sprintf(buff, "%s %s %s %s >%s", 74837414Sbostic CATNAME, asmfname, initfname, asmpass2, obj); 74937414Sbostic #endif 75037414Sbostic #endif 75137414Sbostic sys(buff); 75237414Sbostic *lastc = 'o'; 75337414Sbostic } 75437414Sbostic else 75537414Sbostic { 75637414Sbostic if(verbose) 75737414Sbostic fprintf(diagfile, " ASM."); 75837414Sbostic #if TARGET == INTERDATA 75937414Sbostic sprintf(buff, "%s -o %s %s %s %s %s", asmname, obj, asmfname, 76037414Sbostic initfname, setfname, asmpass2); 76137414Sbostic #endif 76237414Sbostic 76337414Sbostic #if TARGET == VAX || TARGET == TAHOE 76437414Sbostic /* vax assembler currently accepts only one input file */ 76537414Sbostic 76637414Sbostic sprintf(buff, "%s %s %s >>%s", 76737414Sbostic CATNAME, asmpass2, initfname, asmfname); 76837414Sbostic sys(buff); 76937414Sbostic #ifdef UCBVAXASM 77037414Sbostic sprintf(buff, "%s -J -o %s %s", asmname, obj, asmfname); 77137414Sbostic #else 77237414Sbostic sprintf(buff, "%s -o %s %s", asmname, obj, asmfname); 77337414Sbostic #endif 77437414Sbostic #endif 77537414Sbostic 77637414Sbostic #if TARGET == PDP11 77737414Sbostic sprintf(buff, "%s -u -o %s %s %s", asmname, obj, asmfname, asmpass2); 77837414Sbostic #endif 77937414Sbostic 78037414Sbostic #if TARGET!=INTERDATA && TARGET!=PDP11 && TARGET!=VAX && TARGET!=TAHOE 78137414Sbostic sprintf(buff, "%s -o %s %s %s", asmname, obj, asmfname, asmpass2); 78237414Sbostic #endif 78337414Sbostic 78437414Sbostic if( sys(buff) ) 78537414Sbostic fatal("assembler error"); 78637414Sbostic if(verbose) 78737414Sbostic fprintf(diagfile, "\n"); 78837414Sbostic #if HERE==PDP11 && TARGET!=PDP11 78937414Sbostic rmf(obj); 79037414Sbostic #endif 79137414Sbostic } 79237414Sbostic 79337414Sbostic rmf(asmpass2); 79437414Sbostic } 79537414Sbostic 79637414Sbostic 79737414Sbostic 79837414Sbostic doload(v0, v) 79937414Sbostic register char *v0[], *v[]; 80037414Sbostic { 80137414Sbostic char **p; 80237414Sbostic int waitpid; 80337414Sbostic 80437414Sbostic if(sdbflag) 80537414Sbostic *v++ = "-lg"; 80637414Sbostic if (profileflag) 80737414Sbostic { 80837414Sbostic for(p = p_liblist ; *p ; *v++ = *p++) 80937414Sbostic ; 81037414Sbostic } 81137414Sbostic else { 81237414Sbostic for(p = liblist ; *p ; *v++ = *p++) 81337414Sbostic ; 81437414Sbostic } 81537414Sbostic 81637414Sbostic *v++ = "-o"; 81737414Sbostic *v++ = aoutname; 81837414Sbostic *v = NULL; 81937414Sbostic 82037414Sbostic if(verbose) 82137414Sbostic fprintf(diagfile, "LOAD."); 82237414Sbostic if(debugflag) 82337414Sbostic { 82437414Sbostic for(p = v0 ; p<v ; ++p) 82537414Sbostic fprintf(diagfile, "%s ", *p); 82637414Sbostic fprintf(diagfile, "\n"); 82737414Sbostic } 82837414Sbostic 82937414Sbostic #if HERE==PDP11 || HERE==INTERDATA || HERE==VAX || HERE==TAHOE 83037414Sbostic if( (waitpid = fork()) == 0) 83137414Sbostic { 83237414Sbostic enbint(SIG_DFL); 83337414Sbostic execv(ldname, v0); 83437414Sbostic fatalstr("couldn't load %s", ldname); 83537414Sbostic } 83637414Sbostic await(waitpid); 83737414Sbostic #endif 83837414Sbostic 83937414Sbostic #if HERE==INTERDATA 84037414Sbostic if(optimflag) 84137414Sbostic { 84237414Sbostic char buff1[100], buff2[100]; 84337414Sbostic sprintf(buff1, "nopt %s -o junk.%d", aoutname, pid); 84437414Sbostic sprintf(buff2, "mv junk.%d %s", pid, aoutname); 84537414Sbostic if( sys(buff1) || sys(buff2) ) 84637414Sbostic err("bad optimization"); 84737414Sbostic } 84837414Sbostic #endif 84937414Sbostic 85037414Sbostic if(verbose) 85137414Sbostic fprintf(diagfile, "\n"); 85237414Sbostic } 85337414Sbostic 85437414Sbostic /* Process control and Shell-simulating routines */ 85537414Sbostic 85637414Sbostic sys(str) 85737414Sbostic char *str; 85837414Sbostic { 85937414Sbostic register char *s, *t; 86037792Sbostic char *argv[100]; 86137414Sbostic char *inname, *outname; 86237414Sbostic int append; 86337414Sbostic int waitpid; 86437414Sbostic int argc; 86537414Sbostic 86637414Sbostic 86737414Sbostic if(debugflag) 86837414Sbostic fprintf(diagfile, "%s\n", str); 86937414Sbostic inname = NULL; 87037414Sbostic outname = NULL; 87137414Sbostic argv[0] = shellname; 87237414Sbostic argc = 1; 87337414Sbostic 87437414Sbostic t = str; 87537414Sbostic while( isspace(*t) ) 87637414Sbostic ++t; 87737414Sbostic while(*t) 87837414Sbostic { 87937414Sbostic if(*t == '<') 88037414Sbostic inname = t+1; 88137414Sbostic else if(*t == '>') 88237414Sbostic { 88337414Sbostic if(t[1] == '>') 88437414Sbostic { 88537414Sbostic append = YES; 88637414Sbostic outname = t+2; 88737414Sbostic } 88837414Sbostic else { 88937414Sbostic append = NO; 89037414Sbostic outname = t+1; 89137414Sbostic } 89237414Sbostic } 89337414Sbostic else 89437414Sbostic argv[argc++] = t; 89537414Sbostic while( !isspace(*t) && *t!='\0' ) 89637414Sbostic ++t; 89737414Sbostic if(*t) 89837414Sbostic { 89937414Sbostic *t++ = '\0'; 90037414Sbostic while( isspace(*t) ) 90137414Sbostic ++t; 90237414Sbostic } 90337414Sbostic } 90437414Sbostic 90537414Sbostic if(argc == 1) /* no command */ 90637414Sbostic return(-1); 90737414Sbostic argv[argc] = 0; 90837414Sbostic 90937414Sbostic if((waitpid = fork()) == 0) 91037414Sbostic { 91137414Sbostic if(inname) 91237414Sbostic freopen(inname, "r", stdin); 91337414Sbostic if(outname) 91437414Sbostic freopen(outname, (append ? "a" : "w"), stdout); 91537414Sbostic enbint(SIG_DFL); 91637414Sbostic 91737792Sbostic texec(argv[1] , argv); 91837414Sbostic 91937792Sbostic fatalstr("Cannot load %s", argv[1]); 92037414Sbostic } 92137414Sbostic 92237414Sbostic return( await(waitpid) ); 92337414Sbostic } 92437414Sbostic 92537414Sbostic 92637414Sbostic 92737414Sbostic 92837414Sbostic 92937414Sbostic #include "errno.h" 93037414Sbostic 93137414Sbostic /* modified version from the Shell */ 93237414Sbostic texec(f, av) 93337414Sbostic char *f; 93437414Sbostic char **av; 93537414Sbostic { 93637414Sbostic extern int errno; 93737414Sbostic 93837414Sbostic execv(f, av+1); 93937414Sbostic 94037414Sbostic if (errno==ENOEXEC) 94137414Sbostic { 94237414Sbostic av[1] = f; 94337414Sbostic execv(shellname, av); 94437414Sbostic fatal("No shell!"); 94537414Sbostic } 94637414Sbostic if (errno==ENOMEM) 94737414Sbostic fatalstr("%s: too large", f); 94837414Sbostic } 94937414Sbostic 95037414Sbostic 95137414Sbostic 95237414Sbostic 95337414Sbostic 95437414Sbostic 95537414Sbostic done(k) 95637414Sbostic int k; 95737414Sbostic { 95837414Sbostic static int recurs = NO; 95937414Sbostic 96037414Sbostic if(recurs == NO) 96137414Sbostic { 96237414Sbostic recurs = YES; 96337414Sbostic rmfiles(); 96437414Sbostic } 96537414Sbostic exit(k); 96637414Sbostic } 96737414Sbostic 96837414Sbostic 96937414Sbostic 97037414Sbostic 97137414Sbostic 97237414Sbostic 97337414Sbostic enbint(k) 97437414Sbostic int (*k)(); 97537414Sbostic { 97637414Sbostic if(sigivalue == 0) 97737414Sbostic signal(SIGINT,k); 97837414Sbostic if(sigqvalue == 0) 97937414Sbostic signal(SIGQUIT,k); 98037414Sbostic if(sighvalue == 0) 98137414Sbostic signal(SIGHUP,k); 98237414Sbostic if(sigtvalue == 0) 98337414Sbostic signal(SIGTERM,k); 98437414Sbostic } 98537414Sbostic 98637414Sbostic 98737414Sbostic 98837414Sbostic 98937414Sbostic intrupt() 99037414Sbostic { 99137414Sbostic done(2); 99237414Sbostic } 99337414Sbostic 99437414Sbostic 99537414Sbostic #ifdef PSIGNAL 99637414Sbostic /* 99737414Sbostic * Fancy 4.2 BSD signal printing stuff. 99837414Sbostic */ 99937414Sbostic char harmless[NSIG] = { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }; 100037414Sbostic #endif 100137414Sbostic 100237414Sbostic 100337414Sbostic await(waitpid) 100437414Sbostic int waitpid; 100537414Sbostic { 100637414Sbostic 100737414Sbostic #ifdef PSIGNAL 100837414Sbostic extern char *sys_siglist[]; 100937414Sbostic union wait status; 101037414Sbostic #else PSIGNAL 101137414Sbostic int status; 101237414Sbostic #endif PSIGNAL 101337414Sbostic 101437414Sbostic int w; 101537414Sbostic 101637414Sbostic enbint(SIG_IGN); 101737414Sbostic while ( (w = wait(&status)) != waitpid) 101837414Sbostic if(w == -1) 101937414Sbostic fatal("bad wait code"); 102037414Sbostic enbint(intrupt); 102137414Sbostic 102237414Sbostic #ifdef PSIGNAL 102337414Sbostic if(status.w_termsig) 102437414Sbostic { 102537414Sbostic debugflag = 0; /* Prevent us from dumping core ourselves */ 102637414Sbostic if(status.w_termsig != SIGINT && status.w_termsig < NSIG) 102737414Sbostic fprintf(diagfile, "%s%s\n", sys_siglist[status.w_termsig], 102837414Sbostic status.w_coredump ? " -- core dumped" : ""); 102937414Sbostic if(status.w_termsig < NSIG && ! harmless[status.w_termsig]) 103037414Sbostic fatal("see a system manager"); 103137414Sbostic else 103237414Sbostic done(3); 103337414Sbostic } 103437414Sbostic return(status.w_retcode); 103537414Sbostic #else PSIGNAL 103637414Sbostic if(status & 0377) 103737414Sbostic { 103837414Sbostic if(status != SIGINT) 103937414Sbostic fprintf(diagfile, "Termination code %d\n", status); 104037414Sbostic done(3); 104137414Sbostic } 104237414Sbostic return(status>>8); 104337414Sbostic #endif PSIGNAL 104437414Sbostic } 104537414Sbostic 104637414Sbostic /* File Name and File Manipulation Routines */ 104737414Sbostic 104837414Sbostic unreadable(s) 104937414Sbostic register char *s; 105037414Sbostic { 105137414Sbostic register FILE *fp; 105237414Sbostic 105337414Sbostic if(fp = fopen(s, "r")) 105437414Sbostic { 105537414Sbostic fclose(fp); 105637414Sbostic return(NO); 105737414Sbostic } 105837414Sbostic 105937414Sbostic else 106037414Sbostic { 106137414Sbostic fprintf(diagfile, "Error: Cannot read file %s\n", s); 106237414Sbostic return(YES); 106337414Sbostic } 106437414Sbostic } 106537414Sbostic 106637414Sbostic 106737414Sbostic 106837414Sbostic stupid(s) 106937414Sbostic char *s; 107037414Sbostic { 107137414Sbostic char c; 107237414Sbostic 107337414Sbostic if( (c = dotchar(s)) 107437414Sbostic && index("focsreF", c) 107537414Sbostic && access(s, 0) == 0 ) 107637414Sbostic { 107737414Sbostic fprintf(diagfile, "Loading on %s would destroy it\n", s); 107837414Sbostic return(YES); 107937414Sbostic } 108037414Sbostic return(NO); 108137414Sbostic } 108237414Sbostic 108337414Sbostic 108437414Sbostic 108537414Sbostic clf(p) 108637414Sbostic FILEP *p; 108737414Sbostic { 108837414Sbostic if(p!=NULL && *p!=NULL && *p!=stdout) 108937414Sbostic { 109037414Sbostic if(ferror(*p)) 109137414Sbostic fatal("writing error"); 109237414Sbostic fclose(*p); 109337414Sbostic } 109437414Sbostic *p = NULL; 109537414Sbostic } 109637414Sbostic 109737414Sbostic rmfiles() 109837414Sbostic { 109937414Sbostic rmf(textfname); 110037414Sbostic rmf(asmfname); 110137414Sbostic rmf(initfname); 110237414Sbostic rmf(asmpass2); 110337414Sbostic #if TARGET == INTERDATA 110437414Sbostic rmf(setfname); 110537414Sbostic #endif 110637414Sbostic } 110737414Sbostic 110837414Sbostic 110937414Sbostic 111037414Sbostic 111137414Sbostic 111237414Sbostic 111337414Sbostic 111437414Sbostic 111537414Sbostic /* return -1 if file does not exist, 0 if it is of zero length 111637414Sbostic and 1 if of positive length 111737414Sbostic */ 111837414Sbostic content(filename) 111937414Sbostic char *filename; 112037414Sbostic { 112137414Sbostic #ifdef VERSION6 112237414Sbostic struct stat 112337414Sbostic { 112437414Sbostic char cjunk[9]; 112537414Sbostic char size0; 112637414Sbostic int size1; 112737414Sbostic int ijunk[12]; 112837414Sbostic } buf; 112937414Sbostic #else 113037414Sbostic struct stat buf; 113137414Sbostic #endif 113237414Sbostic 113337414Sbostic if(stat(filename,&buf) < 0) 113437414Sbostic return(-1); 113537414Sbostic #ifdef VERSION6 113637414Sbostic return(buf.size0 || buf.size1); 113737414Sbostic #else 113837414Sbostic return( buf.st_size > 0 ); 113937414Sbostic #endif 114037414Sbostic } 114137414Sbostic 114237414Sbostic 114337414Sbostic 114437414Sbostic 114537414Sbostic crfnames() 114637414Sbostic { 114737414Sbostic fname(textfname, "x"); 114837414Sbostic fname(asmfname, "s"); 114937414Sbostic fname(asmpass2, "a"); 115037414Sbostic fname(initfname, "d"); 115137414Sbostic fname(sortfname, "S"); 115237414Sbostic fname(objfdefault, "o"); 115337414Sbostic fname(prepfname, "p"); 115437414Sbostic fname(optzfname, "z"); 115537414Sbostic fname(setfname, "A"); 115637414Sbostic } 115737414Sbostic 115837414Sbostic 115937414Sbostic 116037414Sbostic 116137414Sbostic rmf(fn) 116237414Sbostic register char *fn; 116337414Sbostic { 116437414Sbostic /* if(!debugflag && fn!=NULL && *fn!='\0') */ 116537414Sbostic 116637414Sbostic if(fn!=NULL && *fn!='\0') 116737414Sbostic unlink(fn); 116837414Sbostic } 116937414Sbostic 117037414Sbostic 117137414Sbostic 117237414Sbostic 117337414Sbostic 117437414Sbostic LOCAL fname(name, suff) 117537414Sbostic char *name, *suff; 117637414Sbostic { 117737792Sbostic sprintf(name, "%s/%s%d.%s", _PATH_TMP, temppref, pid, suff); 117837414Sbostic } 117937414Sbostic 118037414Sbostic 118137414Sbostic 118237414Sbostic 118337414Sbostic dotchar(s) 118437414Sbostic register char *s; 118537414Sbostic { 118637414Sbostic for( ; *s ; ++s) 118737414Sbostic if(s[0]=='.' && s[1]!='\0' && s[2]=='\0') 118837414Sbostic return( s[1] ); 118937414Sbostic return(NO); 119037414Sbostic } 119137414Sbostic 119237414Sbostic 119337414Sbostic 119437414Sbostic char *lastfield(s) 119537414Sbostic register char *s; 119637414Sbostic { 119737414Sbostic register char *t; 119837414Sbostic for(t = s; *s ; ++s) 119937414Sbostic if(*s == '/') 120037414Sbostic t = s+1; 120137414Sbostic return(t); 120237414Sbostic } 120337414Sbostic 120437414Sbostic 120537414Sbostic 120637414Sbostic char *lastchar(s) 120737414Sbostic register char *s; 120837414Sbostic { 120937414Sbostic while(*s) 121037414Sbostic ++s; 121137414Sbostic return(s-1); 121237414Sbostic } 121337414Sbostic 121437414Sbostic char *setdoto(s) 121537414Sbostic register char *s; 121637414Sbostic { 121737414Sbostic *lastchar(s) = 'o'; 121837414Sbostic return( lastfield(s) ); 121937414Sbostic } 122037414Sbostic 122137414Sbostic 122237414Sbostic 122337414Sbostic badfile(s) 122437414Sbostic char *s; 122537414Sbostic { 122637414Sbostic fatalstr("cannot open intermediate file %s", s); 122737414Sbostic } 122837414Sbostic 122937414Sbostic 123037414Sbostic 123137414Sbostic ptr ckalloc(n) 123237414Sbostic int n; 123337414Sbostic { 123437414Sbostic ptr p, calloc(); 123537414Sbostic 123637414Sbostic if( p = calloc(1, (unsigned) n) ) 123737414Sbostic return(p); 123837414Sbostic 123937414Sbostic fatal("out of memory"); 124037414Sbostic /* NOTREACHED */ 124137414Sbostic } 124237414Sbostic 124337414Sbostic 124437414Sbostic 124537414Sbostic 124637414Sbostic 124737414Sbostic char *copyn(n, s) 124837414Sbostic register int n; 124937414Sbostic register char *s; 125037414Sbostic { 125137414Sbostic register char *p, *q; 125237414Sbostic 125337414Sbostic p = q = (char *) ckalloc(n); 125437414Sbostic while(n-- > 0) 125537414Sbostic *q++ = *s++; 125637414Sbostic return(p); 125737414Sbostic } 125837414Sbostic 125937414Sbostic 126037414Sbostic 126137414Sbostic char *copys(s) 126237414Sbostic char *s; 126337414Sbostic { 126437414Sbostic return( copyn( strlen(s)+1 , s) ); 126537414Sbostic } 126637414Sbostic 126737414Sbostic 126837414Sbostic 126937414Sbostic 127037414Sbostic 127137414Sbostic oneof(c,s) 127237414Sbostic register c; 127337414Sbostic register char *s; 127437414Sbostic { 127537414Sbostic while( *s ) 127637414Sbostic if(*s++ == c) 127737414Sbostic return(YES); 127837414Sbostic return(NO); 127937414Sbostic } 128037414Sbostic 128137414Sbostic 128237414Sbostic 128337414Sbostic nodup(s) 128437414Sbostic char *s; 128537414Sbostic { 128637414Sbostic register char **p; 128737414Sbostic 128837414Sbostic for(p = loadargs ; p < loadp ; ++p) 128937414Sbostic if( !strcmp(*p, s) ) 129037414Sbostic return(NO); 129137414Sbostic 129237414Sbostic return(YES); 129337414Sbostic } 129437414Sbostic 129537414Sbostic 129637414Sbostic 129737414Sbostic static fatal(t) 129837414Sbostic char *t; 129937414Sbostic { 130037414Sbostic fprintf(diagfile, "Compiler error in file %s: %s\n", infname, t); 130137414Sbostic if(debugflag) 130237414Sbostic abort(); 130337414Sbostic done(1); 130437414Sbostic exit(1); 130537414Sbostic } 130637414Sbostic 130737414Sbostic 130837414Sbostic 130937414Sbostic 131037414Sbostic static fatali(t,d) 131137414Sbostic char *t; 131237414Sbostic int d; 131337414Sbostic { 131437414Sbostic char buff[100]; 131537414Sbostic sprintf(buff, t, d); 131637414Sbostic fatal(buff); 131737414Sbostic } 131837414Sbostic 131937414Sbostic 132037414Sbostic 132137414Sbostic 132237414Sbostic static fatalstr(t, s) 132337414Sbostic char *t, *s; 132437414Sbostic { 132537414Sbostic char buff[100]; 132637414Sbostic sprintf(buff, t, s); 132737414Sbostic fatal(buff); 132837414Sbostic } 132937414Sbostic err(s) 133037414Sbostic char *s; 133137414Sbostic { 133237414Sbostic fprintf(diagfile, "Error in file %s: %s\n", infname, s); 133337414Sbostic } 133437414Sbostic 1335