which make it easier for use Manual page was updated. More regression tests for pkg_grep_summary.
122 lines
3.2 KiB
Bash
Executable file
122 lines
3.2 KiB
Bash
Executable file
#!@SH@
|
|
#-*-mode: 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
|
|
|
|
usage (){
|
|
cat 1>&2 <<EOF
|
|
pkg_grep_summary - output summaries about packages that matches
|
|
the specified condition.
|
|
|
|
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 <field> <awk_condition>
|
|
<field> - PKGNAME, PKGPATH, DEPENDS etc.
|
|
<awk_condition> - boolean expression written in AWK language
|
|
<regexp> - AWK regular expression
|
|
<string> - text string
|
|
|
|
OPTIONS:
|
|
-h|--help display this message
|
|
-e|--empty matches empty and absent fields only
|
|
(equivalent to '<field>' 'fvalue == ""')
|
|
-m matches <field> against regular expression <regexp>
|
|
-s matches <field> equal to <string>
|
|
EXAMPLES:
|
|
pkg_grep_summary -s 'PKGPATH' 'devel/libjudy'
|
|
pkg_grep_summary -m 'PKGPATH' '^wip/'
|
|
pkg_grep_summary 'PKGNAME' 'fvalue ~ /judy/' \\
|
|
pkg_grep_summary 'PKGPATH' 'fvalue ~ /^lang\//' \\
|
|
< /usr/pkgsrc/packages/pkg_summary.txt
|
|
pkg_grep_summary 'DEPENDS' 'fvalue ~ /libX/' \\
|
|
pkg_grep_summary 'COMMENT' 'toupper(fvalue) ~ /DNS/' \\
|
|
pkg_grep_summary -e 'NO_BIN_ON_FTP' \\
|
|
< /usr/pkgsrc/pkg_src_summary.txt
|
|
pkg_grep_summary -e 'NO_BIN_ON_CDROM'
|
|
EOF
|
|
}
|
|
|
|
while test $# -ne 0; do
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 0;;
|
|
-e|--empty)
|
|
empty=1
|
|
field=$2
|
|
shift;;
|
|
-s)
|
|
field=$2
|
|
string=$3
|
|
shift
|
|
shift;;
|
|
-m)
|
|
field=$2
|
|
regex=$3
|
|
shift
|
|
shift;;
|
|
--)
|
|
shift
|
|
break;;
|
|
-*)
|
|
echo "Bad option $1" 1>&2
|
|
exit 1;;
|
|
*)
|
|
break
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if test -n "$empty"; then
|
|
condition='fvalue == ""'
|
|
elif test -n "$string"; then
|
|
condition="fvalue == \"$string\""
|
|
elif test -n "$regex"; then
|
|
re=`echo $regex | sed 's|/|\\\/|g'`
|
|
condition="fvalue ~ /$re/"
|
|
elif test $# -eq 2; then
|
|
field="$1"
|
|
condition="$2"
|
|
shift
|
|
shift
|
|
fi
|
|
|
|
if test -z "$condition" -o $# -ne 0; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
runawk -e '
|
|
#use "pkg_grep_summary.awk"
|
|
|
|
BEGIN {
|
|
grep_summary__field="'"$field"'"
|
|
}
|
|
|
|
function grep_summary__condition (){
|
|
return '"$condition"'
|
|
}
|
|
'
|