pkgsrc-wip/pkg_summary-utils/files/pkg_cmp_summary

164 lines
3.4 KiB
Text
Raw Normal View History

#!/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.
############################################################
#use "pkgsrc-dewey.awk"
############################################################
function usage (){
printf "\
pkg_cmp_summary - compares two summary files\n\
usage: pkg_cmp_summary -h\n\
pkg_cmp_summary [OPTIONS] summary1 summary2\n\
OPTIONS:\n\
-h|--help display this help\n\
-p|--with-pkgpath use PKGPATH:PKGBASE pair for identifing a package\n\
-c|--use-checksum also use CVS_CHECKSUM field in comparing packages\n\
" > "/dev/stderr"
}
BEGIN {
skip = 0
for (i = 1; i <= ARGC; ++i){
if (ARGV [i] ~ /^(-h|--help)$/){
usage()
exit 0
}else if (ARGV [i] ~ /^(-p|--with-pkgpath)$/){
with_pkgpath = 1
ARGV [i] = ""
++skip
}else if (ARGV [i] ~ /^(-c|--use-checksum)$/){
use_checksum = 1
ARGV [i] = ""
++skip
}
}
if (ARGC-skip != 3){
usage()
exit 1
}
file1 = ARGV [1 + skip]
}
function trim (s){
sub(/^[ \t]+/, "", s)
sub(/[ \t]+$/, "", s)
return s
}
$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))
next
}
NF == 0 {
# option PKGPATH
if (with_pkgpath){
pkgname = pkgpath " " pkgname
}
# ver
ver = pkgname
sub(/^.*-/, "", ver)
# pkgbase
pkgbase = pkgname
sub(/-[^-]+$/, "", pkgbase)
# current checksum
curr_checksum = checksum
# cleaning...
pkgname = pkgpath = checksum = ""
#
if (FILENAME == file1){
# first file!
if (pkgbase in names){
2008-05-09 22:56:18 +02:00
duplicates [pkgbase] += 1
}else{
names [pkgbase] = ver
if (use_checksum){
checksums [pkgbase] = curr_checksum
}
}
}else{
2008-05-09 22:56:18 +02:00
# second file!
present [pkgbase] = 0
if (pkgbase in duplicates){
next
}
if (! (pkgbase in names)){
print "+", pkgbase, ver
next
}
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, pkgbase, ver1, ver
}
next
}
END {
for (pkgbase in names){
if (! (pkgbase in present)){
print "-", pkgbase, names [pkgbase]
delete duplicates [pkgbase]
}else if (pkgbase in duplicates){
2008-05-09 22:56:18 +02:00
print duplicates [pkgbase]+1, pkgbase
}
}
}