Skip to content

Commit

Permalink
Convert options processing to getopts_long by Stéphane Chazelas. Than…
Browse files Browse the repository at this point in the history
…ks Stéphane!
  • Loading branch information
rocky committed Sep 30, 2008
1 parent 26d3321 commit 33ef073
Show file tree
Hide file tree
Showing 14 changed files with 872 additions and 63 deletions.
7 changes: 7 additions & 0 deletions AUTHORS
@@ -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
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -30,7 +30,7 @@ pkgdata_DATA = \
# Set up the install target
bin_SCRIPTS = zshdb

EXTRA_DIST = $(pkgdata_DATA) THANKS getopt-test.sh
EXTRA_DIST = $(pkgdata_DATA) THANKS getopts_long.sh

# cvs2cl
MAINTAINERCLEANFILES = ChangeLog
Expand Down
4 changes: 4 additions & 0 deletions THANKS
@@ -1,2 +1,6 @@
Thanks to Peter Stephenson for the adding necessary support to zsh
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.

2 changes: 2 additions & 0 deletions configure.ac
Expand Up @@ -103,6 +103,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-file.sh],
[chmod +x test/unit/test-file.sh])
AC_CONFIG_FILES([test/unit/test-filecache.sh],
Expand Down
2 changes: 1 addition & 1 deletion dbg-main.sh
Expand Up @@ -6,7 +6,7 @@
# Software Foundation; either version 2, or (at your option) any later
# version.
#
# kshd is distributed in the hope that it will be useful, but WITHOUT ANY
# 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.
Expand Down
139 changes: 97 additions & 42 deletions dbg-opts.sh
Expand Up @@ -31,69 +31,124 @@ options:
(Needed in regression tests)
-L libdir | --library libdir
Set the directory location of library helper file: $_Dbg_main
-n | --nx |--no-init Don't run initialization files.
-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_show_version() {
printf 'There is absolutely no warranty for zshdb. Type "show warranty" for details.
'
' >&2
exit 101

}

# 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

# Debugger command file
typeset _Dbg_o_cmdfile='' _Dbg_o_nx='' _Dbg_o_basename='' _Dbg_o_quiet=''

local temp
zparseopts -D -- \
A:=_Dbg_o_annotate -annotate:=_Dbg_o_annotate \
B=_Dbg_o_basename -basename=_Dbg_o_basename \
L:=temp -library:=temp \
V=_Dbg_o_version -version=_Dbg_o_version \
h=_Dbg_o_help -help=_Dbg_o_help \
n=_Dbg_o_nx -nx=_Dbg_o_nx -no-init=_Dbg_o_nx \
q=_Dbg_o_quiet -quiet=_Dbg_o_quiet \
x:=_Dbg_o_cmdfile -command:=_Dbg_o_cmdfile

[[ $? != 0 || "$_Dbg_o_help" != '' ]] && _Dbg_usage

if [[ -z $_Dbg_o_quiet || -n $_Dbg_o_version ]]; then
print "Zsh Shell Debugger, release $_Dbg_release"
printf '
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
[[ -n "$_Dbg_o_version" ]] && _Dbg_show_version
[[ -n "$_Dbg_o_basename" ]] && _Dbg_basename_only=1
[[ -n "$_Dbg_o_cmdfile" ]] && {
typeset -a _Dbg_input
_Dbg_input=($_Dbg_o_cmdfile)
DBG_INPUT=${_Dbg_input[-1]}
unset _Dbg_input
}

fi
(( _Dbg_o_version )) && _Dbg_show_version

# FIXME: check that _Dbg_o_annotate is an integer
if [[ -n $_Dbg_o_annotate ]] ; then
typeset -a level; eval "level=($_Dbg_o_annotate)"
if [[ ${level[-1]} == [0-9]* ]] ; then
if (( ${level[-1]} > 3 || ${level[-1]} < 0)); then
print "Annotation level must be less between 0 and 3. Got: ${level[-1]}."
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
_Dbg_annotate=${level[-1]}
print "Annotate option should be an integer, got ${_Dbg_o_annotate}." >&2
print "Setting annotation level to 0." >&2
fi
else
print "Annotate option should be an integer, got ${level[-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
_Dbg_libdir='.'
_Dbg_parse_options "$@"
typeset -p _Dbg_annotate
typeset -p _Dbg_linetrace
typeset -p _Dbg_basename_only
fi
unset _Dbg_o_annotate _Dbg_o_version _Dbg_o_basename _Dbg_o_cmdfile
7 changes: 2 additions & 5 deletions dbg-pre.sh
Expand Up @@ -44,8 +44,6 @@ typeset -r _Dbg_release='0.01git'
# Will be set to 1 if the top-level call is a debugger.
typeset -i _Dbg_script=0

typeset -i _Dbg_basename_only=0

# Expand filename given as $1.
# we echo the expanded name or return $1 unchanged if a bad filename.
# Return is 0 if good or 1 if bad.
Expand Down Expand Up @@ -97,6 +95,8 @@ _Dbg_tempname() {

# Process command-line options
. ${_Dbg_libdir}/dbg-opts.sh
OPTLIND=1
_Dbg_parse_options "$@"

if [[ ! -d $_Dbg_tmpdir ]] && [[ ! -w $_Dbg_tmpdir ]] ; then
echo "${_Dbg_pname}: cannot write to temp directory $_Dbg_tmpdir." >&2
Expand All @@ -114,9 +114,6 @@ typeset _Dbg_init_cwd=$PWD
# fi
# fi

typeset -a _Dbg_script_args
_Dbg_script_args=($@)

typeset -i _Dbg_running=1 # True we are not finished running the program

typeset -i _Dbg_currentbp=0 # If nonzero, the breakpoint number that we
Expand Down
7 changes: 0 additions & 7 deletions getopt-test.sh

This file was deleted.

0 comments on commit 33ef073

Please sign in to comment.