File: faust2mathdoc

package info (click to toggle)
faust 2.81.10%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 431,496 kB
  • sloc: cpp: 283,941; ansic: 116,215; javascript: 18,529; sh: 14,356; vhdl: 14,052; java: 5,900; python: 5,091; objc: 3,852; makefile: 2,725; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 111; tcl: 26
file content (143 lines) | stat: -rwxr-xr-x 3,768 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#! /bin/bash -e

. usage.sh

# faust2mathdoc.sh
#
# Generate a full Faust documentation, in a '*-mdoc' top directory.
#
# Karim Barkati
# November 2009
#
#   Warning : this script requires several things to be installed :
# - svg2pdf, from the Cairo 2D graphics library;
# - pdflatex, to compile the tex file;
# - breqn, a latex package to break equations;
# - faust ;-)

# Usage.
echoHelp()
{
    usage faust2mathdoc "[options] <file.dsp>"
    require svg2pdf pdflatex breqn
    echo "Generate a full Faust documentation in a '*-mdoc' top directory"
    option
    option "-l LANG" "LANG is usually a 2-lowercase-letters language name, like en, fr, or it."
    option -utf8 "force file.dsp to be recoded in UTF-8 before being processed"
    exit
}

# Visit each directory transmitted as argument,
# in order to convert process.svg files into pdf.
# This function uses the svg2pdf command,
# from the Cairo 2D graphics library.
convert_svgprocesses2pdf()
{
    for DIR in $@ ; do
    if [ -d $DIR ] ; then
        echo "cd " $DIR
        cd $DIR
        FILE="process.svg"
        for SRC in $FILE ; do
        echo ' --> '$SRC
        PDF=${SRC%.svg}'.pdf'
        ##svg2pdf "$SRC" "$PDF"
        inkscape -o "$PDF" "$SRC"
        echo ' <-- '$PDF
        done
        cd -
    else
        echo error : \'$DIR\' is not a directory.
    fi
    done
}

# Visit each directory transmitted as argument,
# in order to convert .svg files into pdf.
# This function uses the svg2pdf command,
# from the Cairo 2D graphics library.
convert_svgdirs2pdf()
{
    for DIR in $@ ; do
    if [ -d $DIR ] ; then
        #echo "cd " $DIR
        cd $DIR
        FILES=`ls | grep -E "\.svg"`
        for SRC in $FILES ; do
        #echo ' --> '$SRC
        PDF=${SRC%.svg}'.pdf'
        ##svg2pdf "$SRC" "$PDF"
        inkscape -o "${PDF}" "${SRC}"
        echo "svg2pdf $SRC $PDF"
        #echo ' <-- '$PDF
        done
        cd ..
    else
        echo error : \'$DIR\' is not a directory.
    fi
    done
}

# In-place recoding of a text file from its current encoding to UTF-8.
# This is useful for .dsp files with accents in comments that are coded
# with a different character set.
recode2utf8()
{
    charset=`file -0 --mime-encoding $1 | cut  -d' ' -f2`
    recode $charset..utf-8 $1
}

MDLANGOPT=""
if [ $1 = "-mdlang" ] || [ $1 = "--mathdoc-lang" ] || [ $1 = "-l" ]
then
    MDLANGOPT="-mdlang $2"
    shift 2
fi

CONVERT=""
if [ "$1" = "-utf8" ] || [ "$1" = "--utf8" ]
then
    CONVERT="utf8"
    shift 1
fi

if [ "$#" -eq 0 ]; then
    echo 'Please, provide a Faust file to process !'
    echo ''
    echoHelp
fi

#    Main loop of this script :
# 1. Compile `faust --mathdoc` to generate the TeX file and SVG block-diagrams.
# 2. Move to the "${FILEPATH%.dsp}-mdoc" directory created by faust.
# 3. Convert SVG files into PDF files recursively (with svg2pdf).
# 4. Compile pdflatex twice (including the top-level block-diagram).
# 5. Copy some important files where needed.
for FILEPATH in $@ ; do
    if [ -f $FILEPATH ] ; then
    FILENAME=`basename $FILEPATH` &&
    case $FILENAME in
        *.dsp )
        if [ "$CONVERT" = "utf8" ]
        then
            recode2utf8 $FILENAME
        fi
        faust $MDLANGOPT -o ${FILEPATH%.dsp}.cpp --mathdoc $FILEPATH  || exit
        cd ${FILEPATH%.dsp}-mdoc/ &&
        cd svg && convert_svgprocesses2pdf svg-* && cd .. &&
        cd tex && xelatex ${FILENAME%.dsp}.tex && xelatex ${FILENAME%.dsp}.tex && cd .. &&
        mkdir -p pdf && cp tex/${FILENAME%.dsp}.pdf pdf &&
        mkdir -p cpp && mv ../${FILENAME%.dsp}.cpp cpp &&
        cd ..
        ;;
        * )
        echo error : \'$FILENAME\' does not have a \'.dsp\' extension.
        exit 2
        ;;
    esac
    else
        echoHelp
    fi
done
exit 0