1dc46b616ecde24693c97daa16be3cd05e128b2d
[ghc-hetmet.git] / glafp-utils / docbook / db2html.dir / db2html.sh
1 if [ ! -f "$DOCBOOK_CATALOG" ] ; then
2   echo "CATALOG file not set up; see installation guide for details."
3   exit 1
4 fi
5
6 HTML_STYLESHEET=$HTML_DIR/html/docbook.css
7 ADMON_GRAPHICS=$HTML_DIR/html/images/*.gif
8
9 output=db2html-dir
10 TMPDIR=DBTOHTML_OUTPUT_DIR$$
11
12 echo TMPDIR is $TMPDIR
13
14 # Dave Mason's option to specify a different stylesheet
15 case $1 in
16     -d) DB_STYLESHEET=$2
17         shift 2
18         ;;
19 esac
20
21 echo "Using stylesheet: \"${DB_STYLESHEET}\""
22
23 if [ $# -gt 2 ]
24 then
25   echo "Usage: `basename $0` [filename.sgml]" >&2
26   exit 1
27 fi
28
29 if [ $# -eq 1 ]
30 then
31   if [ ! -r $1 ]
32   then
33     echo Cannot read \"$1\".  Exiting. >&2
34     exit 1
35   fi
36   if echo $1 | egrep -i '\.sgml$|\.sgm$' >/dev/null 2>&1
37   then
38     # now make sure that the output directory is always a subdirectory
39     # of hte current directory
40     echo
41     input_file=`basename $1`
42     output="`echo $input_file | sed 's,\.sgml$,,;s,\.sgm$,,'`"
43     echo "input file was called $input_file -- output will be in $output"
44     echo
45   fi
46 fi
47
48 # we used to generate a single file, but with the modular DB_STYLESHEETs
49 # it's best to make a new directory with several html files in it
50 #cat $* | jade -d $DB_STYLESHEET -t sgml -V nochunks > $TMPFN
51
52 mkdir $TMPDIR
53 SAVE_PWD=`pwd`
54 if [ $1 = `basename $1` ]; then
55   echo "working on ../$1"
56   (cd $TMPDIR; $JADE -t sgml -ihtml -d ${DB_STYLESHEET}\#html -c $DOCBOOK_CATALOG ../$1; cd $SAVE_PWD)
57 else
58   echo "working on $1"
59   (cd $TMPDIR; $JADE -t sgml -ihtml -d ${DB_STYLESHEET}\#html -c $DOCBOOK_CATALOG $1; cd $SAVE_PWD)
60 fi
61
62 if [ $# -eq 1 ]
63 then
64   if [ -d ${output}.junk ]
65   then
66     rm -rf ${output}.junk
67   fi
68   if [ -d ${output} ]
69   then
70     mv $output ${output}.junk
71   fi
72   echo "about to copy cascading stylesheet and admon graphics to temp dir"
73   cp ${HTML_STYLESHEET} ${TMPDIR}/
74   mkdir ${TMPDIR}/stylesheet-images
75   cp ${ADMON_GRAPHICS} ${TMPDIR}/stylesheet-images
76   echo "about to rename temporary directory to $output"
77   mv ${TMPDIR} $output
78 else
79   cat $TMPDIR/*
80 fi
81
82 rm -rf $TMPDIR
83
84 exit 0