This file is indexed.

/usr/bin/yelp-build is in yelp-tools 3.10.0-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
#!/bin/sh
# yelp-build
# Copyright (C) 2010 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

xsl_mal_cache='/usr/share/yelp-xsl/xslt/mallard/cache/mal-cache.xsl'
xsl_db2html='/usr/share/yelp-xsl/xslt/docbook/html/db2html.xsl'
xsl_db2xhtml='/usr/share/yelp-xsl/xslt/docbook/html/db2xhtml.xsl'
xsl_mal2html='/usr/share/yelp-xsl/xslt/mallard/html/mal2html.xsl'
xsl_mal2xhtml='/usr/share/yelp-xsl/xslt/mallard/html/mal2xhtml.xsl'
yelp_icon_dir='/usr/share/yelp-xsl/icons/hicolor/24x24/status'
yelp_js_dir='/usr/share/yelp-xsl/js'
xsl_mal_epub='/usr/share/yelp-tools/xslt/mal-epub.xsl'
xsl_mal_opf='/usr/share/yelp-tools/xslt/mal-opf.xsl'
xsl_mal_ncx='/usr/share/yelp-tools/xslt/mal-ncx.xsl'

mkdir_p () {
    if [ ! -d "$1" ]; then
        mkdir_p `dirname "$1"`
        mkdir "$1"
    fi
}

urlencode () {
    LANG=C awk '
BEGIN {
  for (i = 1; i <= 255; i++) chars[sprintf("%c", i)] = i;
}
{
  ret = "";
  for (i = 1; i <= length($0); i++) {
    c = substr($0, i, 1);
    if (c ~ /[\/a-zA-Z0-9._-]/)
      ret = ret c;
    else
      ret = ret sprintf("%%%X%X", int(chars[c] / 16), chars[c] % 16);
  }
  print ret;
}'
}

urldecode () {
    LANG=C awk '
BEGIN {
  for(i = 0; i < 10; i++) hex[i] = i;
  hex["A"] = hex["a"] = 10;
  hex["B"] = hex["b"] = 11;
  hex["C"] = hex["c"] = 12;
  hex["D"] = hex["d"] = 13;
  hex["E"] = hex["e"] = 14;
  hex["F"] = hex["f"] = 15;
}
{
  ret = "";
  for (i = 1; i <= length($0); i++) {
    c = substr($0, i, 1);
    if (c == "+") {
      ret = ret " ";
    }
    else if (c == "%") {
      c = sprintf("%c", hex[substr($0, i + 1, 1)] * 16 + hex[substr($0, i + 2, 1)]);
      ret = ret c;
      i += 2;
    }
    else {
      ret = ret c;
    }
  }
  print ret;
}'
}

yelp_usage () {
    (
        echo "Usage: yelp-build <COMMAND> [OPTIONS] [FILES]"
        echo ""
        echo "Commands:"
        echo "  cache         Create a Mallard cache file"
        echo "  epub          Create an EPUB file for Mallard"
        echo "  html          Convert input files to HTML"
        echo "  xhtml         Convert input files to XHTML"
    ) 1>&2
}
yelp_usage_cache () {
    (
        echo "Usage: yelp-build cache <FILES>"
        echo ""
        echo "  Create a Mallard cache file from the page files FILES."
        echo "  If FILES contains directories, all .page files in those"
        echo "  directories will be used."
        echo ""
        echo "Options:"
        echo "  -o OUT        Output cache to the file OUT"
    ) 1>&2
}
yelp_usage_epub () {
    (
        echo "Usage: yelp-build epub [OPTIONS] <FILES>"
        echo ""
        echo "  Create and EPUB file from the Mallard page files FILES."
        echo ""
        echo "Options:"
        echo "  -c CACHE      Use the existing Mallard cache CACHE"
        echo "  -o OUT        Output en EPUB file named OUT"
        echo "  -x CUSTOM     Import the custom XSLT file CUSTOM"
    ) 1>&2
}
yelp_usage_html () {
    (
        echo "Usage: yelp-build <html|xhtml> [OPTIONS] <FILES>"
        echo ""
        echo "  Create HTML or XHTML from the input files FILES."
        echo "  FILES can be DocBook files, Mallard page files,"
        echo "  or directories containing Mallard page files."
        echo ""
        echo "Options:"
        echo "  -c CACHE      Use the existing Mallard cache CACHE"
        echo "  -o OUT        Output files in the directory OUT"
        echo "  -x CUSTOM     Import the custom XSLT file CUSTOM"
    ) 1>&2
}

if [ $# = 0 ]; then
    yelp_usage
    exit 1
fi

yelp_cache_in () {
    echo '<cache:cache xmlns:cache="http://projectmallard.org/cache/1.0/"'
    echo '  xmlns="http://projectmallard.org/1.0/">'
    for page in "$@"; do
        if [ -d "$page" ]; then
            for sub in "$page"/*.page; do
                fbase=`basename "$sub"`
                fdir=`dirname "$sub"`
                fdir=`(cd "$fdir" && pwd)`
                echo "$fdir/$fbase"
            done
        else
            fbase=`basename "$page"`
            fdir=`dirname "$page"`
            fdir=`(cd "$fdir" && pwd)`
            echo "$fdir/$fbase"
        fi
    done | urlencode |
    while read line; do
        echo '<page cache:href="file://'"$line"'"/>'
    done
    echo '</cache:cache>'
}
yelp_cache () {
    cache_out="index.cache"
    while [ "$#" != "0" ]; do
        case "$1" in
            "-o")
                shift
                cache_out="$1"
                shift
                ;;
            *)
                break
                ;;
        esac
    done
    if [ "$#" = "0" -o "x$1" = "x--help" ]; then
        yelp_usage_cache
        exit 1
    fi
    yelp_cache_in "$@" | xsltproc --xinclude -o "$cache_out" "$xsl_mal_cache" -
}

yelp_html_xsl_common () {
    if [ "x$html_internal_datadir" != "x" ]; then
        echo '<xsl:variable name="yelp.internal.datadir" select="'"'$html_internal_datadir'"'"/>'
        echo '<xsl:param name="html.css.root" select="$yelp.internal.datadir"/>'
        echo '<xsl:param name="html.js.root" select="$yelp.internal.datadir"/>'
    else
        echo '<xsl:variable name="yelp.internal.datadir" select="'"''"'"/>'
    fi
    if [ "x$html_internal_xsl" != "x" ]; then
        echo '<xsl:include href="file://'`echo "$html_internal_xsl" | urlencode`'"/>'
    fi
    if [ "x$html_custom" != "x" ]; then
        echo '<xsl:include href="file://'`echo "$html_custom" | urlencode`'"/>'
    fi
    echo '<xsl:template name="html.css">'
    echo ' <xsl:param name="node" select="."/>'
    echo ' <xsl:variable name="yelp.locale">'
    echo '  <xsl:choose>'
    echo '   <xsl:when test="$node/@xml:lang != '"''"'">'
    echo '    <xsl:value-of select="$node/@xml:lang"/>'
    echo '   </xsl:when>'
    echo '   <xsl:when test="$node/@lang != '"''"'">'
    echo '    <xsl:value-of select="$node/@lang"/>'
    echo '   </xsl:when>'
    echo '   <xsl:otherwise>'
    echo '    <xsl:text>C</xsl:text>'
    echo '   </xsl:otherwise>'
    echo '  </xsl:choose>'
    echo ' </xsl:variable>'
    echo ' <exsl:document href="{$yelp.internal.datadir}{$yelp.locale}.css" method="text">'
    echo '  <xsl:call-template name="html.css.content">'
    echo '   <xsl:with-param name="node" select="$node"/>'
    echo '   <xsl:with-param name="direction">'
    echo '    <xsl:call-template name="l10n.direction">'
    echo '     <xsl:with-param name="lang" select="$yelp.locale"/>'
    echo '    </xsl:call-template>'
    echo '   </xsl:with-param>'
    echo '  </xsl:call-template>'
    echo ' </exsl:document>'
    echo ' <link rel="stylesheet" type="text/css" href="{$html.css.root}{$yelp.locale}.css"/>'
    echo '</xsl:template>'
    echo '<xsl:template name="html.js">'
    echo ' <xsl:param name="node" select="."/>'
    echo ' <xsl:call-template name="html.js.jquery">'
    echo '  <xsl:with-param name="node" select="$node"/>'
    echo ' </xsl:call-template>'
    echo ' <xsl:call-template name="html.js.custom">'
    echo '  <xsl:with-param name="node" select="$node"/>'
    echo ' </xsl:call-template>'
    echo ' <exsl:document href="{$yelp.internal.datadir}yelp.js" method="text">'
    echo '  <xsl:call-template name="html.js.content">'
    echo '   <xsl:with-param name="node" select="$node"/>'
    echo '  </xsl:call-template>'
    echo ' </exsl:document>'
    echo ' <script type="text/javascript" src="{$html.js.root}yelp.js"/>'
    echo '</xsl:template>'
}
yelp_html_db2html () {
    for xml in "$@"; do
        xmldir=`dirname "$xml"`
        xmldir=`(cd "$xmldir" && pwd)`
        # Output HTML
        (
            echo '<xsl:stylesheet'
            echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
            echo ' xmlns:exsl="http://exslt.org/common"'
            echo ' xmlns="http://www.w3.org/1999/xhtml"'
            echo ' extension-element-prefixes="exsl"'
            echo ' version="1.0">'
            if [ "x$is_xhtml" = "x1" ]; then
                xsl='file://'`echo "$xsl_db2xhtml" | urlencode`
            else
                xsl='file://'`echo "$xsl_db2html" | urlencode`
            fi
            echo '<xsl:import href="'"$xsl"'"/>'
            yelp_html_xsl_common
            echo '</xsl:stylesheet>'
        ) | xsltproc --xinclude -o "$html_out"/ - "$xml"
        # Copy media
        if [ "x$xmldir" != "x$html_out" ]; then
            (
                echo '<xsl:stylesheet'
                echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
                echo ' xmlns:db="http://docbook.org/ns/docbook"'
                echo ' exclude-result-prefixes="db"'
                echo ' version="1.0">'
                echo '<xsl:output method="text"/>'
                echo '<xsl:template match="/">'
                echo ' <xsl:for-each select="'
                echo '   //audiodata | //imagedata | //videodata |'
                echo '   //db:audiodata | //db:imagedata | //db:videodata">'
                echo '  <xsl:value-of select="concat(@fileref, '"'&#x000A;'"')"/>'
                echo ' </xsl:for-each>'
                echo '</xsl:template>'
                echo '</xsl:stylesheet>'
            ) | xsltproc --xinclude - "$xml" | while read media; do
                mfile=`echo "$media" | urldecode`
                minput="$xmldir/$mfile"
                moutput="$html_out/$mfile"
                mkdir_p `dirname "$moutput"`
                cp "$minput" "$moutput"
            done
        fi
        # Copy icons
        (
            echo '<xsl:stylesheet'
            echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
            echo ' xmlns:db="http://docbook.org/ns/docbook"'
            echo ' exclude-result-prefixes="db"'
            echo ' version="1.0">'
            echo '<xsl:output method="text"/>'
            echo '<xsl:template match="/">'
            echo ' <xsl:for-each select="(//caution|//warning|//db:caution|//db:warning)[1]">'
            echo '  <xsl:text>yelp-note-warning&#x000A;</xsl:text>'
            echo ' </xsl:for-each>'
            echo ' <xsl:for-each select="(//important|//db:important)[1]">'
            echo '  <xsl:text>yelp-note-important&#x000A;</xsl:text>'
            echo ' </xsl:for-each>'
            echo ' <xsl:for-each select="(//tip|//db:tip)[1]">'
            echo '  <xsl:text>yelp-note-tip&#x000A;</xsl:text>'
            echo ' </xsl:for-each>'
            echo ' <xsl:for-each select="(//note|//db:note)[@role='"'bug'"'][1]">'
            echo '  <xsl:text>yelp-note-bug&#x000A;</xsl:text>'
            echo ' </xsl:for-each>'
            echo ' <xsl:for-each select="(//note|//db:note)[not(@role) or @role!='"'bug'"'][1]">'
            echo '  <xsl:text>yelp-note&#x000A;</xsl:text>'
            echo ' </xsl:for-each>'
            echo '</xsl:template>'
            echo '</xsl:stylesheet>'
        ) | xsltproc --xinclude - "$xml" | sort | uniq | while read icon; do
            cp "${yelp_icon_dir}/${icon}.png" "$html_out/$html_internal_datadir"
        done;
        # Copy jQuery
        cp "${yelp_js_dir}/jquery.js" "$html_out/$html_internal_datadir"
        cp "${yelp_js_dir}/jquery.syntax.js" "$html_out/$html_internal_datadir"
        cp "${yelp_js_dir}/jquery.syntax.core.js" "$html_out/$html_internal_datadir"
        cp "${yelp_js_dir}/jquery.syntax.layout.yelp.js" "$html_out/$html_internal_datadir"
        (
            echo '<xsl:stylesheet'
            echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
            echo ' xmlns:db="http://docbook.org/ns/docbook"'
            echo ' xmlns:html="http://www.w3.org/1999/xhtml"'
            echo ' xmlns:exsl="http://exslt.org/common"'
            echo ' exclude-result-prefixes="db"'
            echo ' extension-element-prefixes="exsl"'
            echo ' version="1.0">'
            xsl='file://'`echo "$xsl_db2xhtml" | urlencode`
            echo '<xsl:import href="'"$xsl"'"/>'
            echo '<xsl:output method="text"/>'
            echo '<xsl:template match="/">'
            echo ' <xsl:for-each select="//programlisting[@language] | //db:programlisting[@language]">'
            echo '  <xsl:variable name="out">'
            echo '   <xsl:call-template name="db2html.pre"/>'
            echo '  </xsl:variable>'
            echo '  <xsl:value-of select="exsl:node-set($out)/*/html:pre[last()]/@class"/>'
            echo '  <xsl:text>&#x000A;</xsl:text>'
            echo ' </xsl:for-each>'
            echo '</xsl:template>'
            echo '</xsl:stylesheet>'
        ) | xsltproc --xinclude - "$xml" | sort | uniq \
            | grep '^contents syntax ' | sed -e 's/^contents syntax brush-/brush./' \
            | while read js; do
            cp "${yelp_js_dir}/jquery.syntax.${js}.js" "$html_out/$html_internal_datadir"
        done
    done
}

yelp_html_mal2html () {
    if [ "x$html_cache_file" != "x" ]; then
        html_cache_file=`(cd $(dirname "$html_cache_file") && pwd)`/`basename "$html_cache_file"`
    else
        html_cache_file_is_tmp="yes"
        html_cache_file=`mktemp "${TMPDIR:-/tmp}"/yelp-XXXXXXXX`
        yelp_cache -o "$html_cache_file" "$@"
    fi
    html_tmp_infile=`mktemp "${TMPDIR:-/tmp}"/yelp-XXXXXXXX`
    yelp_cache_in "$@" > "$html_tmp_infile"
    (
        echo '<xsl:stylesheet'
        echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
        echo ' xmlns:mal="http://projectmallard.org/1.0/"'
        echo ' xmlns:cache="http://projectmallard.org/cache/1.0/"'
        echo ' xmlns:exsl="http://exslt.org/common"'
        echo ' xmlns="http://www.w3.org/1999/xhtml"'
        echo ' exclude-result-prefixes="mal cache"'
        echo ' extension-element-prefixes="exsl"'
        echo ' version="1.0">'
        if [ "x$is_xhtml" = "x1" ]; then
            xsl='file://'`echo "$xsl_mal2xhtml" | urlencode`
        else
            xsl='file://'`echo "$xsl_mal2html" | urlencode`
        fi
        echo '<xsl:import href="'"$xsl"'"/>'
        yelp_html_xsl_common
        html_cache_url='file://'`echo "$html_cache_file" | urlencode`
        echo '<xsl:param name="mal.cache.file" select="'"'$html_cache_url'"'"/>'
        echo '<xsl:template match="/">'
        echo '<xsl:for-each select="cache:cache/mal:page">'
        echo '<xsl:for-each select="document(@cache:href)/mal:page">'
        echo '<xsl:call-template name="html.output"/>'
        echo '</xsl:for-each>'
        echo '</xsl:for-each>'
        echo '</xsl:template>'
        echo '</xsl:stylesheet>'
    ) | xsltproc $html_profile --xinclude -o "$html_out"/ - "$html_tmp_infile"
    (
        echo '<xsl:stylesheet'
        echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
        echo ' xmlns:mal="http://projectmallard.org/1.0/"'
        echo ' xmlns:cache="http://projectmallard.org/cache/1.0/"'
        echo ' xmlns:e="http://projectmallard.org/experimental/"'
        echo ' xmlns:exsl="http://exslt.org/common"'
        echo ' xmlns:html="http://www.w3.org/1999/xhtml"'
        echo ' extension-element-prefixes="exsl"'
        echo ' version="1.0">'
        xsl='file://'`echo "$xsl_mal2xhtml" | urlencode`
        echo '<xsl:import href="'"$xsl"'"/>'
        echo '<xsl:output method="text"/>'
        echo '<xsl:template name="dirname">'
        echo ' <xsl:param name="str"/>'
        echo ' <xsl:if test="contains($str, '\''/'\'')">'
        echo '  <xsl:value-of select="substring-before($str, '\''/'\'')"/>'
        echo '  <xsl:text>/</xsl:text>'
        echo '  <xsl:call-template name="dirname">'
        echo '   <xsl:with-param name="str" select="substring-after($str, '\''/'\'')"/>'
        echo '  </xsl:call-template>'
        echo ' </xsl:if>'
        echo '</xsl:template>'
        echo '<xsl:template match="/">'
        echo '<xsl:for-each select="cache:cache/mal:page">'
        echo ' <xsl:variable name="dir">'
        echo '  <xsl:call-template name="dirname">'
        echo '   <xsl:with-param name="str" select="substring-after(@cache:href, '\''file://'\'')"/>'
        echo '  </xsl:call-template>'
        echo ' </xsl:variable>'
        echo ' <xsl:variable name="node" select="document(@cache:href)/mal:page"/>'
        # Media
        echo ' <xsl:for-each select="$node//mal:media | $node//e:mouseover">'
        echo '  <xsl:if test="not(contains(@src, '\'':'\''))">'
        echo '   <xsl:value-of select="concat('"'-'"', $dir, @src, '"' '"')"/>'
        echo '   <xsl:value-of select="concat(@src, '"'&#x000A;'"')"/>'
        echo '  </xsl:if>'
        echo ' </xsl:for-each>'
        # Syntax highlighting
        echo ' <xsl:for-each select="$node//mal:code[@mime]">'
        echo '  <xsl:variable name="out">'
        echo '   <xsl:call-template name="mal2html.pre"/>'
        echo '  </xsl:variable>'
        echo '  <xsl:variable name="class">'
        echo '   <xsl:value-of select="exsl:node-set($out)/*/html:pre[last()]/@class"/>'
        echo '  </xsl:variable>'
        echo '  <xsl:if test="starts-with($class, '\''contents syntax brush-'\'')">'
        echo '   <xsl:text>+'"${yelp_js_dir}"'/jquery.syntax.brush.</xsl:text>'
        echo '   <xsl:value-of select="substring-after($class, '\''contents syntax brush-'\'')"/>'
        echo '   <xsl:text>.js ./&#x000A;</xsl:text>'
        echo '  </xsl:if>'
        echo ' </xsl:for-each>'
        # Icons
        echo ' <xsl:for-each select="$node//mal:note">'
        echo '  <xsl:variable name="style" select="concat('\'' '\'', @style, '\'' '\'')"/>'
        echo '  <xsl:choose>'
        # echo '   <xsl:when test="contains($style, '\'' advanced '\'')">'
        # echo '    <xsl:text>+'"${yelp_icon_dir}"'/yelp-note-advanced.png ./&#x000A;</xsl:text>'
        # echo '   </xsl:when>'
        echo '   <xsl:when test="contains($style, '\'' bug '\'')">'
        echo '    <xsl:text>+'"${yelp_icon_dir}"'/yelp-note-bug.png ./&#x000A;</xsl:text>'
        echo '   </xsl:when>'
        echo '   <xsl:when test="contains($style, '\'' important '\'')">'
        echo '    <xsl:text>+'"${yelp_icon_dir}"'/yelp-note-important.png ./&#x000A;</xsl:text>'
        echo '   </xsl:when>'
        echo '   <xsl:when test="contains($style, '\'' sidebar '\'')"/>'
        echo '   <xsl:when test="contains($style, '\'' tip '\'')">'
        echo '    <xsl:text>+'"${yelp_icon_dir}"'/yelp-note-tip.png ./&#x000A;</xsl:text>'
        echo '   </xsl:when>'
        echo '   <xsl:when test="contains($style, '\'' warning '\'')">'
        echo '    <xsl:text>+'"${yelp_icon_dir}"'/yelp-note-warning.png ./&#x000A;</xsl:text>'
        echo '   </xsl:when>'
        echo '   <xsl:otherwise>'
        echo '    <xsl:text>+'"${yelp_icon_dir}"'/yelp-note.png ./&#x000A;</xsl:text>'
        echo '   </xsl:otherwise>'
        echo '  </xsl:choose>'
        echo ' </xsl:for-each>'
        echo '</xsl:for-each>'
        echo '</xsl:template>'
        echo '</xsl:stylesheet>'
    ) | xsltproc --xinclude - "$html_tmp_infile" | sort | uniq |
    while read line; do
        use_internal_datadir=`expr substr "$line" 1 1`
        line=`expr substr "$line" 2 1000`
        line_src=`echo "$line" | cut -d' ' -f1`
        line_src=`echo "$line_src" | urldecode`
        if [ "x$use_internal_datadir" = "x+" ]; then
            line_dest="$html_out/$html_internal_datadir"`echo "$line" | cut -d' ' -f2`
        else
            line_dest="$html_out/"`echo "$line" | cut -d' ' -f2`
        fi
        line_dest=`echo "$line_dest" | urldecode`
        if [ "$line_src" != "$line_dest" ]; then
            line_dir=`dirname "$line_dest"`
            mkdir_p "$line_dir"
            cp "$line_src" "$line_dest"
        fi
    done
    cp "${yelp_js_dir}/jquery.js" "$html_out/$html_internal_datadir"
    cp "${yelp_js_dir}/jquery.syntax.js" "$html_out/$html_internal_datadir"
    cp "${yelp_js_dir}/jquery.syntax.core.js" "$html_out/$html_internal_datadir"
    cp "${yelp_js_dir}/jquery.syntax.layout.yelp.js" "$html_out/$html_internal_datadir"

    rm "$html_tmp_infile"
    if [ "x$html_cache_file_is_tmp" = "xyes" ]; then
        rm "$html_cache_file"
    fi
}

yelp_html () {
    while [ "$#" != "0" ]; do
        case "$1" in
            "-c")
                shift
                html_cache_file="$1"
                shift
                ;;
            "-o")
                shift
                html_out="$1"
                shift
                ;;
            "-x")
                shift
                html_custom="$1"
                shift
                ;;
            "--profile")
                html_profile="--profile"
                shift
                ;;
            *)
                break
                ;;
        esac
    done
    if [ "x$html_out" = "x" ]; then
        html_out="."
    elif [ ! -d "$html_out" ]; then
        echo "Error: output must be a directory." 1>&2
        exit 1
    fi
    html_out=`(cd "$html_out" && pwd)`
    if [ "x$html_custom" != "x" ]; then
        html_custom_dir=`dirname "$html_custom"`
        html_custom_dir=`(cd "$html_custom_dir" && pwd)`
        html_custom="$html_custom_dir"/`basename "$html_custom"`
    fi
    if [ "$#" = "0" -o "x$1" = "x--help" ]; then
        yelp_usage_html
        exit 1
    fi
    ext=`echo "$1" | sed -e 's/.*\.//'`
    if [ "x$ext" = "xxml" -o "x$ext" = "xdocbook" ]; then
        yelp_html_db2html "$@"
    else
        yelp_html_mal2html "$@"
    fi
}

yelp_epub () {
    while [ "$#" != "0" ]; do
        case "$1" in
            "-c")
                shift
                epub_cache_file="$1"
                shift
                ;;
            "-o")
                shift
                epub_out="$1"
                shift
                ;;
            "-x")
                shift
                html_custom="$1"
                shift
                ;;
            *)
                break
                ;;
        esac
    done
    if [ "$#" = "0" -o "x$1" = "x--help" ]; then
        yelp_usage_epub
        exit 1
    fi
    if [ "x$epub_cache_file" != "x" ]; then
        epub_cache_file=`(cd $(dirname "$epub_cache_file") && pwd)`/`basename "$epub_cache_file"`
    else
        epub_cache_file_is_tmp="yes"
        epub_cache_file=`mktemp "${TMPDIR:-/tmp}"/yelp-XXXXXXXX`
        yelp_cache -o "$epub_cache_file" "$@"
    fi
    html_cache_file="$epub_cache_file"
    epub_data_out=`mktemp -d "${TMPDIR:-/tmp}"/yelp-XXXXXXXX`
    html_out="$epub_data_out/OPS"
    mkdir "$html_out"
    mkdir "$html_out/yelp"
    html_internal_datadir="yelp/"
    html_internal_xsl="$xsl_mal_epub"
    yelp_html_mal2html "$@"

    epub_id=`uuidgen`
    epub_data=`(cd "$html_out" && ls yelp/*.*)`
    xsltproc \
        -o "$html_out/opf.opf" \
        --stringparam opf.id "$epub_id" \
        --stringparam opf.data "$epub_data" \
        "$xsl_mal_opf" "$epub_cache_file"
    xsltproc \
        -o "$html_out/ncx.ncx" \
        --stringparam ncx.id "$epub_id" \
        "$xsl_mal_ncx" "$epub_cache_file"

    echo "application/epub+zip" > "$epub_data_out/mimetype"

    mkdir "$epub_data_out/META-INF"
    (
        echo "<?xml version='1.0' encoding='UTF-8'?>"
        echo "<container version='1.0' xmlns='urn:oasis:names:tc:opendocument:xmlns:container'>"
        echo "<rootfiles>"
        echo "<rootfile full-path='OPS/opf.opf' media-type='application/oebps-package+xml'/>"
        echo "</rootfiles>"
        echo "</container>"
    ) > "$epub_data_out/META-INF/container.xml"

    if [ "x$epub_out" = "x" ]; then
        epub_out=`pwd`/index.epub
    else
        epub_out=`(cd $(dirname "$epub_out") && pwd)`/`basename "$epub_out"`
    fi
    (cd "$epub_data_out" && zip -q -r "$epub_out" mimetype META-INF OPS)

    if [ "x$epub_cache_file_is_tmp" = "xyes" ]; then
        rm "$epub_cache_file"
    fi
    rm -rf "$html_out"
}

cmd="$1"
shift
case "x$cmd" in
    "xcache")
        yelp_cache "$@"
        ;;
    "xepub")
        is_xhtml=1
        yelp_epub "$@"
        ;;
    "xhtml")
        is_xhtml=0
        yelp_html "$@"
        ;;
    "xxhtml")
        is_xhtml=1
        yelp_html "$@"
        ;;
    *)
        yelp_usage
        ;;
esac