2008-05-07 01:03:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Copyright (c) 2007-2008 Aleksey Cheusov <vle@gmx.net>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
set -e
|
2008-05-07 13:03:33 +02:00
|
|
|
|
|
|
|
usage (){
|
|
|
|
cat 1>&2 <<EOF
|
2008-05-07 20:42:06 +02:00
|
|
|
pkg_grep_summary - grep pkg_summary(5) input (stdin) using AWK
|
|
|
|
condition, entire summaries of found packages are output, that is
|
|
|
|
pkg_grep_summary is not per-line but per-package search tool.
|
2008-05-07 13:03:33 +02:00
|
|
|
|
|
|
|
usage: pkg_grep_summary <FIELD> <AWK_CONDITION>
|
|
|
|
|
|
|
|
examples:
|
|
|
|
pkg_grep_summary 'PKGNAME' '$2 ~ /judy/' \
|
2008-05-07 20:42:06 +02:00
|
|
|
< /usr/pkgsrc/packages/pkg_summary.txt
|
2008-05-07 13:03:33 +02:00
|
|
|
pkg_grep_summary 'PKGPATH' '$2 ~ /^lang\//' \
|
2008-05-07 20:42:06 +02:00
|
|
|
< /usr/pkgsrc/packages/pkg_summary.txt
|
2008-05-07 13:03:33 +02:00
|
|
|
pkg_grep_summary 'DEPENDS' '$2 ~ /libX/' \
|
2008-05-07 20:42:06 +02:00
|
|
|
< /usr/pkgsrc/pkg_src_summary.txt
|
2008-05-07 13:03:33 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while test $# -ne 0; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break;;
|
|
|
|
-*)
|
|
|
|
echo "Bad option $1" 1>&2
|
|
|
|
exit 1;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
test $# -eq 2
|
2008-05-07 01:03:26 +02:00
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
field=$1
|
|
|
|
true_condition="$2"
|
|
|
|
shift
|
2008-05-07 01:03:26 +02:00
|
|
|
shift
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
awk -v field="$field" '
|
2008-05-07 01:03:26 +02:00
|
|
|
BEGIN {
|
|
|
|
FS = "="
|
|
|
|
skip = -1 # -1 - unknown, 0 - false, 1 - true
|
2008-05-07 12:25:18 +02:00
|
|
|
count = 0
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_skip (){
|
2008-05-07 12:25:18 +02:00
|
|
|
skip = !('"$true_condition"')
|
2008-05-07 01:03:26 +02:00
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
if (skip == 0){
|
|
|
|
for (i=0; i < count; ++i){
|
|
|
|
print accu [i]
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
delete accu
|
|
|
|
count = 0
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
skip == 1 && NF > 0 {
|
|
|
|
next
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
$1 == field {
|
2008-05-07 01:03:26 +02:00
|
|
|
update_skip()
|
|
|
|
}
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
skip == 0 && NF > 0 {
|
2008-05-07 01:03:26 +02:00
|
|
|
print $0
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
skip == -1 && NF > 0 {
|
|
|
|
accu [count++] = $0
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NF == 0 {
|
|
|
|
if (skip == 0){
|
|
|
|
print ""
|
|
|
|
}
|
|
|
|
|
2008-05-07 12:25:18 +02:00
|
|
|
delete accu
|
|
|
|
count = 0
|
2008-05-07 01:03:26 +02:00
|
|
|
skip = -1
|
|
|
|
}
|
|
|
|
'
|