1*37414Sbostic /* 2*37414Sbostic * f77.c 3*37414Sbostic * 4*37414Sbostic * Driver program for the 4.2 BSD f77 compiler. 5*37414Sbostic * 6*37414Sbostic * University of Utah CS Dept modification history: 7*37414Sbostic * 8*37414Sbostic * $Log: f77.c,v $ 9*37414Sbostic * Revision 1.14 85/03/01 00:07:57 donn 10*37414Sbostic * Portability fix from Ralph Campbell. 11*37414Sbostic * 12*37414Sbostic * Revision 1.13 85/02/12 19:31:47 donn 13*37414Sbostic * Use CATNAME to get the name of a concatenation command instead of 14*37414Sbostic * explicitly running 'cat' -- you can get the wrong 'cat' the old way! 15*37414Sbostic * 16*37414Sbostic * Revision 1.12 85/01/14 06:42:30 donn 17*37414Sbostic * Changed to call the peephole optimizer with the '-f' flag, so that 18*37414Sbostic * floating point moves are translated to integer moves. 19*37414Sbostic * 20*37414Sbostic * Revision 1.11 85/01/14 04:38:59 donn 21*37414Sbostic * Jerry's change to pass -O to f1 so it knows whether the peephole optimizer 22*37414Sbostic * will be run. This is necessary in order to handle movf/movl translation. 23*37414Sbostic * 24*37414Sbostic * Revision 1.10 85/01/14 03:59:12 donn 25*37414Sbostic * Added Jerry Berkman's fix for the '-q' flag. 26*37414Sbostic * 27*37414Sbostic * Revision 1.9 84/11/09 01:51:26 donn 28*37414Sbostic * Cosmetic change to stupid() suggested by John McCarthy at Memorial 29*37414Sbostic * University, St. Johns. 30*37414Sbostic * 31*37414Sbostic * Revision 1.8 84/09/14 16:02:34 donn 32*37414Sbostic * Added changes to notice when people do 'f77 -c foo.f -o bar.o' and tell 33*37414Sbostic * them why it doesn't do what they think it does. 34*37414Sbostic * 35*37414Sbostic * Revision 1.7 84/08/24 21:08:31 donn 36*37414Sbostic * Added call to setrlimit() to prevent core dumps when not debugging. 37*37414Sbostic * Reorganized the include file arrangment somewhat. 38*37414Sbostic * 39*37414Sbostic * Revision 1.6 84/08/24 20:20:24 donn 40*37414Sbostic * Changed stupidity check on Jerry Berkman's suggestion -- now it balks if 41*37414Sbostic * the load file exists and has a sensitive suffix. 42*37414Sbostic * 43*37414Sbostic * Revision 1.5 84/08/15 18:56:44 donn 44*37414Sbostic * Added test for -O combined with -g, suggested by Raleigh Romine. To keep 45*37414Sbostic * things simple, if both are specified then the second in the list is thrown 46*37414Sbostic * out and the user is warned. 47*37414Sbostic * 48*37414Sbostic * Revision 1.4 84/08/05 21:33:15 donn 49*37414Sbostic * Added stupidity check -- f77 won't load on a file that it's asked to 50*37414Sbostic * compile as well. 51*37414Sbostic * 52*37414Sbostic * Revision 1.3 84/08/04 22:58:24 donn 53*37414Sbostic * Improved error reporting -- we now explain why we died and what we did. 54*37414Sbostic * Only works on 4.2. Added at the instigation of Jerry Berkman. 55*37414Sbostic * 56*37414Sbostic * Revision 1.2 84/07/28 13:11:24 donn 57*37414Sbostic * Added Ralph Campbell's changes to reduce offsets to data. 58*37414Sbostic * 59*37414Sbostic */ 60*37414Sbostic 61*37414Sbostic char *xxxvers[] = "\n@(#) F77 DRIVER, VERSION 4.2, 1984 JULY 28\n"; 62*37414Sbostic #include <stdio.h> 63*37414Sbostic #include <sys/types.h> 64*37414Sbostic #include <sys/stat.h> 65*37414Sbostic #include <ctype.h> 66*37414Sbostic #include <signal.h> 67*37414Sbostic 68*37414Sbostic #ifdef SIGPROF 69*37414Sbostic /* 70*37414Sbostic * Some 4.2 BSD capabilities. 71*37414Sbostic */ 72*37414Sbostic #include <sys/time.h> 73*37414Sbostic #include <sys/resource.h> 74*37414Sbostic #define NOCORE 1 75*37414Sbostic #include <sys/wait.h> 76*37414Sbostic #define PSIGNAL 1 77*37414Sbostic #define INLINE 1 78*37414Sbostic #endif 79*37414Sbostic 80*37414Sbostic #include "defines.h" 81*37414Sbostic #include "machdefs.h" 82*37414Sbostic #include "drivedefs.h" 83*37414Sbostic #include "version.h" 84*37414Sbostic 85*37414Sbostic static FILEP diagfile = {stderr} ; 86*37414Sbostic static int pid; 87*37414Sbostic static int sigivalue = 0; 88*37414Sbostic static int sigqvalue = 0; 89*37414Sbostic static int sighvalue = 0; 90*37414Sbostic static int sigtvalue = 0; 91*37414Sbostic 92*37414Sbostic static char *pass1name = PASS1NAME ; 93*37414Sbostic static char *pass2name = PASS2NAME ; 94*37414Sbostic static char *pass2opt = PASS2OPT ; 95*37414Sbostic static char *asmname = ASMNAME ; 96*37414Sbostic static char *ldname = LDNAME ; 97*37414Sbostic static char *footname = FOOTNAME; 98*37414Sbostic static char *proffoot = PROFFOOT; 99*37414Sbostic static char *macroname = "m4"; 100*37414Sbostic static char *shellname = "/bin/sh"; 101*37414Sbostic static char *cppname = "/lib/cpp"; 102*37414Sbostic static char *aoutname = "a.out" ; 103*37414Sbostic static char *temppref = TEMPPREF; 104*37414Sbostic 105*37414Sbostic static char *infname; 106*37414Sbostic static char textfname[44]; 107*37414Sbostic static char asmfname[44]; 108*37414Sbostic static char asmpass2[44]; 109*37414Sbostic static char initfname[44]; 110*37414Sbostic static char sortfname[44]; 111*37414Sbostic static char prepfname[44]; 112*37414Sbostic static char objfdefault[44]; 113*37414Sbostic static char optzfname[44]; 114*37414Sbostic static char setfname[44]; 115*37414Sbostic 116*37414Sbostic static char fflags[50] = "-"; 117*37414Sbostic static char f2flags[50]; 118*37414Sbostic static char cflags[50] = "-c"; 119*37414Sbostic #if TARGET == GCOS 120*37414Sbostic static char eflags[30] = "system=gcos "; 121*37414Sbostic #else 122*37414Sbostic static char eflags[30] = "system=unix "; 123*37414Sbostic #endif 124*37414Sbostic static char rflags[30] = ""; 125*37414Sbostic static char lflag[3] = "-x"; 126*37414Sbostic static char *fflagp = fflags+1; 127*37414Sbostic static char *f2flagp = f2flags; 128*37414Sbostic static char *cflagp = cflags+2; 129*37414Sbostic static char *eflagp = eflags+12; 130*37414Sbostic static char *rflagp = rflags; 131*37414Sbostic static char *cppflags = ""; 132*37414Sbostic static char **cppargs; 133*37414Sbostic static char **loadargs; 134*37414Sbostic static char **loadp; 135*37414Sbostic 136*37414Sbostic static flag erred = NO; 137*37414Sbostic static flag loadflag = YES; 138*37414Sbostic static flag saveasmflag = NO; 139*37414Sbostic static flag profileflag = NO; 140*37414Sbostic static flag optimflag = NO; 141*37414Sbostic static flag debugflag = NO; 142*37414Sbostic static flag verbose = NO; 143*37414Sbostic static flag nofloating = NO; 144*37414Sbostic static flag fortonly = NO; 145*37414Sbostic static flag macroflag = NO; 146*37414Sbostic static flag sdbflag = NO; 147*37414Sbostic static flag namesflag = YES; 148*37414Sbostic 149*37414Sbostic static int ncpp; 150*37414Sbostic 151*37414Sbostic 152*37414Sbostic main(argc, argv) 153*37414Sbostic int argc; 154*37414Sbostic char **argv; 155*37414Sbostic { 156*37414Sbostic int i, c, status; 157*37414Sbostic char *setdoto(), *lastchar(), *lastfield(), *copys(), *argvtos(); 158*37414Sbostic ptr ckalloc(); 159*37414Sbostic register char *s; 160*37414Sbostic char fortfile[20], *t; 161*37414Sbostic char buff[100]; 162*37414Sbostic int intrupt(); 163*37414Sbostic int new_aoutname = NO; 164*37414Sbostic 165*37414Sbostic sigivalue = signal(SIGINT, SIG_IGN) == SIG_IGN; 166*37414Sbostic sigqvalue = signal(SIGQUIT,SIG_IGN) == SIG_IGN; 167*37414Sbostic sighvalue = signal(SIGHUP, SIG_IGN) == SIG_IGN; 168*37414Sbostic sigtvalue = signal(SIGTERM,SIG_IGN) == SIG_IGN; 169*37414Sbostic enbint(intrupt); 170*37414Sbostic 171*37414Sbostic pid = getpid(); 172*37414Sbostic crfnames(); 173*37414Sbostic 174*37414Sbostic cppargs = (char **) ckalloc( argc * sizeof(*cppargs) ); 175*37414Sbostic loadargs = (char **) ckalloc( (argc+20) * sizeof(*loadargs) ); 176*37414Sbostic loadargs[1] = "-X"; 177*37414Sbostic loadargs[2] = "-u"; 178*37414Sbostic #if HERE==PDP11 || HERE==VAX || HERE==TAHOE 179*37414Sbostic loadargs[3] = "_MAIN_"; 180*37414Sbostic #endif 181*37414Sbostic #if HERE == INTERDATA 182*37414Sbostic loadargs[3] = "main"; 183*37414Sbostic #endif 184*37414Sbostic loadp = loadargs + 4; 185*37414Sbostic 186*37414Sbostic --argc; 187*37414Sbostic ++argv; 188*37414Sbostic 189*37414Sbostic while(argc>0 && argv[0][0]=='-' && argv[0][1]!='\0') 190*37414Sbostic { 191*37414Sbostic for(s = argv[0]+1 ; *s ; ++s) switch(*s) 192*37414Sbostic { 193*37414Sbostic case 'T': /* use special passes */ 194*37414Sbostic switch(*++s) 195*37414Sbostic { 196*37414Sbostic case '1': 197*37414Sbostic pass1name = s+1; goto endfor; 198*37414Sbostic case '2': 199*37414Sbostic pass2name = s+1; goto endfor; 200*37414Sbostic case 'p': 201*37414Sbostic pass2opt = s+1; goto endfor; 202*37414Sbostic case 'a': 203*37414Sbostic asmname = s+1; goto endfor; 204*37414Sbostic case 'l': 205*37414Sbostic ldname = s+1; goto endfor; 206*37414Sbostic case 'F': 207*37414Sbostic footname = s+1; goto endfor; 208*37414Sbostic case 'm': 209*37414Sbostic macroname = s+1; goto endfor; 210*37414Sbostic case 't': 211*37414Sbostic temppref = s+1; goto endfor; 212*37414Sbostic default: 213*37414Sbostic fatali("bad option -T%c", *s); 214*37414Sbostic } 215*37414Sbostic break; 216*37414Sbostic 217*37414Sbostic case '6': 218*37414Sbostic if(s[1]=='6') 219*37414Sbostic { 220*37414Sbostic *fflagp++ = *s++; 221*37414Sbostic goto copyfflag; 222*37414Sbostic } 223*37414Sbostic else { 224*37414Sbostic fprintf(diagfile, "invalid flag 6%c\n", s[1]); 225*37414Sbostic done(1); 226*37414Sbostic } 227*37414Sbostic 228*37414Sbostic case 'w': 229*37414Sbostic if(s[1]=='6' && s[2]=='6') 230*37414Sbostic { 231*37414Sbostic *fflagp++ = *s++; 232*37414Sbostic *fflagp++ = *s++; 233*37414Sbostic } 234*37414Sbostic 235*37414Sbostic copyfflag: 236*37414Sbostic case 'u': 237*37414Sbostic case 'U': 238*37414Sbostic case '1': 239*37414Sbostic case 'C': 240*37414Sbostic *fflagp++ = *s; 241*37414Sbostic break; 242*37414Sbostic 243*37414Sbostic case 'O': 244*37414Sbostic if(sdbflag) 245*37414Sbostic { 246*37414Sbostic fprintf(diagfile, "-O and -g are incompatible; -O ignored\n"); 247*37414Sbostic break; 248*37414Sbostic } 249*37414Sbostic optimflag = YES; 250*37414Sbostic #if TARGET == INTERDATA 251*37414Sbostic *loadp++ = "-r"; 252*37414Sbostic *loadp++ = "-d"; 253*37414Sbostic #endif 254*37414Sbostic *fflagp++ = 'O'; 255*37414Sbostic break; 256*37414Sbostic 257*37414Sbostic case 'N': 258*37414Sbostic *fflagp++ = 'N'; 259*37414Sbostic if( oneof(*++s, "qxscn") ) 260*37414Sbostic *fflagp++ = *s++; 261*37414Sbostic else { 262*37414Sbostic fprintf(diagfile, "invalid flag -N%c\n", *s); 263*37414Sbostic done(1); 264*37414Sbostic } 265*37414Sbostic while( isdigit(*s) ) 266*37414Sbostic *fflagp++ = *s++; 267*37414Sbostic *fflagp++ = 'X'; 268*37414Sbostic goto endfor; 269*37414Sbostic 270*37414Sbostic case 'm': 271*37414Sbostic if(s[1] == '4') 272*37414Sbostic ++s; 273*37414Sbostic macroflag = YES; 274*37414Sbostic break; 275*37414Sbostic 276*37414Sbostic case 'S': 277*37414Sbostic strcat(cflags, " -S"); 278*37414Sbostic saveasmflag = YES; 279*37414Sbostic 280*37414Sbostic case 'c': 281*37414Sbostic if( new_aoutname == YES ){ 282*37414Sbostic fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname); 283*37414Sbostic new_aoutname = NO; 284*37414Sbostic } 285*37414Sbostic loadflag = NO; 286*37414Sbostic break; 287*37414Sbostic 288*37414Sbostic case 'v': 289*37414Sbostic verbose = YES; 290*37414Sbostic fprintf(diagfile,"\nBerkeley F77, version %s\n", 291*37414Sbostic VERSIONNUMBER); 292*37414Sbostic break; 293*37414Sbostic 294*37414Sbostic case 'd': 295*37414Sbostic debugflag = YES; 296*37414Sbostic *fflagp++ = 'd'; 297*37414Sbostic s++; 298*37414Sbostic while( isdigit(*s) || *s == ',' ) 299*37414Sbostic *fflagp++ = *s++; 300*37414Sbostic *fflagp++ = 'X'; 301*37414Sbostic goto endfor; 302*37414Sbostic 303*37414Sbostic case 'M': 304*37414Sbostic *loadp++ = "-M"; 305*37414Sbostic break; 306*37414Sbostic 307*37414Sbostic case 'g': 308*37414Sbostic if(optimflag) 309*37414Sbostic { 310*37414Sbostic fprintf(diagfile, "-g and -O are incompatible; -g ignored\n"); 311*37414Sbostic break; 312*37414Sbostic } 313*37414Sbostic strcat(cflags," -g"); 314*37414Sbostic sdbflag = YES; 315*37414Sbostic goto copyfflag; 316*37414Sbostic 317*37414Sbostic case 'p': 318*37414Sbostic profileflag = YES; 319*37414Sbostic strcat(cflags," -p"); 320*37414Sbostic *fflagp++ = 'p'; 321*37414Sbostic if(s[1] == 'g') 322*37414Sbostic { 323*37414Sbostic proffoot = GPRFFOOT; 324*37414Sbostic s++; 325*37414Sbostic } 326*37414Sbostic break; 327*37414Sbostic 328*37414Sbostic case 'q': 329*37414Sbostic namesflag = NO; 330*37414Sbostic *fflagp++ = *s; 331*37414Sbostic break; 332*37414Sbostic 333*37414Sbostic case 'o': 334*37414Sbostic if( ! strcmp(s, "onetrip") ) 335*37414Sbostic { 336*37414Sbostic *fflagp++ = '1'; 337*37414Sbostic goto endfor; 338*37414Sbostic } 339*37414Sbostic new_aoutname = YES; 340*37414Sbostic aoutname = *++argv; 341*37414Sbostic --argc; 342*37414Sbostic if( loadflag == NO ){ 343*37414Sbostic fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname); 344*37414Sbostic new_aoutname = NO; 345*37414Sbostic } 346*37414Sbostic break; 347*37414Sbostic 348*37414Sbostic #if TARGET == PDP11 349*37414Sbostic case 'f': 350*37414Sbostic nofloating = YES; 351*37414Sbostic pass2name = NOFLPASS2; 352*37414Sbostic break; 353*37414Sbostic #endif 354*37414Sbostic 355*37414Sbostic case 'F': 356*37414Sbostic fortonly = YES; 357*37414Sbostic loadflag = NO; 358*37414Sbostic break; 359*37414Sbostic case 'D': 360*37414Sbostic case 'I': 361*37414Sbostic cppargs[ncpp++] = *argv; 362*37414Sbostic goto endfor; 363*37414Sbostic 364*37414Sbostic case 'i': 365*37414Sbostic if((s[1]=='2' || s[1]=='4') && s[2] == '\0') 366*37414Sbostic { 367*37414Sbostic *fflagp++ = *s++; 368*37414Sbostic goto copyfflag; 369*37414Sbostic } 370*37414Sbostic #ifdef INLINE 371*37414Sbostic *f2flagp++ = '-'; 372*37414Sbostic while(*f2flagp++ = *s++) 373*37414Sbostic ; 374*37414Sbostic *f2flagp = ' '; 375*37414Sbostic if(strcmp(pass2name, PASS2NAME) == 0) 376*37414Sbostic pass2name = PASS2INAME; 377*37414Sbostic goto endfor; 378*37414Sbostic #else 379*37414Sbostic fprintf(diagfile, "invalid flag -i%c\n", s[1]); 380*37414Sbostic done(1); 381*37414Sbostic #endif 382*37414Sbostic 383*37414Sbostic case 'l': /* letter ell--library */ 384*37414Sbostic s[-1] = '-'; 385*37414Sbostic *loadp++ = s-1; 386*37414Sbostic goto endfor; 387*37414Sbostic 388*37414Sbostic case 'E': /* EFL flag argument */ 389*37414Sbostic while( *eflagp++ = *++s) 390*37414Sbostic ; 391*37414Sbostic *eflagp++ = ' '; 392*37414Sbostic goto endfor; 393*37414Sbostic case 'R': 394*37414Sbostic while( *rflagp++ = *++s ) 395*37414Sbostic ; 396*37414Sbostic *rflagp++ = ' '; 397*37414Sbostic goto endfor; 398*37414Sbostic default: 399*37414Sbostic lflag[1] = *s; 400*37414Sbostic *loadp++ = copys(lflag); 401*37414Sbostic break; 402*37414Sbostic } 403*37414Sbostic endfor: 404*37414Sbostic --argc; 405*37414Sbostic ++argv; 406*37414Sbostic } 407*37414Sbostic 408*37414Sbostic #ifdef NOCORE 409*37414Sbostic if(!debugflag) 410*37414Sbostic { 411*37414Sbostic struct rlimit r; 412*37414Sbostic 413*37414Sbostic r.rlim_cur = r.rlim_max = 0; 414*37414Sbostic setrlimit(RLIMIT_CORE, &r); 415*37414Sbostic } 416*37414Sbostic #endif NOCORE 417*37414Sbostic 418*37414Sbostic *fflagp = '\0'; 419*37414Sbostic 420*37414Sbostic if (ncpp > 0) 421*37414Sbostic cppflags = argvtos (ncpp,cppargs); 422*37414Sbostic 423*37414Sbostic loadargs[0] = ldname; 424*37414Sbostic #if TARGET == PDP11 425*37414Sbostic if(nofloating) 426*37414Sbostic *loadp++ = (profileflag ? NOFLPROF : NOFLFOOT); 427*37414Sbostic else 428*37414Sbostic #endif 429*37414Sbostic *loadp++ = (profileflag ? proffoot : footname); 430*37414Sbostic 431*37414Sbostic for(i = 0 ; i<argc ; ++i) 432*37414Sbostic switch(c = dotchar(infname = argv[i]) ) 433*37414Sbostic { 434*37414Sbostic case 'r': /* Ratfor file */ 435*37414Sbostic case 'e': /* EFL file */ 436*37414Sbostic if( unreadable(argv[i]) ) 437*37414Sbostic { 438*37414Sbostic erred = YES; 439*37414Sbostic break; 440*37414Sbostic } 441*37414Sbostic s = fortfile; 442*37414Sbostic t = lastfield(argv[i]); 443*37414Sbostic while( *s++ = *t++) 444*37414Sbostic ; 445*37414Sbostic s[-2] = 'f'; 446*37414Sbostic 447*37414Sbostic if(macroflag) 448*37414Sbostic { 449*37414Sbostic sprintf(buff, "%s %s >%s", macroname, infname, prepfname); 450*37414Sbostic if( sys(buff) ) 451*37414Sbostic { 452*37414Sbostic rmf(prepfname); 453*37414Sbostic erred = YES; 454*37414Sbostic break; 455*37414Sbostic } 456*37414Sbostic infname = prepfname; 457*37414Sbostic } 458*37414Sbostic 459*37414Sbostic if(c == 'e') 460*37414Sbostic sprintf(buff, "efl %s %s >%s", eflags, infname, fortfile); 461*37414Sbostic else 462*37414Sbostic sprintf(buff, "ratfor %s %s >%s", rflags, infname, fortfile); 463*37414Sbostic status = sys(buff); 464*37414Sbostic if(macroflag) 465*37414Sbostic rmf(infname); 466*37414Sbostic if(status) 467*37414Sbostic { 468*37414Sbostic erred = YES; 469*37414Sbostic rmf(fortfile); 470*37414Sbostic break; 471*37414Sbostic } 472*37414Sbostic 473*37414Sbostic if( ! fortonly ) 474*37414Sbostic { 475*37414Sbostic infname = argv[i] = lastfield(argv[i]); 476*37414Sbostic *lastchar(infname) = 'f'; 477*37414Sbostic 478*37414Sbostic if( dofort(argv[i]) ) 479*37414Sbostic erred = YES; 480*37414Sbostic else { 481*37414Sbostic if( nodup(t = setdoto(argv[i])) ) 482*37414Sbostic *loadp++ = t; 483*37414Sbostic rmf(fortfile); 484*37414Sbostic } 485*37414Sbostic } 486*37414Sbostic break; 487*37414Sbostic 488*37414Sbostic case 'F': /* C preprocessor -> Fortran file */ 489*37414Sbostic if( unreadable(argv[i]) ) 490*37414Sbostic { 491*37414Sbostic erred = YES; 492*37414Sbostic break; 493*37414Sbostic } 494*37414Sbostic s = fortfile; 495*37414Sbostic t = lastfield(argv[i]); 496*37414Sbostic while( *s++ = *t++) 497*37414Sbostic ; 498*37414Sbostic s[-2] = 'f'; 499*37414Sbostic sprintf(buff,"%s %s %s >%s", cppname, cppflags, infname, fortfile); 500*37414Sbostic status = sys(buff); 501*37414Sbostic if(status) 502*37414Sbostic { 503*37414Sbostic erred = YES; 504*37414Sbostic rmf(fortfile); 505*37414Sbostic break; 506*37414Sbostic } 507*37414Sbostic 508*37414Sbostic if( ! fortonly ) 509*37414Sbostic { 510*37414Sbostic infname = argv[i] = lastfield(argv[i]); 511*37414Sbostic *lastchar(infname) = 'f'; 512*37414Sbostic 513*37414Sbostic if ( dofort(argv[i]) ) 514*37414Sbostic erred = YES; 515*37414Sbostic else { 516*37414Sbostic if (nodup(t = setdoto(argv[i])) ) 517*37414Sbostic *loadp++ = t; 518*37414Sbostic rmf(fortfile); 519*37414Sbostic } 520*37414Sbostic } 521*37414Sbostic break; 522*37414Sbostic 523*37414Sbostic case 'f': /* Fortran file */ 524*37414Sbostic if( unreadable(argv[i]) ) 525*37414Sbostic erred = YES; 526*37414Sbostic else if( dofort(argv[i]) ) 527*37414Sbostic erred = YES; 528*37414Sbostic else if( nodup(t=setdoto(argv[i])) ) 529*37414Sbostic *loadp++ = t; 530*37414Sbostic break; 531*37414Sbostic 532*37414Sbostic case 'c': /* C file */ 533*37414Sbostic case 's': /* Assembler file */ 534*37414Sbostic if( unreadable(argv[i]) ) 535*37414Sbostic { 536*37414Sbostic erred = YES; 537*37414Sbostic break; 538*37414Sbostic } 539*37414Sbostic #if HERE==PDP11 || HERE==VAX || HERE==TAHOE 540*37414Sbostic if( namesflag == YES ) 541*37414Sbostic fprintf(diagfile, "%s:\n", argv[i]); 542*37414Sbostic #endif 543*37414Sbostic sprintf(buff, "cc %s %s", cflags, argv[i] ); 544*37414Sbostic if( sys(buff) ) 545*37414Sbostic erred = YES; 546*37414Sbostic else 547*37414Sbostic if( nodup(t = setdoto(argv[i])) ) 548*37414Sbostic *loadp++ = t; 549*37414Sbostic break; 550*37414Sbostic 551*37414Sbostic case 'o': 552*37414Sbostic if( nodup(argv[i]) ) 553*37414Sbostic *loadp++ = argv[i]; 554*37414Sbostic break; 555*37414Sbostic 556*37414Sbostic default: 557*37414Sbostic if( ! strcmp(argv[i], "-o") ) { 558*37414Sbostic aoutname = argv[++i]; 559*37414Sbostic new_aoutname = YES; 560*37414Sbostic if( loadflag == NO ){ 561*37414Sbostic fprintf(diagfile, "-c prevents loading, -o %s ignored\n", aoutname); 562*37414Sbostic new_aoutname = NO; 563*37414Sbostic } 564*37414Sbostic } else 565*37414Sbostic *loadp++ = argv[i]; 566*37414Sbostic break; 567*37414Sbostic } 568*37414Sbostic 569*37414Sbostic if( loadflag && stupid(aoutname) ) 570*37414Sbostic erred = YES; 571*37414Sbostic if(loadflag && !erred) 572*37414Sbostic doload(loadargs, loadp); 573*37414Sbostic done(erred); 574*37414Sbostic } 575*37414Sbostic 576*37414Sbostic 577*37414Sbostic 578*37414Sbostic /* 579*37414Sbostic * argvtos() copies a list of arguments contained in an array of character 580*37414Sbostic * strings to a single dynamically allocated string. Each argument is 581*37414Sbostic * separated by one blank space. Returns a pointer to the string or null 582*37414Sbostic * if out of memory. 583*37414Sbostic */ 584*37414Sbostic #define SBUFINCR 1024 585*37414Sbostic #define SBUFMAX 10240 586*37414Sbostic 587*37414Sbostic char * 588*37414Sbostic argvtos(argc, argv) 589*37414Sbostic char **argv; 590*37414Sbostic int argc; 591*37414Sbostic { 592*37414Sbostic register char *s; /* string pointer */ 593*37414Sbostic register int i; /* string buffer pointer */ 594*37414Sbostic char *malloc(); /* memory allocator */ 595*37414Sbostic char *realloc(); /* increase size of storage */ 596*37414Sbostic char *sbuf; /* string buffer */ 597*37414Sbostic int nbytes; /* bytes of memory required */ 598*37414Sbostic int nu; /* no. of SBUFINCR units required */ 599*37414Sbostic int sbufsize; /* current size of sbuf */ 600*37414Sbostic int strlen(); /* string length */ 601*37414Sbostic 602*37414Sbostic sbufsize = SBUFINCR; 603*37414Sbostic if ((sbuf = malloc((unsigned)sbufsize)) == NULL) 604*37414Sbostic { 605*37414Sbostic fatal("out of memory (argvtos)"); 606*37414Sbostic /* NOTREACHED */ 607*37414Sbostic } 608*37414Sbostic 609*37414Sbostic for (i = 0; argc-- > 0; ++argv) 610*37414Sbostic { 611*37414Sbostic if ((nbytes = (i+strlen(*argv)+1-sbufsize)) > 0) 612*37414Sbostic { 613*37414Sbostic nu = (nbytes+SBUFINCR-1)/SBUFINCR; 614*37414Sbostic sbufsize += nu * SBUFINCR; 615*37414Sbostic if (sbufsize > SBUFMAX) 616*37414Sbostic { 617*37414Sbostic fatal("argument length exceeded (argvtos)"); 618*37414Sbostic /* NOTREACHED */ 619*37414Sbostic } 620*37414Sbostic if ((sbuf = realloc(sbuf, (unsigned)sbufsize)) == NULL) 621*37414Sbostic { 622*37414Sbostic fatal("out of memory (argvtos)"); 623*37414Sbostic /* NOTREACHED */ 624*37414Sbostic } 625*37414Sbostic } 626*37414Sbostic for (s = *argv; *s != '\0'; i++, s++) 627*37414Sbostic sbuf[i] = *s; 628*37414Sbostic sbuf[i++] = ' '; 629*37414Sbostic } 630*37414Sbostic sbuf[--i] = '\0'; 631*37414Sbostic return(sbuf); 632*37414Sbostic } 633*37414Sbostic 634*37414Sbostic dofort(s) 635*37414Sbostic char *s; 636*37414Sbostic { 637*37414Sbostic int retcode; 638*37414Sbostic char buff[200]; 639*37414Sbostic 640*37414Sbostic infname = s; 641*37414Sbostic sprintf(buff, "%s %s %s %s %s %s", 642*37414Sbostic pass1name, fflags, s, asmfname, initfname, textfname); 643*37414Sbostic switch( sys(buff) ) 644*37414Sbostic { 645*37414Sbostic case 1: 646*37414Sbostic goto error; 647*37414Sbostic case 0: 648*37414Sbostic break; 649*37414Sbostic default: 650*37414Sbostic goto comperror; 651*37414Sbostic } 652*37414Sbostic 653*37414Sbostic if( dopass2() ) 654*37414Sbostic goto comperror; 655*37414Sbostic doasm(s); 656*37414Sbostic retcode = 0; 657*37414Sbostic 658*37414Sbostic ret: 659*37414Sbostic rmf(asmfname); 660*37414Sbostic rmf(initfname); 661*37414Sbostic rmf(textfname); 662*37414Sbostic return(retcode); 663*37414Sbostic 664*37414Sbostic error: 665*37414Sbostic fprintf(diagfile, "\nError. No assembly.\n"); 666*37414Sbostic retcode = 1; 667*37414Sbostic goto ret; 668*37414Sbostic 669*37414Sbostic comperror: 670*37414Sbostic fprintf(diagfile, "\ncompiler error.\n"); 671*37414Sbostic retcode = 2; 672*37414Sbostic goto ret; 673*37414Sbostic } 674*37414Sbostic 675*37414Sbostic 676*37414Sbostic 677*37414Sbostic 678*37414Sbostic dopass2() 679*37414Sbostic { 680*37414Sbostic char buff[100]; 681*37414Sbostic 682*37414Sbostic if(verbose) 683*37414Sbostic fprintf(diagfile, "PASS2."); 684*37414Sbostic 685*37414Sbostic #if FAMILY==DMR 686*37414Sbostic sprintf(buff, "%s %s - %s", pass2name, textfname, asmpass2); 687*37414Sbostic return( sys(buff) ); 688*37414Sbostic #endif 689*37414Sbostic 690*37414Sbostic 691*37414Sbostic #if FAMILY == PCC 692*37414Sbostic # if TARGET==INTERDATA 693*37414Sbostic sprintf(buff, "%s -A%s <%s >%s", pass2name, setfname, textfname, asmpass2); 694*37414Sbostic # else 695*37414Sbostic sprintf(buff, "%s %s %s >%s", 696*37414Sbostic pass2name, f2flags, textfname, asmpass2); 697*37414Sbostic # endif 698*37414Sbostic return( sys(buff) ); 699*37414Sbostic #endif 700*37414Sbostic } 701*37414Sbostic 702*37414Sbostic 703*37414Sbostic 704*37414Sbostic 705*37414Sbostic doasm(s) 706*37414Sbostic char *s; 707*37414Sbostic { 708*37414Sbostic register char *lastc; 709*37414Sbostic char *obj; 710*37414Sbostic char buff[200]; 711*37414Sbostic char *lastchar(), *setdoto(); 712*37414Sbostic 713*37414Sbostic if(*s == '\0') 714*37414Sbostic s = objfdefault; 715*37414Sbostic lastc = lastchar(s); 716*37414Sbostic obj = setdoto(s); 717*37414Sbostic 718*37414Sbostic #if TARGET==PDP11 || TARGET==VAX || TARGET==TAHOE 719*37414Sbostic # ifdef PASS2OPT 720*37414Sbostic if(optimflag) 721*37414Sbostic { 722*37414Sbostic #if TARGET==TAHOE 723*37414Sbostic sprintf(buff, "%s -f %s %s", 724*37414Sbostic #else 725*37414Sbostic sprintf(buff, "%s %s %s", 726*37414Sbostic #endif 727*37414Sbostic pass2opt, asmpass2, optzfname); 728*37414Sbostic if( sys(buff) ) 729*37414Sbostic rmf(optzfname); 730*37414Sbostic else 731*37414Sbostic { 732*37414Sbostic sprintf(buff,"mv %s %s", optzfname, asmpass2); 733*37414Sbostic sys(buff); 734*37414Sbostic } 735*37414Sbostic } 736*37414Sbostic # endif 737*37414Sbostic #endif 738*37414Sbostic 739*37414Sbostic if(saveasmflag) 740*37414Sbostic { 741*37414Sbostic *lastc = 's'; 742*37414Sbostic #if TARGET == INTERDATA 743*37414Sbostic sprintf(buff, "%s %s %s %s %s >%s", CATNAME, asmfname, initfname, 744*37414Sbostic setfname, asmpass2, obj); 745*37414Sbostic #else 746*37414Sbostic #if TARGET == VAX || TARGET == TAHOE 747*37414Sbostic sprintf(buff, "%s %s %s %s >%s", 748*37414Sbostic CATNAME, asmfname, asmpass2, initfname, obj); 749*37414Sbostic #else 750*37414Sbostic sprintf(buff, "%s %s %s %s >%s", 751*37414Sbostic CATNAME, asmfname, initfname, asmpass2, obj); 752*37414Sbostic #endif 753*37414Sbostic #endif 754*37414Sbostic sys(buff); 755*37414Sbostic *lastc = 'o'; 756*37414Sbostic } 757*37414Sbostic else 758*37414Sbostic { 759*37414Sbostic if(verbose) 760*37414Sbostic fprintf(diagfile, " ASM."); 761*37414Sbostic #if TARGET == INTERDATA 762*37414Sbostic sprintf(buff, "%s -o %s %s %s %s %s", asmname, obj, asmfname, 763*37414Sbostic initfname, setfname, asmpass2); 764*37414Sbostic #endif 765*37414Sbostic 766*37414Sbostic #if TARGET == VAX || TARGET == TAHOE 767*37414Sbostic /* vax assembler currently accepts only one input file */ 768*37414Sbostic 769*37414Sbostic sprintf(buff, "%s %s %s >>%s", 770*37414Sbostic CATNAME, asmpass2, initfname, asmfname); 771*37414Sbostic sys(buff); 772*37414Sbostic #ifdef UCBVAXASM 773*37414Sbostic sprintf(buff, "%s -J -o %s %s", asmname, obj, asmfname); 774*37414Sbostic #else 775*37414Sbostic sprintf(buff, "%s -o %s %s", asmname, obj, asmfname); 776*37414Sbostic #endif 777*37414Sbostic #endif 778*37414Sbostic 779*37414Sbostic #if TARGET == PDP11 780*37414Sbostic sprintf(buff, "%s -u -o %s %s %s", asmname, obj, asmfname, asmpass2); 781*37414Sbostic #endif 782*37414Sbostic 783*37414Sbostic #if TARGET!=INTERDATA && TARGET!=PDP11 && TARGET!=VAX && TARGET!=TAHOE 784*37414Sbostic sprintf(buff, "%s -o %s %s %s", asmname, obj, asmfname, asmpass2); 785*37414Sbostic #endif 786*37414Sbostic 787*37414Sbostic if( sys(buff) ) 788*37414Sbostic fatal("assembler error"); 789*37414Sbostic if(verbose) 790*37414Sbostic fprintf(diagfile, "\n"); 791*37414Sbostic #if HERE==PDP11 && TARGET!=PDP11 792*37414Sbostic rmf(obj); 793*37414Sbostic #endif 794*37414Sbostic } 795*37414Sbostic 796*37414Sbostic rmf(asmpass2); 797*37414Sbostic } 798*37414Sbostic 799*37414Sbostic 800*37414Sbostic 801*37414Sbostic doload(v0, v) 802*37414Sbostic register char *v0[], *v[]; 803*37414Sbostic { 804*37414Sbostic char **p; 805*37414Sbostic int waitpid; 806*37414Sbostic 807*37414Sbostic if(sdbflag) 808*37414Sbostic *v++ = "-lg"; 809*37414Sbostic if (profileflag) 810*37414Sbostic { 811*37414Sbostic for(p = p_liblist ; *p ; *v++ = *p++) 812*37414Sbostic ; 813*37414Sbostic } 814*37414Sbostic else { 815*37414Sbostic for(p = liblist ; *p ; *v++ = *p++) 816*37414Sbostic ; 817*37414Sbostic } 818*37414Sbostic 819*37414Sbostic *v++ = "-o"; 820*37414Sbostic *v++ = aoutname; 821*37414Sbostic *v = NULL; 822*37414Sbostic 823*37414Sbostic if(verbose) 824*37414Sbostic fprintf(diagfile, "LOAD."); 825*37414Sbostic if(debugflag) 826*37414Sbostic { 827*37414Sbostic for(p = v0 ; p<v ; ++p) 828*37414Sbostic fprintf(diagfile, "%s ", *p); 829*37414Sbostic fprintf(diagfile, "\n"); 830*37414Sbostic } 831*37414Sbostic 832*37414Sbostic #if HERE==PDP11 || HERE==INTERDATA || HERE==VAX || HERE==TAHOE 833*37414Sbostic if( (waitpid = fork()) == 0) 834*37414Sbostic { 835*37414Sbostic enbint(SIG_DFL); 836*37414Sbostic execv(ldname, v0); 837*37414Sbostic fatalstr("couldn't load %s", ldname); 838*37414Sbostic } 839*37414Sbostic await(waitpid); 840*37414Sbostic #endif 841*37414Sbostic 842*37414Sbostic #if HERE==INTERDATA 843*37414Sbostic if(optimflag) 844*37414Sbostic { 845*37414Sbostic char buff1[100], buff2[100]; 846*37414Sbostic sprintf(buff1, "nopt %s -o junk.%d", aoutname, pid); 847*37414Sbostic sprintf(buff2, "mv junk.%d %s", pid, aoutname); 848*37414Sbostic if( sys(buff1) || sys(buff2) ) 849*37414Sbostic err("bad optimization"); 850*37414Sbostic } 851*37414Sbostic #endif 852*37414Sbostic 853*37414Sbostic if(verbose) 854*37414Sbostic fprintf(diagfile, "\n"); 855*37414Sbostic } 856*37414Sbostic 857*37414Sbostic /* Process control and Shell-simulating routines */ 858*37414Sbostic 859*37414Sbostic sys(str) 860*37414Sbostic char *str; 861*37414Sbostic { 862*37414Sbostic register char *s, *t; 863*37414Sbostic char *argv[100], path[100]; 864*37414Sbostic char *inname, *outname; 865*37414Sbostic int append; 866*37414Sbostic int waitpid; 867*37414Sbostic int argc; 868*37414Sbostic 869*37414Sbostic 870*37414Sbostic if(debugflag) 871*37414Sbostic fprintf(diagfile, "%s\n", str); 872*37414Sbostic inname = NULL; 873*37414Sbostic outname = NULL; 874*37414Sbostic argv[0] = shellname; 875*37414Sbostic argc = 1; 876*37414Sbostic 877*37414Sbostic t = str; 878*37414Sbostic while( isspace(*t) ) 879*37414Sbostic ++t; 880*37414Sbostic while(*t) 881*37414Sbostic { 882*37414Sbostic if(*t == '<') 883*37414Sbostic inname = t+1; 884*37414Sbostic else if(*t == '>') 885*37414Sbostic { 886*37414Sbostic if(t[1] == '>') 887*37414Sbostic { 888*37414Sbostic append = YES; 889*37414Sbostic outname = t+2; 890*37414Sbostic } 891*37414Sbostic else { 892*37414Sbostic append = NO; 893*37414Sbostic outname = t+1; 894*37414Sbostic } 895*37414Sbostic } 896*37414Sbostic else 897*37414Sbostic argv[argc++] = t; 898*37414Sbostic while( !isspace(*t) && *t!='\0' ) 899*37414Sbostic ++t; 900*37414Sbostic if(*t) 901*37414Sbostic { 902*37414Sbostic *t++ = '\0'; 903*37414Sbostic while( isspace(*t) ) 904*37414Sbostic ++t; 905*37414Sbostic } 906*37414Sbostic } 907*37414Sbostic 908*37414Sbostic if(argc == 1) /* no command */ 909*37414Sbostic return(-1); 910*37414Sbostic argv[argc] = 0; 911*37414Sbostic 912*37414Sbostic s = path; 913*37414Sbostic t = "/usr/bin/"; 914*37414Sbostic while(*t) 915*37414Sbostic *s++ = *t++; 916*37414Sbostic for(t = argv[1] ; *s++ = *t++ ; ) 917*37414Sbostic ; 918*37414Sbostic if((waitpid = fork()) == 0) 919*37414Sbostic { 920*37414Sbostic if(inname) 921*37414Sbostic freopen(inname, "r", stdin); 922*37414Sbostic if(outname) 923*37414Sbostic freopen(outname, (append ? "a" : "w"), stdout); 924*37414Sbostic enbint(SIG_DFL); 925*37414Sbostic 926*37414Sbostic texec(path+9, argv); /* command */ 927*37414Sbostic texec(path+4, argv); /* /bin/command */ 928*37414Sbostic texec(path , argv); /* /usr/bin/command */ 929*37414Sbostic 930*37414Sbostic fatalstr("Cannot load %s",path+9); 931*37414Sbostic } 932*37414Sbostic 933*37414Sbostic return( await(waitpid) ); 934*37414Sbostic } 935*37414Sbostic 936*37414Sbostic 937*37414Sbostic 938*37414Sbostic 939*37414Sbostic 940*37414Sbostic #include "errno.h" 941*37414Sbostic 942*37414Sbostic /* modified version from the Shell */ 943*37414Sbostic texec(f, av) 944*37414Sbostic char *f; 945*37414Sbostic char **av; 946*37414Sbostic { 947*37414Sbostic extern int errno; 948*37414Sbostic 949*37414Sbostic execv(f, av+1); 950*37414Sbostic 951*37414Sbostic if (errno==ENOEXEC) 952*37414Sbostic { 953*37414Sbostic av[1] = f; 954*37414Sbostic execv(shellname, av); 955*37414Sbostic fatal("No shell!"); 956*37414Sbostic } 957*37414Sbostic if (errno==ENOMEM) 958*37414Sbostic fatalstr("%s: too large", f); 959*37414Sbostic } 960*37414Sbostic 961*37414Sbostic 962*37414Sbostic 963*37414Sbostic 964*37414Sbostic 965*37414Sbostic 966*37414Sbostic done(k) 967*37414Sbostic int k; 968*37414Sbostic { 969*37414Sbostic static int recurs = NO; 970*37414Sbostic 971*37414Sbostic if(recurs == NO) 972*37414Sbostic { 973*37414Sbostic recurs = YES; 974*37414Sbostic rmfiles(); 975*37414Sbostic } 976*37414Sbostic exit(k); 977*37414Sbostic } 978*37414Sbostic 979*37414Sbostic 980*37414Sbostic 981*37414Sbostic 982*37414Sbostic 983*37414Sbostic 984*37414Sbostic enbint(k) 985*37414Sbostic int (*k)(); 986*37414Sbostic { 987*37414Sbostic if(sigivalue == 0) 988*37414Sbostic signal(SIGINT,k); 989*37414Sbostic if(sigqvalue == 0) 990*37414Sbostic signal(SIGQUIT,k); 991*37414Sbostic if(sighvalue == 0) 992*37414Sbostic signal(SIGHUP,k); 993*37414Sbostic if(sigtvalue == 0) 994*37414Sbostic signal(SIGTERM,k); 995*37414Sbostic } 996*37414Sbostic 997*37414Sbostic 998*37414Sbostic 999*37414Sbostic 1000*37414Sbostic intrupt() 1001*37414Sbostic { 1002*37414Sbostic done(2); 1003*37414Sbostic } 1004*37414Sbostic 1005*37414Sbostic 1006*37414Sbostic #ifdef PSIGNAL 1007*37414Sbostic /* 1008*37414Sbostic * Fancy 4.2 BSD signal printing stuff. 1009*37414Sbostic */ 1010*37414Sbostic char harmless[NSIG] = { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }; 1011*37414Sbostic #endif 1012*37414Sbostic 1013*37414Sbostic 1014*37414Sbostic await(waitpid) 1015*37414Sbostic int waitpid; 1016*37414Sbostic { 1017*37414Sbostic 1018*37414Sbostic #ifdef PSIGNAL 1019*37414Sbostic extern char *sys_siglist[]; 1020*37414Sbostic union wait status; 1021*37414Sbostic #else PSIGNAL 1022*37414Sbostic int status; 1023*37414Sbostic #endif PSIGNAL 1024*37414Sbostic 1025*37414Sbostic int w; 1026*37414Sbostic 1027*37414Sbostic enbint(SIG_IGN); 1028*37414Sbostic while ( (w = wait(&status)) != waitpid) 1029*37414Sbostic if(w == -1) 1030*37414Sbostic fatal("bad wait code"); 1031*37414Sbostic enbint(intrupt); 1032*37414Sbostic 1033*37414Sbostic #ifdef PSIGNAL 1034*37414Sbostic if(status.w_termsig) 1035*37414Sbostic { 1036*37414Sbostic debugflag = 0; /* Prevent us from dumping core ourselves */ 1037*37414Sbostic if(status.w_termsig != SIGINT && status.w_termsig < NSIG) 1038*37414Sbostic fprintf(diagfile, "%s%s\n", sys_siglist[status.w_termsig], 1039*37414Sbostic status.w_coredump ? " -- core dumped" : ""); 1040*37414Sbostic if(status.w_termsig < NSIG && ! harmless[status.w_termsig]) 1041*37414Sbostic fatal("see a system manager"); 1042*37414Sbostic else 1043*37414Sbostic done(3); 1044*37414Sbostic } 1045*37414Sbostic return(status.w_retcode); 1046*37414Sbostic #else PSIGNAL 1047*37414Sbostic if(status & 0377) 1048*37414Sbostic { 1049*37414Sbostic if(status != SIGINT) 1050*37414Sbostic fprintf(diagfile, "Termination code %d\n", status); 1051*37414Sbostic done(3); 1052*37414Sbostic } 1053*37414Sbostic return(status>>8); 1054*37414Sbostic #endif PSIGNAL 1055*37414Sbostic } 1056*37414Sbostic 1057*37414Sbostic /* File Name and File Manipulation Routines */ 1058*37414Sbostic 1059*37414Sbostic unreadable(s) 1060*37414Sbostic register char *s; 1061*37414Sbostic { 1062*37414Sbostic register FILE *fp; 1063*37414Sbostic 1064*37414Sbostic if(fp = fopen(s, "r")) 1065*37414Sbostic { 1066*37414Sbostic fclose(fp); 1067*37414Sbostic return(NO); 1068*37414Sbostic } 1069*37414Sbostic 1070*37414Sbostic else 1071*37414Sbostic { 1072*37414Sbostic fprintf(diagfile, "Error: Cannot read file %s\n", s); 1073*37414Sbostic return(YES); 1074*37414Sbostic } 1075*37414Sbostic } 1076*37414Sbostic 1077*37414Sbostic 1078*37414Sbostic 1079*37414Sbostic stupid(s) 1080*37414Sbostic char *s; 1081*37414Sbostic { 1082*37414Sbostic char c; 1083*37414Sbostic 1084*37414Sbostic if( (c = dotchar(s)) 1085*37414Sbostic && index("focsreF", c) 1086*37414Sbostic && access(s, 0) == 0 ) 1087*37414Sbostic { 1088*37414Sbostic fprintf(diagfile, "Loading on %s would destroy it\n", s); 1089*37414Sbostic return(YES); 1090*37414Sbostic } 1091*37414Sbostic return(NO); 1092*37414Sbostic } 1093*37414Sbostic 1094*37414Sbostic 1095*37414Sbostic 1096*37414Sbostic clf(p) 1097*37414Sbostic FILEP *p; 1098*37414Sbostic { 1099*37414Sbostic if(p!=NULL && *p!=NULL && *p!=stdout) 1100*37414Sbostic { 1101*37414Sbostic if(ferror(*p)) 1102*37414Sbostic fatal("writing error"); 1103*37414Sbostic fclose(*p); 1104*37414Sbostic } 1105*37414Sbostic *p = NULL; 1106*37414Sbostic } 1107*37414Sbostic 1108*37414Sbostic rmfiles() 1109*37414Sbostic { 1110*37414Sbostic rmf(textfname); 1111*37414Sbostic rmf(asmfname); 1112*37414Sbostic rmf(initfname); 1113*37414Sbostic rmf(asmpass2); 1114*37414Sbostic #if TARGET == INTERDATA 1115*37414Sbostic rmf(setfname); 1116*37414Sbostic #endif 1117*37414Sbostic } 1118*37414Sbostic 1119*37414Sbostic 1120*37414Sbostic 1121*37414Sbostic 1122*37414Sbostic 1123*37414Sbostic 1124*37414Sbostic 1125*37414Sbostic 1126*37414Sbostic /* return -1 if file does not exist, 0 if it is of zero length 1127*37414Sbostic and 1 if of positive length 1128*37414Sbostic */ 1129*37414Sbostic content(filename) 1130*37414Sbostic char *filename; 1131*37414Sbostic { 1132*37414Sbostic #ifdef VERSION6 1133*37414Sbostic struct stat 1134*37414Sbostic { 1135*37414Sbostic char cjunk[9]; 1136*37414Sbostic char size0; 1137*37414Sbostic int size1; 1138*37414Sbostic int ijunk[12]; 1139*37414Sbostic } buf; 1140*37414Sbostic #else 1141*37414Sbostic struct stat buf; 1142*37414Sbostic #endif 1143*37414Sbostic 1144*37414Sbostic if(stat(filename,&buf) < 0) 1145*37414Sbostic return(-1); 1146*37414Sbostic #ifdef VERSION6 1147*37414Sbostic return(buf.size0 || buf.size1); 1148*37414Sbostic #else 1149*37414Sbostic return( buf.st_size > 0 ); 1150*37414Sbostic #endif 1151*37414Sbostic } 1152*37414Sbostic 1153*37414Sbostic 1154*37414Sbostic 1155*37414Sbostic 1156*37414Sbostic crfnames() 1157*37414Sbostic { 1158*37414Sbostic fname(textfname, "x"); 1159*37414Sbostic fname(asmfname, "s"); 1160*37414Sbostic fname(asmpass2, "a"); 1161*37414Sbostic fname(initfname, "d"); 1162*37414Sbostic fname(sortfname, "S"); 1163*37414Sbostic fname(objfdefault, "o"); 1164*37414Sbostic fname(prepfname, "p"); 1165*37414Sbostic fname(optzfname, "z"); 1166*37414Sbostic fname(setfname, "A"); 1167*37414Sbostic } 1168*37414Sbostic 1169*37414Sbostic 1170*37414Sbostic 1171*37414Sbostic 1172*37414Sbostic rmf(fn) 1173*37414Sbostic register char *fn; 1174*37414Sbostic { 1175*37414Sbostic /* if(!debugflag && fn!=NULL && *fn!='\0') */ 1176*37414Sbostic 1177*37414Sbostic if(fn!=NULL && *fn!='\0') 1178*37414Sbostic unlink(fn); 1179*37414Sbostic } 1180*37414Sbostic 1181*37414Sbostic 1182*37414Sbostic 1183*37414Sbostic 1184*37414Sbostic 1185*37414Sbostic LOCAL fname(name, suff) 1186*37414Sbostic char *name, *suff; 1187*37414Sbostic { 1188*37414Sbostic sprintf(name, "/tmp/%s%d.%s", temppref, pid, suff); 1189*37414Sbostic } 1190*37414Sbostic 1191*37414Sbostic 1192*37414Sbostic 1193*37414Sbostic 1194*37414Sbostic dotchar(s) 1195*37414Sbostic register char *s; 1196*37414Sbostic { 1197*37414Sbostic for( ; *s ; ++s) 1198*37414Sbostic if(s[0]=='.' && s[1]!='\0' && s[2]=='\0') 1199*37414Sbostic return( s[1] ); 1200*37414Sbostic return(NO); 1201*37414Sbostic } 1202*37414Sbostic 1203*37414Sbostic 1204*37414Sbostic 1205*37414Sbostic char *lastfield(s) 1206*37414Sbostic register char *s; 1207*37414Sbostic { 1208*37414Sbostic register char *t; 1209*37414Sbostic for(t = s; *s ; ++s) 1210*37414Sbostic if(*s == '/') 1211*37414Sbostic t = s+1; 1212*37414Sbostic return(t); 1213*37414Sbostic } 1214*37414Sbostic 1215*37414Sbostic 1216*37414Sbostic 1217*37414Sbostic char *lastchar(s) 1218*37414Sbostic register char *s; 1219*37414Sbostic { 1220*37414Sbostic while(*s) 1221*37414Sbostic ++s; 1222*37414Sbostic return(s-1); 1223*37414Sbostic } 1224*37414Sbostic 1225*37414Sbostic char *setdoto(s) 1226*37414Sbostic register char *s; 1227*37414Sbostic { 1228*37414Sbostic *lastchar(s) = 'o'; 1229*37414Sbostic return( lastfield(s) ); 1230*37414Sbostic } 1231*37414Sbostic 1232*37414Sbostic 1233*37414Sbostic 1234*37414Sbostic badfile(s) 1235*37414Sbostic char *s; 1236*37414Sbostic { 1237*37414Sbostic fatalstr("cannot open intermediate file %s", s); 1238*37414Sbostic } 1239*37414Sbostic 1240*37414Sbostic 1241*37414Sbostic 1242*37414Sbostic ptr ckalloc(n) 1243*37414Sbostic int n; 1244*37414Sbostic { 1245*37414Sbostic ptr p, calloc(); 1246*37414Sbostic 1247*37414Sbostic if( p = calloc(1, (unsigned) n) ) 1248*37414Sbostic return(p); 1249*37414Sbostic 1250*37414Sbostic fatal("out of memory"); 1251*37414Sbostic /* NOTREACHED */ 1252*37414Sbostic } 1253*37414Sbostic 1254*37414Sbostic 1255*37414Sbostic 1256*37414Sbostic 1257*37414Sbostic 1258*37414Sbostic char *copyn(n, s) 1259*37414Sbostic register int n; 1260*37414Sbostic register char *s; 1261*37414Sbostic { 1262*37414Sbostic register char *p, *q; 1263*37414Sbostic 1264*37414Sbostic p = q = (char *) ckalloc(n); 1265*37414Sbostic while(n-- > 0) 1266*37414Sbostic *q++ = *s++; 1267*37414Sbostic return(p); 1268*37414Sbostic } 1269*37414Sbostic 1270*37414Sbostic 1271*37414Sbostic 1272*37414Sbostic char *copys(s) 1273*37414Sbostic char *s; 1274*37414Sbostic { 1275*37414Sbostic return( copyn( strlen(s)+1 , s) ); 1276*37414Sbostic } 1277*37414Sbostic 1278*37414Sbostic 1279*37414Sbostic 1280*37414Sbostic 1281*37414Sbostic 1282*37414Sbostic oneof(c,s) 1283*37414Sbostic register c; 1284*37414Sbostic register char *s; 1285*37414Sbostic { 1286*37414Sbostic while( *s ) 1287*37414Sbostic if(*s++ == c) 1288*37414Sbostic return(YES); 1289*37414Sbostic return(NO); 1290*37414Sbostic } 1291*37414Sbostic 1292*37414Sbostic 1293*37414Sbostic 1294*37414Sbostic nodup(s) 1295*37414Sbostic char *s; 1296*37414Sbostic { 1297*37414Sbostic register char **p; 1298*37414Sbostic 1299*37414Sbostic for(p = loadargs ; p < loadp ; ++p) 1300*37414Sbostic if( !strcmp(*p, s) ) 1301*37414Sbostic return(NO); 1302*37414Sbostic 1303*37414Sbostic return(YES); 1304*37414Sbostic } 1305*37414Sbostic 1306*37414Sbostic 1307*37414Sbostic 1308*37414Sbostic static fatal(t) 1309*37414Sbostic char *t; 1310*37414Sbostic { 1311*37414Sbostic fprintf(diagfile, "Compiler error in file %s: %s\n", infname, t); 1312*37414Sbostic if(debugflag) 1313*37414Sbostic abort(); 1314*37414Sbostic done(1); 1315*37414Sbostic exit(1); 1316*37414Sbostic } 1317*37414Sbostic 1318*37414Sbostic 1319*37414Sbostic 1320*37414Sbostic 1321*37414Sbostic static fatali(t,d) 1322*37414Sbostic char *t; 1323*37414Sbostic int d; 1324*37414Sbostic { 1325*37414Sbostic char buff[100]; 1326*37414Sbostic sprintf(buff, t, d); 1327*37414Sbostic fatal(buff); 1328*37414Sbostic } 1329*37414Sbostic 1330*37414Sbostic 1331*37414Sbostic 1332*37414Sbostic 1333*37414Sbostic static fatalstr(t, s) 1334*37414Sbostic char *t, *s; 1335*37414Sbostic { 1336*37414Sbostic char buff[100]; 1337*37414Sbostic sprintf(buff, t, s); 1338*37414Sbostic fatal(buff); 1339*37414Sbostic } 1340*37414Sbostic err(s) 1341*37414Sbostic char *s; 1342*37414Sbostic { 1343*37414Sbostic fprintf(diagfile, "Error in file %s: %s\n", infname, s); 1344*37414Sbostic } 1345*37414Sbostic 1346