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