[22048] trunk/base/src/pextlib1.0/find.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Feb 15 15:50:04 PST 2007


Revision: 22048
          http://trac.macosforge.org/projects/macports/changeset/22048
Author:   jkh at macports.org
Date:     2007-02-15 15:50:04 -0800 (Thu, 15 Feb 2007)

Log Message:
-----------
Make find always take a boolean expr as its match expression.

Also, for now, simply hide the filename variable as _filename.  This is not
as flexible as allowing the user to specify it with -var varname or something
but it's an easier iteration on the code for now which should also avoid at
least 99.9% of the possible conflict cases.

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/find.c

Modified: trunk/base/src/pextlib1.0/find.c
===================================================================
--- trunk/base/src/pextlib1.0/find.c	2007-02-15 23:22:28 UTC (rev 22047)
+++ trunk/base/src/pextlib1.0/find.c	2007-02-15 23:50:04 UTC (rev 22048)
@@ -66,8 +66,8 @@
 {
 	char *startdir;
 	char *match, *action;
-	char *def_match = "expr 1";
-	char *def_action = "puts \"$filename\"";
+	char *def_match = "1";
+	char *def_action = "puts \"$_filename\"";
 	int depth = 0;
 
 	/* Adjust arguments */
@@ -107,8 +107,7 @@
 {
 	DIR *dirp;
 	struct dirent *dp;
-	Tcl_Obj *result;
-	int val, rval, mlen, alen;
+	int rval, alen;
 	struct stat sb;
 	
 	if ((dirp = opendir(dir)) == NULL)
@@ -116,11 +115,11 @@
 	/* be optimistic */
 	rval = TCL_OK;
 
-	mlen = strlen(match);
 	alen = strlen(action);
 
 	while ((dp = readdir(dirp)) != NULL) {
 		char tmp_path[PATH_MAX];
+		int res;
 
 		if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
 			continue;
@@ -136,21 +135,17 @@
 			if (do_find(interp, depth, tmp_path, match, action) != TCL_OK)
 				return TCL_ERROR;
 		}
-		Tcl_SetVar(interp, "filename", tmp_path, TCL_GLOBAL_ONLY);
-		if (Tcl_EvalEx(interp, match, mlen, TCL_EVAL_GLOBAL) == TCL_OK) {
-			result = Tcl_GetObjResult(interp);
-			if (Tcl_GetIntFromObj(interp, result, &val) != TCL_OK) {
-				rval = TCL_ERROR;
-				break;
-			}
-			if (!val)
-				continue;
-			else {	/* match */
+		Tcl_SetVar(interp, "_filename", tmp_path, TCL_GLOBAL_ONLY);
+		if (Tcl_ExprBoolean(interp, match, &res) == TCL_OK) {
+			if (res == 1) {
+				/* match */
 				if (Tcl_EvalEx(interp, action, alen, TCL_EVAL_GLOBAL) != TCL_OK) {
 					rval = TCL_ERROR;
 					break;
 				}
 			}
+			else
+				continue;
 		}
 		else {
 			rval = TCL_ERROR;
@@ -165,4 +160,3 @@
 	(void)closedir(dirp);
 	return rval;
 }
-

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070215/181252aa/attachment.html


More information about the macports-changes mailing list