File: book2txt.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 (29 lines) | stat: -rwxr-xr-x 804 bytes parent folder | download | duplicates (7)
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
#!/bin/sh

# Convert Yacas books to text
# Usage: book2txt.sh bookname.chapt
# result: bookname.chapt.txt

if [ x"$1" = x ]; then
	echo "Convert Yacas docs to formatted plain text"
	echo "Usage: `basename $0` bookname.chapt"
else
while [ x"$1" != x ]
do
	ourdir=`dirname $0`
	if [ -r "$1" ]; then
		rm -f "$1.txt"
		echo 'ToFile("'"$1"'.txt") [ Use("'"$ourdir"'/book2txt.ys"); Load("'"$1"'"); ];' | yacas -f
		if [ -s "$1.txt" ]; then
			echo "File '$1.txt' was created."
			perl -e 'undef $/; $_=<>; s/<br>/\n/gi; s/<p>/\n/gi; s/<\/p>//gi; s/ +\n/\n/g; s/\n\n\n+/\n\n/g; s/\n ([^ ])/\n$1/g; print;' < "$1.txt" > "$1.txt.tmp"
			mv "$1.txt.tmp" "$1.txt"
		else
			echo "book2txt: Some problem generating file '$1.txt', aborted."
		fi
	else
		echo "Error: cannot read input file '$1'."
	fi
	shift
done
fi