X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FInifile.pm;h=30afc66c1a4731030e63f8c259aee66ad21695d0;hb=991369b17d679e2855f4d5086d0b9769dc2ae1aa;hp=2331ca7712d1ddbf7613151ef2952bce3c764d2c;hpb=dc3cd296e62eb09a16fa694d9b3a7158e4cf63bf;p=kivitendo-erp.git diff --git a/SL/Inifile.pm b/SL/Inifile.pm index 2331ca771..30afc66c1 100644 --- a/SL/Inifile.pm +++ b/SL/Inifile.pm @@ -25,7 +25,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #===================================================================== # # routines to retrieve / manipulate win ini style files @@ -37,58 +38,50 @@ package Inifile; use IO::File; +use strict; + sub new { - $main::lxdebug->enter_sub(); + $main::lxdebug->enter_sub(2); my ($type, $file, %options) = @_; my $id = ""; - my $skip; - - local *FH; + my $cur; - my $self = { "FILE" => $file }; + my $self = { FILE => $file, ORDER => [] }; - open FH, "$file" or Form->error("$file : $!"); + open my $fh, "$file" or $::form->error("$file : $!"); - while () { + for (<$fh>) { chomp; if (!$options{verbatim}) { # strip comments - s/\#.*//; - # remove any trailing whitespace + s/\s*#.*$//; s/^\s*//; - s/\s*$//; } else { - next if (m/^\s*\#/); + next if m/^\s*#/; } next unless $_; - if (m/^\[/) { - s/(\[|\])//g; - - $id = $_; - - $self->{$id} ||= { }; + if (m/^\[(.*)\]$/) { + $id = $1; + $cur = $self->{$1} ||= { }; - push @{ $self->{ORDER} }, $_; - - next; + push @{ $self->{ORDER} }, $1; + } else { + # add key=value to $id + my ($key, $value) = split m/=/, $_, 2; + $cur->{$key} = $value; } - # add key=value to $id - my ($key, $value) = split m/=/, $_, 2; - - $self->{$id}->{$key} = $value; - } - close FH; + close $fh; - $main::lxdebug->leave_sub(); + $main::lxdebug->leave_sub(2); return bless $self, $type; } @@ -99,7 +92,7 @@ sub write { my ($self) = @_; my $file = $self->{FILE}; - my $fh = IO::File->new($file, "w") || Form->error("$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]+$/; @@ -116,4 +109,3 @@ sub write { } 1; -