From: Ian Jackson Date: Wed, 4 Sep 2013 20:36:34 +0000 (+0100) Subject: Code cleanups: X-Git-Tag: debian/4.2.1__iwj2~17 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=7e4802e541e3528f67089f10f7ac299fad97fe75 Code cleanups: * random-word: use strict; -w. --- diff --git a/debian/changelog b/debian/changelog index 6bd8b40..0fa99b3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ chiark-utils (4.2.1~~iwj1) unstable; urgency=low + Code cleanups: * random-word: Some perl-mode emacs formatting glitch workarounds. + * random-word: use strict; -w. -- diff --git a/scripts/random-word b/scripts/random-word index ddd6c52..427e4d0 100755 --- a/scripts/random-word +++ b/scripts/random-word @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # Copyright 2004 Ian Jackson # @@ -16,18 +16,20 @@ # with this program; if not, consult the Free Software Foundation's # website at www.fsf.org, or the GNU Project website at www.gnu.org. +use strict; + use IO::Handle; use IO::File; use POSIX; -$want= 1; -$filename= "/usr/share/dict/words"; -@randfile= ("/dev/urandom", "/dev/random"); +our $want= 1; +our $filename= "/usr/share/dict/words"; +our @randfile= ("/dev/urandom", "/dev/random"); sub fail ($) { die "random-word: $_[0]\n"; } open D, ">/dev/null" or fail("open /dev/null: $!"); -while ($ARGV[0] =~ m/^\-/) { +while (@ARGV && $ARGV[0] =~ m/^\-/) { $_= shift @ARGV; if (m/^\-\-?$/) { last; @@ -49,6 +51,9 @@ sub debug ($) { or fail("write debug: $!"); } +our $randfile; +our $r; + for $randfile (@randfile) { $r= new IO::File "$randfile", 'r'; debug("open $randfile ".($r ? "ok" : "failed $!")); @@ -58,17 +63,19 @@ for $randfile (@randfile) { $r or fail("could not open any random device: $!\n (tried @randfile)"); $r->autoflush(0); -$w= new IO::File $filename, 'r'; +our $w= new IO::File $filename, 'r'; $w or fail("cannot open $filename: $!"); debug("open $filename ok"); -@words= <$w>; +our @words= <$w>; $w->error and fail("cannot read $filename: $!"); debug("read $filename ok"); +our @out; while (@out < $want) { + my $rbytes; $!=0; read $r,$rbytes,4; length $rbytes==4 or fail("cannot read $randfile: $!"); - $wordno= unpack 'L',$rbytes; + my $wordno= unpack 'L',$rbytes; $wordno &= ~0x80000000; $wordno %= @words; $_= $words[$wordno];