Module Name:    src
Committed By:   rillig
Date:           Tue Sep  1 17:56:32 UTC 2020

Modified Files:
        src/usr.bin/make: dir.c dir.h

Log Message:
make(1): make data types in Dir_HasWildcards more precise


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/usr.bin/make/dir.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/dir.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.127 src/usr.bin/make/dir.c:1.128
--- src/usr.bin/make/dir.c:1.127	Sun Aug 30 14:11:42 2020
+++ src/usr.bin/make/dir.c	Tue Sep  1 17:56:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.127 2020/08/30 14:11:42 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.128 2020/09/01 17:56:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.127 2020/08/30 14:11:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.128 2020/09/01 17:56:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.127 2020/08/30 14:11:42 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.128 2020/09/01 17:56:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -517,36 +517,37 @@ DirFindName(const void *p, const void *d
  *	returns TRUE if the word should be expanded, FALSE otherwise
  */
 Boolean
-Dir_HasWildcards(char *name)
+Dir_HasWildcards(const char *name)
 {
-    char *cp;
-    int wild = 0, brace = 0, bracket = 0;
+    const char *cp;
+    Boolean wild = FALSE;
+    int braces = 0, brackets = 0;
 
     for (cp = name; *cp; cp++) {
 	switch (*cp) {
 	case '{':
-	    brace++;
-	    wild = 1;
+	    braces++;
+	    wild = TRUE;
 	    break;
 	case '}':
-	    brace--;
+	    braces--;
 	    break;
 	case '[':
-	    bracket++;
-	    wild = 1;
+	    brackets++;
+	    wild = TRUE;
 	    break;
 	case ']':
-	    bracket--;
+	    brackets--;
 	    break;
 	case '?':
 	case '*':
-	    wild = 1;
+	    wild = TRUE;
 	    break;
 	default:
 	    break;
 	}
     }
-    return wild && bracket == 0 && brace == 0;
+    return wild && brackets == 0 && braces == 0;
 }
 
 /*-

Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.20 src/usr.bin/make/dir.h:1.21
--- src/usr.bin/make/dir.h:1.20	Sat Aug 22 21:42:38 2020
+++ src/usr.bin/make/dir.h	Tue Sep  1 17:56:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.20 2020/08/22 21:42:38 rillig Exp $	*/
+/*	$NetBSD: dir.h,v 1.21 2020/09/01 17:56:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,12 +75,14 @@
 #ifndef	MAKE_DIR_H
 #define	MAKE_DIR_H
 
-typedef struct Path {
+/* A cache of a directory, remembering all the files that exist in that
+ * directory. */
+typedef struct {
     char         *name;	    	/* Name of directory */
     int	    	  refCount; 	/* Number of paths with this directory */
     int		  hits;	    	/* the number of times a file in this
 				 * directory has been found */
-    Hash_Table    files;    	/* Hash table of files in directory */
+    Hash_Table    files;    	/* Hash set of files in directory */
 } Path;
 
 void Dir_Init(void);
@@ -89,7 +91,7 @@ void Dir_InitCur(const char *);
 void Dir_InitDot(void);
 void Dir_End(void);
 void Dir_SetPATH(void);
-Boolean Dir_HasWildcards(char *);
+Boolean Dir_HasWildcards(const char *);
 void Dir_Expand(const char *, Lst, Lst);
 char *Dir_FindFile(const char *, Lst);
 int Dir_FindHereOrAbove(char *, char *, char *, int);
@@ -101,6 +103,6 @@ void Dir_Concat(Lst, Lst);
 void Dir_PrintDirectories(void);
 void Dir_PrintPath(Lst);
 void Dir_Destroy(void *);
-void * Dir_CopyDir(void *);
+void *Dir_CopyDir(void *);
 
 #endif /* MAKE_DIR_H */

Reply via email to