From: Moritz Bunkus Date: Wed, 16 May 2007 13:23:22 +0000 (+0000) Subject: Inifile.pm auch dazu benutzen, um die memers/users einzulesen und neu zu schreiben. X-Git-Tag: release-2.4.3^2~301 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=db53dc8ab328b82c7af17896487674ad98f2af6b;p=kivitendo-erp.git Inifile.pm auch dazu benutzen, um die memers/users einzulesen und neu zu schreiben. --- diff --git a/SL/Inifile.pm b/SL/Inifile.pm index eae4f49e4..f7fe27b3c 100644 --- a/SL/Inifile.pm +++ b/SL/Inifile.pm @@ -35,41 +35,42 @@ package Inifile; +use IO::File; + sub new { $main::lxdebug->enter_sub(); - my ($type, $file, $level) = @_; + my ($type, $file) = @_; my $id = ""; my $skip; local *FH; - $type = ref($self) || $self; + my $self = { "FILE" => $file }; open FH, "$file" or Form->error("$file : $!"); while () { - next if /^(#|;|\s)/; - last if /^\./; + next if m/^(#|;|\s)/; - chop; + chomp; # strip comments - s/\s*(#|;).*//g; + s/(#|;).*//g; # remove any trailing whitespace - s/^\s*(.*?)\s*$/$1/; + s/^\s*//; + s/\s*$//; + + next unless $_; - if (/^\[/) { + if (m/^\[/) { s/(\[|\])//g; $id = $_; - # if there is a level skip - if ($skip = ($id !~ /^$level/)) { - next; - } + $self->{$id} ||= { }; push @{ $self->{ORDER} }, $_; @@ -77,20 +78,39 @@ sub new { } - if (!$skip) { + # add key=value to $id + my ($key, $value) = split m/=/, $_, 2; - # add key=value to $id - my ($key, $value) = split /=/, $_, 2; - - $self->{$id}{$key} = $value; - } + $self->{$id}->{$key} = $value; } close FH; $main::lxdebug->leave_sub(); - bless $self, $type; + return bless $self, $type; +} + +sub write { + $main::lxdebug->enter_sub(); + + my ($self) = @_; + + my $file = $self->{FILE}; + my $fh = IO::File->new($file, "w") || Form->error("$file : $!"); + + foreach my $section_name (sort keys %{ $self }) { + next if $section_name =~ m/^[A-Z]+$/; + + my $section = $self->{$section_name}; + print $fh "[${section_name}]\n"; + map { print $fh "${_}=$section->{$_}\n" } sort keys %{ $section }; + print $fh "\n"; + } + + $fh->close(); + + $main::lxdebug->leave_sub(); } 1; diff --git a/SL/Menu.pm b/SL/Menu.pm index 044ce9b79..89a6ffd15 100644 --- a/SL/Menu.pm +++ b/SL/Menu.pm @@ -34,13 +34,17 @@ package Menu; +use SL::Inifile; + sub new { $main::lxdebug->enter_sub(); - my ($type, $menufile, $level) = @_; + my ($type, $menufile) = @_; + + my $self = {}; + my $inifile = Inifile->new($menufile); - use SL::Inifile; - my $self = Inifile->new($menufile, $level); + map { $self->{$_} = $inifile->{$_} } keys %{ $inifile }; $main::lxdebug->leave_sub();