Permalink
Browse files

Use getopt_long from Stéphane Chazelas. Thanks Stéphane!

  • Loading branch information...
rocky committed Sep 30, 2008
1 parent e6815e5 commit 999996f63ab05d8268c842d716f23674f3c65de3
Showing with 1,068 additions and 295 deletions.
  1. +7 −0 AUTHORS
  2. +19 −4 Makefile.am
  3. +3 −0 THANKS
  4. +6 −23 configure.ac
  5. +125 −140 dbg-opts.sh
  6. +5 −8 dbg-pre.sh
  7. +675 −0 getopts_long.sh
  8. +1 −0 test/unit/.gitignore
  9. +2 −0 test/unit/Makefile.am
  10. +150 −120 test/unit/shunit2
  11. +75 −0 test/unit/test-dbg-opts.sh.in
View
@@ -1 +1,8 @@
R. Bernstein (rocky@gnu.org)
+
+Kate Ward is the author of shunit2 used in unit testing
+
+Stéphane Chazelas is the author of getopts_long.sh for GNU long options
+ processing
+
+Nikolaj Schumacher is the author of elk-test.el used in GNU Emacs testing
View
@@ -1,16 +1,33 @@
+# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+#
+# zshdb 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 2, or (at your option) any later
+# version.
+#
+# zshdb 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 zshdb; see the file COPYING. If not, write to the Free Software
+# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+
SUBDIRS = command emacs lib test
pkgdata_DATA = \
dbg-pre.sh \
dbg-io.sh \
dbg-main.sh \
dbg-opts.sh \
- dbg-trace.sh
+ dbg-trace.sh \
+ getopts_long.sh
# Set up the install target
bin_SCRIPTS = kshdb
-EXTRA_DIST = $(pkgdata_DATA) THANKS getopt-test.sh
+EXTRA_DIST = $(pkgdata_DATA) THANKS
# cvs2cl
MAINTAINERCLEANFILES = ChangeLog
@@ -36,5 +53,3 @@ ACLOCAL_AMFLAGS=-I .
endif
.PHONY: $(CL) test
-
-
View
3 THANKS
@@ -1,2 +1,5 @@
Thanks to David Korn for the adding necessary support to ksh
needed to get this off the ground and make debugging possible.
+
+Thanks to Kate Ward, Stéphane Chazelas and Nikolaj Schumacher for
+programs used in conjunction with zshdb.
View
@@ -6,26 +6,6 @@ AM_PATH_LISPDIR
AM_MAINTAINER_MODE
AM_INIT_AUTOMAKE([no-define])
-AC_SUBST(TRY_GETOPT)
-
-AC_ARG_ENABLE([gnugetopt],
- AC_HELP_STRING([--enable-getopt],
- [Allow GNU-style long options (default enabled)]))
-
-if test "${enable_getopt}" != "no" ; then
- $SH_PROG ${srcdir}/getopt-test.sh
- if test $? -eq 0 ; then
- AC_MSG_RESULT([Good! Your long options seem to be working okay.])
- TRY_GETOPT=1
- else
- AC_MSG_WARN([getopt doesn't seem to handle long options correctly.])
- AC_MSG_WARN([Disabling long-options in] DEBUGGER[.])
- TRY_GETOPT=0
- fi
-else
- TRY_GETOPT=0
-fi
-
AC_CONFIG_SRCDIR(DEBUGGER.in)
if test x$srcdir = x ; then
srcdir=$ac_pwd
@@ -48,8 +28,8 @@ then
fi
if test "$SH_PROG" = no; then
- AC_MSG_ERROR([I didn't find the DEBUGGER executable.\
- You might want to use the --with-DEBUGGER option.])
+ AC_MSG_ERROR([I didn't find the] POSIXSHELL [executable.\
+ You might want to use the] --with-POSIXSHELL [option.])
fi
AC_MSG_CHECKING([Checking whether $SH_PROG is compatible with DEBUGGER])
@@ -98,7 +78,8 @@ else
fi
fi
-AM_CONDITIONAL(INSTALL_EMACS_LISP, test "x$lispdir" != "x")
+AM_CONDITIONAL(INSTALL_EMACS_LISP,
+ [test "x$lispdir" != "x" -a "x$EMACS" != "xno"])
AC_CONFIG_FILES([ \
Makefile \
@@ -121,6 +102,8 @@ AC_CONFIG_FILES([test/example/hanoi.sh],
AC_CONFIG_FILES([test/unit/test-alias.sh], [chmod +x test/unit/test-alias.sh])
AC_CONFIG_FILES([test/unit/test-columns.sh],
[chmod +x test/unit/test-columns.sh])
+AC_CONFIG_FILES([test/unit/test-dbg-opts.sh],
+ [chmod +x test/unit/test-dbg-opts.sh])
AC_CONFIG_FILES([test/unit/test-filecache.sh],
[chmod +x test/unit/test-filecache.sh])
AC_CONFIG_FILES([test/unit/test-fns.sh], [chmod +x test/unit/test-fns.sh])
View
@@ -17,154 +17,139 @@
# with kshdb; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
-typeset _Dbg_tmpdir=/tmp
-typeset -i _Dbg_opt_linetrace=0
-typeset -i o_no_quit=0
+_Dbg_usage() {
+ printf "Usage:
+ ${_Dbg_pname} [OPTIONS] <script_file>
-# Use gdb-style annotate?
-typeset -i _Dbg_annotate=0
-
-function _Dbg_usage_long {
- printf "usage:
- ${_Dbg_pname} [OPTIONS] <script_file>
-
-Runs bash <script_file> under a debugger.
+Runs zsh <script_file> under a debugger.
-options:
- -A | --annotate LEVEL set annotation level.
- -B | --basename basename only on source listings.
+options:
+ -h | --help Print this help.
+ -q | --quiet Do not print introductory and quiet messages.
+ -A | --annotate LEVEL Set the annotation level.
+ -B | --basename Show basename only on source file listings.
(Needed in regression tests)
- -h | --help print this help
- -n | --nx |--no-init Don't run initialization files
- -c cmd | --eval-command cmd Run this passed argument as a script
- -q | --quiet Quiet. Do not print introductory and quiet messages.
-L libdir | --library libdir
- set directory location of library helper file: $_Dbg_main
- The default directory is: $_Dbg_libdir
- -T tmpdir | --tempdir set directory location for temporary files: $_Dbg_tmpdir
- -t tty | --tty tty | --terminal tty
- set debugger terminal
- -x command | --command cmdfile
- execute debugger commands from cmdfile
- -X | --trace set line tracing
- -V | --version show version number and no-warranty and exit.
-
-Long options may be abbreviated, e.g. --lib is okay for --library.
-" 1>&2
+ Set the directory location of library helper file: $_Dbg_main
+ -n | --nx | --no-init Don't run initialization files.
+ -V | --version Print the debugger version number.
+ -x command | --command CMDFILE
+ Execute debugger commands from CMDFILE.
+" >&2
+ exit 100
}
-_Dbg_usage_short() {
- printf "_Dbg_usage:
- ${_Dbg_pname} [OPTIONS] <script_file>
-
-Runs script_file under a debugger.
-
-options:
- -A LEVEL set annotation level.
- -B basename only on source listings. (Needed in regression tests)
- -h print this help
- -n Don't run initialization files
- -c command Run this passed command as a script
- -q Quiet. Do not print introductory and quiet messages.
- -L libdir | --library libdir
- set directory location of library helper file: $_Dbg_main
- the default directory is: $_Dbg_libdir
- -T tmpdir set directory location for temporary files: $_Dbg_tmpdir
- -t tty set debugger terminal
- -x cmdfile execute debugger commands from cmdfile
- -X set line tracing
- -Y set line tracing with variable expansion
- -V show version number and no-warranty and exit.
-" 1>&2
+_Dbg_show_version() {
+ printf 'There is absolutely no warranty for kshdb. Type "show warranty" for details.
+' >&2
+ exit 101
+
}
-# Process using short or long options, depending on the availability
-# of getopt
-TEMP=`getopt -o testing t 2>/dev/null`
-if ((_Dbg_try_getopt && 0 == $? )) ; then
- # Process using long options
- # Note that we use `"$@"' to let each command-line parameter expand to a
- # separate word. The quotes around `$@' are essential!
- # We need TEMP as the `eval set --' would nuke the return value of getopt.
- TEMP=`getopt -o A:Bc:hL:nqt:T::x:XYV \
---long annotate:,basename,command:,debugger,exec-command,help,library:,no-init,quiet,tempdir:,terminal:,trace,tty,version \
- -n 'kshdb' -- "$@"`
-
- if [ $? != 0 ] ; then
- echo "Use --help for option help. Terminating..." >&2 ;
- exit 1 ;
- fi
-
- # Note the quotes around `$TEMP': they are essential!
- eval set -- "$TEMP"
-
- while true ; do
- case $1 in
- -A|--annotate) _Dbg_annotate="$2"; shift ;;
- -B|--basename) _Dbg_basename_only=1 ;;
- -c|--eval-command) _Dbg_cmd="$2"; shift ;;
- --debugger) ;; # This option is for compatibility with bash --debugger
- -h|--help) _Dbg_usage_long; exit 100 ;;
- -L|--library) shift ;; # Handled previously
- -n|--nx|--no-init) _Dbg_no_init=1 ;;
- -q|--quiet) _Dbg_quiet=1 ;;
- -T|--tempdir) _Dbg_tmpdir=$2; shift ;;
- -t|--terminal|--tty)
- if ! $(touch $2 >/dev/null 2>/dev/null); then
- echo "${_Dbg_pname}: Can't access $2 for writing."
- elif [[ ! -w $2 ]] ; then
- echo "${_Dbg_pname}: terminal $2 needs to be writable."
- else
- _Dbg_tty=$2 ;
- fi
- shift
- ;;
- -x|--command) DBG_INPUT="$DBG_INPUT $2"; shift ;;
- -X|--trace) _Dbg_opt_linetrace=1 ;;
- # -Y|--vtrace) _Dbg_opt_linetrace=1 ; _Dbg_opt_linetrace_expand=1 ;;
- -V|--version) show_version=1 ;;
- --) shift ; break ;;
- *)
- echo "Use --help for option help. Terminating..."
- exit 2 ;;
- esac
- shift
- done
-else
- # Process using short options
- while getopts :A:Bc:hL:nqt:T:x:XYV opt; do
- case $opt in
- A) _Dbg_annotate=1 ;;
- B) _Dbg_basename_only=1 ;;
- c) _Dbg_cmd="$OPTARG" ;;
- h) _Dbg_usage_short; exit 100 ;;
- n) _Dbg_no_init=1 ;;
- q) _Dbg_quiet=1 ;;
- L) ;; # Handled previously
- T) _Dbg_tmpdir=$OPTARG ;;
- t)
- if ! $(touch $OPTARG >/dev/null 2>/dev/null); then
- echo "${_Dbg_pname}: Can't access $OPTARG for writing."
- elif [[ ! -w $OPTARG ]] ; then
- echo "${_Dbg_pname}: terminal $OPTARG needs to be writable."
- else
- _Dbg_tty=$OPTARG
- fi
- ;;
- V) show_version=1 ;;
- x) DBG_INPUT="$OPTARG" ;;
- X) _Dbg_opt_linetrace=1 ;;
- # Y) _Dbg_opt_linetrace=1 ; _Dbg_opt_linetrace_expand=1 ;;
- *)
- if ((_Dbg_basename_only == 1)) ; then
- echo "${_Dbg_pname}: unrecognized option -- $OPTARG"
+# Script arguments before adulteration by _Dbg_parse_otps
+typeset -a _Dbg_orig_script_args
+_Dbg_orig_script_args=($@)
+
+
+# The following globals are set by _Dbg_parse_opts. Any values set are
+# the default values.
+typeset -a _Dbg_script_args
+
+typeset -i _Dbg_annotate=0
+typeset -i _Dbg_linetrace=0
+typeset -i _Dbg_basename_only=0
+typeset -i _Dbg_o_nx=0
+
+
+_Dbg_parse_options() {
+
+ . ${_Dbg_libdir}/getopts_long.sh
+
+ typeset -i _Dbg_o_quiet=0
+ typeset -i _Dbg_o_version=0
+
+ while getopts_long A:Bx:hL:nqV opt \
+ annotate required_argument \
+ basename 0 \
+ cmdfile required_argument \
+ help 0 \
+ '?' 0 \
+ library required_argument \
+ no-init 0 \
+ nx 0 \
+ quiet 0 \
+ version 0 \
+ '' "$@"
+ do
+ case "$opt" in
+ A | annotate )
+ _Dbg_o_annotate=$OPTLARG
+ ;;
+ B | basename )
+ _Dbg_basename_only=1
+ ;;
+ x | command )
+ DBG_INPUT=$OPTLARG
+ ;;
+ h | '?' | help )
+ _Dbg_usage
+ ;;
+ L | library )
+ ;;
+ V | version )
+ _Dbg_o_version=1
+ ;;
+ n | nx | no-init )
+ _Dbg_o_nx=1
+ ;;
+ q | quiet )
+ _Dbg_o_quiet=1
+ ;;
+ * )
+ print "Unknown option $opt. Use -h or --help to see options" >&2
+ exit 2
+ ;;
+ esac
+ done
+ shift "$(($OPTLIND - 1))"
+
+ if (( ! _Dbg_o_quiet && ! _Dbg_o_version )); then
+ print "Zsh Shell Debugger, release $_Dbg_release"
+ printf '
+Copyright 2008 Rocky Bernstein
+This is free software, covered by the GNU General Public License, and you are
+welcome to change it and/or distribute copies of it under certain conditions.
+
+'
+ fi
+ (( _Dbg_o_version )) && _Dbg_show_version
+
+ if [[ -n $_Dbg_o_annotate ]] ; then
+ if [[ ${_Dbg_o_annotate} == [0-9]* ]] ; then
+ _Dbg_annotate=$_Dbg_o_annotate
+ if (( _Dbg_annotate > 3 || _Dbg_annotate < 0)); then
+ print "Annotation level must be less between 0 and 3. Got: $_Dbg_annotate." >&2
+ print "Setting Annotation level to 0." >&2
+ _Dbg_annotate=0
+ fi
else
- echo "$0: unrecognized option -- $OPTARG"
+ print "Annotate option should be an integer, got ${_Dbg_o_annotate}." >&2
+ print "Setting annotation level to 0." >&2
fi
- echo "Use -h for option help. Terminating..."
- exit 2
- ;;
- esac
- done
- shift $(($OPTIND - 1))
+ fi
+ unset _Dbg_o_annotate _Dbg_o_version _Dbg_o_quiet
+ _Dbg_script_args=($@)
+}
+
+[[ -n $DBG_INPUT ]] && typeset -p DBG_INPUT
+
+
+# Stand-alone Testing.
+if [[ -n "$_Dbg_dbg_opts_test" ]] ; then
+ OPTLIND=1
+ _Dbg_libdir='.'
+ _Dbg_parse_options "$@"
+ typeset -p _Dbg_annotate
+ typeset -p _Dbg_linetrace
+ typeset -p _Dbg_basename_only
fi
Oops, something went wrong.

0 comments on commit 999996f

Please sign in to comment.