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 96 97 98 99 100
|
dnl This file inplements common sh idioms.
divert(-1)
changequote([, ])
undefine([shift])
dnl GETOPT(CASE-STATEMENT)
dnl Implement a portable getopt
define([GETOPT],
[# Push a token among the arguments that will be used to notice when
# we ended options/arguments parsing.
arg_sep="$$--$$"
set dummy ${1+"[$]@"} "$arg_sep"
shift
while test "x[$]1" != "x$arg_sep"; do
# Handle --option=value by splitting apart and putting back on argv.
case "[$]1" in
--*=*)
opt=`echo "[$]1" | sed -e 's/=.*//'`
val=`echo "[$]1" | sed -e 's/@BKL@^=@BKR@*=//'`
shift
set dummy "$opt" "$val" ${1+"[$]@"}
shift
;;
changequote(, )dnl
-[$option_without_arguments]?*)
changequote([, ])dnl
[#] Prefix [$]1 with x to avoid running `echo -na' for instance.
opt=`echo "x[$]1" | sed -e 's/x-\(.\).*/-\1/'`
rest=`echo "x[$]1" | sed -e 's/x-.\(.*\)/-\1/'`
shift
set dummy "$opt" "$rest" ${1+"[$]@"}
shift
;;
# This case needs to be protected so that the case `-??*' does
# not split long options without arguments
--*)
;;
# This is an option with argument. Split apart and put back on argv.
-??*)
opt=`echo "x[$]1" | sed -e 's/x-\(.\).*/-\1/'`
arg=`echo "x[$]1" | sed -e 's/x-.\(.*\)/\1/'`
shift
set dummy "$opt" "$arg" ${1+"[$]@"}
shift
;;
esac
[#] Now, handle the options. [$]1 is the option *only*. If it has an
[#] argument, it is now necessarily in [$]2 etc. Remember to shift
[#] when fetching an argument.
case "[$]1" in
[$1]
--) # What remains are not options.
shift
while test "x[$]1" != "x$arg_sep"; do
set dummy ${1+"[$]@"} "[$]1"
shift
shift
done
break;;
-*)
echo "$program: Unknown or ambiguous option \`[$]1'." >&2
echo "$program: Try \`--help' for more information." >&2
exit 1;;
*) set dummy ${1+"[$]@"} "[$]1"
shift
;;
esac
shift
done
# Pop the token
shift
])
dnl A short GPL
define([GPL],
[ifelse([$1],,,[# $1
])
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can either send email to this
# program's maintainer or write to: The Free Software Foundation,
# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.])
divert(0)dnl
|