File: book2xml.sh

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (42 lines) | stat: -rwxr-xr-x 1,268 bytes parent folder | download | duplicates (6)
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
#!/bin/sh

# Convert Yacas books to XML
# Usage: book2xml.sh bookname.book
# result: bookname.book.xml

ourdir=`dirname $0`

if [ x"$1" = x-run ]; then
	shift
	yacas="$1"
	shift
else
	yacas="$ourdir/../src/yacas --rootdir $ourdir/../scripts/"
fi

if [ x"$1" = x ]; then
	echo "`basename $0`: convert Yacas docs to XML"
	echo "Usage: `basename $0` [-run /path/yacas] bookname.book [outputname.xml]"
else
if [ x"$2" = x ]; then
	target="$1.xml"
else
	target="$2"
fi

if [ -r "$1" ]; then
	rm -f "$target"
	echo 'ToFile("'"$target"'") [ Use("'"$ourdir"'/book2xml.ys"); Load("'"$1"'"); XMLFinishUp(); ];' | $yacas -f
	if [ -s "$target" ]; then
		echo "File '$target' was created."
		# replace right double quotes by left ones where possible
		# avoid {verbatim}; do not replace "" inside {}
		#perl -e '$out_of_verbatim=1; while(<>) { if($out_of_verbatim) { 1 while s/^([^{}|]*(?:\{[^{}]*\}[^{}|]*|\\verb\|[^|]*\|[^{}|]*)*[^{}|]*[- ()|\[\]\t])"/$1``/g; s/^"/``/; if (/\\begin\{verbatim\}/) {$out_of_verbatim=0; } } elsif(/\\end\{verbatim\}/) { $out_of_verbatim=1 }; print; }' < "$target" > "$target.tmp"
		#mv "$target.tmp" "$target"
	else
		echo "`basename $0`: Some problem generating file '$target', aborted."
	fi
else
	echo "Error: cannot read input file '$1'."
fi
fi