pkgsrc-wip/pkg_summary-utils/files/pkg_grep_summary.in

103 lines
2.7 KiB
Text
Raw Normal View History

#!@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:50:13 +02:00
pkg_grep_summary - output summaries about packages that matches
the specified condition.
2008-05-07 13:03:33 +02:00
USAGE: pkg_grep_summary -h
pkg_grep_summary <FIELD> <AWK_CONDITION>
pkg_grep_summary -e <FIELD>
2008-05-07 20:50:13 +02:00
<FIELD> - PKGNAME, PKGPATH, DEPENDS etc.
<AWK_CONDITION> - boolean expression written in AWK language
OPTIONS:
-h|--help display this message
-e|--empty <field> matches empty and absent fields only
(equivalent to '<field>' 'fvalue == ""')
EXAMPLES:
pkg_grep_summary 'PKGNAME' 'fvalue ~ /judy/' \\
2008-05-07 20:42:06 +02:00
< /usr/pkgsrc/packages/pkg_summary.txt
pkg_grep_summary 'PKGPATH' 'fvalue ~ /^lang\//' \\
2008-05-07 20:42:06 +02:00
< /usr/pkgsrc/packages/pkg_summary.txt
pkg_grep_summary 'DEPENDS' 'fvalue ~ /libX/' \\
2008-05-07 20:42:06 +02:00
< /usr/pkgsrc/pkg_src_summary.txt
pkg_grep_summary 'COMMENT' 'toupper(fvalue) ~ /DNS/' \\
< /usr/pkgsrc/pkg_src_summary.txt
pkg_grep_summary -e 'NO_BIN_ON_FTP' \\
< /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;;
-e|--empty)
empty_field=$2
shift;;
2008-05-07 13:03:33 +02:00
--)
shift
break;;
-*)
echo "Bad option $1" 1>&2
exit 1;;
*)
break
esac
shift
done
if test -z "$empty_field" -a $# -ne 2 ||
test -n "$empty_field" -a $# -ne 0
then
usage
exit 1
fi
if test -z "$empty_field"; then
field=$1
condition="$2"
shift
shift
else
field="$empty_field"
condition='fvalue == ""'
fi
runawk -e '
#use "pkg_grep_summary.awk"
BEGIN {
grep_summary__field="'"$field"'"
}
function grep_summary__condition (){
return '"$condition"'
}
'