Module Name:    src
Committed By:   christos
Date:           Sun Feb 17 01:20:57 UTC 2013

Modified Files:
        src/lib: checkver

Log Message:
modernize


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/checkver

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/checkver
diff -u src/lib/checkver:1.13 src/lib/checkver:1.14
--- src/lib/checkver:1.13	Wed Apr 30 09:10:50 2008
+++ src/lib/checkver	Sat Feb 16 20:20:57 2013
@@ -1,5 +1,5 @@
 #!/bin/sh
-#	$NetBSD: checkver,v 1.13 2008/04/30 13:10:50 martin Exp $
+#	$NetBSD: checkver,v 1.14 2013/02/17 01:20:57 christos Exp $
 #
 # Copyright (c) 1998 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -67,18 +67,22 @@
 #
 
 TMP=/tmp/checkver.$$
+PROG="$(basename "$PROG")"
 # Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
 # internal malloc!
 trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
 trap "[ -d $TMP ] && rm -rf $TMP" 0
 
 Usage() {
-    echo "Usage: $1 [-q] [-v version_file] -d [installedlibdir [library name]]"
-    echo "       $1 [-q] [-v version_file] -s [setlistdir [library name]]"
-    echo "       $1 [-q] [-v version_file] -f liblistfile [library name]"
-    echo "	$1 is a script that looks for installed libraries with"
-    echo "	   versions greater than that in the version file."
-    echo "	For more information, read the comments."
+cat << EOF 1>&2
+Usage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]]
+       $PROG [-q] [-v version_file] -s [setlistdir [library name]]
+       $PROG [-q] [-v version_file] -f liblistfile [library name]
+       $PROG is a script that looks for installed libraries with
+       versions greater than that in the version file.
+       For more information, read the comments.
+EOF
+	exit 1
 }
 
 basedir=/usr/src
@@ -91,144 +95,138 @@ quiet=0
 usedir=0
 usefile=0
 usesets=0
-CWD=`pwd`
-args=`getopt "df:shqv:" "$@"`
-if [ $? -ne 0 ] ; then
-    Usage $0
-    exit 0
-fi
-
-set -- $args
-
-while [ ! -z "$1" ]; do
-    case "$1" in
-	-d) usedir=1 ; shift
-	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
-		Usage $0 ; exit 2
-	    fi;;
-	-f) usefile=1 ; arg1=$2 ; shift ; shift
-	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
-		Usage $0 ; exit 2
-	    fi;;
-	-s) usesets=1 ; shift
-	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
-		Usage $0 ; exit 2
-	    fi;;
-	-v) shlib_version=$2; shift ; shift ;;
-	-h) Usage $0 ; exit 0;;
-	-q) quiet=1 ; shift;;
-	--) shift ; break;;
-    esac
+CWD=$(pwd)
+
+fixone() {
+	local instmajor=$(basename $1 | awk 'BEGIN { FS="." } { print $3 }')
+	local instminor=$(basename $1 | awk 'BEGIN { FS="." } { print $4 }')
+	local instteeny=$(basename $1 | awk 'BEGIN { FS="." } { print $5 + 0 }')
+	local ms="The following libraries have versions greater than the source"
+
+	# If they're greater than the source, complain.
+	if [ "0$major" -eq "0$instmajor" ]; then
+		if [ "0$minor" -eq "0$instminor" ]; then
+			if [ "0$teeny" -lt "0$instteeny" ]; then
+				if [ $error -eq 0 -a $quiet -eq 0 ]; then
+					echo "$ms" 1>&2
+				fi
+				echo $1 1>&2
+				error=1
+			fi
+		elif [ "0$minor" -lt "0$instminor" ]; then
+			if [ $error -eq 0 -a $quiet -eq 0 ]; then
+				echo "$ms" 1>&2
+			fi
+			echo $1 1>&2
+			error=1
+		fi
+	elif [ "0$major" -lt "0$instmajor" ]; then
+		if [ $error -eq 0 -a $quiet -eq 0 ]; then
+			echo "$ms" 1>&2
+		fi
+		echo $1 1>&2
+		error=1
+	fi
+}
+
+while getopts df:shqv: f; do
+	case $f in
+	d)	usedir=1 
+		if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
+			Usage
+		fi;;
+	f)	usefile=1; arg1=$OPTARG
+		if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
+			Usage 
+		fi;;
+	s)	usesets=1 
+		if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
+			Usage
+		fi;;
+	-v)	shlib_version=$OPTARG;;
+	-q)	quiet=1;;
+	*)	Usage;;
+	esac
 done
 
-if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
-    Usage $0 ; exit 2
+shift $(($OPTIND - 1))
+
+if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then
+	Usage
 fi
 
-if [ $usefile -eq 1 ] ; then
-   LIBLIST="$arg1"
+if [ $usefile -eq 1 ]; then
+	LIBLIST="$arg1"
 else
-   mkdir -m 0700 $TMP
-   if [ $?  != 0 ]; then
-	echo "$0: Unable to create temp directory."
-	exit 2
-   fi
-   LIBLIST=$TMP/libs.lst
+	if ! mkdir -m 0700 $TMP; then
+		echo "$PROG: Unable to create temp directory." 1>&2
+		exit 2
+	fi
+	LIBLIST=$TMP/libs.lst
 fi
 
 # Build list from the installed libraries.
-if [ $usedir -eq 1 ] ; then
-    if [ "X$1" != "X" ] ; then
-	libdir="$1"
-    fi
-    for f in $libdir ; do
-	ls $f/lib*.so.*.*
-    done > $LIBLIST 2> /dev/null
+if [ $usedir -eq 1 ]; then
+	if [ -n "$1" ]; then
+		libdir="$1"
+	fi
+	for f in $libdir; do
+		ls $f/lib*.so.*.*
+	done > $LIBLIST 2> /dev/null
 fi
 
 # Build list from set lists.  Parameter may be either
 # the "lists" directory or the top of the source tree.
-if [ $usesets -eq 1 ] ; then
-    if [ "X$1" != "X" ] ; then
-	setsdir="$1"
-	if [ -d "$setsdir/distrib/sets/lists" ] ; then
-	    setsdir="$setsdir/distrib/sets/lists"
+if [ $usesets -eq 1 ]; then
+	if [ -n "$1" ]; then
+		setsdir="$1"
+		if [ -d "$setsdir/distrib/sets/lists" ]; then
+			setsdir="$setsdir/distrib/sets/lists"
+		fi
 	fi
-    fi
-    (cd $setsdir ;
-     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
-		  | sort -u > $LIBLIST
-    )
+	(cd $setsdir;
+	 cat */[a-z]* |
+	 grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' |
+	 sort -u > $LIBLIST)
 fi
 
 #
 # The file $LIBLIST now contains a list of libraries.
 #
-
-if [ "X$2" = "X" ] ; then
-    makefile=$CWD/Makefile
-    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
-
-    # Assume the library name is the name of the current directory.
-    if [ -z $libname ]; then
-	libname=`basename $CWD`
-    fi
+if [ -z "$2" ]; then
+	makefile=$CWD/Makefile
+	libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//')
+
+	# Assume the library name is the name of the current directory.
+	if [ -z "$libname" ]; then
+		libname=$(basename $CWD)
+	fi
 else
-    libname="$2"
+	    libname="$2"
 fi
 echo $libname | grep "^lib" 1>&2 2> /dev/null
 if [ $? != 0 ]; then
-    libname="lib$libname"
+	libname="lib$libname"
 fi
 
 
-if [ ! -f $shlib_version ] ; then
-    echo "$0: unable to find $shlib_version"
-    exit 2
+if [ ! -f $shlib_version ]; then
+	echo "$PROG: unable to find $shlib_version" 1>&2
+	exit 2
 fi
 
 # Grab major and minor numbers from the source.
 . $shlib_version
 
-if [ "X$minor" = "X" -o "X$major" = "X" ] ; then
-    echo "$0: $shlib_version doesn't contain the version."
-    exit 2
+if [ -z "$minor" -o -z "$major" ]; then
+	echo "$PROG: $shlib_version doesn't contain the version." 1>&2
+	exit 2
 fi
 
 # Find every shared object library with the same base name.
- for instlib in `grep $libname.so "$LIBLIST" ` ; do
-    # Grab the major and minor from the installed library.
-    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
-    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
-    instteeny=`basename $instlib | awk 'BEGIN { FS="." } { print $5 + 0 } '`
-
-    # If they're greater than the source, complain.
-    if [ "0$major" -eq "0$instmajor" ] ; then
-	if [ "0$minor" -eq "0$instminor" ] ; then
-	    if [ "0$teeny" -lt "0$instteeny" ] ; then
-		if [ $error -eq 0 -a $quiet -eq 0 ]; then
-		    echo -n "The following libraries have versions greater"
-		    echo " than the source:"
-	        fi
-		echo $instlib > /dev/stderr
-		error=1
-	    fi
-        elif [ "0$minor" -lt "0$instminor" ] ; then
-	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
-		echo -n "The following libraries have versions greater"
-		echo " than the source:"
-	    fi
-	    echo $instlib > /dev/stderr
-	    error=1
-	fi
-    elif [ "0$major" -lt "0$instmajor" ] ; then
-	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
-	    echo -n "The following libraries have versions greater"
-	    echo " than the source:"
-	fi
-	echo $instlib > /dev/stderr
-	error=1
-    fi
- done
+for instlib in $(grep $libname.so "$LIBLIST"); do
+	# Grab the major and minor from the installed library.
+	fixone "$instlib"
+done
 
 exit $error

Reply via email to