summaryrefslogtreecommitdiff
path: root/phpdoc.sh
blob: cfd140d57fd947bfd4feec3ca7d5e927dfb7534b (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
#!/bin/bash

set -u
set -e

W3M="$(/usr/bin/which w3m)" || true

function usage
{
    echo "Usage: $0 -f <function>"
}

function lookup_function
{
    local name="$1"
    local filename="function.$(echo "${name}" | /usr/bin/sed 's/_/-/g').html"

    if [ ! -n "${W3M}" ]; then
        echo "w3m not found."
        exit 1;
    fi

    ${W3M} "/usr/share/doc/php/php-chunked-xhtml/${filename}"
}

opt_f=

# Parse the arguments
while getopts :f: opt ; do
    case ${opt} in
        f)
            opt_f="${OPTARG}"
            ;;
        \?)
            echo "Invalid option -${OPTARG}."
            exit 1
            ;;
        :)
            echo "Missing parameter for -${OPTARG}."
            exit 1
            ;;
    esac
done

if [ -n "${opt_f}" ]; then
    lookup_function "${opt_f}"
else
    usage "$0"
    exit 1
fi