lilypond-1.3.23
[lilypond.git] / scripts / ly2dvi-old.sh
blob2020a405412700b6fe5a1c86b314b84d7f51cc2d
1 #!/bin/sh
3 # Script to make a LaTeX file for Lilypond
5 # Written by Jan Arne Fagertun <Jan.A.Fagertun@energy.sintef.no>
6 # Sat Nov 22 22:26:43 CET 1997
8 # $Id: ly2dvi-old.sh,v 1.1 1998/10/19 10:09:06 fred Exp $
10 # Original LaTeX file made by Mats Bengtsson, 17/8 1997
13 VERSION="0.12.jcn1"
14 NAME=ly2dvi.sh
15 IDENTIFICATION="$NAME $VERSION"
16 NOW=`date`
17 echo "$IDENTIFICATION" 1>&2
19 # TODO:
20 # prevent orphaned "Lily is here" strings
22 # NEWS
24 # 0.12.jcn1
25 # - mudelaDefs really fixed (sorry, PC)
27 # 0.12
28 # - -S/--sourcedir switch
31 #0.11.jcn3
32 # - mudelaDefs fixes, (thanks PC)
33 #0.11.jcn2
34 # - pass -I, --include to Lily
35 # - bf: split $LILYINCLUDE and try all dirs
36 # - bf: geometry left/top
38 #0.11.pc
39 # - fix backslash gobbling, reduce number of separate processes used
40 # - require readable rc files, allow rc file in /usr/local/share/lilypond/lilyrc
41 # - use latex path, not tex path
42 # - Don't override if kpsepath returns non-NULL
43 # - Don't clobber x.tex if it wasn't created by ly2dvi
46 #0.11.jcn1
47 # - find .fly files too
49 #0.11.hwn1
50 # - height vs heigth
51 # - robustification: give \nonstopmode as LaTeX arg; no hanging if no TeX file.
52 # - robustification: notice failed cp.
54 #0.11
55 # - more papersizes (thanks Han-Wen) - don't expect LaTeX to accept all...
56 # - -W,--Width= : set paper width (points)
57 # - -H,--Height= : set paper height (points)
58 # - -H and -W is used only when an unknown papersize is to be specified,
59 # and has to be combined with a papersize option known to LaTeX
60 #NB! - -F,--headers= : name of additional LaTeX headers input file.
61 #NB! Changed from -H to -F
62 # - -d,--dependencies : passed to lilypond
65 #0.10.jcn1
66 # - HEIGHT -> HEIGHT
67 # - vertical margins (for a4), same on both sides
68 # - textheight from lilypond output file (mudelapapertextheight)
69 # - piece titling
70 # - mudelapiece, mudelaopus
72 #0.10
73 # - -K,--keeplilypond : Keep lilypond output files (default delete)
74 # - -k,--keeply2dvi : Keep ly2dvi output files (default delete)
75 # - -L,--landscape : Set landscape orientation
76 # - -N,--nonumber : Turn off page numbering (\pagestyle{empty})
77 # - Could not reinsert "\usepackage[T1]{fontenc}" because
78 # "los-toros" won't work with it
79 # - Ekstra LaTeX headers from input file
80 #0.9.hwn1
81 # - option to remove output of lily
82 # 0.9
83 # - Trap Lilypond abort
84 # - Replaced "\usepackage[T1]{fontenc}" with
85 # \usepackage[latin1]{inputenc} (takk, Mats)
86 # - Removed "()" around "\LilyIdString" (Janne didn't want it)
87 # 0.8 - Trap Lilypond segmentation fault
88 # - Function for cleanup
89 # - Trap line
90 # - More human-readable variables
91 # - Some logics concerning rc-files
92 # 0.7
93 # - Improved Lilypond error checking
94 # - Output orientation (landscape...). Overrides mudela file
95 # variable orientation="landscape";
96 # - Paper width and height put into variables (only A4!)
97 # - Adjusted top margin to default.....
99 #TODO
100 # - Include more papersizes.
101 # - Manual page.......
102 # 0.6.jaf2
103 # - LILYINCLUDE update
105 # 0.6.hwn1
106 # - handle LILYINCLUDE
107 # - --output
109 # 0.6
110 # - Source rc-files, if present. Files are:
111 # /usr/local/share/lilyrc /etc/lilyrc $HOME/.lilyrc ./.lilyrc
112 # - tee output from Lilypond
113 # - Handles margins for A4 paper (equal on both sides)
114 # - new option -s (--separate) for one LaTeX run per file,
115 # else all files are run together
117 # 0.5
118 # - More useful ("two-level") debug.
119 # - The Q&D hack to find file names and not handling \include
120 # is replaced by grabbing output file names from Lilypond.
121 # = Detects multiple output files - adds them when running
122 # LaTeX.
123 # - Works with multiple input files - no matter if they are
124 # (a mix of) input to or output from Lilypond.
126 #TODO
127 # - Still no margins handling.
128 # - We have to discuss how to handle multiple output files
129 # from Lilypond - 'ly2dvi standchen' gives a rather odd
130 # result....
132 # 0.4.1
133 # - Always exit after printing help info
134 # 0.4
135 # - Changes to ensure for more strict grep'ing of parameters
136 # Thanks to from G.B.Stott@bolton.ac.uk
137 # - More efficient use of sed -e 's///' -e 's///'
138 # Thanks to Johan Vromans <jvromans@squirrel.nl> and GBS
139 # - Ask tex for location of titledefs.tex (Thanks to JV)
140 # - Accept only exact match of "\def\mudelacomposer{"
141 # (or whatever mudela* defined in titledefs.tex)
142 # - Even more efficient use of sed (Thanks to JV)
143 # - Default file name for single output file implemented.
144 # - Moved help into function - finally included from 0.1.jcn1
146 #TODO
147 # - Still doesn't handle \include
148 # - The Q&D for finding output file name from the sequence of
149 # \paper \output \midi \output really needs to be looked at.
150 # I have improved it a lot, but it's only capable of finding
151 # one (the last) file name.
152 # Well, I have to rewrite this entirely to handle \include,
153 # then I can fix it.
154 # - Still no margins handling.
156 #WARNING
157 # - Some lines of output from lilypond do NOT start
158 # at first character position, therefore I have removed "^"
159 # in sed'ing and grep'ing.
161 # 0.3.hwn1
162 # - add "Creator: " line to output
164 # 0.3
165 # - multiple input files to make score from several files
166 # (extra files assumed to be Lilypond output)
167 # - cp dvi-file instead of mv, to allow for xdvi reload
168 # - check for illegal long options
169 # - put in pt in text width, if not given
170 # - put in \nonstopmode in LaTeX file
171 # - restored LaTeX exit value check
173 # 0.2.1
174 # - temporarily omit LaTeX exit value check
175 # - remove ALL temporary files
177 # 0.2
178 # - fix for solaris - included from 0.1.jcn1
179 # - long option hack - included from 0.1.jcn1 - modified
180 # - moved help into function - NOT included from 0.1.jcn1 yet
181 # - various improvements - included from 0.1.jcn1
182 # - find mudela definitions from titledefs.tex
183 # - find papersize from lilypond output file (mudelapapersize),
184 # overridden by option '-p size' or '--papersize=size'
185 # - option -l lang or --language=lang overrides
186 # lilypond output file definition (mudelalanguage)
187 # - textwidth from lilypond output file (mudelapaperlinewidth)
189 # 0.1.jcn1
190 # - fix for solaris
191 # - long option hack
192 # - moved help into function
195 # Clean up
197 cleanup() {
198 if [ "$KEEP_LY2DVI_OUTPUT" != "Y" ]
199 then
200 [ -n "$LatF" -a -f "$LatF" ] && rm -f $LatF
201 [ -n "$LOGFILE" -a -f "$LOGFILE" ] && rm -f $LOGFILE
202 [ -n "$FN" ] && rm -f $FN.*
203 for F in *$$* $TMP/*$$*
205 rm -f $F
206 done
208 if [ "$KEEP_LILY_OUTPUT" != "Y" ]
209 then
210 for F in $LILY_OUTPUT_FILES
212 [ -f $F ] && rm -f $F
213 done
218 # print usage
220 help() {
221 cat << EOF
222 Generate dvi file from mudela or lilypond output
223 Usage: $0 [OPTION]... [FILE]...
225 Options:
226 -D,--debug increase verbosity
227 -F,--headers= name of additional LaTeX headers file
228 -H,--Height= set paper height (points) (see manual page)
229 -I,--include=DIR add DIR to search path of LilyPond
230 -K,--keeplilypond keep lilypond output files
231 -L,--landscape set landscape orientation
232 -N,--nonumber switch off page numbering
233 -O,--orientation= set orientation (obsolete - use -L instead)
234 -W,--Width= set paper width (points) (see manual page)
235 -d,--dependencies tell lilypond make a dependencies file
236 -h,--help this help text
237 -k,--keeply2dvi keep ly2dvi output files
238 -l,--language= give LaTeX language (babel)
239 -o,--output= set output directory
240 -p,--papersize= give LaTeX papersize (eg. a4)
241 -s,--separate run all files separately through LaTeX
242 -S,--sourcedir set sourcedir
244 files may be (a mix of) input to or output from lilypond(1)
250 # SVr4 echo swallows backslashes, and there's no way to turn it off.
251 # Therefore use Echo whenever backslashes may be important.
252 # printf is in the posix.2 standard -- which means it's in
253 # all modern shells.
255 Echo() {
256 printf "%s\n" "$@"
260 setPaperZize() {
261 case "$PAPERSIZE" in
262 a0*)
263 PWIDTH=2389
264 PHEIGHT=3381
265 PAPERSIZE=a0paper
267 a1|a1p*)
268 PWIDTH=1690
269 PHEIGHT=2389
270 PAPERSIZE=a1paper
272 a2*)
273 PWIDTH=1194
274 PHEIGHT=1690
275 PAPERSIZE=a2paper
277 a3*)
278 PWIDTH=845
279 PHEIGHT=1194
280 PAPERSIZE=a3paper
282 a4*)
283 PWIDTH=597
284 PHEIGHT=845
285 PAPERSIZE=a4paper
287 a5*)
288 PWIDTH=423
289 PHEIGHT=597
290 PAPERSIZE=a5paper
292 a6*)
293 PWIDTH=298
294 PHEIGHT=423
295 PAPERSIZE=a6paper
297 a7*)
298 PWIDTH=211
299 PHEIGHT=298
300 PAPERSIZE=a7paper
302 a8*)
303 PWIDTH=305
304 PHEIGHT=211
305 PAPERSIZE=a8paper
307 a9*)
308 PWIDTH=105
309 PHEIGHT=305
310 PAPERSIZE=a9paper
312 a10*)
313 PWIDTH=74
314 PHEIGHT=105
315 PAPERSIZE=a10paper
317 b0*)
318 PWIDTH=2847
319 PHEIGHT=4023
320 PAPERSIZE=b0paper
322 b1*)
323 PWIDTH=2012
324 PHEIGHT=2847
325 PAPERSIZE=b1paper
327 b2*)
328 PWIDTH=1423
329 PHEIGHT=2012
330 PAPERSIZE=b2paper
332 b3*)
333 PWIDTH=1006
334 PHEIGHT=1423
335 PAPERSIZE=b3paper
337 b4*)
338 PWIDTH=712
339 PHEIGHT=1006
340 PAPERSIZE=b4paper
342 b5*)
343 PWIDTH=503
344 PHEIGHT=712
345 PAPERSIZE=b5paper
347 archA)
348 PWIDTH=650
349 PHEIGHT=867
351 archB)
352 PWIDTH=867
353 PHEIGHT=1301
355 archC)
356 PWIDTH=1301
357 PHEIGHT=1734
359 archD)
360 PWIDTH=1734
361 PHEIGHT=2602
363 archE)
364 PWIDTH=2602
365 PHEIGHT=3469
367 flsa|flse)
368 PWIDTH=614
369 PHEIGHT=940
371 halfletter)
372 PWIDTH=397
373 PHEIGHT=614
375 ledger)
376 PWIDTH=1229
377 PHEIGHT=795
379 legal)
380 PWIDTH=614
381 PHEIGHT=1012
383 letter)
384 PWIDTH=614
385 PHEIGHT=795
387 note)
388 PWIDTH=542
389 PHEIGHT=723
392 echo ""
393 echo $0": unknown papersize -- "$PAPERSIZE
394 echo ""
396 esac
399 doRcFiles()
402 # RC-files ?
404 for D in /usr/local/share/ /usr/local/share/lilypond/ /etc/ $HOME/. ./.
406 RCfile=$D"lilyrc"
407 [ -r $RCfile ] && . $RCfile
408 done
409 fORI=$ORIENTATION
410 fLNG=$LANGUAGE
411 fPSZ=$PAPERSIZE
412 fLHF=$LATEXHF
413 unset ORIENTATION LANGUAGE PAPERSIZE LATEXHF
419 # Trap function (cleanup)
424 trap cleanup 0 9 15
429 # Various defaults
431 [ -z "$TMP" ] && TMP=/tmp
432 if [ ! -d $TMP ]
433 then
434 $debug_echo $IDENTIFICATION": temporary directory "$TMP" not found, set to /tmp"
435 TMP=/tmp
437 LOGFILE=$TMP/lilylog.$$ # Logfile for lilypond
438 PAPERSIZE=a4 # Default papersize name
439 PWIDTH=597 # Default paperwidth
440 PHEIGHT=845 # Default paperheight
441 PNUM="%" # Page numbering on
442 LILYOPTS="" # Options to lilypond
443 SOURCEDIR=""
444 LILYPOND_EXECUTABLE=lilypond
445 doRcFiles
449 # Keywords defined in titledefs.tex
451 TF="`kpsewhich -n latex tex titledefs.tex`"
452 MU_DEF=""
453 if [ -r "${TF:=/usr/local/share/texmf/tex/lilypond/titledefs.tex}" ]
454 then
455 MU_DEF=`sed -n -e 's/.*newcommand\*{.\(mudela[^}]*\)}.*$/\1/p' "$TF"`
458 : "${MU_DEF:=mudelatitle mudelasubtitle mudelacomposer \
459 mudelameter mudelaopus mudelaarranger mudelapiece \
460 mudelapoet mudelainstrument \
464 # debugging
466 debug_echo=:
468 # All files in one LaTeX run
470 SEPFILE=N
472 # Find command line options and switches
474 # "x:" x takes argument
476 switches="DF:H:I:KLNO:W:dhkl:o:p:S:s\?"
477 options=""
479 # ugh, "\-" is a hack to support long options
480 # while getopts \-:$options$switches O
481 # must be in double quotes for bash-2.0
482 while getopts "\-:$options$switches" O
484 $debug_echo "O: \`$O'"
485 $debug_echo "arg: \`$OPTARG'"
486 case $O in
488 [ $debug_echo = echo ] && set -x
489 debug_echo=echo
492 LATEXHF=$OPTARG
495 PHEIGHT=$OPTARG
498 LILYOPTS="$LILYOPTS -I $OPTARG"
499 LILYINCLUDE="$LILYINCLUDE:$OPTARG"
502 KEEP_LILY_OUTPUT=Y
505 ORIENTATION=landscape
508 ORIENTATION=$OPTARG
511 PNUM="\pagestyle{empty}"
514 PWIDTH=$OPTARG
517 LILYOPTS=$LILYOPTS" -d"
520 help;
521 exit 0
524 KEEP_LY2DVI_OUTPUT=Y
527 LANGUAGE=$OPTARG
530 OUTPUTDIR=$OPTARG
533 PAPERSIZE=$OPTARG
536 SEPFILE=Y
539 SOURCEDIR=$OPTARG
541 \? )
542 help;
543 exit -1
545 # a long option!
547 $debug_echo "long option: \`$OPTARG'"
548 case "$OPTARG" in
549 He*|-He*)
550 PHEIGHT"`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"=
552 W*|-W*)
553 PWIDTH="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
555 dep*|-dep*)
556 LILYOPTS="$LILYOPTS -d"
558 d*|-d*)
559 [ $debug_echo = echo ] && set -x
560 debug_echo=echo
562 hea*|-hea*)
563 LATEXHF="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
565 h*|-h*)
566 help;
567 exit 0
569 i*|-i*)
570 dir="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
571 LILYOPTS="$LILYOPTS --include=$dir"
572 LILYINCLUDE="$LILYINCLUDE:$dir"
574 keepli*|-keepli*)
575 KEEP_LILY_OUTPUT=Y
577 k*|-k*)
578 KEEP_LY2DVI_OUTPUT=Y
580 land*|-land*)
581 ORIENTATION=landscape
583 lang*|-lang*)
584 LANGUAGE="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
586 n*|-n*)
587 PNUM="\pagestyle{empty}"
589 or*|-or*)
590 ORIENTATION="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
592 ou*|-ou*)
593 OUTPUTDIR="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
595 p*|-p*)
596 PAPERSIZE="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
598 separa*|-sep*)
599 SEPFILE=Y
601 sourcedir*|-sourcedir*)
602 SOURCEDIR=$OPTARG
604 *|-*)
605 echo "$0: illegal option -- \"$OPTARG\""
606 help;
607 exit -1
609 esac
610 esac
611 done
612 shift `expr $OPTIND - 1`
614 if [ "$SOURCEDIR" != "" ]; then
615 # apparently MakeTeXTFM can't handle relative dirs
616 SOURCEDIR=`cd $SOURCEDIR; pwd`
617 LILYINCLUDE="$SOURCEDIR/init:$SOURCEDIR/mf/out:$LILYINCLUDE"
618 TEXINPUTS="$SOURCEDIR/tex:$TEXINPUTS:"
619 MFINPUTS="$SOURCEDIR/mf:$MFINPUTS:"
620 LILYPOND_EXECUTABLE="$SOURCEDIR/lily/out/lilypond"
621 export MFINPUTS LILYPOND_EXECUTABLE TEXINPUTS SOURCEDIR
625 # Input file name
627 if [ "$1" = "" ]
628 then
629 help
630 $debug_echo "$IDENTIFICATION: No input file name given"
631 exit 1
633 # regexp_quote -- quote a string as a regular expression for egrep or sed
634 regexp_quote(){
635 Echo "$@" | sed 's/\([]\[\.*?+^$]\)/\\\1/g'
639 mudelaDefs(){
640 # Include \def\mudela-definitions
641 # The aim here is to pick up the definition for the
642 # current file, then any other file.
644 mudelatmp=$TMP/mudelaDefs$$
645 # Use `cat' to prevent filenames being prepended
647 cat "$File" $OF | fgrep "$MU_DEF" > $mudelatmp
648 for L in $MU_DEF
650 # This converts \def\mudelatitle{fred}
651 # to \mudelatitle{fred} or to
652 # \def\mudelatitle{fred}
653 # and stops after the first one found.
654 sed -n '/\\def\\'"$L"'{\([^}]*\)}.*$/{
655 s//'"`regexp_quote \"$1\"`"'\\'"$L"'{\1}%/p
657 }' $mudelatmp >> $LatF
658 done
659 rm -f $mudelatmp
663 startFile(){
665 # LaTeX file name
667 BN=`basename "$File" .tex`
668 FN="$BN.$$"
669 if [ "$KEEP_LY2DVI_OUTPUT" != "Y" ]
670 then
671 LatF="$TMP/$FN.tex"
672 else
673 LatF="$FN.tex"
676 # Find:
677 # paper size (PAPERSIZE, overridden by command line option -p)
678 # paper orientation (ORIENTATION, overridden by option -o)
679 # language (LANGUAGE, overridden by option -l)
680 # textwidth
682 eval `sed -n \\
683 -e 's/\\\\def\\\\mudelalanguage{\([^}]*\).*$/fLNG=\1;/p' \\
684 -e 's/\\\\def\\\\mudelalatexheaders{\([^}]*\).*$/fLHF=\1;/p' \\
685 -e 's/\\\\def\\\\mudelaorientation{\([^}]*\).*$/fORI=\1;/p' \\
686 -e 's/\\\\def\\\\mudelapaperlinewidth{\([^}]*\).*$/TWN=\1;/p' \\
687 -e 's/\\\\def\\\\mudelapapertextheight{\([^}]*\).*$/THN=\1;/p' \\
688 -e 's/\\\\def\\\\mudelapapersize{\([^}]*\).*$/fPSZ=\1;/p' \\
689 "$File"`
691 if [ -z "$LATEXHF" ]
692 then
693 LATEXHF="$fLHF"
695 LLHF="%"
696 if [ -n "$LATEXHF" ]
697 then
698 [ -f "$LATEXHF" ] && LLHF="\input{$LATEXHF}"
701 if [ -z "$PAPERSIZE" ]
702 then
703 PAPERSIZE="$fPSZ"
705 if [ -n "$PAPERSIZE" ]
706 then
707 setPaperZize
708 PAPEROPT="$PAPERSIZE"
711 if [ -z "$ORIENTATION" ]
712 then
713 ORIENTATION="$fORI"
715 if [ -n "$ORIENTATION" ]
716 then
717 if [ -z "$PAPEROPT" ]
718 then
719 PAPEROPT="$ORIENTATION"
720 else
721 PAPEROPT="$PAPEROPT,$ORIENTATION"
725 if [ -n "$PAPEROPT" ]
726 then
727 PAPER="[$PAPEROPT]"
730 if [ -z "$LANGUAGE" ]
731 then
732 LANGUAGE="$fLNG"
734 if [ -n "$LANGUAGE" ]
735 then
736 LLNG="\usepackage[$LANGUAGE]{babel}"
737 else
738 LLNG="%"
742 # Find textwidth
744 if [ -n "$TWN" ]
745 then
746 TW="$TWN"
747 case "$TW" in
748 *mm)
750 *cm)
752 *pt)
755 TW="${TW}pt"
757 esac
758 $debug_echo "Text width = $TW"
760 TWp=`Echo $TW | sed -e 's/\..*$//'`
761 PWp="$PWIDTH"
763 # Find textheight
765 if [ -n "$THN" ]
766 then
767 TH=$THN
768 case $TH in
769 *mm)
771 *cm)
773 *pt)
776 TH="${TH}pt"
778 esac
779 $debug_echo "Text height = $TH"
781 THp="`echo $TH | sed -e 's/\..*$//'`"
782 PHp="$PHEIGHT"
783 if [ "$ORIENTATION" = "landscape" ]
784 then
785 PWp="$PHEIGHT"
786 PHp="$PWIDTH"
788 HMARG="`expr '(' $PWp - $TWp ')' / 2`"pt
789 $debug_echo "Text left = $HMARG"
790 VMARG="`expr '(' $PHp - $THp ')' / 2`"pt
791 $debug_echo "Text top = $VMARG"
793 # Geometry: /var/lib/texmf/latex/geometry/geometry.dvi
796 # Write LaTeX file
798 cat << EOF > $LatF
799 % Creator: $IDENTIFICATION
800 % Automatically generated from $IF, $NOW
802 \documentclass$PAPER{article}
804 $LLNG
805 \usepackage{geometry}
806 \usepackage[latin1]{inputenc}
807 %\usepackage[T1]{fontenc}
808 $PNUM
809 %\addtolength{\oddsidemargin}{-1cm}
810 %\addtolength{\topmargin}{-1cm}
811 %\setlength{\textwidth}{$TW}
812 %\setlength{\textheight}{$TH}
813 \geometry{width=$TW, left=$HMARG, height=$TH, top=$VMARG}
814 \input lilyponddefs
815 \input titledefs
816 $LLHF
817 \begin{document}
819 mudelaDefs
820 cat << EOF >> $LatF
821 \cmrtwenty% ugh
822 \makelilytitle
825 nextFile(){
826 cat << EOF >> $LatF
827 \def\theopus{}%
828 \def\thepiece{}%
829 \def\mudelaopus{}%
830 \def\mudelapiece{}%
832 mudelaDefs "\\def"
833 cat << EOF >> $LatF
834 \def\theopus{\mudelaopus}% ugh
835 \def\thepiece{\mudelapiece}%
836 \makelilypiecetitle
840 # Conclusion
842 endFile(){
843 cat << EOF >> $LatF
844 \vfill\hfill{\LilyIdString}
845 \end{document}
848 # Run LaTeX
850 latex '\nonstopmode \input '$LatF || exit 5
852 # Rename dvi file
854 if [ -f $FN.dvi ]
855 then
856 RESULT="$BN.dvi"
857 [ -n "$OUTPUTDIR" ] && RESULT="$OUTPUTDIR/$RESULT"
859 cp "$FN.dvi" "$RESULT" || exit 5
862 # Output some info
864 cat << EOF
866 $IDENTIFICATION: dvi file name is $RESULT
871 # ugh. GF is side-effect.
872 findInput() {
873 # should check for LILYINCLUDE
874 OIFS="$IFS"
875 IFS=':'
876 x=`echo $LILYINCLUDE | sed "s!:! !g"`
877 IFS="$OIFS"
878 for lypath in . $x
880 if [ -f "$lypath/$1" ]
881 then
882 GF="$lypath/$1"
883 return
886 if [ -f "$lypath/$1.ly" ]
887 then
888 GF="$lypath/$1.ly"
889 return
891 if [ -f "$lypath/$1.fly" ]
892 then
893 GF="$lypath/$1.fly"
894 return
896 done
897 $debug_echo "$IDENTIFICATION: Input file \"$GF\" not found"
898 echo "$NAME: Input file \"$GF\" not found" 1>&2
899 exit 2
902 # Loop through all files
905 LILY_OUTPUT_FILES=
907 for GF
909 findInput $GF
912 # Check whether the file is input to or output from lilypond
914 L1=`head -1 $GF`
915 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
916 if [ -n "$OP" ]
917 then
919 # OK - it's the output from lilypond.
921 # Get lilypond source file name
923 OF=$GF
924 IFL=`grep mudelafilename $OF`
925 if [ "$IFL" != "" ]
926 then
927 IF=`echo $IFL | sed -e 's/.*{//' -e 's/}*.$//'`
929 # Check if source file exists
931 if [ ! -f $IF ]
932 then
933 $debug_echo $IDENTIFICATION": Mudela file not found."
934 TW=15.5cm
935 TH=25.0cm
937 else
938 $debug_echo $IDENTIFICATION": Mudela file name not found."
939 TW=15.5cm
940 TH=25.0cm
942 else
944 # I have to assume this is the lilypond input file
945 # Find output file name, if defined
947 IF=$GF
949 # Run lilypond
950 # Grab output file names
952 $debug_echo "lilypond "$LILYOPTS $IF
954 $LILYPOND_EXECUTABLE $LILYOPTS $IF 2>&1 | tee $LOGFILE
955 OF="`sed -n -e 's/TeX output to \([^\.]*\.tex\)\.\.\.$/\1/p' $LOGFILE`"
956 $debug_echo "==> $OF"
957 LILY_OUTPUT_FILES="$LILY_OUTPUT_FILES $OF"
958 STATUS=`egrep -i "error|segmentation|abort" $LOGFILE`
959 echo $STATUS
960 if [ ! -z "$STATUS" ]
961 then
962 exit 10
966 # "Spin through" all the files
968 for File in $OF
970 $debug_echo "--- "$File
972 # Check if output file is generated
974 if [ ! -f "$File" ]
975 then
976 $debug_echo "$IDENTIFICATION: hmm, I could not find the output file $File"
977 exit 4
980 # Is this the first file?
982 if [ -z "$FFile" ]
983 then
984 FFile="$File"
985 startFile
986 else
987 nextFile
989 cat << EOF >> $LatF
990 \input{$File}
992 if [ $SEPFILE = Y ]
993 then
994 FFile=""
995 endFile
997 done
998 done
999 if [ $SEPFILE = N ]
1000 then
1001 endFile
1004 # OK - finished