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