NetBSD Problem Report #46785

From mw@fenrir.wzff.de  Wed Aug  8 10:10:08 2012
Return-Path: <mw@fenrir.wzff.de>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 8703863B882
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  8 Aug 2012 10:10:08 +0000 (UTC)
Message-Id: <20120808100916.2DAF1EEA4A7@fenrir.wzff.de>
Date: Wed,  8 Aug 2012 12:09:16 +0200 (CEST)
From: Moritz Wilhelmy <mw@wzff.de>
Reply-To: Moritz Wilhelmy <mw@wzff.de>
To: gnats-bugs@gnats.NetBSD.org
Subject: pkgdep: Eliminate use of undefined variable and deprecated getopts.pl
X-Send-Pr-Version: 3.95

>Number:         46785
>Category:       pkg
>Synopsis:       pkgdep: Eliminate use of undefined variable and deprecated getopts.pl
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 08 10:15:01 +0000 2012
>Originator:     Moritz Wilhelmy
>Release:        NetBSD 6.0_BETA2, pkgsrc-current
>Organization:
Fictional Enterprises Ltd
>Environment:
System: NetBSD fenrir.wzff.de 6.0_BETA2 NetBSD 6.0_BETA2 (GENERIC) i386
Architecture: i386
Machine: i386

/usr/pkgsrc/pkgtools/pkgdep/files/pkgdep.pl:
     $NetBSD: pkgdep.pl,v 1.3 2011/05/23 08:28:42 cheusov Exp $
     $indexfile: $
>Description:
	This patch converts pkgdep to use Getopt::Std, which seems to be the
	de-facto way of parsing options in Perl 5.  Previously, the Perl 4
	'getopts.pl' was used, which was deprecated by the perl developers and
	scheduled for removal for the next release.

	The $VERSION variable was introduced and usage_and_exit was renamed
	HELP_MESSAGE, because perl uses these for --help and --version output.

	Also, it spews warnings because $pkgdir{$_} in line 166 is used
	unconditionally, after it is checked for being defined, which is also
	fixed by the patch below.
>How-To-Repeat:
	Run pkgdep.pl in Perl 5.14.2, observe it warning about deprecation of
	getopts.pl and spew warnings about $pkgdir{$_} being used undefined.
>Fix:
Index: files/pkgdep.pl
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkgdep/files/pkgdep.pl,v
retrieving revision 1.3
diff -u -p -r1.3 pkgdep.pl
--- files/pkgdep.pl	23 May 2011 08:28:42 -0000	1.3
+++ files/pkgdep.pl	8 Aug 2012 09:58:59 -0000
@@ -1,14 +1,15 @@
 #!/usr/bin/env perl
 # $NetBSD: pkgdep.pl,v 1.3 2011/05/23 08:28:42 cheusov Exp $

-require 'getopts.pl';
+use Getopt::Std;
 use strict;
 $^W=1;
 $|=1;
-
-use vars qw($opt_I $opt_h $opt_e $opt_r $opt_v);
+use vars qw($opt_I $opt_h $opt_e $opt_r $opt_v $VERSION);
+$VERSION = '$NetBSD$';
+$Getopt::Std::STANDARD_HELP_VERSION = 1;
 my (%pkgdir, %builddeps, %rundeps, %buildreqd, %runreqd, %printed);
-my ($indexfile) = "@PKGSRCDIR@/INDEX";
+my ($indexfile) = '@PKGSRCDIR@/INDEX';
 my ($package, $match_pkgs);
 my (%node, %arrow, $home_level);
 my(%color);
@@ -16,10 +17,10 @@ $color{"D"} = "black";
 $color{"B"} = "blue";
 $color{"R"} = "red";

-if (!&Getopts('I:herv') || $opt_h) {&usage_and_exit;}
+&HELP_MESSAGE if !&getopts('I:herv') || $opt_h;
 if (defined($opt_I)) {$indexfile = $opt_I;}
 $package = shift;
-if (!defined($package)) {&usage_and_exit;}
+&HELP_MESSAGE if !defined($package);

 open(INDEX, $indexfile) || die "$indexfile: $!\n";
 while (<INDEX>) {
@@ -111,7 +112,7 @@ if (!defined($opt_v)) {
 	print "}\n";
 }

-sub usage_and_exit { 
+sub HELP_MESSAGE { 
 	print <<EOF;
 Usage: pkgdep [opts] package
   -I INDEX file path (default: $indexfile)
@@ -161,8 +162,12 @@ sub printdeps {
 	print "\t$depname depends on:\n";
 	if (defined($deps{$pkg}) && $deps{$pkg} ne "") {
 		for (sort split(/ /, $deps{$pkg})) {
-			if (!defined($pkgdir{$_})) {$_ = &searchpkg($_);}
-			print "\t\t$_ [$pkgdir{$_}]\n";
+			if (!defined($pkgdir{$_})) {
+				$_ = &searchpkg($_);
+				print "\t\t$_\n"
+			} else {
+				print "\t\t$_ [$pkgdir{$_}]\n";
+			}
 			if ($opt_r) {@rpkg = (@rpkg, $_);}
 		}
 	} else {

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.