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