From 7e5672eb837597a08dc886dc022f704be9b97665 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 24 Jul 2001 10:23:21 +0000 Subject: generalize the use of chomp_ as the functional alternative to chomp (and works on lists) --- perl-install/Xconfig.pm | 5 ++--- perl-install/any.pm | 5 ++--- perl-install/bootlook.pm | 3 +-- perl-install/commands.pm | 4 ++-- perl-install/common.pm | 6 +++--- perl-install/detect_devices.pm | 4 ++-- perl-install/install_any.pm | 4 ++-- perl-install/standalone/diskdrake | 2 +- perl-install/standalone/draknet | 4 ++-- perl-install/timezone.pm | 4 ++-- perl-install/unused/scsi.pm | 4 ++-- 11 files changed, 21 insertions(+), 24 deletions(-) (limited to 'perl-install') diff --git a/perl-install/Xconfig.pm b/perl-install/Xconfig.pm index c91f5f666..0797d6c8b 100644 --- a/perl-install/Xconfig.pm +++ b/perl-install/Xconfig.pm @@ -203,9 +203,8 @@ sub getinfoFromDDC { } my ($h, $v, $size, @m) = @l; - chop $h; chop $v; - $O->{hsyncrange} ||= $h; - $O->{vsyncrange} ||= $v; + $O->{hsyncrange} ||= chomp_($h); + $O->{vsyncrange} ||= chomp_($v); $O->{size} ||= to_float($size); $O->{modelines} ||= join '', @m; $o; diff --git a/perl-install/any.pm b/perl-install/any.pm index 793017880..444fed381 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -319,8 +319,7 @@ sub partitions_suggestions { my @etc_pass_fields = qw(name pw uid gid realname home shell); sub unpack_passwd { my ($l) = @_; - chomp $l; - my %l; @l{@etc_pass_fields} = split ':', $l; + my %l; @l{@etc_pass_fields} = split ':', chomp_($l); \%l; } sub pack_passwd { @@ -373,7 +372,7 @@ sub writeandclean_ldsoconf { sub shells { my ($prefix) = @_; - grep { -x "$prefix$_" } map { chomp; $_ } cat_("$prefix/etc/shells"); + grep { -x "$prefix$_" } chomp_(cat_("$prefix/etc/shells")); } sub inspect { diff --git a/perl-install/bootlook.pm b/perl-install/bootlook.pm index a8c5f693c..4a75f24db 100644 --- a/perl-install/bootlook.pm +++ b/perl-install/bootlook.pm @@ -54,8 +54,7 @@ my $a_mode = (-e "/etc/aurora/Monitor") ? 1 : 0; my $l_mode = isAutologin(); my %auto_mode = get_autologin(""); my $inmain = 0; -my $lilogrub = `detectloader -q`; -chomp $lilogrub; +my $lilogrub = chomp_(`detectloader -q`); my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window ("toplevel"); $window->signal_connect(delete_event => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) }); diff --git a/perl-install/commands.pm b/perl-install/commands.pm index 291161943..b34b7df33 100644 --- a/perl-install/commands.pm +++ b/perl-install/commands.pm @@ -398,10 +398,10 @@ sub unpack_ { local *F; open F, $_[0] or die "can't open file $_: $!\n"; while (1) { - my ($size) = chop_(scalar ); + my $size = chomp_(scalar ); defined $size or last; $size =~ /^\d+$/ or die "bad format (can't find file size)\n"; - my ($filename) = chop_(scalar ) or die "expecting filename\n"; + my $filename = chomp_(scalar ) or die "expecting filename\n"; print "$filename\n"; my $dir = dirname($filename); diff --git a/perl-install/common.pm b/perl-install/common.pm index 0eed816b1..e9e2bb93d 100644 --- a/perl-install/common.pm +++ b/perl-install/common.pm @@ -6,9 +6,9 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $printable_chars $sizeof_int $bitof_int @ISA = qw(Exporter); %EXPORT_TAGS = ( - common => [ qw(__ may_apply even odd arch better_arch compat_arch min max sqr sum and_ or_ if_ if__ sign product bool invbool listlength bool2text bool2yesno text2bool to_int to_float ikeys member divide is_empty_array_ref is_empty_hash_ref add2hash add2hash_ put_in_hash set_new set_add round round_up round_down first second top uniq translate untranslate warp_text formatAlaTeX formatLines deref next_val_in_array) ], + common => [ qw(__ may_apply even odd arch better_arch compat_arch min max sqr sum and_ or_ if_ if__ chomp_ sign product bool invbool listlength bool2text bool2yesno text2bool to_int to_float ikeys member divide is_empty_array_ref is_empty_hash_ref add2hash add2hash_ put_in_hash set_new set_add round round_up round_down first second top uniq translate untranslate warp_text formatAlaTeX formatLines deref next_val_in_array) ], functional => [ qw(fold_left compose mapgrep map_index grep_index find_index map_each grep_each list2kv map_tab_hash mapn mapn_ difference2 before_leaving catch_cdie cdie combine) ], - file => [ qw(dirname basename touch all glob_ cat_ cat__ catMaybeCompressed output symlinkf renamef chop_ mode typeFromMagic expand_symlinks) ], + file => [ qw(dirname basename touch all glob_ cat_ cat__ catMaybeCompressed output symlinkf renamef mode typeFromMagic expand_symlinks) ], system => [ qw(sync makedev unmakedev psizeof strcpy gettimeofday syscall_ salt getVarsFromSh setVarsInSh setVarsInShMode setVarsInCsh substInFile availableMemory availableRamMB removeXiBSuffix formatXiB template2file template2userfile update_userkderc list_skels formatTime formatTimeRaw unix2dos setVirtual isCdNotEjectable) ], constant => [ qw($printable_chars $sizeof_int $bitof_int $SECTORSIZE %compat_arch) ], ); @@ -94,7 +94,7 @@ sub deref { ref $_[0] eq "ARRAY" ? @{$_[0]} : ref $_[0] eq "HASH" ? %{$_[0]} : $ sub linkf { unlink $_[1]; link $_[0], $_[1] } sub symlinkf { unlink $_[1]; symlink $_[0], $_[1] } sub renamef { unlink $_[1]; rename $_[0], $_[1] } -sub chop_ { map { my $l = $_; chomp $l; $l } @_ } +sub chomp_ { my @l = map { my $l = $_; chomp $l; $l } @_; wantarray ? @l : $l[0] } sub divide { my $d = int $_[0] / $_[1]; wantarray ? ($d, $_[0] % $_[1]) : $d } sub round { int ($_[0] + 0.5) } sub round_up { my ($i, $r) = @_; $i = int $i; $i += $r - ($i + $r - 1) % $r - 1; } diff --git a/perl-install/detect_devices.pm b/perl-install/detect_devices.pm index a210515b5..6bc394744 100644 --- a/perl-install/detect_devices.pm +++ b/perl-install/detect_devices.pm @@ -147,9 +147,9 @@ sub getIDE() { #- Great. 2.2 kernel, things are much easier and less error prone. foreach my $d (sort @{[glob_('/proc/ide/hd*')]}) { - my ($t) = chop_(cat_("$d/media")); + my $t = chomp_(cat_("$d/media")); my $type = $ {{disk => 'hd', cdrom => 'cdrom', tape => 'tape', floppy => 'fd'}}{$t} or next; - my ($info) = chop_(cat_("$d/model")); $info ||= "(none)"; + my $info = chomp_(cat_("$d/model")) || "(none)"; my $num = ord (($d =~ /(.)$/)[0]) - ord 'a'; push @idi, { type => $type, device => basename($d), info => $info, bus => $num/2, id => $num%2 }; diff --git a/perl-install/install_any.pm b/perl-install/install_any.pm index a8eb54f50..979216b8f 100644 --- a/perl-install/install_any.pm +++ b/perl-install/install_any.pm @@ -454,7 +454,7 @@ sub setAuthentication { } sub killCardServices { - my $pid = chop_(cat_("/tmp/cardmgr.pid")); + my $pid = chomp_(cat_("/tmp/cardmgr.pid")); $pid and kill(15, $pid); #- send SIGTERM } @@ -521,7 +521,7 @@ sub install_urpmi { cdrom => "removable_cdrom_$::i://mnt/cdrom" }}{$method} . "/$_->{rpmsdir}"; local *FILES; open FILES, "$ENV{LD_LOADER} parsehdlist /tmp/$_->{hdlist} |"; - chop, print LIST "$dir/$_\n" foreach ; + print LIST "$dir/$_\n" foreach chomp_(); close FILES or log::l("parsehdlist failed"), return; close LIST; diff --git a/perl-install/standalone/diskdrake b/perl-install/standalone/diskdrake index 57a6045a0..7bf80d398 100755 --- a/perl-install/standalone/diskdrake +++ b/perl-install/standalone/diskdrake @@ -68,7 +68,7 @@ my ($hds, $lvms) = I'll try to go on blanking bad partitions"), $err]); }; -$SIG{__DIE__} = sub { chomp (my $m = $_[0]); log::l("ERROR: $m") }; +$SIG{__DIE__} = sub { my $m = chomp_($_[0]); log::l("ERROR: $m") }; my $fstab = [ fsedit::get_fstab(@$hds, @$lvms) ]; fs::get_mntpoints_from_fstab($fstab); diff --git a/perl-install/standalone/draknet b/perl-install/standalone/draknet index 374a0e423..37d9cadcf 100755 --- a/perl-install/standalone/draknet +++ b/perl-install/standalone/draknet @@ -138,7 +138,7 @@ $hbox1->pack_start($button_new,0,0,5); my $hbox2 = new Gtk::HBox(0,0); $vbox1->pack_start($hbox2,1,1,0); $hbox2->pack_start(new Gtk::Label(_("Hostname: ")),0,0,0); -chop (my $hostname = `hostname`); +my $hostname = chomp_(`hostname`); my $label_host = new Gtk::Label($hostname); $hbox2->pack_start($label_host,0,0,0); @@ -348,7 +348,7 @@ sub apply { } sub update { - chop (my $h = `hostname`); + my $h = chomp_(`hostname`); $label_host->set ($h); $label4->set($netcnx->{type}); $label5->set($netcnx->{type} eq 'lan' ? _("Gateway:") : _("Interface:")); diff --git a/perl-install/timezone.pm b/perl-install/timezone.pm index 7da47f135..1b45d243a 100644 --- a/perl-install/timezone.pm +++ b/perl-install/timezone.pm @@ -13,9 +13,9 @@ sub getTimeZones { my ($prefix) = @_; local *F; open F, "cd $prefix/usr/share/zoneinfo && find [A-Z]* -type f |"; - my @l = sort map { chop; $_ } ; + my @l = chomp_(); close F or die "cannot list the available zoneinfos"; - @l; + sort @l; } sub read { diff --git a/perl-install/unused/scsi.pm b/perl-install/unused/scsi.pm index b92185d46..8e20f7d70 100644 --- a/perl-install/unused/scsi.pm +++ b/perl-install/unused/scsi.pm @@ -60,9 +60,9 @@ sub ideGetDevices { #- Great. 2.2 kernel, things are much easier and less error prone. foreach my $d (glob_('/proc/ide/hd*')) { - my ($t) = chop_(cat_("$d/media")); + my ($t) = chomp_(cat_("$d/media")); my $type = $ {{disk => 'hd', cdrom => 'cdrom', tape => 'tape', floppy => 'fd'}}{$t} or next; - my ($info) = chop_(cat_("$d/model")); $info ||= "(none)"; + my ($info) = chomp_(cat_("$d/model")); $info ||= "(none)"; my $num = ord (($d =~ /(.)$/)[0]) - ord 'a'; push @idi, { type => $type, device => basename($d), info => $info, bus => $num/2, id => $num%2 }; -- cgit v1.2.1