Rename interpretor to interpreter.
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / tools / faust2appls / faust2mathviewer
1 #!/bin/bash
2
3 # faust2mathviewer.sh
4 #
5 # Generate a full Faust documentation, in a '*-mdoc' top directory
6 # and open the resulting pdf file
7 #
8 # Karim Barkati
9 # November 2009
10 #
11 # Warning : this script requires several things to be installed :
12 # - svg2pdf, from the Cairo 2D graphics library;
13 # - pdflatex, to compile the tex file;
14 # - breqn, a latex package to break equations;
15 # - faust ;-)
16
17
18 # Usage.
19 print_usage()
20 {
21 echo Usage : args of faust2mathviewer should be a \'.dsp\' file, or a list of \'.dsp\' files.
22 }
23
24
25 # Visit each directory transmited as argument,
26 # in order to convert .svg files into pdf.
27 # This function uses the svg2pdf command,
28 # from the Cairo 2D graphics library.
29 convert_svgdirs2pdf()
30 {
31 for DIR in $@ ; do
32 if [ -d $DIR ] ; then
33 echo "cd " $DIR
34 cd $DIR
35 FILES=`ls | grep -E "\.svg"`
36 for SRC in $FILES ; do
37 echo ' --> '$SRC
38 PDF=${SRC%.svg}'.pdf'
39 svg2pdf "$SRC" "$PDF"
40 echo ' <-- '$PDF
41 done
42 cd -
43 else
44 echo error : \'$DIR\' is not a directory.
45 fi
46 done
47 }
48
49
50 # Main loop of this script :
51 # 1. Compile `faust -mdoc` to generate the TeX file and SVG block-diagrams.
52 # 2. Move to the "${FILEPATH%.dsp}-mdoc" directory created by faust.
53 # 3. Convert SVG files into PDF files recursively (with svg2pdf).
54 # 4. Compile pdflatex twice (including the top-level block-diagram).
55 # 5. Copy some important files where needed.
56
57 if [[ $(uname) == Darwin ]]; then
58 OPEN=open
59 export PATH="/usr/texbin:$PATH"
60 else
61 OPEN=xdg-open
62 fi
63
64 for FILEPATH in $@ ; do
65 if [ -f $FILEPATH ] ; then
66 FILENAME=`basename $FILEPATH` &&
67 case $FILENAME in
68 *.dsp )
69 faust -o ${FILEPATH%.dsp}.cpp --mathdoc $FILEPATH &&
70 cd ${FILEPATH%.dsp}-mdoc/ &&
71 cd svg && convert_svgdirs2pdf svg-* && cd .. &&
72 cd tex && pdflatex ${FILENAME%.dsp}.tex && pdflatex ${FILENAME%.dsp}.tex && cd .. &&
73 mkdir -p pdf && cp tex/${FILENAME%.dsp}.pdf pdf &&
74 mkdir -p cpp && mv ../${FILENAME%.dsp}.cpp cpp &&
75 ${OPEN} tex/${FILENAME%.dsp}.pdf &&
76 cd ..
77 ;;
78 * )
79 echo error : \'$FILENAME\' does not have a \'.dsp\' extension.
80 exit 2
81 ;;
82 esac
83 else
84 print_usage
85 exit 1
86 fi
87 done
88 exit 0
89