makequery 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/sh
  2. # The contents of this file are subject to the Mozilla Public
  3. # License Version 1.1 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of
  5. # the License at http://www.mozilla.org/MPL/
  6. #
  7. # Software distributed under the License is distributed on an "AS
  8. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. # implied. See the License for the specific language governing
  10. # rights and limitations under the License.
  11. #
  12. # The Original Code is the Bugzilla Bug Tracking System.
  13. #
  14. # The Initial Developer of the Original Code is
  15. # Andreas Franke <afranke@mathweb.org>.
  16. # Corporation. Portions created by Andreas Franke are
  17. # Copyright (C) 2001,2005 Andreas Franke. All
  18. # Rights Reserved.
  19. #
  20. # Contributor(s):
  21. conf="`dirname $0`/query.conf"
  22. query="https://bugzilla.mozilla.org/buglist.cgi?ctype=csv"
  23. chart=0
  24. and=0
  25. while test "X$1" != "X"; do
  26. arg="$1"
  27. shift
  28. if test 0 != `expr "X$arg" : 'X--[^=]*\$'`; then
  29. # long option: --name val (without '=')
  30. name=`expr "X$arg" : 'X--\(.*\)'`
  31. val="$1"
  32. shift
  33. elif test 0 != `expr "X$arg" : 'X--[^=][^=]*='`; then
  34. # long option: --name=val
  35. name=`expr "X$arg" : 'X--\([^=]*\)'`
  36. val=`expr "X$arg" : 'X--[^=]*=\(.*\)'`
  37. elif test 0 != `expr "X$arg" : 'X-[a-zA-Z]\$'`; then
  38. # short option like -X foo (with space in between)
  39. name=`expr "X$arg" : 'X-\(.\)'`
  40. val="$1"
  41. shift
  42. elif test 0 != `expr "X$arg" : 'X-[a-zA-Z]='`; then
  43. # reject things like -X=foo
  44. echo "Unrecognized option $arg" 1>&2
  45. echo "Use -Xfoo or -X foo instead of -X=foo" 1>&2
  46. exit 1
  47. elif test 0 != `expr "X$arg" : 'X-[a-zA-Z]'`; then
  48. # short option like -Xfoo (without space)
  49. name=`expr "X$arg" : 'X-\(.\)'`
  50. val=`expr "X$arg" : 'X-.\(.*\)'`
  51. else
  52. name="default"
  53. val="$arg"
  54. #echo "Unrecognized option $arg" 1>&2
  55. #exit 1
  56. fi
  57. # plausibility check: val must not be empty, nor start with '-'
  58. if test "X$val" = "X"; then
  59. echo "No value found for '$name'!" 1>&2
  60. exit 1
  61. elif test 0 != `expr "X$val" : "X-"` && \
  62. test 0 = `expr "X$val" : "X---"`; then
  63. echo "Suspicious value for '$name': '$val' looks like an option!" 1>&2
  64. exit 1
  65. fi
  66. # find field and comparison type for option ${name}
  67. field=`grep "\"$name\"" "$conf" | awk '{printf $1}'`
  68. type=`grep "\"$name\"" "$conf" | awk '{printf $2}'`
  69. if test "X$field" = "X" || test "X$type" = "X"; then
  70. if test "X$name" = "Xdefault"; then
  71. echo 1>&2 "Error: unexpected argument '$arg'"
  72. cat 1>&2 <<EOF
  73. Use short options like -P1 or long options like --priority=1 ,
  74. or enable the 'default' behaviour in the 'query.conf' file.
  75. EOF
  76. else
  77. echo "Unknown field name '$name'." 1>&2
  78. fi
  79. exit 1
  80. fi
  81. # split val into comma-separated alternative values
  82. or=0
  83. while test "X$val" != "X"; do
  84. # val1 gets everything before the first comma; val gets the rest
  85. if test 0 != `expr "X$val" : 'X[^,]*,'`; then
  86. val1=`expr "X$val" : 'X\([^,]*\),'`
  87. val=`expr "X$val" : 'X[^,]*,\(.*\)'`
  88. else
  89. val1="$val"
  90. val=""
  91. fi
  92. # append to query
  93. query="${query}&field${chart}-${and}-${or}=${field}"
  94. query="${query}&type${chart}-${and}-${or}=${type}"
  95. query="${query}&value${chart}-${and}-${or}=${val1}"
  96. #echo "----- ${name} : ${field} : ${type} : ${val1} -----" 1>&2
  97. or=`expr ${or} + 1`
  98. done
  99. chart=`expr ${chart} + 1`
  100. done
  101. echo "${query}"