pkg_grep_summary: new option -t
This commit is contained in:
parent
03d2c192af
commit
35c1d318e6
5 changed files with 224 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: pkg_grep_summary.1,v 1.11 2010/03/27 21:45:33 cheusov Exp $
|
||||
.\" $NetBSD: pkg_grep_summary.1,v 1.12 2010/05/29 15:20:56 cheusov Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2008 by Aleksey Cheusov (vle@gmx.net)
|
||||
.\" Absolutely no warranty.
|
||||
|
@ -53,7 +53,7 @@ etc. but it is different. Unlike
|
|||
uses a summary for one package instead of line of text as a basic element.
|
||||
Unlike
|
||||
.B pkgfind
|
||||
it doesn't scan pkgsrc source and therefore works drammatically faster.
|
||||
it doesn't scan pkgsrc source tree and therefore works drammatically faster.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B "-h|--help"
|
||||
|
|
|
@ -1,11 +1,51 @@
|
|||
|
||||
#use "has_prefix.awk"
|
||||
#use "has_suffix.awk"
|
||||
#use "psu_funcs.awk"
|
||||
|
||||
#env "LC_ALL=C"
|
||||
|
||||
BEGIN {
|
||||
grep_summary__skip = -1 # -1 - unknown, 0 - false, 1 - true
|
||||
count = 0
|
||||
}
|
||||
|
||||
function match_first_word (s, word){
|
||||
if (s == word)
|
||||
return 1
|
||||
else if (!has_prefix(s, word))
|
||||
return 0
|
||||
else{
|
||||
return substr(s, length(word)+1, 1) ~ /^[^A-Za-z0-9]$/
|
||||
}
|
||||
}
|
||||
|
||||
function match_last_word (s, word){
|
||||
if (s == word)
|
||||
return 1
|
||||
else if (!has_suffix(s, word))
|
||||
return 0
|
||||
else
|
||||
return substr(s, length(s)-length(word), 1) ~ /^[^A-Za-z0-9]$/
|
||||
}
|
||||
|
||||
function match_word (s, word, idx){
|
||||
if (s == word)
|
||||
return 1
|
||||
|
||||
idx=index(s, word)
|
||||
if (!idx)
|
||||
return 0
|
||||
|
||||
if (idx > 1 && substr(s, idx-1, 1) ~ /[A-Za-z0-9]$/)
|
||||
return 0
|
||||
|
||||
idx += length(word)
|
||||
if (idx <= length(s) && substr(s, idx, 1) ~ /[A-Za-z0-9]$/)
|
||||
return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
function update_skip (){
|
||||
grep_summary__skip = grep_summary__condition()
|
||||
if (grep_summary__skip == 0 || grep_summary__skip == 1){
|
||||
|
|
|
@ -24,22 +24,28 @@
|
|||
|
||||
set -e
|
||||
|
||||
export LC_ALL=C
|
||||
|
||||
usage (){
|
||||
cat 1>&2 <<EOF
|
||||
pkg_grep_summary - output summaries about packages that matches
|
||||
the specified condition.
|
||||
the specified condition, summaries are read from stdin.
|
||||
|
||||
USAGE: pkg_grep_summary -h
|
||||
pkg_grep_summary -e <field>
|
||||
pkg_grep_summary -m <field> <regexp>
|
||||
pkg_grep_summary -s <field> <string>
|
||||
pkg_grep_summary -S <field> <file>
|
||||
pkg_grep_summary -t <strategy> <field> <string>
|
||||
pkg_grep_summary <field> <awk_condition>
|
||||
<field> - PKGBASE, PKGNAME, PKGPATH, DEPENDS etc.
|
||||
<awk_condition> - boolean expression written in AWK language
|
||||
<awk_condition> - Boolean expression written in AWK language
|
||||
<regexp> - AWK regular expression
|
||||
<string> - text string
|
||||
|
||||
<string> - Text string
|
||||
<strategy> - Search strategy. The following strategies are supported:
|
||||
exact, prefix, suffix, substring, word (separate words within
|
||||
fields are matched), re (extended regular expresion), first (only
|
||||
first word is matched), last (only last word is matched)
|
||||
OPTIONS:
|
||||
-h|--help display this message
|
||||
-e|--empty matches empty and absent fields only
|
||||
|
@ -75,6 +81,13 @@ while test $# -ne 0; do
|
|||
regex=$3
|
||||
shift
|
||||
shift;;
|
||||
-t)
|
||||
strategy=$2
|
||||
field=$3
|
||||
string=$4
|
||||
shift
|
||||
shift
|
||||
shift;;
|
||||
--)
|
||||
shift
|
||||
break;;
|
||||
|
@ -87,7 +100,27 @@ while test $# -ne 0; do
|
|||
shift
|
||||
done
|
||||
|
||||
if test -n "$empty"; then
|
||||
if test -n "$strategy"; then
|
||||
case "$strategy" in
|
||||
exact)
|
||||
condition="fvalue == \"$string\"";;
|
||||
prefix)
|
||||
condition="has_prefix(fvalue, \"$string\")";;
|
||||
suffix)
|
||||
condition="has_suffix(fvalue, \"$string\")";;
|
||||
substring)
|
||||
condition="index(fvalue, \"$string\")";;
|
||||
first)
|
||||
condition="match_first_word(fvalue, \"$string\")";;
|
||||
last)
|
||||
condition="match_last_word(fvalue, \"$string\")";;
|
||||
word)
|
||||
condition="match_word(fvalue, \"$string\")";;
|
||||
*)
|
||||
echo "Unknown search strategy: $strategy" 1>&2
|
||||
exit 1;;
|
||||
esac
|
||||
elif test -n "$empty"; then
|
||||
condition='fvalue == ""'
|
||||
elif test -n "$string"; then
|
||||
condition="fvalue == \"$string\""
|
||||
|
@ -117,6 +150,7 @@ BEGIN {
|
|||
while(xgetline0(strings_fn)){
|
||||
strings [$0] = 1
|
||||
}
|
||||
close(strings_fn)
|
||||
}
|
||||
grep_summary__field="'"$field"'"
|
||||
}
|
||||
|
|
|
@ -313,6 +313,102 @@ COMMENT=Library for manipulating PNG images
|
|||
MAINTAINER=wiz@NetBSD.org
|
||||
CATEGORIES=graphics
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'substring' 'PKGNAME' 'dict'
|
||||
PKGPATH=textproc/dictem
|
||||
PKGNAME=dictem-0.82
|
||||
|
||||
PKGNAME=dict-server-1.10.11nb2
|
||||
PKGPATH=wip/dict-server
|
||||
|
||||
PKGNAME=dict-client-1.9.15nb2
|
||||
PKGPATH=textproc/dict-client
|
||||
|
||||
PKGNAME=dict-client-1.10.11nb2
|
||||
PKGPATH=wip/dict-client
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'substring' 'PKGNAME' 'distcc'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'first' 'PKGNAME' 'dict'
|
||||
PKGNAME=dict-server-1.10.11nb2
|
||||
PKGPATH=wip/dict-server
|
||||
|
||||
PKGNAME=dict-client-1.9.15nb2
|
||||
PKGPATH=textproc/dict-client
|
||||
|
||||
PKGNAME=dict-client-1.10.11nb2
|
||||
PKGPATH=wip/dict-client
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'first' 'PKGNAME' 'dic'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'last' 'PKGBASE' 'client'
|
||||
PKGNAME=dict-client-1.9.15nb2
|
||||
PKGPATH=textproc/dict-client
|
||||
|
||||
PKGNAME=pkg_online-client-0.5.0
|
||||
PKGPATH=wip/pkg_online-client
|
||||
|
||||
PKGNAME=dict-client-1.10.11nb2
|
||||
PKGPATH=wip/dict-client
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'last' 'PKGBASE' 'lient'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'exact' 'PKGBASE' 'dictem'
|
||||
PKGPATH=textproc/dictem
|
||||
PKGNAME=dictem-0.82
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'exact' 'PKGBASE' 'dict'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'prefix' 'PKGBASE' 'awk'
|
||||
PKGNAME=awk-pkgsrc-dewey-0.5.6
|
||||
PKGPATH=wip/awk-pkgsrc-dewey
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'prefix' 'PKGBASE' 'ruby'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'suffix' 'PKGBASE' 'ldap'
|
||||
PKGNAME=ap22-vhost-ldap-1.2.0nb1
|
||||
PKGPATH=www/ap22-vhost-ldap
|
||||
|
||||
PKGNAME=ap2-vhost-ldap-1.2.0nb1
|
||||
PKGPATH=www/ap2-vhost-ldap:PKG_APACHE=apache2
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'suffix' 'PKGBASE' 'nis'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'word' 'PKGBASE' 'dict'
|
||||
PKGNAME=dict-server-1.10.11nb2
|
||||
PKGPATH=wip/dict-server
|
||||
|
||||
PKGNAME=dict-client-1.9.15nb2
|
||||
PKGPATH=textproc/dict-client
|
||||
|
||||
PKGNAME=dict-client-1.10.11nb2
|
||||
PKGPATH=wip/dict-client
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'word' 'PKGBASE' 'dic'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'word' 'PKGBASE' 'ldap'
|
||||
PKGNAME=ap22-vhost-ldap-1.2.0nb1
|
||||
PKGPATH=www/ap22-vhost-ldap
|
||||
|
||||
PKGNAME=ap2-vhost-ldap-1.2.0nb1
|
||||
PKGPATH=www/ap2-vhost-ldap:PKG_APACHE=apache2
|
||||
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'word' 'PKGBASE' 'dap'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'word' 'PKGBASE' 'nis'
|
||||
--------------------------------------------------
|
||||
------- args: 'pkg_grep_summary' '-t' 'word' 'PKGBASE' 'dictem'
|
||||
PKGPATH=textproc/dictem
|
||||
PKGNAME=dictem-0.82
|
||||
|
||||
--------------------------------------------------
|
||||
------- pkg_cmp_summary #1.1
|
||||
- ap2-vhost-ldap 1.2.0nb1
|
||||
|
|
|
@ -73,6 +73,52 @@ runtest pkg_grep_summary -S PKGPATH pkgs.txt < src_summary.txt
|
|||
runtest pkg_grep_summary -S PKGPATHe pkgs.txt < src_summary.txt
|
||||
|
||||
|
||||
grep_PKGNAME_n_PKGBASE_only (){
|
||||
grep -E '^(PKGNAME|PKGPATH)=|^$|^-' "$@"
|
||||
}
|
||||
|
||||
runtest pkg_grep_summary -t substring PKGNAME dict < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t substring PKGNAME distcc < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
runtest pkg_grep_summary -t first PKGNAME dict < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t first PKGNAME dic < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
runtest pkg_grep_summary -t last PKGBASE client < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t last PKGBASE lient < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
runtest pkg_grep_summary -t exact PKGBASE dictem < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t exact PKGBASE dict < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
runtest pkg_grep_summary -t prefix PKGBASE awk < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t prefix PKGBASE ruby < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
runtest pkg_grep_summary -t suffix PKGBASE ldap < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t suffix PKGBASE nis < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
runtest pkg_grep_summary -t word PKGBASE dict < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t word PKGBASE dic < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t word PKGBASE ldap < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t word PKGBASE dap < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t word PKGBASE nis < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
runtest pkg_grep_summary -t word PKGBASE dictem < src_summary.txt |
|
||||
grep_PKGNAME_n_PKGBASE_only
|
||||
|
||||
# pkg_cmp_summary
|
||||
echo '--------------------------------------------------'
|
||||
|
|
Loading…
Reference in a new issue