[BusyBox] -not support in find

Andrew Dixon andrew.dixon at seranoa.com
Thu Dec 27 16:28:09 UTC 2001


Hi All,

The following patch gives find in bb-60.2 support for the "-not" flag. 
This behaves a bit differently than -not on gnu find.  My patch negates
the entire output where gnu find gives you the granularity to negate
only one option.

I also checked out the latest code from CVS.  I noticed that the build
system has changed significantly.  I'll submit a patch for the code in
CVS once I get it figured out (I haven't really had a chance to look at
it yet so if anyone point me in the right direction that'd be helpful.)

later,
Andy

-- 
Andrew Dixon
Software Engineer
Seranoa Networks
978.897.3434 x231
-------------- next part --------------
--- find.c	Mon Nov 19 18:34:17 2001
+++ /home/dixon/find.c	Thu Dec 27 17:49:01 2001
@@ -3,8 +3,8 @@
  * Mini find implementation for busybox
  *
  *
- * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee at debian.org>
+ * Copyright (C) 1999,2000,2001 by Lineo, inc.
+ * Written by Erik Andersen <andersen at lineo.com>, <andersee at debian.org>
  * Reworked by David Douthitt <n9ubh at callsign.net> and
  *  Matt Kraai <kraai at alumni.carnegiemellon.edu>.
  *
@@ -37,6 +37,10 @@
 
 static char *pattern;
 
+#ifdef BB_FEATURE_FIND_NOT
+static int negate = 1;
+#endif /*BB_FEATURE_FIND_NOT*/
+
 #ifdef BB_FEATURE_FIND_TYPE
 static int type_mask = 0;
 #endif
@@ -60,12 +64,20 @@
 			tmp = fileName;
 		else
 			tmp++;
-		if (!(fnmatch(pattern, tmp, FNM_PERIOD) == 0))
+		if (!(fnmatch(pattern, tmp, FNM_PERIOD) == 0)
+#ifdef BB_FEATURE_FIND_NOT
+ == negate
+#endif /*BB_FEATURE_FIND_NOT*/
+)
 			goto no_match;
 	}
 #ifdef BB_FEATURE_FIND_TYPE
 	if (type_mask != 0) {
-		if (!((statbuf->st_mode & S_IFMT) == type_mask))
+		if (!((statbuf->st_mode & S_IFMT) == type_mask)
+#ifdef BB_FEATURE_FIND_NOT
+ == negate
+#endif /*BB_FEATURE_FIND_NOT*/
+)
 			goto no_match;
 	}
 #endif
@@ -73,7 +85,11 @@
 	if (perm_mask != 0) {
 		if (!((isdigit(perm_char) && (statbuf->st_mode & 07777) == perm_mask) ||
 			 (perm_char == '-' && (statbuf->st_mode & perm_mask) == perm_mask) ||
-			 (perm_char == '+' && (statbuf->st_mode & perm_mask) != 0)))
+			 (perm_char == '+' && (statbuf->st_mode & perm_mask) != 0))
+#ifdef BB_FEATURE_FIND_NOT
+ == negate
+#endif /*BB_FEATURE_FIND_NOT*/
+)
 			goto no_match;
 	}
 #endif
@@ -84,7 +100,11 @@
 		if (!((isdigit(mtime_char) && mtime_secs >= file_age &&
 						mtime_secs < file_age + 24 * 60 * 60) ||
 				(mtime_char == '+' && mtime_secs >= file_age) || 
-				(mtime_char == '-' && mtime_secs < file_age)))
+				(mtime_char == '-' && mtime_secs < file_age))
+#ifdef BB_FEATURE_FIND_NOT
+ == negate
+#endif /*BB_FEATURE_FIND_NOT*/
+)
 			goto no_match;
 	}
 #endif
@@ -150,6 +170,13 @@
 			if (++i == argc)
 				error_msg_and_die("option `-name' requires an argument");
 			pattern = argv[i];
+#ifdef BB_FEATURE_FIND_NOT
+                                } else if (strcmp(argv[i], "-not") == 0){
+                                  if (++i == argc)
+                                    error_msg_and_die("option '-not' requires an expression");
+                                  --i;
+                                  negate = 0;
+#endif /*BB_FEATURE_FIND_NOT*/
 #ifdef BB_FEATURE_FIND_TYPE
 		} else if (strcmp(argv[i], "-type") == 0) {
 			if (++i == argc)



More information about the busybox mailing list