groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff-commit] groff/contrib/lilypond ChangeLog groff_lilypond...


From: Bernd Warken
Subject: [Groff-commit] groff/contrib/lilypond ChangeLog groff_lilypond...
Date: Sat, 23 Feb 2013 02:00:42 +0000

CVSROOT:        /cvsroot/groff
Module name:    groff
Changes by:     Bernd Warken <bwarken>  13/02/23 02:00:42

Modified files:
        contrib/lilypond: ChangeLog groff_lilypond.man groff_lilypond.pl 

Log message:
        New version v0.4 of groff_lilypond.
        
        * groff_lilypond_pl: Major rewrite.
        New options: --file_prefix, --temp_dir, and --license. 
        
        * groff_lilypond.man: documents the new features.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/groff/contrib/lilypond/ChangeLog?cvsroot=groff&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/groff/contrib/lilypond/groff_lilypond.man?cvsroot=groff&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/groff/contrib/lilypond/groff_lilypond.pl?cvsroot=groff&r1=1.4&r2=1.5

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/groff/groff/contrib/lilypond/ChangeLog,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ChangeLog   16 Feb 2013 21:26:42 -0000      1.5
+++ ChangeLog   23 Feb 2013 02:00:40 -0000      1.6
@@ -1,3 +1,10 @@
+2013-02-23  Bernd Warken  <address@hidden>
+
+       New version v0.4 of groff_lilypond.
+       * groff_lilypond_pl: Major rewrite.
+       New options: --file_prefix, --temp_dir, and --license. 
+       * groff_lilypond.man: documents the new features.
+
 2013-02-16  Bernd Warken  <address@hidden>
 
        * groff_lilypond.man: Minor corrections.

Index: groff_lilypond.man
===================================================================
RCS file: /cvsroot/groff/groff/contrib/lilypond/groff_lilypond.man,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- groff_lilypond.man  16 Feb 2013 21:26:42 -0000      1.4
+++ groff_lilypond.man  23 Feb 2013 02:00:40 -0000      1.5
@@ -2,7 +2,7 @@
 .SH NAME
 groff\-lilypond \[em] integrate \f[CI]lilypond\f[] parts into \f[CI]groff\f[]
 .
-.\" The .SH was moved to this place in order to appease `apropos'.
+.\" This .SH was moved to this place in order to appease `apropos'.
 .
 .\" --------------------------------------------------------------------
 .\" Legalese
@@ -12,10 +12,21 @@
 This file was written by Bernd Warken
 .MT address@hidden
 .ME .
+.
+Last update: 22 Feb 2013
 ..
 .
 .
 .de copying
+groff_lilypond \[em] integrate lilypond into groff files
+.
+.P
+.EX
+Source file position: <groff-source>/contrib/lilypond/groff_lilypond.man
+Installed position: <prefix>/share/man/man1/groff_lilypond.1
+.EE
+.
+.P
 Copyright \(co 2013
 .RS
 .ft CI
@@ -26,23 +37,49 @@
 .P
 This file is part of
 .ft CI
-groff\\f[R], a free software project.
+GNU groff\\f[R].
 .
 .P
-You can redistribute it and/or modify it under the terms of the
-.nh
+.ft CI
+GNU groff
+.ft R
+is free software is free software: you can redistribute it and/or modify it
+under the terms of the
 .ft CI
 GNU General Public License
 .ft R
-.hy
 as published by the
-.nh
 .ft CI
-Free Software Foundation (FSF)\\f[R],
-.hy
-either version 3 of the License, or (at your option) any later version.
+Free Software Foundation\fR, either
+.ft CI
+version 3
+.ft R
+of the
+.IR License ,
+or
+.RI ( "at your option" )
+any later version.
 .
 .P
+.ft CI
+GNU groff
+.ft R
+is distributed in the hope that it will be useful, but
+.ft CI
+WITHOUT ANY WARRANTY\fR; without even the implied warranty of
+.ft CI
+MERCHANTABILITY
+.ft R
+or
+.ft CI FITNESS FOR A PARTICULAR PURPOSE\fR.
+See the
+.ft CI
+GNU General Public License
+.ft R
+for more details.
+.
+.P
+.P
 You should have received a copy of the
 .nh
 .ft CI
@@ -51,8 +88,7 @@
 .hy
 along with
 .ft CI
-groff\\f[R],
-see the files
+groff\\f[R], see the files
 .nh
 .ft CB
 COPYING
@@ -68,10 +104,14 @@
 .ft R
 source package.
 .
-.P
-You can also visit
-.UR http://\\:www.gnu.org/\\:licenses
+If not, see
+.UR http://\\:www.gnu.org/\\:licenses/
+ the
+.ft CI
+GNU licenses
+.ft R
 .UE .
+.
 ..
 .
 .
@@ -120,14 +160,6 @@
 .OP \%filespec \*[Ellipsis]
 .YS
 .
-.SY groff_lilypond
-.BR -h | --help
-.YS
-.
-.SY groff_lilypond
-.BR -v | --version
-.YS
-.
 .
 .\" --------------------------------------------------------------------
 .SH DESCRIPTION
@@ -144,18 +176,24 @@
 .
 .
 .P
-Without arguments,
+Without arguments or without
+.I filespec
+arguments,
 .FONT CB groff_lilypond
 reads from standard input.
 .
-Several files can be used, including
+Several files can be used; the minus character
 .FONT CB \[em]
-for standard input.
+stands for standard input.
+.
 .
 .\" --------------------------------------------------------------------
 .SH "OPTION OVERVIEW"
 .\" --------------------------------------------------------------------
 .
+.\" --------------------------------------------------------------------
+.SS "Breaking Options"
+.\" --------------------------------------------------------------------
 .TP
 .I breaking options
 .RS
@@ -163,6 +201,7 @@
 .SY
 .OP -h\~\fR|\fB\~--help
 .OP -v\~\fR|\fB\~--version
+.OP \fB\~--license
 .YS
 .RE
 .
@@ -190,13 +229,50 @@
 .
 .TP
 .OP --ly2eps
-.
 Here the
 .FONT CB lilypond
 program creates
 .FONT CI eps
 files directly.
 .
+.
+.RE
+.
+.
+.TP
+.I \%directories and files
+.RS
+.
+.TP
+.OP --file_prefix name
+Normally all temporary files get names that start with the
+.FONT CB ly CI \*[Ellipsis]
+prefix.
+.
+With this option, you can freely change this prefix.
+.
+.
+.TP
+.OP --keep_files
+Normally all temporary files without the
+.FONT CI eps
+files are deleted.
+.
+With this opton, all generated files either by the
+.FONT CB lilypond
+program or other format transposers are kept.
+.
+.
+.TP
+.OP --temp_dir dir
+With this option, you can change the directory in which the temporary
+files are stored.
+.
+No extensions are used for this directory.
+.
+If the directory does not exist it will be created.
+.
+.
 .RE
 .
 .
@@ -243,13 +319,15 @@
 .FONT CI lilypond
 files is given by
 .EX
-FONT CB ".lilypond include \*[Ellipsis]"
+.FONT CB ".lilypond include" I " file_name"
 .EE
 in
 .FONT CI groff
 files.
 .
-One or more file names can be included.
+One file can be included per
+.FONT CI include
+command.
 .
 .
 .P
@@ -289,7 +367,7 @@
 .FONT CI eps
 files, using
 .EX
-.FONT CB "lilypond \-\-ps \-dbackend=eps \-dgs\-load\-fonts \-\-output=" I 
file\-name
+.FONT CB "$ lilypond \-\-ps \-dbackend=eps \-dgs\-load\-fonts \-\-output=" I 
file\-name
 .EE
 for each
 .FONT CB .ly
@@ -377,7 +455,7 @@
 .FONT CB pdf2ps
 program using
 .EX
-.FONT CB "pdf2ps " CI file-name CB ".pdf " CI file-name CB ".ps"
+.FONT R "$ " CB "pdf2ps " CI file-name CB ".pdf " CI file-name CB ".ps"
 .EE
 .
 .
@@ -391,7 +469,7 @@
 .FONT CB ps2eps
 program using
 .EX
-.FONT CB "ps2eps " CI file-name CB ".ps"
+.FONT R "$ " CB "ps2eps " CI file-name CB ".ps"
 .EE
 .
 .
@@ -469,15 +547,15 @@
 .
 .
 .\" --------------------------------------------------------------------
-.SH "AUTHOR"
+.SH "AUTHORS"
 .\" --------------------------------------------------------------------
-.author
+.authors
 .
 .
 .\" --------------------------------------------------------------------
 .SH "COPYING"
 .\" --------------------------------------------------------------------
-.copyleft
+.copying
 .
 .
 .\" --------------------------------------------------------------------

Index: groff_lilypond.pl
===================================================================
RCS file: /cvsroot/groff/groff/contrib/lilypond/groff_lilypond.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- groff_lilypond.pl   11 Feb 2013 22:31:06 -0000      1.4
+++ groff_lilypond.pl   23 Feb 2013 02:00:41 -0000      1.5
@@ -1,262 +1,614 @@
 #! /usr/bin/env perl
 
-# groff_lilypond - integrate lilypond into groff files
+use strict;
+# use warnings;
+
+
+########################################################################
+# legalese
+########################################################################
+
+my $Version = 'v0.4'; # version of groff_lilypond
+my $LastUpdate = '22 Feb 2013';
+
 
-# Source file position: <groff-source>/contrib/lilypond/groff_lilypond.pl
-# Installed position: <prefix>/bin/groff_lilypond
+my $License =    ### `$License' is the license for this file, `GPL' >= 3
+'
+groff_lilypond - integrate lilypond into groff files
 
-# Copyright (C) 2013 Free Software Foundation, Inc.
-# Written by Bernd Warken <address@hidden>.
+Source file position: <groff-source>/contrib/lilypond/groff_lilypond.pl
+Installed position: <prefix>/bin/groff_lilypond
 
-# Last update: 12 Feb 2013
+Copyright (C) 2013 Free Software Foundation, Inc.
+  Written by Bernd Warken <address@hidden>
 
-# This file is part of `groff'.
+This file is part of GNU groff.
 
-# `groff' is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+  GNU groff is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
 
-# `groff' is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
+  GNU groff is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
 
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+  You should have received a copy of the GNU General Public License
+along with groff, see the files COPYING and LICENSE in the top
+directory of the groff source package.  If not, see
+ http://www.gnu.org/licenses/>.
 
+';
+
+##### end legalese
+
+
+########################################################################
+# global variables
 ########################################################################
 
-use strict;
-use warnings;
+use File::Spec;
+use File::Path qw[];
+use Cwd qw[];
+
+
+# `$IsInstalled' is 1 if groff is installed, 0 when in source package
+my $IsInstalled = ( '@VERSION@' =~ /address@hidden@]$/ ) ? 0 : 1;
 
-my $version = 'v0.3';
 
-# for temporary directories see @tempdirs
+my $Prog = &get_prog_name;
+
+my $GroffVersion = ''; # when not installed
+$GroffVersion = '@VERSION@' if ( $IsInstalled ); # @...@ was replaced
+
+
+# command line arguments
+my $EpsMode = 'ly2eps'; # default
+my $KeepFiles = 0;
+
+
+my $TempDir = ''; # temporary directory
+my $FilePrefix = 'ly'; # names of temporary files start with this
+
+# read files or stdin
+my $FilePrefix; # `$TempDir/ly_'
+my $FileNumbered; # `$FilePrefix_[0-9]'
+my $FileLy; # `$FileNumbered.ly'
+
+
+# `§Cwd' stores the current directory
+my $Cwd = Cwd::getcwd; # get current working directory
+
+##### end global variables
+
+
+########################################################################
+# command line arguments
+########################################################################
 
-my $eps_mode = 'ly2eps';
 {
-    my $minus_minus = 0;
+  my $double_minus = 0;
     my @FILES = ();
-    foreach (@ARGV) {
-       if ($minus_minus) {
-           push @FILES, $_;
-           next;
+
+  my $has_arg = '';
+  my $former_arg = ''; # for options with argument
+
+ my $arg = ''; # needed here for subs
+
+  my %only_minus = (
+                   '-' => sub { push @FILES, '-'; },
+                   '--' => sub { $double_minus = 1; },
+                  );
+
+  my @opt;
+
+  $opt[2] = { # option abbreviations of 2 characters
+             '-h' => sub { &usage; exit; },               # `-h'
+             '-v' => sub { &version; exit; },             # `-v'
+            };
+
+
+  $opt[3] = { # option abbreviations of 3 characters
+             '--f' => sub {                               # `--file_prefix'
+               if ( $arg =~ /^.*=(.*)$/ ) { # opt arg is within $arg
+                 $FilePrefix = $1;
+               } else { # opt arg is the next command line argument
+                 $has_arg = '--file_prefix';
+               } # end if for `='
+               next ARGS;
+             }, # end `--file_prefix'
+
+             '--h' => sub { &usage; exit; },               # `--help'
+             '--v' => sub { &version; exit; },             # `--version'
+             '--k' => sub { $KeepFiles = 1; next ARGS; },  # `--keep_files'
+             '--p' => sub { $EpsMode = 'pdf2eps'; next ARGS; }, # `--pdf2eps'
+
+             '--t' => sub {                                # `--temp_dir'
+               if ( $arg =~ /^.*=(.*)$/ ) {
+                 my $dir = $1;
+                 $dir =~ s/^\s*(.*)\s*$/$1/;
+                 my $res = &make_dir ( $dir ) or
+                   die "The directory $dir cannot be used.\n";
+                 $TempDir = $res;
+               } else { # next command line argument is the option argument
+                 $has_arg = '--temp_dir';
+               } # end if for `='
+               next ARGS;
+             }, # end sub of `--t'
+
+           }; # end `$opt[3]'
+
+
+  $opt[4] = { # option abbreviations of 4 characters
+             '--li' => sub { &license; exit; },
+             '--ly' => sub { $EpsMode = 'ly2eps'; next ARGS; },
+            };
+
+  sub check_arg { # is used in `ARGS forever
+    # 2 arguments:
+    # - content of $arg
+    # - a number between 2 and 4
+    my ( $arg, $n ) = @_;
+
+    my $re = qr/^(.{$n})/;
+    if ( $arg =~ $re ) {
+      my $arg = $1;
+      if ( exists $opt[ $n ]-> { $arg } ) {
+       &{ $opt[ $n ] -> { $arg } };
+       next ARGS; # for running `next'
+      }
+    }
+  }
+
+
+ ARGS: foreach (@ARGV) {
+    chomp;
+    s/^\s*(.*)\s*$/$1/;
+    $arg = $_;
+
+    if ( $has_arg ) {
+      # only `--temp_dir' and `--file_prefix' expect an argument
+
+      if ( $has_arg eq '--temp_dir' ) {
+       my $dir = &make_dir ( $arg ) or
+         die "The directory $arg cannot be used.\n";
+
+       $TempDir = $dir;
+       $has_arg = '';
+       next ARGS;
+      }
+
+      if ( $has_arg eq '--file_prefix' ) {
+       $FilePrefix = $arg;
+       $has_arg = '';
+       next ARGS;
        }
-       if (/^--$/) { # argument `--'
-           $minus_minus = 1;
+
+      die "Wrong value for \$has_arg";
+    }
+
+
+    if ( $double_minus ) { # `--' was former arg
+      push @FILES, $arg;
            next;
-       } elsif (/^(-|[^-].*)$/) { # argument `-' or file name
-           push @FILES, $_;
+    } # file arg after --
+
+
+    if ( $arg =~ /^[^-].*$/ ) { # arg is a file name without `-'
+      push @FILES, $arg;
            next;
-       } elsif (/^(-v|--version).*$/) {
-           &version;
-           goto QUIT;
-       } elsif (/^(-h|--help).*$/) {
-           &usage;
-           goto QUIT;
-       } elsif (/^--pdf2eps.*$/) {
-           $eps_mode = 'pdf2eps';
-           shift;
-       } elsif (/^--ly2eps.*$/) {
-           $eps_mode = 'ly2eps';
-           shift;
-       } else {
-           die "wrong argument for groff_lilypond: $_";
        }
+
+
+    # now only args with starting '-'
+
+    if ( exists $only_minus { $arg } ) {
+      &{ $only_minus { $arg } };
+      next;
     }
-    @ARGV = @FILES;
-}
 
-my $dir_time;
-{
-    $dir_time = localtime(time());
-    $dir_time =~  tr/: /_/;
+    # deal with @opt
+    &check_arg ( $arg, $_ ) foreach ( qw[ 4 3 2 ] );
 
-    use Time::HiRes qw[];
-    (my $second, my $micro_second) = Time::HiRes::gettimeofday();
 
-    $dir_time = $dir_time . '_' . $micro_second;
-}
+    # wrong argument
+    print STDERR "Wrong argument for groff_lilypond: $_\n";
+    next;
 
-my $tempdir;
-{
-    use File::Path qw[];
 
-    use Cwd qw[];
-    my $cwd = Cwd::getcwd();
-    $cwd =~ s(/*$)(/tmp);
+  } # end ARGS: foreach @ARGV
 
-    my $home = $ENV{'HOME'};
-    $home =~ s(/*$)(/tmp);
 
-    my @tempdirs = ('/tmp',  $home, $cwd);
-    foreach (@tempdirs) {
-       if (-e $_) {   # exists
-           if (-d) {  # is directory
-               next unless (-w $_);   # not writable
-           }
-       } else {       #  does not exist
-           File::Path::make_path $_, {mask=>oct('0700')} or next;
-       }
-       # directory $_ exists and is writable
-       my $dir = $_;
-       $dir =~ s(/+)(/)g;
-       $dir =~ s(/*$)(/groff);
-       if (-e $dir) {     # exists
-           next unless (-d $dir); # if no dir
-           next unless (-w $dir); # if not writable
-       } else {
-           File::Path::make_path $dir, {mask=>oct('0700')} or next;
+  if ( $has_arg ) {
+    print STDERR "Option --temp_dir needs an argument.\n";
        }
 
-       $dir =~ s(/*$)(/$dir_time);
-       File::Path::make_path $dir, {mask=>oct('0700')} or next;
-       not -e $dir or not -d $dir or not -w $dir and next;
 
-       $tempdir = $dir; # tmp/groff/time
-       last;
-    }
+  @ARGV = @FILES;
+
+
 }
-$tempdir =~ s(/*$)(/);
 
-my $file_prefix = $tempdir . 'ly' . '_';
-my $ly_number = 0;
-my $file_numbered;
+# end command line arguments
 
-my $file_ly;
-my $lilypond_mode = 0;
 
-foreach (<>) {
-    chomp;
-    if (/^(\.\s*lilypond\s+include)(.*$)/) { # `.lilypond include file...'
-       my $args = $2;
-       $args =~ s/\s*$//;
-       my @files = ();
-       while ($args) {
-           if ($args =~ /^\s+"([^"]+)"(.*)$/) { # ` "file name"...'
-               push @files, $1;
-               $args = $2;
-           } elsif ($args =~ /^\s+'([^']+)'(.*)$/) { # ` 'file name'...'
-               push @files, $1;
-               $args = $2;
-           } elsif ($args =~ /^\s+(\S+)(.*)$/) { # ` filename...'
-               push @files, $1;
-               $args = $2;
+########################################################################
+# temporary directory .../tmp/groff/USER/lilypond/TIME
+########################################################################
+
+unless ( "$TempDir" ) { # not given by `--temp_dir'
+
+  my $home;
+  {
+    $home = $ENV{'HOME'};
+    $home =~ s(/*$)(/tmp);
            }
+
+
+  my $cwd;
+  {
+    $cwd = $Cwd; # current working directory
+    $cwd =~ s(/*$)(/tmp);
        }
-       unless ($lilypond_mode) { # then FILE_LY must be opened
-           $ly_number++;
-           $file_numbered = $file_prefix . $ly_number;
-           $file_ly =  $file_numbered . '.ly';
 
-           open FILE_LY, ">", $file_ly or
-               die "cannot open .ly file: $!";
+
+  my $user = $ENV{'USER'};
+  {
+    $user =~ s([\s/])()g;
        }
 
-       foreach (@files) { # included .ly files
-           my $file = $_;
-           unless ($file) {
-               print STDERR "Empty file name at `.lilypond include'\n";
-               next;
+
+  use Time::HiRes qw[];
+
+
+  { # search for or create a temporary directory
+
+    my $path_extension = '/groff/';
+    $path_extension .= $user. '/' if ($user);
+    $path_extension .= 'lilypond/';
+
+
+    my @temp_dirs = ('/tmp',  $home, $cwd);
+    foreach (@temp_dirs) {
+
+      my $dir_begin = $_ . $path_extension; # beginning of directory name
+      my $dir_free = 0; # `1' when directory not exists, free for creating 
+      my $dir; #final directory name in `until' loop
+
+      until ( $dir_free ) {
+        $dir = $dir_begin . &dir_time;
+        if ( -d $dir ) {
+          Time::HiRes::usleep(1); # wait 1 microsecond
+        } else {
+          my $res = &make_dir( $dir );
+          $dir = $res;
+          $dir_free = 1;
            }
-           unless (-e $file) {
-               print STDERR
-                   "File `$file' at `.lilypond include' does not exist.\n";
-               next;
            }
-           unless (-r $file) {
-               print STDERR
-                   "File `$file' at `.lilypond include' is not readable.\n";
-               next;
+
+      next unless ( -d $dir && -w $dir  );
+
+      $TempDir = $dir; # tmp/groff/USER/lilypond/TIME
+      last;
+    } # end foreach tmp directories
+  } # end to create a temporary directory
+} # end temporary directory
+$TempDir =~ s(/*$)(/);
+
+print STDERR "Temporary directory: $TempDir\n";
+
+
+# end temporary directory
+
+
+########################################################################
+# read files or stdin
+########################################################################
+
+{ # read files or stdin
+  my $ly_number = 0;
+  my $lilypond_mode = 0;
+
+  my $arg1 = ''; # first argument for `.lilypond'
+  my $arg2 = ''; # argument for `.lilypond include'
+
+  $FilePrefix = $TempDir . $FilePrefix . '_';
+
+  my %lilypond_args = (
+
+                      'start' => sub {
+                        die "Line `.lilypond stop' expected."
+                          if ($lilypond_mode);
+                        $lilypond_mode = 1;
+                        $ly_number++;
+                        $FileNumbered = $FilePrefix . $ly_number;
+                        $FileLy =  $FileNumbered . '.ly';
+                        open FILELY, ">", $FileLy or
+                          die "cannot open *.ly file: $!";
+                        next LILYPOND;
+                      },
+
+
+                      'end' => sub {
+print STDERR "start: \n";
+
+                        die "Line `.lilypond start' expected."
+                          unless ( $lilypond_mode );
+                        $lilypond_mode = 0;
+                        close FILELY;
+                        &create_eps;
+                        next LILYPOND;
+                      },
+
+
+                      'include' => sub { # `.lilypond include file...'
+
+                        my $file = &check_file( $arg2 );
+                        next LILYPOND unless ( $file );
+                        # file can be read now
+
+                        unless ( $lilypond_mode ) {
+                          # then FILELY must be opened
+                          $ly_number++;
+                          $FileNumbered = $FilePrefix . $ly_number;
+                          $FileLy =  $FileNumbered . '.ly';
+
+                          open FILELY, ">", $FileLy or
+                            die "cannot open .ly file: $!";
            }
 
-           open FILE, "<", "$file" # for reading
-               or die "file `$file' could not be read: $!";
+                        open FILE, "<", $file                # for reading
+                          or die "File `$file' could not be read: $!";
            foreach (<FILE>) {
                chomp;
-               print FILE_LY $_ . "\n";
+                          print FILELY $_ . "\n";
            }
            close FILE;
-       }
+
        unless ($lilypond_mode) {
-           close FILE_LY;
+                          close FILELY;
            &create_eps;
+                        } # end non-lilypond-mode
+
+                        next LILYPOND;
+                      }, # end `.lilypond include'
+
+                     ); # end definition %lilypond_args
+
+
+  sub check_file { # for argument of `.lilypond include'
+    my $file = shift;
+print STDERR "##### $file\n";
+    unless ( $file ) {
+      print STDERR
+       'Line ".lilypond include" without argument';
+      return '';;
        }
-    } elsif (/^\.\s*lilypond\s+start/) { # `.lilypond start'
-       die "Line `.lilypond stop' expected." if ($lilypond_mode);
-       $lilypond_mode = 1;
-       $ly_number++;
-       $file_numbered = $file_prefix . $ly_number;
-       $file_ly =  $file_numbered . '.ly';
-       open FILE_LY, ">", $file_ly or
-           die "cannot open .ly file: $!";
-       next;
-    } elsif (/^\.\s*lilypond\s+stop/) { # `.lilypond stop'
-       die "Line `.lilypond start' expected." unless ($lilypond_mode);
-       $lilypond_mode = 0;
-       close FILE_LY;
-       &create_eps;
-       next;
-    } elsif ($lilypond_mode) {
-       print FILE_LY $_ . "\n";
+
+    unless ( -f $file && -r $file ) {
+      print STDERR 'Argument "' . $file .
+       '" in ".lilypond include" ' .
+         'is not a readable file' . "\n";
+      return '';
+    }
+
+    return $file;
+  } # end sub check_file()
+
+
+ LILYPOND: foreach (<>) {
+    chomp;
+
+    my $line = $_;
+
+
+    # now the lines with '.lilypond ...'
+
+    if ( /^[.']\s*lilypond\s*(.*)\s*(.*)\s*$/ ) { # .lilypond ...
+      my $arg1 = $1;
+      my $arg2 = $2;
+      if ( exists $lilypond_args{ $arg1 } ) {
+       & { $lilypond_args{ $arg1 } }
     } else {
+       # not a suitable argument of `.lilypond'
        print $_ . "\n";
     }
-}
+      next LILYPOND;
+    }
 
-unlink glob $file_prefix . "*.[a-df-z]*";
+    if ( $lilypond_mode ) { # do lilypond-mode
+      print FILELY $line . "\n" or # see `.lilypond start'
+       die "could not print to FILELY in lilypond-mode\n";
+      next LILYPOND;
+    } # do lilypond-mode
+
+    # unknown line without lilypond
+    unless ( /^[.']\s*lilypond/ ) { # not a `.lilypond' line
+      print $line . "\n"; # to STDOUT
+      next LILYPOND;
+    }
+
+
+  } # end foreach <>
+} # end read files or stdin
+
+
+# Remove all temporary files except the eps files.
+# With --keep_files, no files are removed.
+unlink glob $FilePrefix . "*.[a-df-z]*" unless $KeepFiles;
+
+# end read files and stdin
+
+
+########################################################################
+# subs
+########################################################################
 
 sub create_eps() {
-    if ($eps_mode =~ /^pdf2eps$/) { # `--pdf2eps'
+  if ($EpsMode eq 'ly2eps') { # `--ly2eps'
+    # `$ lilypond --ps -dbackend=eps -dgs-load-fonts
+    #      output=file_without_extension file.ly'
+    # extensions are added automatically
+    system 'lilypond', '--ps', '-dbackend=eps', '-dinclude-eps-fonts',
+      '-dgs-load-fonts', "--output=$FileNumbered", $FileLy
+       and die 'Program lilypond does not work.';
+
+    foreach (glob $FileNumbered . '-*' . '.eps') {
+      print '.PSPIC ' . $_ . "\n";
+    } # end foreach *.eps
+
+  } elsif ($EpsMode eq 'pdf2eps') { # `--pdf2eps'
        # `$ lilypond --pdf --output=file_with_no_extension file.ly'
-       # .pdf is added automatically
-       system "lilypond", "--pdf", "--output=$file_numbered", $file_ly
+    # Extension .pdf is added automatically
+    system "lilypond", "--pdf", "--output=$FileNumbered", $FileLy
            and die 'Program lilypond does not work.';
        # `$ pdf2ps file.pdf file.ps'
-       system 'pdf2ps', $file_numbered . '.pdf', $file_numbered . '.ps'
+    system 'pdf2ps', $FileNumbered . '.pdf', $FileNumbered . '.ps'
            and die 'Program pdf2ps does not work.';
        # `$ ps2eps file.ps'
-       system 'ps2eps', $file_numbered . '.ps'
+    system 'ps2eps', $FileNumbered . '.ps'
            and die 'Program ps2eps does not work.';
 
        # print into groff output
-       print '.PSPIC ' . $file_numbered  . '.eps' . "\n";
-    } elsif ($eps_mode =~ /^ly2eps$/) { # `--ly2eps'
-       # `$ lilypond --ps -dbackend=eps -dgs-load-fonts
-       #      output=file_without_extension file.ly'
-       # extensions are added automatically
-       system 'lilypond', '--ps', '-dbackend=eps',
-       '-dgs-load-fonts', "--output=$file_numbered", $file_ly
-           and die 'Program lilypond does not work.';
-
-       foreach (glob $file_numbered . '-*' . '.eps') {
-           print '.PSPIC ' . $_ . "\n";
-       }
+    print '.PSPIC ' . $FileNumbered  . '.eps' . "\n";
 
     } else {
-       die "Wrong eps mode: $eps_mode";
+    die "Wrong eps mode: $EpsMode";
     }
-}
+} # end sub create_eps()
+
 
-sub version {
-    print "groff_lilypond version $version is part of groff\n";
+sub dir_time() { # time and microseconds for temporary directory name
+  my $res;
+  my ( $sec, $min, $hour, $day_of_month, $month, $year,
+       $weak_day, $day_of_year, $is_summer_time ) =
+        localtime( time() );
+
+  $year += 1900;
+  $month += 1;
+  $month = '0' . $month if ( $month < 10 );
+  $day_of_month = '0' . $day_of_month if ( $day_of_month < 10 );
+  $hour = '0' . $hour if ( $hour < 10 );
+  $min = '0' . $min if ( $min < 10 );
+  $sec = '0' . $sec if ( $sec < 10 );
+
+  $res = $year . '-' . $month . '-' . $day_of_month . '_';
+  $res .= $hour . '-' . $min . '-' . $sec;
+
+  (my $second, my $micro_second) = Time::HiRes::gettimeofday();
+  $res .= '_' . $micro_second;
+} # end sub dir_time(). time for temporary directory
+
+
+sub get_prog_name {
+  my ($v, $d, $f) = File::Spec->splitpath($0);
+  return $f;
 }
 
-sub usage {
-    print <<EOF
-groff_lilypond [options] [filename]
-groff_lilypond -h|--help
-groff_lilypond -v|--version
-Read a roff file or standard input and transform `lilypond' parts
-(everything between `.lilypond start' and `.lilypond end')
-into temporary EPS-files that can be read by groff using `.PSPIC'.
-Options are
---pdf2eps
---ly2eps
-for influencing the way how the EPS files for roff display are generated.
-EOF
+
+sub license {
+  &version;
+  print $License;
 }
 
 
+sub make_dir() { # make directory or check if exists
+  my $arg = $_[0];
+  $arg =~ s/^\s*(.*)\s*$/$1/;
+
+  unless ( m<^/> ) { # starts not with `/', so it's not absolute
+    my $cwd = $Cwd;
+    chomp $cwd;
+
+    die "Could not create directory $arg because current working " .
+      "directory is not writable." unless ( -w $cwd );
+
+    $cwd =~ s(/*$)(/);
+
+    $arg = $cwd . $arg;
+  }
+
+
+  return 0 unless ( $arg );
+
+  if ( -d $arg ) { # $arg is a directory
+    return 0 unless ( -w $arg );
+  } else { # $arg is not a directory
+    if ( -e $arg ) { # $arg exists
+      -w $arg && unlink $arg || die "could not delete " . $arg . ": $!";
+    } # end of if, existing $arg
+
+    File::Path::make_path( $arg, {mask=>oct('0700')}) #  `mkdir -P'
+       or die "Could not create directory '$arg': $!";
+
+  } # end if, else: not a directory
+  return $arg;
+} # end sub mike_dir()
+
+
+sub usage { # for `--help'
+
+  my $usage =
+'
+groff_lilypond [options] [--] [filename ...]
+
+# breaking options:
+groff_lilypond -h|--help               # usage
+groff_lilypond -v|--version            # version information
+groff_lilypond --license               # the license is GPL >= 3
+
+Read a roff file or standard input and transform `lilypond' . "'" .
+' parts
+(everything between `.lilypond start' . "'" . 
+' and `.lilypond end' . "'" . ') into
+temporary EPS-files that can be read by groff using `.PSPIC' . "'" .
+'.  There
+is also a command (`.lilypond include file_name' . "'" .
+') that can include a
+complete lilypond file into the groff document.
+
+There are 2 options for influencing the way how the EPS files for the
+roff display are generated:
+--pdf2eps       `lilypond' . "'" . ' generates a pdf file which is transformed
+--ly2eps        `lilypond' . "'" . ' generates EPS files directly
+
+--keep_files    do not delete any temporary files
+
+Options with an argument:
+--file_prefix=...   start for the names of temporary files
+--temp_dir=...      provide the directory for temporary files (is created).
+                    Directories must start with `/' . "'" .
+', this is done by the option.
+
+'; print $usage;
+
+} # end sub usage()
+
+
+sub version { # for `--version'
+    print $Prog . " version " . $Version . " of " . $LastUpdate .
+       " is part of GNU groff";
+    if ( $GroffVersion ) {
+      print "\n version " . $GroffVersion . "\n";
+    } else  {
+      print ".\n";
+    }
+} # end sub version()
+
+
+# end subs
+
+
+########################################################################
+# leaving file
+########################################################################
+
 QUIT:
+
+
+########################################################################
+### Emacs settings
+# Local Variables:
+# mode: CPerl
+# End:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]