Annotation of 40BSD/cmd/make/files.c, revision 1.1

1.1     ! root        1: /* UNIX DEPENDENT PROCEDURES */
        !             2: 
        !             3: 
        !             4: /* DEFAULT RULES FOR UNIX */
        !             5: 
        !             6: char *builtin[] =
        !             7:        {
        !             8: #ifdef pwb
        !             9:        ".SUFFIXES : .L .out .o .c .f .e .r .y .yr .ye .l .s .z .x .t .h .cl",
        !            10: #else
        !            11:        ".SUFFIXES : .out .o .c .f .e .r .y .yr .ye .l .s .cl .p",
        !            12: #endif
        !            13:        "YACC=yacc",
        !            14:        "YACCR=yacc -r",
        !            15:        "YACCE=yacc -e",
        !            16:        "YFLAGS=",
        !            17:        "LEX=lex",
        !            18:        "LFLAGS=",
        !            19:        "CC=cc",
        !            20: #ifdef vax
        !            21:        "AS=as",
        !            22: #else
        !            23:        "AS=as -",
        !            24: #endif
        !            25:        "PC=pc",
        !            26:        "PFLAGS=",
        !            27:        "CFLAGS=",
        !            28:        "RC=f77",
        !            29:        "RFLAGS=",
        !            30:        "EC=f77",
        !            31:        "EFLAGS=",
        !            32:        "FFLAGS=",
        !            33:        "LOADLIBES=",
        !            34: #ifdef pwb
        !            35:        "SCOMP=scomp",
        !            36:        "SCFLAGS=",
        !            37:        "CMDICT=cmdict",
        !            38:        "CMFLAGS=",
        !            39: #endif
        !            40: 
        !            41:        ".c.o :",
        !            42:        "\t$(CC) $(CFLAGS) -c $<",
        !            43: 
        !            44:        ".p.o :",
        !            45:        "\t$(PC) $(PFLAGS) -c $<",
        !            46: 
        !            47:        ".cl.o :",
        !            48:        "\tclass -c $<",
        !            49: 
        !            50:        ".e.o .r.o .f.o :",
        !            51:        "\t$(FC) $(RFLAGS) $(EFLAGS) $(FFLAGS) -c $<",
        !            52: 
        !            53:        ".s.o :",
        !            54:        "\t$(AS) -o $@ $<",
        !            55: 
        !            56:        ".y.o :",
        !            57:        "\t$(YACC) $(YFLAGS) $<",
        !            58:        "\t$(CC) $(CFLAGS) -c y.tab.c",
        !            59:        "\trm y.tab.c",
        !            60:        "\tmv y.tab.o $@",
        !            61: 
        !            62:        ".yr.o:",
        !            63:        "\t$(YACCR) $(YFLAGS) $<",
        !            64:        "\t$(RC) $(RFLAGS) -c y.tab.r",
        !            65:        "\trm y.tab.r",
        !            66:        "\tmv y.tab.o $@",
        !            67: 
        !            68:        ".ye.o :",
        !            69:        "\t$(YACCE) $(YFLAGS) $<",
        !            70:        "\t$(EC) $(RFLAGS) -c y.tab.e",
        !            71:        "\trm y.tab.e",
        !            72:        "\tmv y.tab.o $@",
        !            73: 
        !            74:        ".l.o :",
        !            75:        "\t$(LEX) $(LFLAGS) $<",
        !            76:        "\t$(CC) $(CFLAGS) -c lex.yy.c",
        !            77:        "\trm lex.yy.c",
        !            78:        "\tmv lex.yy.o $@",
        !            79: 
        !            80:        ".y.c :",
        !            81:        "\t$(YACC) $(YFLAGS) $<",
        !            82:        "\tmv y.tab.c $@",
        !            83: 
        !            84:        ".l.c :",
        !            85:        "\t$(LEX) $(LFLAGS) $<",
        !            86:        "\tmv lex.yy.c $@",
        !            87: 
        !            88:        ".yr.r:",
        !            89:        "\t$(YACCR) $(YFLAGS) $<",
        !            90:        "\tmv y.tab.r $@",
        !            91: 
        !            92:        ".ye.e :",
        !            93:        "\t$(YACCE) $(YFLAGS) $<",
        !            94:        "\tmv y.tab.e $@",
        !            95: 
        !            96: #ifdef pwb
        !            97:        ".o.L .c.L .t.L:",
        !            98:        "\t$(SCOMP) $(SCFLAGS) $<",
        !            99: 
        !           100:        ".t.o:",
        !           101:        "\t$(SCOMP) $(SCFLAGS) -c $<",
        !           102: 
        !           103:        ".t.c:",
        !           104:        "\t$(SCOMP) $(SCFLAGS) -t $<",
        !           105: 
        !           106:        ".h.z .t.z:",
        !           107:        "\t$(CMDICT) $(CMFLAGS) $<",
        !           108: 
        !           109:        ".h.x .t.x:",
        !           110:        "\t$(CMDICT) $(CMFLAGS) -c $<",
        !           111: #endif
        !           112: 
        !           113:        ".s.out .c.out .o.out :",
        !           114:        "\t$(CC) $(CFLAGS) $< $(LOADLIBES) -o $@",
        !           115: 
        !           116:        ".f.out .r.out .e.out :",
        !           117:        "\t$(FC) $(EFLAGS) $(RFLAGS) $(FFLAGS) $< $(LOADLIBES) -o $@",
        !           118:        "\t-rm $*.o",
        !           119: 
        !           120:        ".y.out :",
        !           121:        "\t$(YACC) $(YFLAGS) $<",
        !           122:        "\t$(CC) $(CFLAGS) y.tab.c $(LOADLIBES) -ly -o $@",
        !           123:        "\trm y.tab.c",
        !           124: 
        !           125:        ".l.out :",
        !           126:        "\t$(LEX) $(LFLAGS) $<",
        !           127:        "\t$(CC) $(CFLAGS) lex.yy.c $(LOADLIBES) -ll -o $@",
        !           128:        "\trm lex.yy.c",
        !           129: 
        !           130:        0 };
        !           131: 
        !           132: #include "defs"
        !           133: #include <sys/types.h>
        !           134: 
        !           135: 
        !           136: TIMETYPE exists(filename)
        !           137: char *filename;
        !           138: {
        !           139: #include <sys/stat.h>
        !           140: struct stat buf;
        !           141: register char *s;
        !           142: TIMETYPE lookarch();
        !           143: 
        !           144: for(s = filename ; *s!='\0' && *s!='(' ; ++s)
        !           145:        ;
        !           146: 
        !           147: if(*s == '(')
        !           148:        return(lookarch(filename));
        !           149: 
        !           150: if(stat(filename,&buf) < 0) 
        !           151:        return(0);
        !           152: else   return(buf.st_mtime);
        !           153: }
        !           154: 
        !           155: 
        !           156: TIMETYPE prestime()
        !           157: {
        !           158: TIMETYPE t;
        !           159: time(&t);
        !           160: return(t);
        !           161: }
        !           162: 
        !           163: 
        !           164: 
        !           165: #include <sys/dir.h>
        !           166: FSTATIC char n15[15];
        !           167: FSTATIC char *n15end   = &n15[14];
        !           168: 
        !           169: 
        !           170: 
        !           171: struct depblock *srchdir(pat, mkchain, nextdbl)
        !           172: register char *pat; /* pattern to be matched in directory */
        !           173: int mkchain;  /* nonzero if results to be remembered */
        !           174: struct depblock *nextdbl;  /* final value for chain */
        !           175: {
        !           176: FILE * dirf;
        !           177: register int i;
        !           178: int nread, cldir;
        !           179: char *dirname, *dirpref, *endir, *filepat, *p, temp[100];
        !           180: char fullname[100], *p1, *p2;
        !           181: struct nameblock *q;
        !           182: struct depblock *thisdbl;
        !           183: struct opendir *od;
        !           184: struct pattern *patp;
        !           185: 
        !           186: struct direct entry[32];
        !           187: 
        !           188: 
        !           189: thisdbl = 0;
        !           190: 
        !           191: if(mkchain == NO)
        !           192:        for(patp=firstpat ; patp ; patp = patp->nxtpattern)
        !           193:                if(! unequal(pat, patp->patval)) return(0);
        !           194: 
        !           195: patp = ALLOC(pattern);
        !           196: patp->nxtpattern = firstpat;
        !           197: firstpat = patp;
        !           198: patp->patval = copys(pat);
        !           199: 
        !           200: endir = 0;
        !           201: 
        !           202: for(p=pat; *p!='\0'; ++p)
        !           203:        if(*p=='/') endir = p;
        !           204: 
        !           205: if(endir==0)
        !           206:        {
        !           207:        dirname = ".";
        !           208:        dirpref = "";
        !           209:        filepat = pat;
        !           210:        }
        !           211: else   {
        !           212:        dirname = pat;
        !           213:        *endir = '\0';
        !           214:        dirpref = concat(dirname, "/", temp);
        !           215:        filepat = endir+1;
        !           216:        }
        !           217: 
        !           218: dirf = NULL;
        !           219: cldir = NO;
        !           220: 
        !           221: for(od = firstod; od; od = od->nxtopendir)
        !           222:        if(! unequal(dirname, od->dirn) )
        !           223:                {
        !           224:                dirf = od->dirfc;
        !           225:                fseek(dirf, 0L, 0); /* start over at the beginning  */
        !           226:                break;
        !           227:                }
        !           228: 
        !           229: if(dirf == NULL)
        !           230:        {
        !           231:        dirf = fopen(dirname, "r");
        !           232:        if(nopdir >= MAXDIR)
        !           233:                cldir = YES;
        !           234:        else    {
        !           235:                ++nopdir;
        !           236:                od = ALLOC(opendir);
        !           237:                od->nxtopendir = firstod;
        !           238:                firstod = od;
        !           239:                od->dirfc = dirf;
        !           240:                od->dirn = copys(dirname);
        !           241:                }
        !           242:        }
        !           243: 
        !           244: if(dirf == NULL)
        !           245:        {
        !           246:        fprintf(stderr, "Directory %s: ", dirname);
        !           247:        fatal("Cannot open");
        !           248:        }
        !           249: 
        !           250: else do
        !           251:        {
        !           252:        nread = fread( (char *) &entry[0], sizeof(struct direct), 32, dirf) ;
        !           253:        for(i=0; i<nread; ++i)
        !           254:                if(entry[i].d_ino!= 0)
        !           255:                        {
        !           256:                        p1 = entry[i].d_name;
        !           257:                        p2 = n15;
        !           258:                        while( (p2<n15end) &&
        !           259:                          (*p2++ = *p1++)!='\0' );
        !           260:                        if( amatch(n15,filepat) )
        !           261:                                {
        !           262:                                concat(dirpref,n15,fullname);
        !           263:                                if( (q=srchname(fullname)) ==0)
        !           264:                                        q = makename(copys(fullname));
        !           265:                                if(mkchain)
        !           266:                                        {
        !           267:                                        thisdbl = ALLOC(depblock);
        !           268:                                        thisdbl->nxtdepblock = nextdbl;
        !           269:                                        thisdbl->depname = q;
        !           270:                                        nextdbl = thisdbl;
        !           271:                                        }
        !           272:                                }
        !           273:                        }
        !           274: 
        !           275:        } while(nread==32);
        !           276: 
        !           277: if(endir != 0)  *endir = '/';
        !           278: 
        !           279: if(cldir)
        !           280:        fclose(dirf);
        !           281: return(thisdbl);
        !           282: }
        !           283: 
        !           284: /* stolen from glob through find */
        !           285: 
        !           286: static amatch(s, p)
        !           287: char *s, *p;
        !           288: {
        !           289:        register int cc, scc, k;
        !           290:        int c, lc;
        !           291: 
        !           292:        scc = *s;
        !           293:        lc = 077777;
        !           294:        switch (c = *p) {
        !           295: 
        !           296:        case '[':
        !           297:                k = 0;
        !           298:                while (cc = *++p) {
        !           299:                        switch (cc) {
        !           300: 
        !           301:                        case ']':
        !           302:                                if (k)
        !           303:                                        return(amatch(++s, ++p));
        !           304:                                else
        !           305:                                        return(0);
        !           306: 
        !           307:                        case '-':
        !           308:                                k |= (lc <= scc)  & (scc <= (cc=p[1]) ) ;
        !           309:                        }
        !           310:                        if (scc==(lc=cc)) k++;
        !           311:                }
        !           312:                return(0);
        !           313: 
        !           314:        case '?':
        !           315:        caseq:
        !           316:                if(scc) return(amatch(++s, ++p));
        !           317:                return(0);
        !           318:        case '*':
        !           319:                return(umatch(s, ++p));
        !           320:        case 0:
        !           321:                return(!scc);
        !           322:        }
        !           323:        if (c==scc) goto caseq;
        !           324:        return(0);
        !           325: }
        !           326: 
        !           327: static umatch(s, p)
        !           328: char *s, *p;
        !           329: {
        !           330:        if(*p==0) return(1);
        !           331:        while(*s)
        !           332:                if (amatch(s++,p)) return(1);
        !           333:        return(0);
        !           334: }
        !           335: 
        !           336: #ifdef METERFILE
        !           337: #include <pwd.h>
        !           338: int meteron    = 0;    /* default: metering off */
        !           339: 
        !           340: meter(file)
        !           341: char *file;
        !           342: {
        !           343: TIMETYPE tvec;
        !           344: char *p, *ctime();
        !           345: FILE * mout;
        !           346: struct passwd *pwd, *getpwuid();
        !           347: 
        !           348: if(file==0 || meteron==0) return;
        !           349: 
        !           350: pwd = getpwuid(getuid());
        !           351: 
        !           352: time(&tvec);
        !           353: 
        !           354: if( (mout=fopen(file,"a")) != NULL )
        !           355:        {
        !           356:        p = ctime(&tvec);
        !           357:        p[16] = '\0';
        !           358:        fprintf(mout,"User %s, %s\n",pwd->pw_name,p+4);
        !           359:        fclose(mout);
        !           360:        }
        !           361: }
        !           362: #endif
        !           363: 
        !           364: 
        !           365: /* look inside archives for notations a(b) and a((b))
        !           366:        a(b)    is file member   b   in archive a
        !           367:        a((b))  is entry point  _b  in object archive a
        !           368: */
        !           369: 
        !           370: #ifdef ASCARCH
        !           371: #      include <ar.h>
        !           372: #else
        !           373: #      include <ar.h>
        !           374: #endif
        !           375: #include <a.out.h>
        !           376: 
        !           377: static long arflen;
        !           378: static long arfdate;
        !           379: static char arfname[16];
        !           380: FILE *arfd;
        !           381: long int arpos, arlen;
        !           382: 
        !           383: static struct exec objhead;
        !           384: 
        !           385: static struct nlist objentry;
        !           386: 
        !           387: 
        !           388: TIMETYPE lookarch(filename)
        !           389: char *filename;
        !           390: {
        !           391: char *p, *q, *send, s[15];
        !           392: int i, nc, nsym, objarch;
        !           393: 
        !           394: for(p = filename; *p!= '(' ; ++p)
        !           395:        ;
        !           396: *p = '\0';
        !           397: openarch(filename);
        !           398: *p++ = '(';
        !           399: 
        !           400: if(*p == '(')
        !           401:        {
        !           402:        objarch = YES;
        !           403:        nc = 8;
        !           404:        ++p;
        !           405:        }
        !           406: else
        !           407:        {
        !           408:        objarch = NO;
        !           409:        nc = 14;
        !           410:        }
        !           411: send = s + nc;
        !           412: 
        !           413: for( q = s ; q<send && *p!='\0' && *p!=')' ; *q++ = *p++ )
        !           414:        ;
        !           415: while(q < send)
        !           416:        *q++ = '\0';
        !           417: while(getarch())
        !           418:        {
        !           419:        if(objarch)
        !           420:                {
        !           421:                getobj();
        !           422:                nsym = objhead.a_syms / sizeof(objentry);
        !           423:                for(i = 0; i<nsym ; ++i)
        !           424:                        {
        !           425:                        fread( (char *) &objentry, sizeof(objentry),1,arfd);
        !           426:                        if( (objentry.n_type & N_EXT)
        !           427:                           && ((objentry.n_type & ~N_EXT) || objentry.n_value)
        !           428:                           && eqstr(objentry.n_un.n_name,s,nc))
        !           429:                                {
        !           430:                                clarch();
        !           431:                                return(arfdate);
        !           432:                                }
        !           433:                        }
        !           434:                }
        !           435: 
        !           436:        else if( eqstr(arfname, s, nc))
        !           437:                {
        !           438:                clarch();
        !           439:                return(arfdate);
        !           440:                }
        !           441:        }
        !           442: 
        !           443: clarch();
        !           444: return( 0L);
        !           445: }
        !           446: 
        !           447: 
        !           448: clarch()
        !           449: {
        !           450: fclose( arfd );
        !           451: }
        !           452: 
        !           453: 
        !           454: openarch(f)
        !           455: register char *f;
        !           456: {
        !           457: #ifdef ASCARCH
        !           458: char magic[SARMAG];
        !           459: #endif
        !           460: int word;
        !           461: #include <sys/stat.h>
        !           462: struct stat buf;
        !           463: 
        !           464: stat(f, &buf);
        !           465: arlen = buf.st_size;
        !           466: 
        !           467: arfd = fopen(f, "r");
        !           468: if(arfd == NULL)
        !           469:        fatal1("cannot open %s", f);
        !           470: 
        !           471:        fread( (char *) &word, sizeof(word), 1, arfd);
        !           472: #ifdef ASCARCH
        !           473:        fseek(arfd, 0L, 0);
        !           474:        fread(magic, SARMAG, 1, arfd);
        !           475:        arpos = SARMAG;
        !           476:        if( ! eqstr(magic, ARMAG, SARMAG) )
        !           477: #else
        !           478:        arpos = sizeof(word);
        !           479:        if(word != ARMAG)
        !           480: #endif
        !           481:                fatal1("%s is not an archive", f);
        !           482: 
        !           483: arflen = 0;
        !           484: }
        !           485: 
        !           486: 
        !           487: 
        !           488: getarch()
        !           489: {
        !           490:        struct ar_hdr arhead;
        !           491:        long atol();
        !           492: 
        !           493: arpos += (arflen + 1) & ~1L;   /* round archived file length up to even */
        !           494: if(arpos >= arlen)
        !           495:        return(0);
        !           496: fseek(arfd, arpos, 0);
        !           497: 
        !           498:        fread( (char *) &arhead, sizeof(arhead), 1, arfd);
        !           499:        arpos += sizeof(arhead);
        !           500: #ifdef ASCARCH
        !           501:        arflen = atol(arhead.ar_size);
        !           502:        arfdate = atol(arhead.ar_date);
        !           503: #else
        !           504:        arflen = arhead.ar_size;
        !           505:        arfdate = arhead.ar_date;
        !           506: #endif
        !           507:        strncpy(arfname, arhead.ar_name, sizeof(arhead.ar_name));
        !           508: return(1);
        !           509: }
        !           510: 
        !           511: 
        !           512: getobj()
        !           513: {
        !           514: long int skip;
        !           515: 
        !           516: fread( (char *) &objhead, sizeof(objhead), 1, arfd);
        !           517: if (N_BADMAG(objhead))
        !           518:        fatal1("%s is not an object module", arfname);
        !           519: skip = objhead.a_text + objhead.a_data;
        !           520: #ifdef vax
        !           521: skip += objhead.a_trsize + objhead.a_drsize;
        !           522: #else
        !           523: if(! objhead.a_flag )
        !           524:        skip *= 2;
        !           525: #endif
        !           526: fseek(arfd, skip, 1);
        !           527: }
        !           528: 
        !           529: 
        !           530: eqstr(a,b,n)
        !           531: register char *a, *b;
        !           532: int n;
        !           533: {
        !           534: register int i;
        !           535: for(i = 0 ; i < n ; ++i)
        !           536:        if(*a++ != *b++)
        !           537:                return(NO);
        !           538: return(YES);
        !           539: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.