From 046406ab6b13659f4be843d3d2d5639efaf425fe Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Tue, 12 Nov 2002 12:05:40 +0000 Subject: printer related modules cleaning : - create the printer/ hierarchy - split services related stuff into services.pm & printer::services, - move things that've nothing to do with printers into common.pm (alternatives, permissions, ...) - move eveything related to cups, gimp-print, detection, {star,open}office to the corresponding splited printer:: module - big consolidation of printer::office (it was obvious there were tons of duplication between staroffice and openoffice managment) - move other stuff into printer::main, printer::common, status : print.pm has been heavily splited (now one can begin to understand the little bits). printerdrake still needs to be splited/cleaned and eventually removed since printer/printerdrake modules separation is not understandable by other people till, in printer::gimp, $lprcommand is neither declared nor setted nowhere. idem in mdk9.0 ... --- perl-install/printer/common.pm | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 perl-install/printer/common.pm (limited to 'perl-install/printer/common.pm') diff --git a/perl-install/printer/common.pm b/perl-install/printer/common.pm new file mode 100644 index 000000000..13e5919f9 --- /dev/null +++ b/perl-install/printer/common.pm @@ -0,0 +1,91 @@ +package printer::common; + +use strict; + + +sub addentry { + my ($section, $entry, $filecontent) = @_; + my $sectionfound = 0; + my $entryinserted = 0; + my @lines = split("\n", $filecontent); + foreach (@lines) { + if (!$sectionfound) { + if (/^\s*\[\s*$section\s*\]\s*$/) { + $sectionfound = 1; + } + } else { + if (!/^\s*$/ && !/^\s*;/) { #-# + $_ = "$entry\n$_"; + $entryinserted = 1; + last; + } + } + } + if ($sectionfound && !$entryinserted) { + push(@lines, $entry); + } + return join ("\n", @lines); +} + +sub addsection { + my ($section, $filecontent) = @_; + my $entryinserted = 0; + my @lines = split("\n", $filecontent); + foreach (@lines) { + if (/^\s*\[\s*$section\s*\]\s*$/) { + # section already there, nothing to be done + return $filecontent; + } + } + return $filecontent . "\n[$section]"; +} + +sub removeentry { + my ($section, $entry, $filecontent) = @_; + my $sectionfound = 0; + my $done = 0; + my @lines = split("\n", $filecontent); + foreach (@lines) { + $_ = "$_\n"; + next if $done; + if (!$sectionfound) { + if (/^\s*\[\s*$section\s*\]\s*$/) { + $sectionfound = 1; + } + } else { + if (/^\s*\[.*\]\s*$/) { # Next section + $done = 1; + } elsif (/^\s*$entry/) { + $_ = ""; + $done = 1; + } + } + } + return join ("", @lines); +} + +sub removesection { + my ($section, $filecontent) = @_; + my $sectionfound = 0; + my $done = 0; + my @lines = split("\n", $filecontent); + foreach (@lines) { + $_ = "$_\n"; + next if $done; + if (!$sectionfound) { + if (/^\s*\[\s*$section\s*\]\s*$/) { + $_ = ""; + $sectionfound = 1; + } + } else { + if (/^\s*\[.*\]\s*$/) { # Next section + $done = 1; + } else { + $_ = ""; + } + } + } + return join ("", @lines); +} + +1; -- cgit v1.2.1