pkgsrc-wip/pkg_summary-utils/files/pkg_cmp_summary.in
Aleksey Cheusov c0dc2bbba0 RUNAWK scripts use latest power_getopt.awk module.
This make arguments handling code cleaner, easier and shorter.
DEPENDS on latest runawk.
2009-05-10 13:44:00 +00:00

196 lines
4.3 KiB
Text
Executable file

#!/usr/bin/env runawk
# 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.
############################################################
#env "LC_ALL=C"
#use "pkgsrc-dewey.awk"
#use "power_getopt.awk"
############################################################
#.begin-str help
# pkg_cmp_summary - compares two summary files
# usage: pkg_cmp_summary -h
# pkg_cmp_summary [OPTIONS] summary1 summary2
# OPTIONS:
# -h|--help display this help
# -p|--with-pkgpath use PKGPATH:PKGBASE pair for identifing a package
# -c|--use-checksum also use CVS_CHECKSUM field in comparing packages
# -m|--multi support multi-variant packages, that is packages
# with building options in PKGPATH section
# -P|--pkgpath use PKGPATH only for comparison, ignore PKGNAME
#.end-str
############################################################
BEGIN {
with_pkgname = 1
with_pkgpath = getarg("p")
use_checksum = getarg("c")
if (getarg("P")){
with_pkgpath = 1
with_pkgname = 0
}
if (getarg("m")){
with_multivar = 1
with_pkgpath = 1
}
for (ind=1; ind < ARGC && ARGV [ind] == ""; ++ind);
if (ARGC != ind+2){
usage()
exit 1
}
file1 = ARGV [ind]
}
function trim (s){
sub(/^[ \t]+/, "", s)
sub(/[ \t]+$/, "", s)
return s
}
with_pkgname && $0 ~ /^PKGNAME=/ {
pkgname = trim(substr($0, 9))
next
}
use_checksum && $0 ~ /^CVS_CHECKSUM=/ {
checksum = trim(substr($0, 14))
next
}
with_pkgpath && $0 ~ /^PKGPATH=/ {
pkgpath = trim(substr($0, 9))
full_pkgpath = pkgpath
if (with_multivar && pkgpath ~ /:/){
sub(/:.*$/, "", pkgpath)
}
next
}
NF == 0 {
# ver
ver = pkgname
sub(/^.*-/, "", ver)
# pkgbase
sub(/-[^-]+$/, "", pkgname)
# option PKGPATH
if (with_pkgpath && with_pkgname){
pkgbase = pkgpath " " pkgname
full_pkgbase = full_pkgpath " " pkgname
}else if (with_pkgpath){
pkgbase = pkgpath
full_pkgbase = full_pkgpath
}else{
pkgbase = pkgname
full_pkgbase = pkgname
}
# current checksum
curr_checksum = checksum
# cleaning...
pkgname = pkgpath = checksum = ""
#
if (FILENAME == file1){
# first file!
if (pkgbase in names){
duplicates [pkgbase] += 1
}else{
names [pkgbase] = ver
if (with_multivar && pkgpath != full_pkgpath){
full_pkgpaths [pkgbase] = full_pkgbase
}
if (use_checksum){
checksums [pkgbase] = curr_checksum
}
}
}else{
# second file!
present [pkgbase] = 0
if (pkgbase in duplicates){
next
}
if (! (pkgbase in names)){
if (ver != "")
print "+", full_pkgbase, ver
else
print "+", full_pkgbase
next
}
if (with_pkgname){
ver1 = names [pkgbase]
res = dewey_cmp(ver1, ver)
if (use_checksum && res == "="){
prev_checksum = checksums [pkgbase]
if (prev_checksum != "" &&
curr_checksum != "" &&
prev_checksum != curr_checksum)
{
res = "!"
}
}
print res, full_pkgbase, ver1, ver
}else{
print "=", full_pkgbase
}
}
next
}
END {
for (pkgbase in names){
if (! (pkgbase in present)){
if (names [pkgbase] != ""){
nm = " " names [pkgbase]
}else{
nm = ""
}
if (pkgbase in full_pkgpaths)
print "-", full_pkgpaths [pkgbase] nm
else
print "-", pkgbase nm
delete duplicates [pkgbase]
}else if (pkgbase in duplicates){
print duplicates [pkgbase]+1, pkgbase
}
}
}