]> git.donarmstrong.com Git - lilypond.git/blobdiff - bin/mudela-book.in
release: 0.1.50
[lilypond.git] / bin / mudela-book.in
old mode 100644 (file)
new mode 100755 (executable)
index 11f27a4..f23b428
@@ -1,30 +1,65 @@
-#!@PERL@ -w            
+#!@PERL@ -w
 # -*-Perl-*-
 my $mudcount = 0;
 my $mudela_b = 0;
 my $outname = "-";
+my $outdir;
 use Getopt::Long;
 
+
+# do something, check return status
+sub my_system
+{
+    my (@cmds) = @_;
+    foreach $cmd (@cmds) {
+       my ($ignoreret)=0;
+       if ( $cmd  =~ /^-/ ) {
+           $ignoreret = 1;
+           $cmd = substr ($cmd, 1);
+       }
+       
+       my $ret =  ( system ($cmd));
+       if ($ret) {
+           if ($ignoreret) {
+               print STDERR "ignoring failed command \`$cmd\' (status $ret)\n";
+           }else {
+               print STDERR "\nmudela-book: failed on command \`$cmd\' (status $ret)\n";
+               exit 2;
+           }
+       }
+    }
+}
 sub gen_mufile
 {
     return "$outdir/$outname$mudcount.ly";
 }
 
+sub gen_texbase
+{
+    return "$outname$mudcount.tex";
+}
 sub gen_texfile
 {
-    return "$outdir/$outname$mudcount.tex";
+    return "$outdir/" . gen_texbase;
 }
 
 sub close_mudela
 {
     $mudela_b = 0;
     if ($fragment_b) {
-       print MUDELA "}\n \\paper { linewidth = -1.0\\cm; castingalgorithm = \\Wordwrap; } }\n";
+       print MUDELA "}\n \\paper { linewidth = -1.0\\cm;";
+       print MUDELA "castingalgorithm = \\Wordwrap; } }\n";
        $fragment_b =0;
     }
-    if ( $verbatim_b)  {
-       print BOOK "\\end{verbatim}\n\\interexample";
-       $verbatim_b =0;
+    if ($verbatim_b)  {
+       print BOOK "\\end{verbatim}";
+    }
+    if ($center_b) {
+       print BOOK "\\end{minipage}";
+    }
+    if ($verbatim_b)  {
+       print BOOK "\\interexample";
+       $verbatim_b = 0;
     }
     close MUDELA;
     my $status =0;
@@ -39,11 +74,19 @@ sub close_mudela
     }
     
     if ( ! -f gen_texfile) {
-       system "lilypond ". gen_mufile;
-       rename "lelie.tex", gen_texfile;
+       my_system "lilypond ". gen_mufile;
+       rename gen_texbase, gen_texfile;
     }
-    print BOOK "\\preexample\\input " . gen_texfile . "\n\\postexample\n";
-       
+
+    if ($center_b) {
+       print BOOK "\\begin{minipage}[c]{.5\\textwidth}\n";
+    }
+    print BOOK "\\input " . gen_texfile . "%\n";
+    if ($center_b) {
+       print BOOK "\\end{minipage}";
+       $center_b = 0;
+    }
+    print BOOK "\\postexample%\n";
 }
 
 sub open_mudela
@@ -51,11 +94,18 @@ sub open_mudela
     $mudcount++;
     $mudela_b = 1      ;
     open MUDELA, ">$outdir/book-mudela.ly";
+    print BOOK "\\preexample%\n";
+    if ($center_b) {
+       print BOOK "\\begin{minipage}[c]{.5\\textwidth}\n";
+    }
     if ($verbatim_b) {
        print BOOK "\\begin{verbatim}\n";
     }
     if ($fragment_b) {
-       print MUDELA "\\score { \\melodic {";
+       print MUDELA "\\score { \\melodic {\\octave c';";
+    } else {
+       print MUDELA "default_paper = \\paper { \\paper_sixteen ";
+       print MUDELA "linewidth = 7.\\cm;}";
     }
 
 }
@@ -78,6 +128,7 @@ sub parse_mudela_opts
 
    $verbatim_b =1 if ($s =~ /verbatim/ );
    $fragment_b = 1 if ($s =~ /fragment/ );
+   $center_b = 1 if ($s =~ /center/ );
 }   
 
 sub help
@@ -94,12 +145,15 @@ options:
 sub main
 {
     GetOptions( 'outdir=s', 'outname=s', 'help');
-    help    if ( $opt_help ) ;
+    if ( $opt_help ) {
+       help();
+       $opt_help = 0;  # to extinguish typo check. brr, what a language
+    }
 
     if  (defined ($opt_outdir)) {
        $outdir = $opt_outdir .  "/";
     } else {
-       $outdir = "";
+       $outdir = ".";
     }
    
     if (defined ($ARGV[0])) {
@@ -110,12 +164,17 @@ sub main
     if (defined ($opt_outname)) {
        $outname = $opt_outname ;
     } else { 
-       die "Need to have an output name, use --outname" if ( $infile == "-");
+       die "Need to have an output name, use --outname" if ( $infile eq "-");
        $outname = "$infile.tex";
     }
-    
+
+    my $openout ="$outdir$outname"; 
+    if  ( $infile eq $openout ) {
+       die "The input can't be the output\n";
+    }
+
     open INFILE, "<$infile";
-    open BOOK, ">$outdir$outname";
+    open BOOK, ">$openout";
     while (<INFILE>) {
        if ($mudela_b) {
            if (end_b "mudela") {