Debian Codegraph @

xmldoc/convertdoc

raw
1 #!/bin/bash -e
2
3 fixem() {
4 encapsulate=$1
5 echo encapsulate "$encapsulate"
6 for file in *.xml
7 do
8 if [ "$file" != "allchapters.xml" ]; then
9 if [ "$file" != "_chapters.xml" ]; then
10 echo "converting $file ($(wc -c "$file" | awk '{print $1}') bytes)"
11 if [ "$encapsulate" = "yes" ]; then
12 echo -e "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.5//EN\" \"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd\">\n<book><chapter><title>T</title>\n$(cat $file)" > "$file"
13 echo "</chapter></book>" >> "$file"
14 fi
15 xmllint --noout --valid "$file" || true
16 # db4-upgrade.xsl from https://docbook.org/xml/5.1/docbook-v5.1-os.zip
17 xsltproc -o "$file".new /home/tsteven4/builds/docbook-v5.1/tools/db4-upgrade.xsl "$file"
18 if [ "$encapsulate" == "yes" ]; then
19 head --lines=-1 "$file".new | tail --lines=+3 > "$file"
20 else
21 tail --lines=+2 "$file".new > "$file"
22 fi
23 rm "$file".new
24 fi
25 fi
26 done
27 }
28
29 pushd xmldoc
30 pushd formats
31 fixem yes
32 # 4.5 productname defaulted to class=trade. 5.0 does not, use trademark
33 for file in *.xml
34 do
35 echo -e "<fake>\n$(cat $file)" > "$file"
36 echo "</fake>" >> "$file"
37 xsltproc -o "$file".trademark ../tmissue.xsl "$file"
38 head --lines=-1 "$file".trademark | tail --lines=+2 > "$file"
39 rm "$file".trademark
40 done
41 pushd options
42 # for some reason the upgrade wants to insert a ^L character in gpx-urlbase.xml unless we
43 sed -e 's|\\|\\\\|g' -i gpx-urlbase.xml
44 sed -e 's|\\|\\\\|g' -i subrip-format.xml
45 sed -e 's|\\|\\\\|g' -i exif-filename.xml
46 fixem yes
47 popd
48 popd
49 pushd filters
50 fixem yes
51 pushd options
52 fixem yes
53 popd
54 popd
55 pushd chapters
56 sed -e 's|&filters;|[[[filters]]]|' -i filters.xml
57 sed -e 's|&formats;|[[[formats]]]|' -i formats.xml
58 fixem no
59 sed -e 's|\[\[\[filters\]\]\]|\&filters;|' -i filters.xml
60 sed -e 's|\[\[\[formats\]\]\]|\&formats;|' -i formats.xml
61 #sed -i -e '$a\' formats.xml
62 #sed -i -e '$a\' filters.xml
63 popd
64 # the 5.1 version of db4-update.xsl drops the term/ulink
65 patch -p0 <build.patch
66 nonewlines=$(pcregrep -LMr '\n\Z' .)
67 for file in ${nonewlines[@]}
68 do
69 echo fixing newline in "$file"
70 sed -i -e '$a\' "$file"
71 done
72 popd
73 perl xmldoc/makedoc
74
75
76