Debian Codegraph @

tools/faust2appls/faust2mathdoc

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #! /bin/bash -e
2
3 . usage.sh
4
5 # faust2mathdoc.sh
6 #
7 # Generate a full Faust documentation, in a '*-mdoc' top directory.
8 #
9 # Karim Barkati
10 # November 2009
11 #
12 # Warning : this script requires several things to be installed :
13 # - svg2pdf, from the Cairo 2D graphics library;
14 # - pdflatex, to compile the tex file;
15 # - breqn, a latex package to break equations;
16 # - faust ;-)
17
18 # Usage.
19 echoHelp()
20 {
21 usage faust2mathdoc "[options] <file.dsp>"
22 require svg2pdf pdflatex breqn
23 echo "Generate a full Faust documentation in a '*-mdoc' top directory"
24 option
25 option "-l LANG" "LANG is usually a 2-lowercase-letters language name, like en, fr, or it."
26 option -utf8 "force file.dsp to be recoded in UTF-8 before being processed"
27 exit
28 }
29
30 # Visit each directory transmitted as argument,
31 # in order to convert process.svg files into pdf.
32 # This function uses the svg2pdf command,
33 # from the Cairo 2D graphics library.
34 convert_svgprocesses2pdf()
35 {
36 for DIR in $@ ; do
37 if [ -d $DIR ] ; then
38 echo "cd " $DIR
39 cd $DIR
40 FILE="process.svg"
41 for SRC in $FILE ; do
42 echo ' --> '$SRC
43 PDF=${SRC%.svg}'.pdf'
44 ##svg2pdf "$SRC" "$PDF"
45 inkscape --without-gui --file="$SRC" --export-pdf="$PDF"
46 echo ' <-- '$PDF
47 done
48 cd -
49 else
50 echo error : \'$DIR\' is not a directory.
51 fi
52 done
53 }
54
55 # Visit each directory transmitted as argument,
56 # in order to convert .svg files into pdf.
57 # This function uses the svg2pdf command,
58 # from the Cairo 2D graphics library.
59 convert_svgdirs2pdf()
60 {
61 for DIR in $@ ; do
62 if [ -d $DIR ] ; then
63 #echo "cd " $DIR
64 cd $DIR
65 FILES=`ls | grep -E "\.svg"`
66 for SRC in $FILES ; do
67 #echo ' --> '$SRC
68 PDF=${SRC%.svg}'.pdf'
69 ##svg2pdf "$SRC" "$PDF"
70 inkscape --without-gui --file="$SRC" --export-pdf="$PDF"
71 echo "svg2pdf $SRC $PDF"
72 #echo ' <-- '$PDF
73 done
74 cd ..
75 else
76 echo error : \'$DIR\' is not a directory.
77 fi
78 done
79 }
80
81 # In-place recoding of a text file from its current encoding to UTF-8.
82 # This is useful for .dsp files with accents in comments that are coded
83 # with a different character set.
84 recode2utf8()
85 {
86 charset=`file -0 --mime-encoding $1 | cut -d' ' -f2`
87 recode $charset..utf-8 $1
88 }
89
90 MDLANGOPT=""
91 if [ $1 = "-mdlang" ] || [ $1 = "--mathdoc-lang" ] || [ $1 = "-l" ]
92 then
93 MDLANGOPT="-mdlang $2"
94 shift 2
95 fi
96
97 CONVERT=""
98 if [ "$1" = "-utf8" ] || [ "$1" = "--utf8" ]
99 then
100 CONVERT="utf8"
101 shift 1
102 fi
103
104 if [ "$#" -eq 0 ]; then
105 echo 'Please, provide a Faust file to process !'
106 echo ''
107 echoHelp
108 fi
109
110 # Main loop of this script :
111 # 1. Compile `faust --mathdoc` to generate the TeX file and SVG block-diagrams.
112 # 2. Move to the "${FILEPATH%.dsp}-mdoc" directory created by faust.
113 # 3. Convert SVG files into PDF files recursively (with svg2pdf).
114 # 4. Compile pdflatex twice (including the top-level block-diagram).
115 # 5. Copy some important files where needed.
116 for FILEPATH in $@ ; do
117 if [ -f $FILEPATH ] ; then
118 FILENAME=`basename $FILEPATH` &&
119 case $FILENAME in
120 *.dsp )
121 if [ "$CONVERT" = "utf8" ]
122 then
123 recode2utf8 $FILENAME
124 fi
125 faust $MDLANGOPT -o ${FILEPATH%.dsp}.cpp --mathdoc $FILEPATH || exit
126 cd ${FILEPATH%.dsp}-mdoc/ &&
127 cd svg && convert_svgprocesses2pdf svg-* && cd .. &&
128 cd tex && xelatex ${FILENAME%.dsp}.tex && xelatex ${FILENAME%.dsp}.tex && cd .. &&
129 mkdir -p pdf && cp tex/${FILENAME%.dsp}.pdf pdf &&
130 mkdir -p cpp && mv ../${FILENAME%.dsp}.cpp cpp &&
131 cd ..
132 ;;
133 * )
134 echo error : \'$FILENAME\' does not have a \'.dsp\' extension.
135 exit 2
136 ;;
137 esac
138 else
139 echoHelp
140 fi
141 done
142 exit 0
143