3 # get the name of this command for errors, warnings and messages
4 command_name=`basename $0`
7 # initialize the variables that get set by options
9 typeset -i decompress=0
16 typeset -i uncompressed=0
21 # We use this string a couple of different places.
22 c_and_d="Compress (-c) and decompress (-d)"
25 # Create a funtion to call on fatal error before we know about file
28 echo "$command_name fatal error:"
34 # Create a funtion to call on fatal error merging any error files.
36 echo "$command_name fatal error:"
38 if [[ -a $basename.out.err ]]; then
39 cat $basename.out.err >> $basename.log
40 rm -f $basename.out.err
46 # Create a function to call for warnings.
48 echo "$command_name warning:"
53 # Process the options.
55 getopts ":cdg:hlm:o:rs:t:uvxH:I:L:S:" opt
60 (g) if [[ "$catfiles" = "" ]] then
63 catfiles="$catfiles -m $OPTARG"
66 (i) info_dir="$OPTARG";;
68 (m) mapfiles="$mapfiles $OPTARG";;
70 if [[ $oname = -* ]] then
71 warn "Output file name (-o $oname) begins with a \"-\""
74 (s) sgml_dir="$OPTARG";;
75 (t) dbk_lib="$OPTARG";;
79 # undocumented options to be used at build time
80 (H) helptag2="$OPTARG";;
81 (I) instant="$OPTARG";;
82 (L) x_locale="$OPTARG";;
85 (?) fatal "Unknown option: -$OPTARG";;
89 dbk_lib="${dbk_lib:-/usr/dt/dthelp/dtdocbook}" # if no -t, use installed dir
90 sgml_dir="${sgml_dir:-${dbk_lib}}" # if no -s, use -t
91 info_dir="${info_dir:-/usr/dt/infolib}" # if no -i, use installed dir
92 sgml_cat="${sgml_dir}/SGML"
93 if [[ ${#sgmls} -eq 0 ]] then # if no -S, use installed one
94 if [[ -x ${info_dir}/etc/nsgmls ]] then
95 sgmls="${info_dir}/etc/nsgmls"
97 sgmls="${info_dir}/etc/sgmls"
100 sgmls="${sgmls:-${info_dir}/etc/sgmls}" # if no -S, use installed one
101 instant="${instant:-${dbk_lib}/instant}" # if no -I, use installed one
102 x_locale="${x_locale:-${dbk_lib}/xlate_locale}" # if no -L, use installed one
103 helptag2="${helptag2:-dthelp_htag2}" # if no -H, use one in PATH
105 # Set the environment variables for instant(1) to find its files
106 export TPT_LIB="${dbk_lib}"
107 export LOCALE_DIR="${dbk_lib}/$($x_locale)"
109 # Determine whether we are using sgmls or nsgmls
110 parser=`basename $sgmls`
112 # If running sgmls, set the environment variable for sgmls(1) to find
113 # its files; if running nsgmls (or anything besides sgmls), set the
114 # environment variable for finding the default catalog - also, if we
115 # are running sgmls, delete any -g options since sgmls doesn't support
117 if ([[ "$parser" = sgmls ]]) then
118 export SGML_PATH="${sgml_cat}/%P:${sgml_cat}/%S:%S"
120 elif ([[ "$SGML_CATALOG_FILES" = "" ]]) then
121 export SGML_CATALOG_FILES="${sgml_cat}/catalog"
123 export SGML_CATALOG_FILES="${SGML_CATALOG_FILES}:${sgml_cat}/catalog"
126 # Set the environment variable to be picked up inside instant(1) when it
128 export DBKTCL_DIR="${dbk_lib}/"
131 # The user asked for help, give it and exit.
133 echo "$command_name [options] <file>"
135 echo " -c compress an existing SDL file"
136 echo " -d decompress an existing SDL file"
137 echo " -g specify additional catalog file (repeatable)"
138 echo " -h emit this message"
139 echo " -l leave <basename>.log in current directory"
140 echo " -m <maps> add <maps> to list of SDATA or CMAP files"
141 echo " -o <file> use <file> as the output file name"
142 echo " -r remove leftover intermediate files"
143 echo " -s <dir> docbook.sgml is in <dir>"
144 echo " -t <dir> read translation specs, etc., from <dir>"
145 echo " -u do not compress during translation"
147 echo " -x leave intermediate files, for debugging"
152 # Check for too many input files or none.
153 if (( $OPTIND < $# )); then
154 fatal "Too many names after the options, should only be input file name"
155 elif (( $OPTIND > $# )); then
156 fatal "No input file name specified"
160 # Get the name of the input file.
161 iname=`eval echo \\\${\$OPTIND}`
163 # Check for mutually exclusive options.
164 if (( $compress && $decompress )); then
165 fatal "$c_and_d are mutually exclusive."
169 # Get the basename and directory of the input file.
170 basename=`basename $iname`
171 dirname=`dirname $iname`
174 # Look for an extension on the input file, if it's .sgm (or .sdl for
175 # -c and -d), use it as is, else add the proper extension.
176 if [[ $basename != *.* ]] then
177 if (( $compress || $decompress )); then
183 iname=$dirname/$basename
184 set -A basearray `echo $basename | tr "." " "`
185 basename=${basearray[0]}
186 length=${#basearray[*]}
187 if (( length = $length - 1 )); then
188 if (( $compress || $decompress )); then
189 if [[ ${basearray[$length]} = "sgm" ]] then
190 fatal "$c_and_d take .sdl as an extension, not .sgm"
191 elif [[ ${basearray[$length]} = "sdl" ]] then
192 unset basearray[$length]
197 if [[ ${basearray[$length]} = "sdl" ]] then
198 fatal "Use .sgm or no extension, not .sdl"
199 elif [[ ${basearray[$length]} = "sgm" ]] then
200 unset basearray[$length]
206 for i in ${basearray[*]}
208 basename=$basename.$i
214 # If no output file was specified, use <basename>.sdl.
215 if [[ $oname = "" ]] then
220 # Did the user ask to only remove old files (i.e., "clean")? If so,
222 if (( $remove )); then
223 if (( $verbose )); then
224 echo "rm -f $basename.esis"
227 if (( $verbose )); then
228 echo "rm -f $basename.out.sdl"
230 rm -f $basename.out.sdl
231 if (( $verbose )); then
232 echo "rm -f $basename.out.snb"
234 rm -f $basename.out.snb
235 if (( $verbose )); then
236 echo "rm -f $basename.log"
239 if (( $verbose )); then
240 echo "rm -f $basename.out.err"
242 rm -f $basename.out.err
243 if (( $verbose )); then
250 # make sure the error files are clean
251 if (( $verbose )); then
252 echo "rm -f $basename.log"
256 fatal "Could not remove $basename.log - permissions?"
258 if (( $verbose )); then
259 echo "rm -f $basename.out.err"
261 rm -f $basename.out.err
263 fatal "Could not remove $basename.out.err - permissions?"
267 # Did the user ask for only compression an existing .sdl file?
268 # If so, do it and exit with the return code of dthelp_htag2.
269 if (( $compress )); then
270 if (( $verbose )); then
271 echo $helptag2 -c $iname
275 $helptag2 -c $iname 2>/dev/null
280 # Did the user ask for only decompression an existing .sdl file?
281 # If so, do it and exit with the return code of dthelp_htag2.
282 if (( $decompress )); then
283 if (( $verbose )); then
284 echo $helptag2 -d $iname
288 $helptag2 -d $iname 2>/dev/null
293 # If we get here, we really want to process a .sgm file. First run
295 if [[ -a $basename.esis ]] then
296 if (( $verbose )); then
297 echo rm $basename.esis
301 fatalError "Could not remove $basename.esis - permissions?"
304 if (( $verbose )); then
305 echo "${sgmls} -deglru$catfiles ${sgml_dir}/docbook.sgml $iname > $basename.esis"
306 ${sgmls} -deglru$catfiles ${sgml_dir}/docbook.sgml $iname > $basename.esis
308 if (( !$debug )); then
309 echo "rm -f $basename.esis"
312 fatalError "Error processing $iname by $parser"
315 ${sgmls} -deglru$catfiles ${sgml_dir}/docbook.sgml $iname \
316 > $basename.esis 2> $basename.log
318 if (( !$debug )); then
321 fatalError "Error processing $iname by $parser"
326 # The sgmls(1) run succeeded. Run instant(1) on the result to create
327 # an unenhanced .sdl file (e.g., no LOIDS yet).
328 if [[ -a $basename.out.sdl ]] then
329 if (( $verbose )); then
330 echo rm -f $basename.out.sdl
332 rm -f $basename.out.sdl
334 fatalError "Could not remove $basename.out.sdl - permissions?"
336 if (( $verbose )); then
337 echo rm -f $basename.out.snb
339 rm -f $basename.out.snb
341 fatalError "Could not remove $basename.out.snb - permissions?"
344 if (( $verbose )); then
345 echo "${instant} -o $basename.out.sdl \\\\"
346 if [[ $mapfiles != "" ]] then
347 echo " $mapfiles \\\\"
349 echo " -c docbook.cmap \\\\"
350 echo " -t docbook.ts \\\\"
351 echo " $basename.esis"
352 ${instant} -o $basename.out.sdl \
358 if ([[ $status -eq 255 ]]) then
359 warn "Warning(s) processing $basename.esis by instant"
360 elif ([[ $status -eq 1 ]]) then
361 if (( !$debug )); then
362 echo "rm -f $basename.esis"
364 echo "rm -f $basename.out.sdl"
365 rm -f $basename.out.sdl
366 echo "rm -f $basename.out.snb"
367 rm -f $basename.out.snb
369 fatalError "Error processing $basename.esis by instant"
372 ${instant} -o $basename.out.sdl \
376 $basename.esis 2> $basename.log
378 if ([[ $status -eq 255 ]]) then
379 warn "Warning(s) processing $basename.esis by instant"
380 elif ([[ $status -eq 1 ]]) then
381 if (( !$debug )); then
383 rm -f $basename.out.sdl
384 rm -f $basename.out.snb
386 fatalError "Error processing $basename.esis by instant"
389 if (( !$debug )); then
390 if (( $verbose )); then
391 echo "rm -f $basename.esis"
397 # The run of instant(1) succeeded. Run dthelp_htag2(1) to create the
398 # generated elements (e.g., the list of ids or LOIDS), incorporate the
399 # table of semantics and styles (TOSS) and do the compression, if
401 if (( $uncompressed )); then
406 if [[ -a $oname ]] then
407 if (( $verbose )); then
412 fatalError "Could not remove $oname - permissions?"
415 if (( $verbose )); then
416 echo "$helptag2 $flags $basename.out.sdl $oname"
417 $helptag2 $flags $basename.out.sdl $oname
419 if (( !$debug )); then
420 echo "rm -f $basename.out.sdl"
421 rm -f $basename.out.sdl
422 echo "rm -f $basename.out.snb"
423 rm -f $basename.out.snb
427 fatalError "Error processing $basename.out.sdl by $helptag2"
430 $helptag2 $flags $basename.out.sdl $oname 2>/dev/null
432 if (( !$debug )); then
433 rm -f $basename.out.sdl
434 rm -f $basename.out.snb
437 fatalError "Error processing $basename.out.sdl by $helptag2"
440 if (( !$debug )); then
441 if (( $verbose )); then
442 echo "rm -f $basename.out.sdl"
444 rm -f $basename.out.sdl
445 if (( $verbose )); then
446 echo "rm -f $basename.out.snb"
448 rm -f $basename.out.snb
452 # If we get here, all went well - we know the .log files are writable.
453 if (( !$debug )); then
454 if (( $verbose )); then
455 echo "cat $basename.out.err >> $basename.log"
457 cat $basename.out.err >> $basename.log
458 if (( $verbose )); then
459 echo "rm -f $basename.out.err"
461 rm -f $basename.out.err
464 # if we're not in debug mode and the log file wasn't requested, remove it
465 if (( !$debug & !$log )); then
466 if (( $verbose )); then
467 echo "rm -f $basename.log"
472 if (( $verbose )); then
473 echo "$command_name successfully processed $iname"