diff --git a/bashdb.in b/bashdb.in index 0cd36c5..ca709a3 100755 --- a/bashdb.in +++ b/bashdb.in @@ -64,12 +64,12 @@ typeset _Dbg_libdir="@PKGDATADIR@" typeset -xa _Dbg_script_args; _Dbg_script_args=("$@") typeset -i _Dbg_i for ((_Dbg_i=0; _Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do - typeset arg=${_Dbg_script_args[$_Dbg_i]} - if [[ $arg == '-L' || $arg == '--library' ]] ; then + typeset _Dbg_script_arg=${_Dbg_script_args[$_Dbg_i]} + if [[ $_Dbg_script_arg == '-L' || $_Dbg_script_arg == '--library' ]] ; then ((_Dbg_i++)) _Dbg_libdir="${_Dbg_script_args[$_Dbg_i]}" break - elif [[ $arg == '--' ]] ; then + elif [[ $_Dbg_script_arg == '--' ]] ; then # We hit the end of bashdb args break fi diff --git a/command/help.sh b/command/help.sh index 794994e..4d1cfc4 100644 --- a/command/help.sh +++ b/command/help.sh @@ -78,8 +78,8 @@ function _Dbg_do_help { if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then _Dbg_msg_rst "${_Dbg_command_help[$dbg_cmd]}" else - _Dbg_alias_expand $dbg_cmd - dbg_cmd="$expanded_alias" + typeset _Dbg_expanded_alias; _Dbg_alias_expand $dbg_cmd + dbg_cmd="$_Dbg_expanded_alias" if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then _Dbg_msg_rst "${_Dbg_command_help[$dbg_cmd]}" else diff --git a/command/info.sh b/command/info.sh index b79653d..823d2b9 100644 --- a/command/info.sh +++ b/command/info.sh @@ -39,6 +39,8 @@ _Dbg_do_info() { typeset subcmd=$1 shift + typeset -i found=0 + if [[ -n ${_Dbg_debugger_info_commands[$subcmd]} ]] ; then ${_Dbg_debugger_info_commands[$subcmd]} "$@" return $? diff --git a/command/info_sub/files.sh b/command/info_sub/files.sh index ee6a1ef..58fe6bf 100644 --- a/command/info_sub/files.sh +++ b/command/info_sub/files.sh @@ -29,6 +29,7 @@ _Dbg_do_info_files() { typeset -a list=() typeset -i i=0 typeset key + typeset file for key in "${!_Dbg_file2canonic[@]}"; do list[$i]="$key" ((i++)) diff --git a/dbg-main.sh b/dbg-main.sh index 78e2605..971908d 100644 --- a/dbg-main.sh +++ b/dbg-main.sh @@ -74,12 +74,12 @@ if [[ ${_Dbg_libdir:0:1} == '.' ]] ; then _Dbg_libdir="$(_Dbg_expand_filename "${_Dbg_init_cwd}/${_Dbg_libdir}")" fi -for source_file in "${_Dbg_o_init_files[@]}" "$DBG_RESTART_FILE"; do - if [[ -n "$source_file" ]] ; then - if [[ -r "$source_file" ]] && [[ -f "$source_file" ]] ; then - source "$source_file" +for _Dbg_source_file in "${_Dbg_o_init_files[@]}" "$DBG_RESTART_FILE"; do + if [[ -n "$_Dbg_source_file" ]] ; then + if [[ -r "$_Dbg_source_file" ]] && [[ -f "$_Dbg_source_file" ]] ; then + source "$_Dbg_source_file" else - _Dbg_errmsg "Unable to read shell script: ${source_file}" + _Dbg_errmsg "Unable to read shell script: ${_Dbg_source_file}" fi fi done diff --git a/lib/alias.sh b/lib/alias.sh index 9f21889..1e59e09 100644 --- a/lib/alias.sh +++ b/lib/alias.sh @@ -32,13 +32,13 @@ _Dbg_alias_remove() { return 0 } -# Expand alias $1. The result is set in variable expanded_alias which +# Expand alias $1. The result is set in variable _Dbg_expanded_alias which # could be declared local in the caller. _Dbg_alias_expand() { (( $# != 1 )) && return 1 - expanded_alias="$1" + _Dbg_expanded_alias="$1" [[ -z "$1" ]] && return 0 - [[ -n ${_Dbg_aliases[$1]} ]] && expanded_alias=${_Dbg_aliases[$1]} + [[ -n ${_Dbg_aliases[$1]} ]] && _Dbg_expanded_alias=${_Dbg_aliases[$1]} return 0 } diff --git a/lib/complete.sh b/lib/complete.sh index 0ab2fb6..7fe9900 100644 --- a/lib/complete.sh +++ b/lib/complete.sh @@ -26,8 +26,8 @@ typeset -a _Dbg_matches; _Dbg_matches=() # We get the list of completions from _Dbg._*subcmd*_cmds. # If no completion, we return the empty list. _Dbg_subcmd_complete() { - subcmd=$1 - text=$2 + typeset subcmd=$1 + typeset text=$2 _Dbg_matches=() typeset list='' if [[ $subcmd == 'set' ]] ; then diff --git a/lib/help.sh b/lib/help.sh index 7f404a7..201700f 100644 --- a/lib/help.sh +++ b/lib/help.sh @@ -44,8 +44,9 @@ function _Dbg_help_add { # Add help text $3 for in subcommand $1 under key $2 function _Dbg_help_add_sub { - add_command=${4:-1} + typeset add_command; add_command=${4:-1} (($# != 3)) && (($# != 4)) && return 1 + typeset -i add_command; add_command=${4:-1} eval "_Dbg_command_help_$1[$2]=\"$3\"" if (( add_command )) ; then eval "_Dbg_debugger_${1}_commands[$2]=\"_Dbg_do_${1}_${2}\"" diff --git a/lib/info.sh b/lib/info.sh index a532c8a..e300c8e 100644 --- a/lib/info.sh +++ b/lib/info.sh @@ -28,6 +28,7 @@ _Dbg_info_help() { typeset -a list _Dbg_section 'List of info subcommands:' + typeset thing for thing in $_Dbg_info_cmds ; do _Dbg_info_help $thing 1 done diff --git a/lib/processor.sh b/lib/processor.sh index 6d927e1..4348efd 100644 --- a/lib/processor.sh +++ b/lib/processor.sh @@ -102,11 +102,11 @@ function _Dbg_process_commands { _Dbg_continue_rc=-1 # Don't continue exectuion unless told to do so. _Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore" - typeset key + typeset _Dbg_key # Evaluate all hooks - for key in ${!_Dbg_cmdloop_hooks[@]} ; do - ${_Dbg_cmdloop_hooks[$key]} + for _Dbg_key in ${!_Dbg_cmdloop_hooks[@]} ; do + ${_Dbg_cmdloop_hooks[$_Dbg_key]} done # Loop over all pending open input file descriptors @@ -146,15 +146,15 @@ function _Dbg_process_commands { _Dbg_preloop typeset _Dbg_cmd - typeset args - typeset rc + typeset _Dbg_args + typeset _Dbg_rc while : ; do set -o history _Dbg_input_desc=${_Dbg_fd[_Dbg_fd_last]} if [[ $_Dbg_tty == '&1' ]] ; then echo -n "$_Dbg_prompt" - if ! read _Dbg_cmd args <&$_Dbg_input_desc 2>&1; then + if ! read _Dbg_cmd _Dbg_args <&$_Dbg_input_desc 2>&1; then break fi else @@ -163,7 +163,7 @@ function _Dbg_process_commands { else _Dbg_read_fn='read' fi - if ! $_Dbg_read_fn $_Dbg_edit -p "$_Dbg_prompt" _Dbg_cmd args \ + if ! $_Dbg_read_fn $_Dbg_edit -p "$_Dbg_prompt" _Dbg_cmd _Dbg_args \ <&$_Dbg_input_desc 2>>$_Dbg_prompt_output ; then set +o history break @@ -172,11 +172,11 @@ function _Dbg_process_commands { # FIXME: until I figure out to fix builtin readc, this happens # on command completion: - if [[ $_Dbg_cmd =~ ' ' && -z $args ]] ; then - typeset -a ary; IFS=' ' ary=( $_Dbg_cmd ) - _Dbg_cmd=${ary[0]} - unset ary[0] - args="${ary[@]}" + if [[ $_Dbg_cmd =~ ' ' && -z $_Dbg_args ]] ; then + typeset -a _Dbg_ary; IFS=' ' _Dbg_ary=( $_Dbg_cmd ) + _Dbg_cmd=${_Dbg_ary[0]} + unset _Dbg_ary[0] + _Dbg_args="${_Dbg_ary[@]}" fi set +o history if (( _Dbg_brkpt_commands_defining )) ; then @@ -200,14 +200,14 @@ function _Dbg_process_commands { continue ;; *) - _Dbg_brkpt_commands[${#_Dbg_brkpt_commands[@]}]="$_Dbg_cmd $args" + _Dbg_brkpt_commands[${#_Dbg_brkpt_commands[@]}]="$_Dbg_cmd $_Dbg_args" (( _Dbg_brkpt_commands_end[$_Dbg_brkpt_commands_current]++ )) continue ;; esac - rc=$? + _Dbg_rc=$? else - _Dbg_onecmd "$_Dbg_cmd" "$args" + _Dbg_onecmd "$_Dbg_cmd" "$_Dbg_args" _Dbg_postcmd fi ((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc @@ -238,13 +238,13 @@ _Dbg_annotation() { } # Run a single command -# Parameters: _Dbg_cmd and args +# Parameters: _Dbg_cmd and _Dbg_args # _Dbg_onecmd() { - typeset full_cmd=$@ + typeset _Dbg_full_cmd=$@ typeset _Dbg_orig_cmd="$1" - typeset expanded_alias; _Dbg_alias_expand "$_Dbg_orig_cmd" - typeset _Dbg_cmd="$expanded_alias" + typeset _Dbg_expanded_alias; _Dbg_alias_expand "$_Dbg_orig_cmd" + typeset _Dbg_cmd="$_Dbg_expanded_alias" shift typeset _Dbg_args="$@" @@ -252,26 +252,26 @@ _Dbg_onecmd() { if [[ -z $_Dbg_cmd ]]; then _Dbg_cmd=$_Dbg_last_next_step_cmd _Dbg_args=$_Dbg_last_next_step_args - full_cmd="$_Dbg_cmd $_Dbg_args" + _Dbg_full_cmd="$_Dbg_cmd $_Dbg_args" fi # If "set trace-commands" is "on", echo the the command if [[ $_Dbg_set_trace_commands == 'on' ]] ; then - _Dbg_msg "+$full_cmd" + _Dbg_msg "+$_Dbg_full_cmd" fi - local dq_cmd=$(_Dbg_esc_dq "$_Dbg_cmd") - local dq_args=$(_Dbg_esc_dq "$_Dbg_args") + local _Dbg_dq_cmd=$(_Dbg_esc_dq "$_Dbg_cmd") + local _Dbg_dq_args=$(_Dbg_esc_dq "$_Dbg_args") # _Dbg_write_journal_eval doesn't work here. Don't really understand # how to get it to work. So we do this in two steps. _Dbg_write_journal \ - "_Dbg_history[${#_Dbg_history[@]}]=\"$dq_cmd $dq_args\"" + "_Dbg_history[${#_Dbg_history[@]}]=\"$_Dbg_dq_cmd $_Dbg_dq_args\"" _Dbg_history[${#_Dbg_history[@]}]="$_Dbg_cmd $_Dbg_args" _Dbg_hi=${#_Dbg_history[@]} - history -s -- "$full_cmd" + history -s -- "$_Dbg_full_cmd" typeset -i _Dbg_redo=1 while (( _Dbg_redo )) ; do @@ -280,25 +280,25 @@ _Dbg_onecmd() { [[ -z $_Dbg_cmd ]] && _Dbg_cmd=$_Dbg_last_cmd if [[ -n $_Dbg_cmd ]] ; then - typeset -i found=0 - typeset found_cmd + typeset -i _Dbg_found=0 + typeset _Dbg_found_cmd if [[ -n ${_Dbg_debugger_commands[$_Dbg_cmd]} ]] ; then - found=1 - found_cmd=$_Dbg_cmd + _Dbg_found=1 + _Dbg_found_cmd=$_Dbg_cmd else # Look for a unique abbreviation - typeset -i count=0 - typeset list; list="${!_Dbg_debugger_commands[@]}" - for try in $list ; do + typeset -i _Dbg_count=0 + typeset _Dbg_list; _Dbg_list="${!_Dbg_debugger_commands[@]}" + for try in $_Dbg_list ; do if [[ $try =~ ^$_Dbg_cmd ]] ; then - found_cmd=$try - ((count++)) + _Dbg_found_cmd=$try + ((_Dbg_count++)) fi done - ((found=(count==1))) + ((_Dbg_found=(_Dbg_count==1))) fi - if ((found)); then - ${_Dbg_debugger_commands[$found_cmd]} $_Dbg_args + if ((_Dbg_found)); then + ${_Dbg_debugger_commands[$_Dbg_found_cmd]} $_Dbg_args IFS=$_Dbg_space_IFS; eval "_Dbg_prompt=$_Dbg_prompt_str" ((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc diff --git a/lib/sig.sh b/lib/sig.sh index f303155..1e19ecc 100644 --- a/lib/sig.sh +++ b/lib/sig.sh @@ -79,6 +79,7 @@ _Dbg_save_handler() { _Dbg_subst_handler_var() { typeset -i i typeset result='' + typeset arg for arg in $* ; do case $arg in '$LINENO' ) diff --git a/test/unit/test-alias.sh.in b/test/unit/test-alias.sh.in index 3b98420..1a7ffe0 100755 --- a/test/unit/test-alias.sh.in +++ b/test/unit/test-alias.sh.in @@ -3,12 +3,12 @@ test_alias() { _Dbg_alias_add u up - typeset expanded_alias=''; _Dbg_alias_expand u - assertEquals 'up' $expanded_alias + typeset _Dbg_expanded_alias=''; _Dbg_alias_expand u + assertEquals 'up' $_Dbg_expanded_alias _Dbg_alias_add q quit - expanded_alias=''; _Dbg_alias_expand q - assertEquals 'quit' $expanded_alias + _Dbg_expanded_alias=''; _Dbg_alias_expand q + assertEquals 'quit' $_Dbg_expanded_alias typeset aliases_found='' _Dbg_alias_find_aliased quit @@ -19,14 +19,14 @@ test_alias() assertEquals 'exit, q' "$aliases_found" _Dbg_alias_remove q - expanded_alias=''; _Dbg_alias_expand q - assertEquals 'q' $expanded_alias + _Dbg_expanded_alias=''; _Dbg_alias_expand q + assertEquals 'q' $_Dbg_expanded_alias _Dbg_alias_find_aliased quit assertEquals 'exit' "$aliases_found" - expanded_alias=''; _Dbg_alias_expand u - assertEquals 'up' $expanded_alias + _Dbg_expanded_alias=''; _Dbg_alias_expand u + assertEquals 'up' $_Dbg_expanded_alias } if [ '@abs_top_srcdir@' = '' ] ; then