summaryrefslogtreecommitdiff
path: root/tools/gnome-doc-tool.in
blob: d485b6cfa1edae49507543f04f68384d4d793981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
#!/bin/bash
# gnome-doc-html - Convert documentation to HTML
# gnome-doc-html.  Generated from gnome-doc-html.in by configure.
# Copyright (C) 2006 Shaun McCance <shaunm@gnome.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.

progname=`echo "$0" | sed 's%^.*/%%'`

PROGRAM=gnome-doc-html
PACKAGE=@PACKAGE@
VERSION=@VERSION@
prefix=@prefix@
datarootdir=@datarootdir@
datadir=@datadir@
pkgdatadir=@datadir@/gnome-doc-utils
xsltdir=@datadir@/xml/gnome/xslt

# This is important to make sure string manipulation is handled
# byte-by-byte.
export LANG=C

XSL_ICONS='
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mal="http://projectmallard.org/1.0/"
  version="1.0">
<xsl:import href="'$xsltdir'/gettext/gettext.xsl"/>
<xsl:output method="text" encoding="utf-8"/>
<xsl:template match="*">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match="text()"/>
<xsl:template match="caution">
  <xsl:text>admon-caution&#x000A;</xsl:text>
</xsl:template>
<xsl:template match="important">
  <xsl:text>admon-important&#x000A;</xsl:text>
</xsl:template>
<xsl:template match="note">
  <xsl:choose>
    <xsl:when test="@role='\''bug'\''">
      <xsl:text>admon-bug&#x000A;</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>admon-note&#x000A;</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:template match="tip">
  <xsl:text>admon-tip&#x000A;</xsl:text>
</xsl:template>
<xsl:template match="warning">
  <xsl:text>admon-warning&#x000A;</xsl:text>
</xsl:template>
<xsl:template match="mal:note">
  <xsl:choose>
    <xsl:when test="contains(concat('\'' '\'', @style, '\'' '\''), '\''advanced'\'')">
      <xsl:text>admon-important&#x000A;</xsl:text>
    </xsl:when>
    <xsl:when test="contains(concat('\'' '\'', @style, '\'' '\''), '\''bug'\'')">
      <xsl:text>admon-bug&#x000A;</xsl:text>
    </xsl:when>
    <xsl:when test="contains(concat('\'' '\'', @style, '\'' '\''), '\''important'\'')">
      <xsl:text>admon-important&#x000A;</xsl:text>
    </xsl:when>
    <xsl:when test="contains(concat('\'' '\'', @style, '\'' '\''), '\''tip'\'')">
      <xsl:text>admon-tip&#x000A;</xsl:text>
    </xsl:when>
    <xsl:when test="contains(concat('\'' '\'', @style, '\'' '\''), '\''warning'\'')">
      <xsl:text>admon-warning&#x000A;</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>admon-note&#x000A;</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:template match="/FALSE">
  <xsl:if test="//blockquote[1]">
    <xsl:call-template name="l10n.gettext">
      <xsl:with-param name="msgid" select="'\''blockquote-watermark-201C'\''"/>
    </xsl:call-template>
    <xsl:text>&#x000A;</xsl:text>
  </xsl:if>
  <xsl:if test="//classsynopsis[@language = '"'"'cpp'"'"'][1] or //programlisting[@language = '"'"'cpp'"'"']">
    <xsl:text>watermark-code-cpp&#x000A;</xsl:text>
  </xsl:if>
  <xsl:if test="//classsynopsis[@language = '"'"'python'"'"'][1] or //programlisting[@language = '"'"'python'"'"']">
    <xsl:text>watermark-code-python&#x000A;</xsl:text>
  </xsl:if>
</xsl:template>
</xsl:stylesheet>'

XSL_CACHE_LS='
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cache="http://projectmallard.org/cache/1.0/"
  xmlns:mal="http://projectmallard.org/1.0/"
  version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
  <xsl:for-each select="cache:cache/mal:page">
    <xsl:value-of select="@cache:href"/>
    <xsl:text>&#x000A;</xsl:text>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>'

XSL_DOCBOOK_MEDIA='
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
<xsl:output method="text" encoding="utf-8"/>
<xsl:template match="/">
  <xsl:for-each select="//audiodata|//imagedata|//videodata">
    <xsl:choose>
      <xsl:when test="@fileref">
        <xsl:value-of select="@fileref"/>
      </xsl:when>
      <xsl:when test="@entityref">
        <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
      </xsl:when>
    </xsl:choose>
    <xsl:text>&#x000A;</xsl:text>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>'

XSL_MALLARD_CSS='
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mal="http://projectmallard.org/1.0/"
  version="1.0">
<xsl:import href="'$xsltdir'/gettext/gettext.xsl"/>
<xsl:import href="'$xsltdir'/common/theme.xsl"/>
<xsl:import href="'$xsltdir'/mallard/html/mal2html-css.xsl"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="mal2html.css.content"/>
</xsl:template>
</xsl:stylesheet>'

XSL_MALLARD_MEDIA='
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mal="http://projectmallard.org/1.0/"
  version="1.0">
<xsl:output method="text" encoding="utf-8"/>
<xsl:template match="/">
  <xsl:for-each select="//mal:media">
    <xsl:value-of select="@src"/>
    <xsl:text>&#x000A;</xsl:text>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>'

error() {
    echo "$progname: $1" 1>&2;
    exit 1;
}

print_help() {
    cat <<EOF
Usage: $progname <COMMAND> [OPTIONS] FILES...
Process a documentation file.

COMMAND is one of:
  list-icons   list automatic icons and watermarks
  list-media   list all referenced media files
  html         convert the documents to HTML
  xhtml        convert the documents to XHTML
  css          create a CSS file for a Mallard document
  help         display this help and exit
EOF
}

print_help_css() {
cat <<EOF
Usage $progname css [OPTIONS] [FILE]
Create a CSS file for a Mallard document.
If FILE is not supplied, uses index.page as input.

CSS Options:
  -o, --output=PATH               the file to output to

Miscellaneous:
  -v, --verbose                   print all the commands executed
  -V, --version                   print version information and exit
  -h, --help                      display this help and exit
EOF
}

print_help_html() {
    format="$1"
    upformat=`echo $format | tr a-z A-Z`
    cat <<EOF
Usage: $progname $format [OPTIONS] FILE
Convert FILE into $upformat.

Basic Output Control:
  -c, --css-file=FILE             file to output CSS to
  -e, --extension=EXT             the extension to append to output files
  -n, --no-figures                do not copy figures into the output directory
  -o, --output=PATH               the file or directory to output to
  -x, --custom-xslt=PATH          custom XSLT to include in the transform
                                  (currently only for Mallard)

Automatic Graphics:
  --copy-graphics                 copy graphics into the output directory
  --admon-graphics-path=PATH      the path to the admonition graphics
  --admon-graphics-size=INT       the size of the admonition graphics

Docbook Chunking:
  -d, --chunk-depth=INT           how deep sections should be chunked

DocBook Styling:
  --classsynopsis-language=LANG   the default programming language to be used
                                  for classsynopsis elements
  --funcsynopsis-style=STYLE      the style to be used to render funcsynopsis
                                  elements, either 'KR' or 'ANSI'

Miscellaneous:
  -v, --verbose                   print all the commands executed
  -V, --version                   print version information and exit
  -h, --help                      display this help and exit
EOF
}

echo_verbose() {
    if [ "x$doc_verbose" = "x1" ]; then echo $1; fi
}

mkdir_p() {
    __dir__='';
    echo $1 | sed -e 's/\//\n/g' | while read d; do
	__dir__="$__dir__$d/"
	if [ ! -d "$__dir__" ]; then
	    echo_verbose "mkdir \"$__dir__\""
	    mkdir "$__dir__" || error "Could not create directory"
	fi
    done || exit 1;
}

urlencode() {
    arg="$1"
    i="0"
    while [ "$i" -lt ${#arg} ]; do
	c=${arg:$i:1}
	if echo "$c" | grep -q '[a-zA-Z/:_\.\-]'; then
	    echo -n "$c"
	else
	    echo -n "%"
	    printf "%X" "'$c'"
	fi
	i=$((i+1))
    done
}

urldecode() {
    arg="$1"
    i="0"
    while [ "$i" -lt ${#arg} ]; do
	c0=${arg:$i:1}
	if [ "x$c0" = "x%" ]; then
	    c1=${arg:$((i+1)):1}
	    c2=${arg:$((i+2)):1}
	    printf "\x$c1$c2"
	    i=$((i+3))
	else
	    echo -n "$c0"
	    i=$((i+1))
	fi
    done
}

copy_icons() {
    if [ "x$doc_copy_icons" = "x1" ]; then
	if [ "x$doc_icons_admon_path" = "x" ]; then
	    p="$pkgdatadir/icons/hicolor/"
	    if [ "x$doc_icons_admon_size" != "x" ]; then
		doc_icons_admon_path="${p}${doc_icons_admon_size}x${doc_icons_admon_size}/status"
	    else
		doc_icons_admon_path="${p}48x48/status"
	    fi
	    unset p
	fi
	for doc_icon in $(echo $doc_icons_to_copy | tr ' ' '\n' | grep '^admon-' | sort | uniq); do
	    doc_icon_file="${doc_icon}.png"
	    cmd="cp \"$doc_icons_admon_path/$doc_icon_file\" \"$doc_outdir/$doc_icon_file\""
	    echo_verbose "$cmd"
	    eval "$cmd"
	done
    fi
}

list_icons() {
    while [ "$#" != "0" ]; do
	if [ -d "$1" ]; then
	    list_icons "$1/"*.page
	else
	    echo "$XSL_ICONS" | xsltproc --nonet --xinclude - "$1"
	fi
	shift
    done | sort | uniq
}

list_media() {
    if [ "x$(echo "$1" | sed -e 's/.*\.//')" = "xpage" -o -d "$1" ]; then
	XSL_MEDIA="$XSL_MALLARD_MEDIA"
    else
	XSL_MEDIA="$XSL_DOCBOOK_MEDIA"
    fi
    while [ "$#" != "0" ]; do
	if [ -d "$1" ]; then
	    list_media "$1/"*.page
	else
	    doc_indir=$(dirname "$1")
	    if [ "$doc_indir" = "." ]; then
		doc_indir=""
	    else
		doc_indir="$doc_indir/"
	    fi
	    echo "$XSL_MEDIA" | xsltproc --nonet --xinclude - "$1" \
		| while read doc_media; do
		echo "$doc_indir$doc_media"
	    done
	fi
	shift
    done | sort | uniq
}

convert_docbook2html() {
    if [ "x$doc_extension" = "x" ]; then doc_extension=".$doc_format"; fi
    if [ "x$doc_output" = "x" ]; then
	doc_outdir=`pwd`
    elif [ -d "$doc_output" -o $(echo "$doc_output" | sed -e 's/.*\/$/\//') = "/" ]; then
	mkdir_p "$doc_output"
	doc_outdir=`(cd "$doc_output" && pwd)`
    else
	if [ "$#" != "1" ]; then
	    error "With multiple input files, output must be a directory"
	fi
	dir=`dirname "$doc_output"`
	mkdir_p "$dir"
	doc_outdir=`(cd "$dir" && pwd)`
	doc_outfile=`basename "$doc_output"`
	doc_outfile_q="1"
	if [ "x$doc_extension" = "x" ]; then
	    doc_extension=`echo "$doc_outfile" | grep -o '\..*'`
	fi;
    fi;
    while [ "$#" != "0" ]; do
	doc_input="$1"
	shift

	if [ ! -f "$doc_input" ]; then error "$doc_input: No such file"; fi
	doc_indir=$( (cd $(dirname "$doc_input") && pwd) )
	doc_infile=$(basename "$doc_input")
	doc_inbase=$(basename "$doc_infile" ".xml")
	if [ "$doc_inbase" = "$doc_infile" ]; then
	    doc_inbase=$(basename "$doc_infile" ".docbook")
	fi;

	if [ "x$doc_outfile_q" != "x1" ]; then
	    doc_outfile="${doc_inbase}${doc_extension}"
	fi
	doc_outbase=$(basename "$doc_outfile" "$doc_extension")

	params='--param db.chunk.chunk_top 0'
	params="$params --stringparam db.chunk.basename \"$doc_outbase\""
	params="$params --stringparam db.chunk.extension \"$doc_extension\""
	if [ "x$doc_chunk_depth" != "x" ]; then
	    params="$params --param db.chunk.max_depth $doc_chunk_depth"
	fi
	if [ "x$doc_css_file" != "x" ]; then
	    params="$params --stringparam db2html.css.file \"$doc_css_file\""
	fi

	if [ "x$doc_copy_icons" = "x1" ]; then
	    doc_icons=$(list_icons "$doc_indir/$doc_infile")
	    doc_icons_to_copy="$doc_icons $doc_icons_to_copy"
	    for doc_icon in $(echo $doc_icons | tr ' ' '\n' | grep '^admon-' | sort | uniq); do
		param="theme.icon."$(echo $doc_icon | sed -e 's/-/./');
		params="$params --stringparam $param \"$doc_icon\""
	    done
	fi
	if [ "x$doc_copy_icons" != "x1" -a "x$doc_icons_path" != "x" ]; then
	    params="$params --stringparam theme.icon.admon.path \"$doc_icons_admon_path\""
	fi
	if [ "x$doc_admon_graphics_size" != "x" ]; then
	    params="$params --stringparam theme.icon.admon.size \"$doc_icons_admon_size\""
	fi
	if [ "x$doc_classsynopsis_language" != "x" ]; then
	    params="$params --stringparam db2html.classsynopsis.language"
	    params="$params \"$doc_classsynopsis_language\""
	fi
	if [ "x$doc_funcsynopsis_style" != "x" ]; then
	    params="$params --stringparam db2html.funcsynopsis.style"
	    params="$params \"$doc_funcsynopsis_style\""
	fi

	cmd="xmllint --nonet --xinclude \"$doc_indir/$doc_infile\" |\
          xsltproc $params -o \"$doc_outdir/$doc_outfile\" \"$xsltdir/docbook/html/db2$doc_format.xsl\" -"
	echo_verbose "$cmd"
	eval "$cmd"
	exit 0

	if [ "x$doc_no_figures" != "x1" -a "$doc_indir" != "$doc_outdir" ]; then
	    echo "$XSL_DOCBOOK_MEDIA" \
		| xsltproc --nonet --xinclude - "$doc_indir/$doc_infile" \
		| while read doc_media; do
		mkdir_p "$doc_outdir/"`dirname "$fig"`
		cmd="cp \"$doc_indir/$fig\" \"$doc_outdir/$fig\""
		echo_verbose "$cmd"
		eval "$cmd"
	    done
	fi
    done
    copy_icons
}

convert_mallard2html() {
    if [ "x$doc_extension" = "x" ]; then doc_extension=".$doc_format"; fi
    if [ "x$doc_output" = "x" ]; then
	doc_outdir=`pwd`
    elif [ -d "$doc_output" -o $(echo "$doc_output" | sed -e 's/.*\/$/\//') = "/" ]; then
	mkdir_p "$doc_output"
	doc_outdir=`(cd "$doc_output" && pwd)`
    else
	if [ "$#" != "1" -o -d "$1" ]; then
	    error "With multiple input files, output must be a directory"
	fi
	dir=`dirname "$doc_output"`
	mkdir_p "$dir"
	doc_outdir=`(cd "$dir" && pwd)`
	doc_outfile=`basename "$doc_output"`
	doc_outfile_q="1"
	if [ "x$doc_extension" = "x" ]; then
	    doc_extension=`echo "$doc_outfile" | grep -o '\..*'`
	fi;
    fi;
    doc_cache_in="$doc_outdir/index.cache.in"
    doc_cache="$doc_outdir/index.cache"
    doc_tmpfiles="$doc_tmpfiles doc_cache_in doc_cache_out"
    (
	echo '<cache:cache xmlns:cache="http://projectmallard.org/cache/1.0/"'
	echo '             xmlns="http://projectmallard.org/1.0/">'
	while [ "$#" != "0" ]; do
	    doc_input="$1"
	    shift
	    if [ -d "$doc_input" ]; then
		doc_input_full=$(cd "$doc_input" && pwd)
		for doc_input_file in "$doc_input_full/"*.page; do
		    echo "$doc_input_file"
		done
		unset doc_input_full
	    else
		echo "$(pwd)/$doc_input"
	    fi
	done | while read doc_input; do
	    doc_input_esc=$(urlencode "$doc_input" | sed -e 's/\&/\&amp;/g' -e 's/</\&lt;/g' -e "s/'/\&apos;/g")
	    echo "<page cache:href='file://$doc_input_esc'/>"
	done
	echo '</cache:cache>'
    ) > "$doc_cache_in"
    xsltproc -o "$doc_cache" "$xsltdir/mallard/cache/mal-cache.xsl" "$doc_cache_in"
    rm "$doc_cache_in"
    echo "$XSL_CACHE_LS" | xsltproc - "$doc_cache" | while read doc_input; do
	doc_input=$(urldecode $(echo "$doc_input" | sed -e 's/^file:\/\///'))
	doc_indir=$( (cd $(dirname "$doc_input") && pwd) )
	doc_infile=$(basename "$doc_input")
	doc_inbase=$(basename "$doc_infile" ".page")

	if [ "x$doc_outfile_q" != "x1" ]; then
	    doc_outfile="${doc_inbase}${doc_extension}"
	fi

	params='--param mal.chunk.chunk_top 0'
	params="$params --stringparam mal.cache.file \"$doc_cache\""

	if [ "x$doc_css_file" != "x" ]; then
	    params="$params --stringparam mal2html.css.file \"$doc_css_file\""
	fi

	if [ "x$doc_copy_icons" = "x1" ]; then
	    doc_icons=$(list_icons "$doc_indir/$doc_infile")
	    doc_icons_to_copy="$doc_icons $doc_icons_to_copy"
	    for doc_icon in $(echo $doc_icons | tr ' ' '\n' | grep '^admon-' | sort | uniq); do
		param="theme.icon."$(echo $doc_icon | sed -e 's/-/./');
		params="$params --stringparam $param \"$doc_icon\""
	    done
	fi
	if [ "x$doc_copy_icons" != "x1" -a "x$doc_icons_path" != "x" ]; then
	    params="$params --stringparam theme.icon.admon.path \"$doc_icons_admon_path\""
	fi
	if [ "x$doc_admon_graphics_size" != "x" ]; then
	    params="$params --stringparam theme.icon.admon.size \"$doc_icons_admon_size\""
	fi

	if [ "x$doc_custom_xslt" != "x" ]; then
	    cmd="echo '<stylesheet xmlns=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\
                       <import href=\"$xsltdir/mallard/html/mal2$doc_format.xsl\"/>\
                       <include href=\"$doc_custom_xslt\"/></stylesheet>' |\
                 xsltproc --nonet --xinclude $params -o \"$doc_outdir/$doc_outfile\"\
                 - \"$doc_indir/$doc_infile\""
	else
	    cmd="xsltproc --nonet --xinclude $params -o \"$doc_outdir/$doc_outfile\"\
                 \"$xsltdir/mallard/html/mal2$doc_format.xsl\" \"$doc_indir/$doc_infile\""
	fi
	echo_verbose "$cmd"
	eval "$cmd"

	if [ "x$doc_no_figures" != "x1" -a "$doc_indir" != "$doc_outdir" ]; then
	    echo "$XSL_MALLARD_MEDIA" \
		| xsltproc --nonet --xinclude - "$doc_indir/$doc_infile" \
		| while read doc_media; do
		mkdir_p "$doc_outdir/"`dirname "$doc_media"`
		cmd="cp \"$doc_indir/$doc_media\" \"$doc_outdir/$doc_media\""
		echo_verbose "$cmd"
		eval "$cmd"
	    done
	fi
    done
    copy_icons
}

create_css() {
    longopts='
      -loutput:
      -lverbose
      -lversion
      -lhelp
    ';
    options=`getopt -qn$progname $longopts -- o:vVh "$@"`
    if [ "$?" != "0" ]; then print_help_css 1>&2; exit 1; fi
    eval set -- "$options";
    while [ "$1" != "--" ]; do
	case "$1" in
	    -o | --output)
		doc_output="$2";;

	    -v | --verbose)
		doc_verbose=1;;

	    -V | --version)
		echo "$PROGRAM ($PACKAGE) $VERSION"
		exit 0;;
	    -h | --help)
		print_help_css
		exit 0;;
	    --)
		print_help_css 1>&2
		exit 1;;
	esac
	shift
    done
    shift

    doc_input_page="$1"
    if [ "x$doc_input_page" = "x" ]; then
	doc_input_page="index.page"
    fi
    if [ "x$doc_output" = "x" ]; then
	doc_output="index.css"
    fi

    echo_verbose "Creating $doc_output using $doc_input_page"
    echo "$XSL_MALLARD_CSS" | xsltproc -o "$doc_output" - "$doc_input_page";
}

convert_2html() {
    doc_format="$1"
    shift
    longopts='
      -lcss-file:
      -lchunk-depth:
      -lextension:
      -lno-figures
      -loutput:
      -lcustom-xslt:
      -lcopy-graphics
      -ladmon-graphics-path:
      -ladmon-graphics-size:
      -lclasssynopsis-language:
      -lfuncsynopsis-style:
      -lverbose
      -lversion
      -lhelp
    ';
    options=`getopt -qn$progname $longopts -- c:d:e:o:x:nvVh "$@"`
    if [ "$?" != "0" ]; then print_help_html $doc_format 1>&2; exit 1; fi
    eval set -- "$options";
    while [ "$1" != "--" ]; do
	case "$1" in
	    -c | --css-file)
		doc_css_file="$2";;
	    -d | --chunk-depth)
		doc_chunk_depth="$2";;
	    -e | --extension)
		doc_extension="$2";;
	    -n | --no-figures)
		doc_no_figures="1";;
	    -o | --output)
		doc_output="$2";;
	    -x | --custom-xslt)
		doc_custom_xslt="$2";;

	    --copy-graphics)
		doc_copy_icons="1";;
	    --admon-graphics-path)
		doc_icons_admon_path="$2";;
	    --admon-graphics-size)
		doc_icons_admon_size="$2";;
	    --classsynopsis-language)
		doc_classsynopsis_language="$2";;
	    --funcsynopsis-style)
		doc_funcsynopsis_style="$2";;

	    -v | --verbose)
		doc_verbose=1;;

	    -V | --version)
		echo "$PROGRAM ($PACKAGE) $VERSION"
		exit 0;;
	    -h | --help)
		print_help_html $doc_format
		exit 0;;
	    --)
		print_help_html $doc_format 1>&2
		exit 1;;
	esac
	shift
    done
    shift

    if [ "$#" = "0" ]; then print_help_html $doc_format 1>&2; exit 1; fi
    if [ "x$(echo "$1" | sed -e 's/.*\.//')" = "xpage" -o -d "$1" ]; then
	convert_mallard2html $@;
    else
	convert_docbook2html $@;
    fi
    exit 0
}


command="$1";
if [ "x$command" = "x" ]; then
    print_help 1>&2;
    exit 1;
fi;
shift;
if [ "$command" = "html" -o "$command" = "xhtml" ]; then
    convert_2html "$command" $@;
elif [ "$command" = "css" ]; then
    create_css $@;
elif [ "$command" = "list-icons" ]; then
    list_icons $@;
elif [ "$command" = "list-media" ]; then
    list_media $@;
elif [ "$command" = "-V" -o "$command" = "--version" ]; then
    echo "$PROGRAM ($PACKAGE) $VERSION";
    exit 0;
elif [ "$command" = "help" ]; then
    print_help;
    exit 0;
else
    print_help 1>&2;
    exit 1;
fi;