aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/cmdline/makequery
blob: e2008c3f642041909616fab47ed49ded41bff4ee (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
#!/bin/sh
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

conf="`dirname $0`/query.conf"

query="https://bugzilla.mozilla.org/buglist.cgi?ctype=csv"

chart=0
and=0
while test "X$1" != "X"; do
    arg="$1"
    shift
    if test 0 != `expr "X$arg" : 'X--[^=]*\$'`; then
        # long option: --name val (without '=')
        name=`expr "X$arg" : 'X--\(.*\)'`
        val="$1"
        shift
    elif test 0 != `expr "X$arg" : 'X--[^=][^=]*='`; then
        # long option: --name=val
        name=`expr "X$arg" : 'X--\([^=]*\)'`
        val=`expr "X$arg" : 'X--[^=]*=\(.*\)'`
    elif test 0 != `expr "X$arg" : 'X-[a-zA-Z]\$'`; then
        # short option like -X foo (with space in between)
        name=`expr "X$arg" : 'X-\(.\)'`
        val="$1"
        shift
    elif test 0 != `expr "X$arg" : 'X-[a-zA-Z]='`; then
	# reject things like -X=foo
        echo "Unrecognized option $arg" 1>&2
        echo "Use -Xfoo or -X foo instead of -X=foo" 1>&2
        exit 1
    elif test 0 != `expr "X$arg" : 'X-[a-zA-Z]'`; then
        # short option like -Xfoo (without space)
        name=`expr "X$arg" : 'X-\(.\)'`
        val=`expr "X$arg" : 'X-.\(.*\)'`
    else
        name="default"
        val="$arg"
        #echo "Unrecognized option $arg" 1>&2
        #exit 1
    fi

    # plausibility check: val must not be empty, nor start with '-'
    if test "X$val" = "X"; then
        echo "No value found for '$name'!" 1>&2
        exit 1
    elif test 0 != `expr "X$val" : "X-"` && \
         test 0 = `expr "X$val" : "X---"`; then
        echo "Suspicious value for '$name': '$val' looks like an option!" 1>&2
        exit 1
    fi

    # find field and comparison type for option ${name}
    field=`grep "\"$name\"" "$conf" | awk '{printf $1}'`
    type=`grep "\"$name\"" "$conf" | awk '{printf $2}'`
    if test "X$field" = "X"  || test "X$type" = "X"; then
        if test "X$name" = "Xdefault"; then
            echo 1>&2 "Error: unexpected argument '$arg'"
            cat 1>&2 <<EOF
Use short options like -P1 or long options like  --priority=1 ,  
or enable the 'default' behaviour in the 'query.conf' file.
EOF
        else
            echo "Unknown field name '$name'." 1>&2
        fi
        exit 1
    fi

    # split val into comma-separated alternative values
    or=0
    while test "X$val" != "X"; do
        # val1 gets everything before the first comma; val gets the rest
        if test 0 != `expr "X$val" : 'X[^,]*,'`; then
            val1=`expr "X$val" : 'X\([^,]*\),'`
	    val=`expr "X$val" : 'X[^,]*,\(.*\)'`
        else
            val1="$val"
            val=""
        fi
        # append to query
        query="${query}&field${chart}-${and}-${or}=${field}"
        query="${query}&type${chart}-${and}-${or}=${type}"
        query="${query}&value${chart}-${and}-${or}=${val1}"
        #echo "----- ${name} : ${field} : ${type} : ${val1} -----" 1>&2
        or=`expr ${or} + 1`
    done
    chart=`expr ${chart} + 1`
done

echo "${query}"