tamir_docbookxml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #! /bin/bash
  2. usage()
  3. {
  4. cat <<EOF
  5. Usage: $pname [OPTION]
  6. Known values for OPTION are:
  7. --prefix=DIR change the output directory for catalog files
  8. [default $DIR]
  9. --show display the output filenames and paths
  10. --version=x.y.z change the DocBook version [default $VERSION]
  11. --debug display script action information
  12. --help display this help and exit
  13. EOF
  14. }
  15. setdefault()
  16. {
  17. echo Unable to update root catalog $ROOTCATALOG
  18. ROOTCATALOG=$HOME/xmlcatalog
  19. CATALOG=$HOME/dbkxmlcatalog
  20. DIR=$HOME
  21. CAT=xmlcatalog
  22. echo Using $ROOTCATALOG as the root catalog
  23. echo Remember to export XML_CATALOG_FILES=$ROOTCATALOG
  24. echo
  25. prefix=1
  26. }
  27. fixname()
  28. {
  29. #
  30. # ROOTCATALOG contains the full pathname for the catalog. We will
  31. # split that into the directory name and the filename, then we will
  32. # see if the directory exists. If it does not, we will attempt to
  33. # create it.
  34. #
  35. if test $verbose = 1
  36. then
  37. echo Checking path $ROOTCATALOG for permissions
  38. fi
  39. # First we split the filename and directory name
  40. CAT=`basename $ROOTCATALOG`
  41. DIR=`dirname $ROOTCATALOG`
  42. if test "$DIR" = ""
  43. then
  44. echo Unable to isolate directory name from '$ROOTCATALOG' - exiting
  45. exit 1
  46. fi
  47. CATALOG=${DIR}/docbook
  48. parent=`dirname $DIR`
  49. if test "$parent" == ""
  50. then
  51. parent=/
  52. fi
  53. if [ ! -d $DIR ]
  54. then
  55. if test $verbose = 1
  56. then
  57. echo Directory $DIR missing - I will try to create it
  58. fi
  59. if [ ! -w $parent ]
  60. then
  61. if test $verbose = 1
  62. then
  63. echo No write permission for directory $parent
  64. fi
  65. setdefault
  66. else
  67. newdir=1
  68. fi
  69. else
  70. if [ -f $ROOTCATALOG -a ! -w $ROOTCATALOG ] ||
  71. [ -e $ROOTCATALOG -a ! -f $ROOTCATALOG ] ||
  72. [ ! -e $ROOTCATALOG -a ! -w $DIR ]
  73. then
  74. setdefault
  75. fi
  76. fi
  77. }
  78. finddbx()
  79. {
  80. dtd421=""
  81. s="//OASIS//DTD DocBook XML V${VERSION}//EN"
  82. found=`find $1 -name docbookx.dtd -exec grep -l "$s" {} \;`
  83. for dtd in $found; do
  84. docbookdir=`dirname $dtd`
  85. echo Found DocBook XML $VERSION DTD in $docbookdir
  86. #
  87. # The original script had a check for write permission on the file
  88. # but I can't see why it should be necessary
  89. #
  90. dtd421=$dtd
  91. break
  92. done
  93. }
  94. #
  95. # Preset script control params
  96. show=0
  97. prefix=0
  98. newdir=0
  99. verbose=0
  100. #
  101. # Isolate the script name for messages
  102. pname=`basename $0`
  103. VERSION=4.1.2
  104. if test "$XML_CATALOG_FILES" != ""
  105. then
  106. ROOTCATALOG=$XML_CATALOG_FILES
  107. else
  108. ROOTCATALOG=/etc/xml/catalog
  109. fi
  110. #
  111. # Interpret script parameters
  112. while test $# -gt 0; do
  113. case "$1" in
  114. -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  115. *) optarg= ;;
  116. esac
  117. case "$1" in
  118. -p=* | --prefix=*)
  119. ROOTCATALOG=$optarg/catalog
  120. prefix=1
  121. ;;
  122. -s | --show)
  123. show=1
  124. ;;
  125. -v=* | --version=*)
  126. VERSION=$optarg
  127. ;;
  128. -d | --debug)
  129. verbose=1
  130. ;;
  131. -h | --help)
  132. usage
  133. exit 0
  134. ;;
  135. * )
  136. echo Invalid argument "$1"
  137. usage
  138. exit 1
  139. ;;
  140. esac
  141. shift
  142. done
  143. fixname
  144. if test $prefix != 0
  145. then
  146. export XML_CATALOG_FILES=$ROOTCATALOG
  147. fi
  148. if test $show != 0
  149. then
  150. echo XML Catalog is $ROOTCATALOG
  151. echo Docbook Catalog is $CATALOG
  152. exit 0
  153. fi
  154. if test $newdir!=0
  155. then
  156. mkdir -p $DIR
  157. chmod 755 $DIR
  158. fi
  159. echo Starting run
  160. #
  161. # create the catalogs root and docbook specific
  162. #
  163. if [ ! -r $ROOTCATALOG ] ; then
  164. echo creating XML Catalog root $ROOTCATALOG
  165. xmlcatalog --noout --create $ROOTCATALOG
  166. fi
  167. if [ ! -r $ROOTCATALOG ] ; then
  168. echo Failed creating XML Catalog root $ROOTCATALOG
  169. exit 1
  170. fi
  171. if [ ! -r $CATALOG ] ; then
  172. echo creating DocBook XML Catalog $CATALOG
  173. xmlcatalog --noout --create $CATALOG
  174. fi
  175. if [ ! -r $CATALOG ] ; then
  176. echo Failed creating DocBook XML Catalog $CATALOG
  177. exit 1
  178. fi
  179. #
  180. # find the prefix for DocBook DTD
  181. #
  182. finddbx /usr/share/xml
  183. if [ "$dtd421" = "" ] ; then
  184. finddbx $HOME
  185. fi
  186. if [ "$dtd421" = "" ] ; then
  187. finddbx /usr/local
  188. fi
  189. if [ "$dtd421" = "" ] ; then
  190. finddbx /usr/share/sgml
  191. fi
  192. if [ "$dtd421" = "" ] ; then
  193. echo could not locate version $VERSION of DocBook XML
  194. exit 1
  195. fi
  196. xmlcatalog --noout --add "public" \
  197. "-//OASIS//ELEMENTS DocBook XML Information Pool V${VERSION}//EN" \
  198. "file://$docbookdir/dbpoolx.mod" $CATALOG
  199. xmlcatalog --noout --add "public" \
  200. "-//OASIS//DTD DocBook XML V${VERSION}//EN" \
  201. "file://$docbookdir/docbookx.dtd" $CATALOG
  202. xmlcatalog --noout --add "public" \
  203. "-//OASIS//ENTITIES DocBook XML Character Entities V${VERSION}//EN" \
  204. "file://$docbookdir/dbcentx.mod" $CATALOG
  205. xmlcatalog --noout --add "public" \
  206. "-//OASIS//ENTITIES DocBook XML Notations V${VERSION}//EN" \
  207. "file://$docbookdir/dbnotnx.mod" $CATALOG
  208. xmlcatalog --noout --add "public" \
  209. "-//OASIS//ENTITIES DocBook XML Additional General Entities V${VERSION}//EN" \
  210. "file://$docbookdir/dbgenent.mod" $CATALOG
  211. xmlcatalog --noout --add "public" \
  212. "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${VERSION}//EN" \
  213. "file://$docbookdir/dbhierx.mod" $CATALOG
  214. xmlcatalog --noout --add "public" \
  215. "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
  216. "file://$docbookdir/soextblx.dtd" $CATALOG
  217. xmlcatalog --noout --add "public" \
  218. "-//OASIS//DTD DocBook XML CALS Table Model V${VERSION}//EN" \
  219. "file://$docbookdir/calstblx.dtd" $CATALOG
  220. xmlcatalog --noout --add "rewriteSystem" \
  221. "http://www.oasis-open.org/docbook/xml/${VERSION}" \
  222. "file://$docbookdir" $CATALOG
  223. xmlcatalog --noout --add "rewriteURI" \
  224. "http://www.oasis-open.org/docbook/xml/${VERSION}" \
  225. "file://$docbookdir" $CATALOG
  226. xmlcatalog --noout --add "delegatePublic" \
  227. "-//OASIS//ENTITIES DocBook XML" \
  228. "file://$CATALOG" $ROOTCATALOG
  229. xmlcatalog --noout --add "delegatePublic" \
  230. "-//OASIS//DTD DocBook XML" \
  231. "file://$CATALOG" $ROOTCATALOG
  232. xmlcatalog --noout --add "delegateSystem" \
  233. "http://www.oasis-open.org/docbook/" \
  234. "file://$CATALOG" $ROOTCATALOG
  235. xmlcatalog --noout --add "delegateURI" \
  236. "http://www.oasis-open.org/docbook/" \
  237. "file://$CATALOG" $ROOTCATALOG
  238. #
  239. # find the prefix for ISO DocBook entities
  240. #
  241. top=`dirname $docbookdir`
  242. found=`find $top -name isoamsb.ent`
  243. if [ "$found" = "" ] ; then
  244. found=`find /usr/share/xml -name isoamsb.ent`
  245. fi
  246. if [ "$found" = "" ] ; then
  247. found=`find $HOME -name isoamsb.ent`
  248. fi
  249. if [ "$found" = "" ] ; then
  250. found=`find /usr/local -name isoamsb.ent`
  251. fi
  252. if [ "$found" = "" ] ; then
  253. found=`find /usr/share/sgml -name isoamsb.ent`
  254. fi
  255. if [ "$found" = "" ] ; then
  256. echo could not locate isoamsb.ent of ISO DocBook entities
  257. exit 1
  258. fi
  259. entxml=""
  260. for tst in $found; do
  261. check=`grep '<!ENTITY ominus' $tst`
  262. if [ "$check" != "" ] ; then
  263. entxml=$tst
  264. break
  265. fi
  266. done
  267. if [ "$entxml" = "" ] ; then
  268. echo could not locate ISO DocBook entities
  269. exit 1
  270. fi
  271. isodir=`dirname $entxml`
  272. echo Found ISO DocBook entities in $isodir
  273. xmlcatalog --noout --add "public" \
  274. "ISO 8879:1986//ENTITIES Publishing//EN" \
  275. "file://$isodir/isopub.ent" $CATALOG
  276. xmlcatalog --noout --add "public" \
  277. "ISO 8879:1986//ENTITIES Greek Letters//EN" \
  278. "file://$isodir/isogrk1.ent" $CATALOG
  279. xmlcatalog --noout --add "public" \
  280. "ISO 8879:1986//ENTITIES Box and Line Drawing//EN" \
  281. "file://$isodir/isobox.ent" $CATALOG
  282. xmlcatalog --noout --add "public" \
  283. "ISO 8879:1986//ENTITIES Greek Symbols//EN" \
  284. "file://$isodir/isogrk3.ent" $CATALOG
  285. xmlcatalog --noout --add "public" \
  286. "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN" \
  287. "file://$isodir/isoamsn.ent" $CATALOG
  288. xmlcatalog --noout --add "public" \
  289. "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN" \
  290. "file://$isodir/isonum.ent" $CATALOG
  291. xmlcatalog --noout --add "public" \
  292. "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN" \
  293. "file://$isodir/isogrk4.ent" $CATALOG
  294. xmlcatalog --noout --add "public" \
  295. "ISO 8879:1986//ENTITIES Diacritical Marks//EN" \
  296. "file://$isodir/isodia.ent" $CATALOG
  297. xmlcatalog --noout --add "public" \
  298. "ISO 8879:1986//ENTITIES Monotoniko Greek//EN" \
  299. "file://$isodir/isogrk2.ent" $CATALOG
  300. xmlcatalog --noout --add "public" \
  301. "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN" \
  302. "file://$isodir/isoamsa.ent" $CATALOG
  303. xmlcatalog --noout --add "public" \
  304. "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN" \
  305. "file://$isodir/isoamso.ent" $CATALOG
  306. xmlcatalog --noout --add "public" \
  307. "ISO 8879:1986//ENTITIES Russian Cyrillic//EN" \
  308. "file://$isodir/isocyr1.ent" $CATALOG
  309. xmlcatalog --noout --add "public" \
  310. "ISO 8879:1986//ENTITIES General Technical//EN" \
  311. "file://$isodir/isotech.ent" $CATALOG
  312. xmlcatalog --noout --add "public" \
  313. "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN" \
  314. "file://$isodir/isoamsc.ent" $CATALOG
  315. xmlcatalog --noout --add "public" \
  316. "ISO 8879:1986//ENTITIES Added Latin 1//EN" \
  317. "file://$isodir/isolat1.ent" $CATALOG
  318. xmlcatalog --noout --add "public" \
  319. "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN" \
  320. "file://$isodir/isoamsb.ent" $CATALOG
  321. xmlcatalog --noout --add "public" \
  322. "ISO 8879:1986//ENTITIES Added Latin 2//EN" \
  323. "file://$isodir/isolat2.ent" $CATALOG
  324. xmlcatalog --noout --add "public" \
  325. "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN" \
  326. "file://$isodir/isoamsr.ent" $CATALOG
  327. xmlcatalog --noout --add "public" \
  328. "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN" \
  329. "file://$isodir/isocyr2.ent" $CATALOG
  330. xmlcatalog --noout --add "delegatePublic" \
  331. "ISO 8879:1986" \
  332. "file://$CATALOG" $ROOTCATALOG
  333. #
  334. # find the prefix for XSLT stylesheets
  335. #
  336. top=`dirname $docbookdir`
  337. found=`find $top -name chunk.xsl`
  338. if [ "$found" = "" ] ; then
  339. found=`find /usr/share/xml -name chunk.xsl`
  340. fi
  341. if [ "$found" = "" ] ; then
  342. found=`find $HOME -name chunk.xsl`
  343. fi
  344. if [ "$found" = "" ] ; then
  345. found=`find /usr/local -name chunk.xsl`
  346. fi
  347. if [ "$found" = "" ] ; then
  348. found=`find /usr/share/sgml -name chunk.xsl`
  349. fi
  350. if [ "$found" = "" ] ; then
  351. echo could not locate chunk-common.xsl of DocBook XSLT stylesheets
  352. exit 1
  353. fi
  354. xsldir=""
  355. for tst in $found; do
  356. dir=`dirname $tst`
  357. dir=`dirname $dir`
  358. if [ -r $dir/html/docbook.xsl -a -r $dir/common/l10n.xml ]; then
  359. xsldir=$dir
  360. break
  361. fi
  362. done
  363. if [ "$xsldir" = "" ] ; then
  364. echo could not locate DocBook XSLT stylesheets
  365. exit 1
  366. fi
  367. echo Found DocBook XSLT stylesheets in $xsldir
  368. for version in current 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 \
  369. 1.48 1.49 1.50
  370. do
  371. xmlcatalog --noout --add "rewriteSystem" \
  372. "http://docbook.sourceforge.net/release/xsl/$version" \
  373. "file://$xsldir" $CATALOG
  374. xmlcatalog --noout --add "rewriteURI" \
  375. "http://docbook.sourceforge.net/release/xsl/$version" \
  376. "file://$xsldir" $CATALOG
  377. done
  378. xmlcatalog --noout --add "delegateSystem" \
  379. "http://docbook.sourceforge.net/release/xsl/" \
  380. "file://$CATALOG" $ROOTCATALOG
  381. xmlcatalog --noout --add "delegateURI" \
  382. "http://docbook.sourceforge.net/release/xsl/" \
  383. "file://$CATALOG" $ROOTCATALOG
  384. #
  385. #