1dnl This file inplements common sh idioms.
2divert(-1)
3changequote([, ])
4undefine([shift])
5
6dnl GETOPT(CASE-STATEMENT)
7dnl Implement a portable getopt
8define([GETOPT],
9[# Push a token among the arguments that will be used to notice when
10# we ended options/arguments parsing.
11arg_sep="$$--$$"
12set dummy ${1+"[$]@"} "$arg_sep"
13shift
14while test "x[$]1" != "x$arg_sep"; do
15
16  # Handle --option=value by splitting apart and putting back on argv.
17  case "[$]1" in
18    --*=*)
19      opt=`echo "[$]1" | sed -e 's/=.*//'`
20      val=`echo "[$]1" | sed -e 's/@BKL@^=@BKR@*=//'`
21      shift
22      set dummy "$opt" "$val" ${1+"[$]@"}
23      shift
24      ;;
25
26changequote(, )dnl
27    -[$option_without_arguments]?*)
28changequote([, ])dnl
29      [#] Prefix [$]1 with x to avoid running `echo -na' for instance.
30      opt=`echo "x[$]1" | sed -e 's/x-\(.\).*/-\1/'`
31      rest=`echo "x[$]1" | sed -e 's/x-.\(.*\)/-\1/'`
32      shift
33      set dummy "$opt" "$rest" ${1+"[$]@"}
34      shift
35      ;;
36
37    # This case needs to be protected so that the case `-??*' does
38    # not split long options without arguments
39    --*)
40      ;;
41
42    # This is an option with argument.  Split apart and put back on argv.
43    -??*)
44      opt=`echo "x[$]1" | sed -e 's/x-\(.\).*/-\1/'`
45      arg=`echo "x[$]1" | sed -e 's/x-.\(.*\)/\1/'`
46      shift
47      set dummy "$opt" "$arg" ${1+"[$]@"}
48      shift
49      ;;
50  esac
51
52  [#] Now, handle the options.  [$]1 is the option *only*.  If it has an
53  [#] argument, it is now necessarily in [$]2 etc.  Remember to shift
54  [#] when fetching an argument.
55  case "[$]1" in
56[$1]
57
58    --) # What remains are not options.
59      shift
60      while test "x[$]1" != "x$arg_sep"; do
61        set dummy ${1+"[$]@"} "[$]1"
62        shift
63	shift
64      done
65      break;;
66
67    -*)
68      echo "$program: Unknown or ambiguous option \`[$]1'." >&2
69      echo "$program: Try \`--help' for more information." >&2
70      exit 1;;
71    *) set dummy ${1+"[$]@"} "[$]1"
72       shift
73       ;;
74   esac
75   shift
76done
77# Pop the token
78shift
79])
80
81dnl A short GPL
82define([GPL],
83[ifelse([$1],,,[# $1
84])
85# This program is free software; you can redistribute it and/or modify
86# it under the terms of the GNU General Public License as published by
87# the Free Software Foundation; either version 2, or (at your option)
88# any later version.
89#
90# This program is distributed in the hope that it will be useful,
91# but WITHOUT ANY WARRANTY; without even the implied warranty of
92# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
93# GNU General Public License for more details.
94#
95# You should have received a copy of the GNU General Public License
96# along with this program; if not, you can either send email to this
97# program's maintainer or write to: The Free Software Foundation,
98# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.])
99
100divert(0)dnl
101