ports/40699: [patch] allow exclude patterns in `make search`

Roman Neuhauser neuhauser at chello.cz
Wed Apr 21 19:39:34 PDT 2004


This patch gives me all the functionality I've been missing in the search
target in Mk/bsd.port.subdir.mk. Any and all feedback is welcome.

The code is completely undocumented, but putting (a shorter version of)
this text in Mk/bsd.port.subdir.mk could mitigate that.

Besides the good old key and name variables, this patch adds support for
path, info, maint, cat, bdeps, and rdeps, which match on the appropriate
fields, plus their exclusion counterparts: xkey, xname, etc.

Examples:

 Find all ports whose names contain "pear-" but not "html" or "http":

    make search name=pear- xname='ht(tp|ml)'
    
 Find ports whose names contain "pear-" and which don't have apache
 listed in build-time dependencies:

    make search name=pear- xbdeps=apache

The positive variables (name, key, maint, etc) are AND-ed, their
negative versions are OR-ed; in other words, matching any x- variable
will cause the port to be skipped, mismatch on any non-x- variable
will cause it to be skipped.

Examples:

 Find ports that are both in the www category and maintained by
 Thierry Thomas:

    make search maint=thierry@ path=/www/

 Find ports in the archivers category that are either not orphaned or
 don't have "zip" in their names (contrived):

    make search cat=archivers xmaint=ports at freebsd xname=zip

It is possible to select fields to display.

Example:

 Find PEAR ports that don't build-depend on apache, displaying only
 Port:, Path:, and Info: lines:

    make search name=pear- xbdeps=apache display=name,path,info

Case-sensitivity can now be turned of with icase=1.

Example:

 Find ports with @freebsd.org maintainer addresses without the "proper"
 capitalization (@FreeBSD.org), display their paths and maintainer
 addresses:

    make search maint=@freebsd\\.org icase=0 display=maint,path

The key and xkey variables can be limited in scope to displayed fields
by setting keylim to 1.

Example:

 Find ports that contain "apache" in either of the name, path, info
 fields, ignore the rest of the record (dependencies, maintainer
 address, etc):

    make search key=apache display=name,path,info keylim=1

-- 
If you cc me or remove the list(s) completely I'll most likely ignore
your message.    see http://www.eyrie.org./~eagle/faqs/questions.html
-------------- next part --------------
Index: Mk/bsd.port.subdir.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.subdir.mk,v
retrieving revision 1.53
diff -u -u -r1.53 bsd.port.subdir.mk
--- Mk/bsd.port.subdir.mk	2 Apr 2004 07:25:23 -0000	1.53
+++ Mk/bsd.port.subdir.mk	22 Apr 2004 02:17:18 -0000
@@ -315,19 +315,86 @@
 	PKGINSTALLVER="${PKGINSTALLVER:S/"/"'"'"/g:S/\$/\$\$/g:S/\\/\\\\/g}"
 .endif
 
-
+PORTSEARCH_DISPLAY_FIELDS?=name,path,info,maint,index,bdeps,rdeps
 
 search: ${PORTSDIR}/${INDEXFILE}
 	@here=`pwd`; \
 	cd ${PORTSDIR}; \
-	top=`pwd -P`; \
-	there=`echo "$$here/" | sed s%$$top%${PORTSDIR}%`; \
-	if [ -n "$$key" ]; then \
-	  grep $$there ${PORTSDIR}/${INDEXFILE} | grep -i "${key}" | awk -F\| '{ printf("Port:\t%s\nPath:\t%s\nInfo:\t%s\nMaint:\t%s\nIndex:\t%s\nB-deps:\t%s\nR-deps:\t%s\n\n", $$1, $$2, $$4, $$6, $$7, $$8, $$9); }'; \
-	elif [ $$name ]; then \
-	  grep $$there ${PORTSDIR}/${INDEXFILE} | grep -i "^[^|]*${name}[^|]*|" | awk -F\| '{ printf("Port:\t%s\nPath:\t%s\nInfo:\t%s\nMaint:\t%s\nIndex:\t%s\nB-deps:\t%s\nR-deps:\t%s\n\n", $$1, $$2, $$4, $$6, $$7, $$8, $$9); }'; \
-	else \
+	if [ -z "$$key"   -a -z "$$xkey"   -a \
+	     -z "$$name"  -a -z "$$xname"  -a \
+	     -z "$$path"  -a -z "$$xpath"  -a \
+	     -z "$$info"  -a -z "$$xinfo"  -a \
+	     -z "$$maint" -a -z "$$xmaint" -a \
+	     -z "$$bdeps" -a -z "$$xbdeps" -a \
+	     -z "$$rdeps" -a -z "$$xrdeps" ]; \
+	then \
 	  echo "The search target requires a keyword parameter or name parameter,"; \
 	  echo "e.g.: \"make search key=somekeyword\""; \
 	  echo "or    \"make search name=somekeyword\""; \
-	fi;
+	  exit; \
+	fi; \
+	awk -F\| -v there="$$here/" -v top="$$(pwd -P)" \
+	    -v icase="$${icase:-1}" -v keylim="$${keylim:-0}" \
+	    -v key="$$key"          -v xkey="$$xkey" \
+	    -v name="$$name"        -v xname="$$xname" \
+	    -v path="$$path"        -v xpath="$$xpath" \
+	    -v info="$$info"        -v xinfo="$$xinfo" \
+	    -v maint="$$maint"      -v xmaint="$$xmaint" \
+	    -v cat="$$cat"          -v xcat="$$xcat" \
+	    -v bdeps="$$bdeps"      -v xbdeps="$$xbdeps" \
+	    -v rdeps="$$rdeps"      -v xrdeps="$$xrdeps" \
+	    -v display="$${display:-${PORTSEARCH_DISPLAY_FIELDS}}" \
+	'BEGIN { \
+	    sub(top, "${PORTSDIR}", there); \
+	    IGNORECASE=icase; \
+	    keylen = length(key); keylim = keylim && keylen; \
+	    if (!keylim && keylen) \
+	      parms[0] = key; \
+	    xkeylen = length(xkey); xkeylim = xkeylim && xkeylen; \
+	    if (!xkeylim && xkeylen) \
+	      xparms[0] = xkey; \
+	    if (length(name))  parms[1] = name;  if (length(xname))  xparms[1] = xname; \
+	    if (length(path))  parms[2] = path;  if (length(xpath))  xparms[2] = xpath; \
+	    if (length(info))  parms[4] = info;  if (length(xinfo))  xparms[4] = xinfo; \
+	    if (length(maint)) parms[6] = maint; if (length(xmaint)) xparms[6] = xmaint; \
+	    if (length(cat))   parms[7] = cat;   if (length(xcat))   xparms[7] = xcat; \
+	    if (length(bdeps)) parms[8] = bdeps; if (length(xbdeps)) xparms[8] = xbdeps; \
+	    if (length(rdeps)) parms[9] = rdeps; if (length(xrdeps)) xparms[9] = xrdeps; \
+	    fields["name"]  = 1; names[1] = "Port"; \
+	    fields["path"]  = 2; names[2] = "Path"; \
+	    fields["info"]  = 4; names[4] = "Info"; \
+	    fields["maint"] = 6; names[6] = "Maint"; \
+	    fields["cat"]   = 7; names[7] = "Index"; \
+	    fields["bdeps"] = 8; names[8] = "B-deps"; \
+	    fields["rdeps"] = 9; names[9] = "R-deps"; \
+	    split(display, d, /,[ \t]*/); \
+	    for (i in d) { \
+	      fldname = d[i]; \
+	      fldpos  = fields[fldname]; \
+	      disp[fldpos] = fldname; \
+	    } \
+	  } \
+	  { \
+	    if ($$2 !~ there) \
+	      next; \
+	    for (i in parms) \
+	      if ($$i !~ parms[i]) \
+	        next; \
+	    for (i in xparms) \
+	      if ($$i ~ xparms[i]) \
+	        next; \
+	    found = 0; \
+	    for (i = 1; i < 10; i++) \
+	      if (i in disp) { \
+	        if (xkeylim && $$i ~ xkey) \
+	          next; \
+	        if (!found && keylim && $$i ~ key) \
+	          found = 1; \
+	      } \
+	    if (keylim && !found) \
+	      next; \
+	    for (i = 1; i < 10; i++) \
+	      if (i in disp) \
+	        printf("%s:\t%s\n", names[i], $$i); \
+	    print(""); \
+	  }' ${PORTSDIR}/${INDEXFILE}


More information about the freebsd-ports mailing list