aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/xohtml/xohtml.sh
blob: 58d52388d61cadae0d4ac6a301ab8a1b4ba7cf75 (plain) (blame)
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
#!/bin/sh
# $FreeBSD$
#!/bin/sh
#
# Copyright (c) 2014, Juniper Networks, Inc.
# All rights reserved.
# This SOFTWARE is licensed under the LICENSE provided in the
# ../Copyright file. By downloading, installing, copying, or otherwise
# using the SOFTWARE, you agree to be bound by the terms of that
# LICENSE.
# Phil Shafer, July 2014
#

BASE=/usr/share/libxo
VERSION=0.8.4
CMD=cat
DONE=
WEB=https://juniper.github.io/libxo/${VERSION}/xohtml

do_help () {
    echo "xohtml: wrap libxo-enabled output in HTML"
    echo "Usage: xohtml [options] [command [arguments]]"
    echo "Valid options are:"
    echo "    -b <basepath> | --base <basepath>"
    echo "    -c <command> | --command <command>"
    echo "    -f <output-file> | --file <output-file>"
    exit 1
}

while [ -z "$DONE" -a ! -z "$1" ]; do
    case "$1" in
        -b|--base)
            shift;
            BASE="$1";
	    shift;
            ;;
        -c|--command)
            shift;
            CMD="$1";
	    shift;
            ;;
        -f|--file)
            shift;
            FILE="$1";
	    shift;
	    exec > "$FILE";
            ;;
        -w|--web)
            shift;
            BASE="${WEB}";
            ;;

	-*)
	    do_help
	    ;;
	*)
	    DONE=1;
	    XX=$1;
	    shift;
	    CMD="$XX --libxo=html $@"
	    ;;
    esac
done

if [ "$CMD" = "cat" -a -t 0 ]; then
    do_help
fi

echo '<html>'
echo '<head>'
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8"/>'
echo '<link rel="stylesheet" href="'$BASE'/xohtml.css">'
echo '<link rel="stylesheet" href="'$BASE'/external/jquery.qtip.css"/>'
echo '<script type="text/javascript" src="'$BASE'/external/jquery.js"></script>'
echo '<script type="text/javascript" src="'$BASE'/external/jquery.qtip.js"></script>'
echo '<script type="text/javascript" src="'$BASE'/xohtml.js"></script>'
echo '<script>'
echo '</script>'
echo '</head>'
echo '<body>'

$CMD

echo '</body>'
echo '</html>'

exit 0