File indexing completed on 2024-05-05 04:48:33

0001 #!/usr/bin/perl -w
0002 #
0003 # This script updates all format strings in amarokc config file
0004 # according to new syntax, replaces %token with %token% if It's needed.
0005 
0006 use strict;
0007 
0008 sub isUpdated($) {
0009     return ($_[0] =~ m/%[a-zA-Z0-9]+%/);
0010 }
0011 
0012 sub syntaxUpdate($) {
0013     my $value = $_[0];
0014     $value =~ s/(%[a-zA-Z0-9]+)/$1%/g;
0015     return $value;
0016 }
0017 
0018 #replaceKey("section", "key", "new value");
0019 sub replaceKey($$$) {
0020     my ($section, $key, $value) = @_;
0021     print("# DELETE $section$key\n");
0022     print("$section\n$key=$value\n");
0023 }
0024 
0025 my $section = "";
0026 
0027 while (<>) {
0028     chomp();
0029     if (/^\[/) {
0030         $section = $_;
0031     }
0032     elsif (($section eq "[OrganizeCollectionDialog]" and (/^Custom Scheme/ or /^Format Presets/)) or
0033            ($section eq "[FilenameLayoutDialog]" and /^Custom Scheme/ )) {
0034         my ($key,$value) = split(/=/);
0035         next unless length($value);
0036         replaceKey($section, $key, syntaxUpdate($value)) unless isUpdated($value);
0037     }
0038 }