=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/dir.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- src/usr.bin/make/dir.c 1996/09/02 16:04:09 1.5 +++ src/usr.bin/make/dir.c 1996/11/30 21:08:53 1.6 @@ -1,5 +1,5 @@ -/* $OpenBSD: dir.c,v 1.5 1996/09/02 16:04:09 briggs Exp $ */ -/* $NetBSD: dir.c,v 1.11 1996/08/13 16:42:02 christos Exp $ */ +/* $OpenBSD: dir.c,v 1.6 1996/11/30 21:08:53 millert Exp $ */ +/* $NetBSD: dir.c,v 1.12 1996/11/06 17:59:04 christos Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -41,9 +41,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)dir.c 5.6 (Berkeley) 12/28/90"; +static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$OpenBSD: dir.c,v 1.5 1996/09/02 16:04:09 briggs Exp $"; +static char rcsid[] = "$OpenBSD: dir.c,v 1.6 1996/11/30 21:08:53 millert Exp $"; #endif #endif /* not lint */ @@ -218,7 +218,7 @@ dirSearchPath = Lst_Init (FALSE); openDirectories = Lst_Init (FALSE); Hash_InitTable(&mtimes, 0); - + /* * Since the Path structure is placed on both openDirectories and * the path we give Dir_AddDir (which in this case is openDirectories), @@ -298,7 +298,7 @@ char *name; /* name to check */ { register char *cp; - + for (cp = name; *cp; cp++) { switch(*cp) { case '{': @@ -334,12 +334,12 @@ Path *p; /* Directory to search */ Lst expansions; /* Place to store the results */ { - Hash_Search search; /* Index into the directory's table */ + Hash_Search search; /* Index into the directory's table */ Hash_Entry *entry; /* Current entry in the table */ Boolean isDot; /* TRUE if the directory being searched is . */ - + isDot = (*p->name == '.' && p->name[1] == '\0'); - + for (entry = Hash_EnumFirst(&p->files, &search); entry != (Hash_Entry *)NULL; entry = Hash_EnumNext(&search)) @@ -558,7 +558,7 @@ if (DEBUG(DIR)) { printf("expanding \"%s\"...", word); } - + cp = strchr(word, '{'); if (cp) { DirExpandCurly(word, cp, path, expansions); @@ -632,7 +632,7 @@ * First the files in dot */ DirMatchFiles(word, dot, expansions); - + /* * Then the files in every other directory on the path. */ @@ -677,7 +677,7 @@ Boolean hasSlash; /* true if 'name' contains a / */ struct stat stb; /* Buffer for stat, if necessary */ Hash_Entry *entry; /* Entry for mtimes table */ - + /* * Find the final component of the name and note whether it has a * slash in it (the name, I mean) @@ -690,7 +690,7 @@ hasSlash = FALSE; cp = name; } - + if (DEBUG(DIR)) { printf("Searching for %s...", name); } @@ -709,7 +709,7 @@ dot->hits += 1; return (estrdup (name)); } - + if (Lst_Open (path) == FAILURE) { if (DEBUG(DIR)) { printf("couldn't open path, file not found\n"); @@ -717,7 +717,7 @@ misses += 1; return ((char *) NULL); } - + /* * We look through all the directories on the path seeking one which * contains the final component of the given name and whose final @@ -782,7 +782,7 @@ } } } - + /* * We didn't find the file on any existing members of the directory. * If the name doesn't contain a slash, that means it doesn't exist. @@ -802,10 +802,10 @@ misses += 1; return ((char *) NULL); } - + if (*name != '/') { Boolean checkedDot = FALSE; - + if (DEBUG(DIR)) { printf("failed. Trying subdirectories..."); } @@ -824,15 +824,15 @@ if (DEBUG(DIR)) { printf("checking %s...", file); } - - + + if (stat (file, &stb) == 0) { if (DEBUG(DIR)) { printf("got it.\n"); } - + Lst_Close (path); - + /* * We've found another directory to search. We know there's * a slash in 'file' because we put one there. We nuke it after @@ -847,7 +847,7 @@ *cp = '\0'; Dir_AddDir (path, file); *cp = '/'; - + /* * Save the modification time so if it's needed, we don't have * to fetch it again. @@ -865,7 +865,7 @@ free (file); } } - + if (DEBUG(DIR)) { printf("failed. "); } @@ -882,7 +882,7 @@ return(NULL); } } - + /* * Didn't find it that way, either. Sigh. Phase 3. Add its directory * onto the search path in any case, just in case, then look for the @@ -904,7 +904,7 @@ cp[-1] = '\0'; Dir_AddDir (path, name); cp[-1] = '/'; - + bigmisses += 1; ln = Lst_Last (path); if (ln == NILLNODE) { @@ -912,7 +912,7 @@ } else { p = (Path *) Lst_Datum (ln); } - + if (Hash_FindEntry (&p->files, cp) != (Hash_Entry *)NULL) { return (estrdup (name)); } else { @@ -922,7 +922,7 @@ if (DEBUG(DIR)) { printf("Looking for \"%s\"...", name); } - + bigmisses += 1; entry = Hash_FindEntry(&mtimes, name); if (entry != (Hash_Entry *)NULL) { @@ -952,7 +952,7 @@ * Dir_MTime -- * Find the modification time of the file described by gn along the * search path dirSearchPath. - * + * * Results: * The modification time or 0 if it doesn't exist * @@ -970,7 +970,7 @@ char *fullName; /* the full pathname of name */ struct stat stb; /* buffer for finding the mod time */ Hash_Entry *entry; - + if (gn->type & OP_ARCHV) { return Arch_MTime (gn); } else if (gn->path == (char *)NULL) { @@ -978,7 +978,7 @@ } else { fullName = gn->path; } - + if (fullName == (char *)NULL) { fullName = estrdup(gn->name); } @@ -1008,7 +1008,7 @@ if (fullName && gn->path == (char *)NULL) { gn->path = fullName; } - + gn->mtime = stb.st_mtime; return (gn->mtime); } @@ -1024,7 +1024,7 @@ * none * * Side Effects: - * A structure is added to the list and the directory is + * A structure is added to the list and the directory is * read and hashed. *----------------------------------------------------------------------- */ @@ -1038,7 +1038,7 @@ register Path *p; /* pointer to new Path structure */ DIR *d; /* for reading directory */ register struct dirent *dp; /* entry in directory */ - + ln = Lst_Find (openDirectories, (ClientData)name, DirFindName); if (ln != NILLNODE) { p = (Path *)Lst_Datum (ln); @@ -1051,20 +1051,20 @@ printf("Caching %s...", name); fflush(stdout); } - + if ((d = opendir (name)) != (DIR *) NULL) { p = (Path *) emalloc (sizeof (Path)); p->name = estrdup (name); p->hits = 0; p->refCount = 1; Hash_InitTable (&p->files, -1); - + /* * Skip the first two entries -- these will *always* be . and .. */ (void)readdir(d); (void)readdir(d); - + while ((dp = readdir (d)) != (struct dirent *) NULL) { #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */ /* @@ -1137,9 +1137,9 @@ char *tstr; /* the current directory preceded by 'flag' */ LstNode ln; /* the node of the current directory */ Path *p; /* the structure describing the current directory */ - + str = estrdup (""); - + if (Lst_Open (path) == SUCCESS) { while ((ln = Lst_Next (path)) != NILLNODE) { p = (Path *) Lst_Datum (ln); @@ -1148,7 +1148,7 @@ } Lst_Close (path); } - + return (str); } @@ -1210,8 +1210,8 @@ Dir_Destroy((ClientData) p); } } - + /*- *----------------------------------------------------------------------- * Dir_Concat -- @@ -1249,7 +1249,7 @@ { LstNode ln; Path *p; - + printf ("#*** Directory Cache:\n"); printf ("# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n", hits, misses, nearmisses, bigmisses, @@ -1268,7 +1268,7 @@ static int DirPrintDir (p, dummy) ClientData p; ClientData dummy; -{ +{ printf ("%s ", ((Path *) p)->name); return (dummy ? 0 : 0); }