5 detect \lyrics and \melodic, and do substitution accordingly.
8 Ugh . Perl sux. Anybody for Python?
15 # version of "supporting" engine, not mudela conversions.
21 $convert_mudela_version = "0.1.1";
35 my(@a)= split /\./,$a;
36 my(@b)= split /\./,$b;
39 return $a[$i] <=> $b[$i] if ($a[$i] != $b[$i]);
44 sub version_string_conv
46 my ($from_version, $to_version) = @_;
47 s/\version \"$from_version\"/\version \"$to_version\"/g;
50 ################################################################
56 sub convert_0_0_52_to_0_0_53
59 s/include \"/$1\\include \"/g;
63 sub convert_0_0_54_to_0_0_55
69 sub convert_0_0_53_to_0_0_54
71 print STDERR
"Not smart enough to convert \\transpose\n" if (/\\transpose/) ;
74 # we-re not at 58 yet, but this is at least one of the rules
75 sub convert_0_0_55_to_0_0_56
80 sub convert_0_0_56_to_0_0_57
82 s/\(([ \]\[|\t-\.>]|\\[<!>a-z]+)*\)/\~ $1/g;
85 sub convert_0_0_57_to_0_0_58
87 s/\[ *([^\[\]]*)\] *([1-9]*) *\/ *([1-9]*)/[$2\
/$3 $1]1\/1/g
;
90 sub convert_0_0_58_to_0_0_59
92 die "Not smart enough to convert 0.0.58 to 0.0.59\n";
95 sub convert_0_0_59_to_0_0_60
97 s/(\\unitspace [0-9.mcptin\\ ]+|\\geometric [0-9.]+|\\width [0-9.mcp\\tin]+)/$1;/g;
98 s/(\\output \"[^\"]+\")/$1;/;
99 s/(\\tempo [0-9: ]+)/$1;/;
102 sub convert_0_0_60_to_0_0_61
104 s/(\\unitspace|\\geometric|\\width)/$1=/g;
108 ###############################################################
118 print STDERR
"This is convert-mudela " . $convert_mudela_version .
119 " (up to mudela version ", last_conversion
, ")\n";
125 print STDERR
"Usage: convert-mudela [options] [mudela-file]...\n"
126 . "Convert old mudela source from mudela-file or stdin\n\n"
128 . " -e, --edit perform in-place conversion\n"
129 . " -f, --from=PATHLEVEL use source version 0.0.PATCHLEVEL\n"
130 . " -h, --help print this help\n"
131 . " -o, --output=FILE name output file\n"
132 . " -s, --show-rules print all known conversion rules\n"
133 . " -t, --to=VERSION convert to version VERSION\n"
137 my %minor_conversions = ("0.0.50" => \
&no_conv
,
138 "0.0.52" => \
&convert_0_0_50_to_0_0_52
,
139 "0.0.53" => \
&convert_0_0_52_to_0_0_53
,
140 "0.0.54" => \
&convert_0_0_53_to_0_0_54
,
141 "0.0.55" => \
&convert_0_0_54_to_0_0_55
,
142 "0.0.56" => \
&convert_0_0_55_to_0_0_56
,
143 "0.0.57" => \
&convert_0_0_56_to_0_0_57
,
144 "0.0.58" => \
&convert_0_0_57_to_0_0_58
,
145 "0.0.59" => \
&convert_0_0_58_to_0_0_59
,
146 "0.0.60" => \
&convert_0_0_59_to_0_0_60
,
147 "0.0.61" => \
&convert_0_0_60_to_0_0_61
153 return (sort keys %minor_conversions);
159 print "Rules: ", join(", ", sort keys %minor_conversions), "\n";
167 my @applicable_conversion;
170 # die "This is too old to convert " if $from < 50;
173 if (version_compare
($ver, $from) > 0 && version_compare
($ver,$to) <= 0 ){
174 push @applicable_conversion, $minor_conversions{$ver};
175 push @mudela_levels, $ver;
179 print STDERR
"Applying following rules: ", join(", ", @mudela_levels) , "\n";
182 foreach $subroutine (@applicable_conversion) {
187 version_string_conv
$from, $to;
196 open INLY
, $fn || die "Can't open";
199 s/^.*\\version \"([^\"]*)\".*$//;
201 print STDERR
"Guessing version: ", $1, ".. ";
207 print STDERR
"can't determine mudela version in $fn.\n";
219 $outfile = $opt_output if (defined($opt_output));
224 if (( ! -f
$infile) && (! $infile =~ /\\.ly$/s ) ){
229 if ($opt_edit && $infile ne "-") {
231 $outfile = "$infile.NEW";
234 print STDERR
"Input ", (($infile eq "-") ?
"STDIN" : $infile), " .. ";
242 local ($from_version, $to_version);
243 $from_version = $opt_from;
244 $to_version = $opt_to;
246 ($from_version = get_auto_from
$infile) unless defined($opt_from);
247 return if (!defined($from_version));
249 ($to_version = last_conversion
) unless (defined($opt_to));
251 die "can't open \`$infile\'" unless open INLY
,$infile ;
252 die "can't open \`$outfile\'" unless open OUTLY
, ">$outfile";
254 do_conversion
$from_version, $to_version;
259 rename $infile, "$infile~";
260 rename $outfile, "$infile";
269 GetOptions
("help", "output=s", "from=i", "to=i", "minor=i", "edit", "show-rules");
273 $opt_help = 0; # to extinguish typo check.
277 if ($opt_show_rules) {
279 $opt_show_rules = 0; # to extinguish typo check.
283 local ( $infile,$outfile);
286 while (defined($ARGV[0])) {
291 do_one_arg
unless ($processed_one);