~ubuntu-branches/ubuntu/jaunty/localization-config/jaunty

« back to all changes in this revision

Viewing changes to conffiles.d/common/editconfig.pl

  • Committer: Bazaar Package Importer
  • Author(s): Konstantinos Margaritis
  • Date: 2005-05-23 00:36:51 UTC
  • Revision ID: james.westby@ubuntu.com-20050523003651-2xfe4l262j5ij3xa
Tags: 0.116
* Translatios
  - Bulgarian added. Closes: #308129
  - Updated Greek and Vietnamese. Closes: #309055
  - Fixed templates file that included extra test messages for session
  chooser
* Closes forgotten bugs. Closes: #306084, #306052.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# to manipulate config files.
6
6
#
7
7
 
 
8
require '/usr/lib/localization-config/common/log.pl';
 
9
 
8
10
# Return 0 if the file wasn't changed and 1 if the file was updated
9
11
sub AppendIfMissingLine {
10
12
    my ($filename, $line) = @_;
24
26
    }
25
27
 
26
28
    if ($updated) {
27
 
        print "Updating $filename\n" if $debug;
28
 
        open(FILE, ">$filename.new") || die "Unable to write $filename.new";
 
29
        log_msg("$0: Updating $filename");
 
30
        open(FILE, ">$filename.new") || log_die("$0: Unable to write $filename.new");
29
31
        print FILE @lines;
30
32
        close(FILE);
31
33
        rename "$filename.new", $filename;
35
37
 
36
38
# Return 0 if nothing changed, and 1 if the file was updated
37
39
sub UpdateOrAppendVariable {
38
 
    my ($filename, $variable, $content) = @_;
 
40
    my ($filename, $variable, $content, $delimeter, $section, $prefix) = @_;
39
41
    my $updated = 0;
40
 
    my $newline = "$variable=$content\n";
 
42
    my $newline;
 
43
    if (defined($prefix)) {
 
44
        $newline = "\t";
 
45
    }
 
46
    $newline .= "$variable$delimeter$content\n";
41
47
 
42
48
    my @lines;
43
49
    if (open(FILE, "<$filename")) {
45
51
        close(FILE);
46
52
    }
47
53
 
48
 
    if (grep /^$variable=/, @lines ) {
49
 
        @lines = map { if ($_ =~ m/^$variable=/ && $_ ne $newline)
 
54
    if (defined($section)) {
 
55
        if (! grep /\[$section\]/, @lines ) {
 
56
            $updated = 1;
 
57
            push(@lines, "\[$section\]\n");
 
58
        }
 
59
    }
 
60
    
 
61
    if (grep /$variable.*$delimeter/, @lines ) {
 
62
        @lines = map { if ($_ =~ m/$variable.*$delimeter/ && ! ($_ =~ /$variable.*$content/) )
50
63
                       { $updated = 1;
51
64
                         $newline; }
52
65
                       else
53
66
                       { $_; }
54
67
                   } @lines;
55
68
    } else {
56
 
        $updated = 1;
57
 
        push(@lines, $newline);
 
69
        if (defined($section)) {
 
70
            $newline = "\[$section\]\n".$newline;
 
71
            @lines = map { if ($_ =~ m/^\[$section\]/ )
 
72
                        { $updated = 1;
 
73
                            $newline; }
 
74
                        else
 
75
                        { $_; }
 
76
                    } @lines;
 
77
        } else {
 
78
            $updated = 1;
 
79
            push(@lines, $newline);
 
80
        }
58
81
    }
 
82
    
59
83
    if ($updated) {
60
 
        print "Updating $filename\n" if $debug;
61
 
        open(FILE, ">$filename.new") || die "Unable to write $filename.new";
 
84
        log_msg("$0: Updating $filename");
 
85
        open(FILE, ">$filename.new") || log_die("$0: Unable to write $filename.new");
62
86
        print FILE @lines;
63
87
        close(FILE);
64
88
        rename "$filename.new", $filename;