#!/bin/sh # # port2errors -- remove error lines marked "NC", add description # after first erro of a given type. Needs to use the same # database as the run of port did. # #set -x DBPATH=/opt/DCWport/databases ProgName=`basename $0` Database="linux" main() { if [ $# -lt 1 ]; then say "$ProgName error: you must supply an errors file" say "Usage: $0 [-d database] file.errors" exit 1 fi while [ "$1" != "" ]; do case "$1" in -d) Database=$2 shift ;; -*) say "Unrecognized option $1 ignored." ;; *) break ;; esac shift done name=$1 cat $name |\ egrep '^"' |\ egrep -v ' NC' |\ port2errors } # # port2errors -- insert port database description after # first error of a given type. port2errors() { name=$1 cat $name |\ nawk ' BEGIN { interface = "" } /^#/ { next } /^%/ { next } /Interface Name/ { # We hit the table at the end, we can stop now. exit } /.*/ { if (interface != $4) { print $0 description($4) interface = $4 } else { print $0 } } function description(name, line,active) { active = 0 while (getline line < "'$DBPATH/$Database.ref'") { if (line ~ "^NAME:[ ]*" name "[ ]*$") { active = 1 } else if (line ~ /END_EXAMPLE/) { if (active == 1) { # End of this function print "# END_EXAMPLE" print "" break } } else if (line ~ /END_COMMENT/ \ || line ~ /BEGIN_EXAMPLE/) { continue; } if (active) { print "# " line } } close "'$DBPATH/$Database.ref'" if (active == 0) { print "ERROR: interface \"" name "\" not found in '$DBPATH/$Database.ref'" } } ' } say() { echo "$@" 1>&2 } main "$@"