Skip to content

Commit 122c3f5

Browse files
committed
Fix pollution of global variables
1 parent c9cf5f7 commit 122c3f5

File tree

12 files changed

+67
-61
lines changed

12 files changed

+67
-61
lines changed

bashdb.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ typeset _Dbg_libdir="@PKGDATADIR@"
6464
typeset -xa _Dbg_script_args; _Dbg_script_args=("$@")
6565
typeset -i _Dbg_i
6666
for ((_Dbg_i=0; _Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do
67-
typeset arg=${_Dbg_script_args[$_Dbg_i]}
68-
if [[ $arg == '-L' || $arg == '--library' ]] ; then
67+
typeset _Dbg_script_arg=${_Dbg_script_args[$_Dbg_i]}
68+
if [[ $_Dbg_script_arg == '-L' || $_Dbg_script_arg == '--library' ]] ; then
6969
((_Dbg_i++))
7070
_Dbg_libdir="${_Dbg_script_args[$_Dbg_i]}"
7171
break
72-
elif [[ $arg == '--' ]] ; then
72+
elif [[ $_Dbg_script_arg == '--' ]] ; then
7373
# We hit the end of bashdb args
7474
break
7575
fi

command/help.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ function _Dbg_do_help {
7878
if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
7979
_Dbg_msg_rst "${_Dbg_command_help[$dbg_cmd]}"
8080
else
81-
_Dbg_alias_expand $dbg_cmd
82-
dbg_cmd="$expanded_alias"
81+
typeset _Dbg_expanded_alias; _Dbg_alias_expand $dbg_cmd
82+
dbg_cmd="$_Dbg_expanded_alias"
8383
if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
8484
_Dbg_msg_rst "${_Dbg_command_help[$dbg_cmd]}"
8585
else

command/info.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ _Dbg_do_info() {
3939
typeset subcmd=$1
4040
shift
4141

42+
typeset -i found=0
43+
4244
if [[ -n ${_Dbg_debugger_info_commands[$subcmd]} ]] ; then
4345
${_Dbg_debugger_info_commands[$subcmd]} "$@"
4446
return $?

command/info_sub/files.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ _Dbg_do_info_files() {
2929
typeset -a list=()
3030
typeset -i i=0
3131
typeset key
32+
typeset file
3233
for key in "${!_Dbg_file2canonic[@]}"; do
3334
list[$i]="$key"
3435
((i++))

dbg-main.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ if [[ ${_Dbg_libdir:0:1} == '.' ]] ; then
7474
_Dbg_libdir="$(_Dbg_expand_filename "${_Dbg_init_cwd}/${_Dbg_libdir}")"
7575
fi
7676

77-
for source_file in "${_Dbg_o_init_files[@]}" "$DBG_RESTART_FILE"; do
78-
if [[ -n "$source_file" ]] ; then
79-
if [[ -r "$source_file" ]] && [[ -f "$source_file" ]] ; then
80-
source "$source_file"
77+
for _Dbg_source_file in "${_Dbg_o_init_files[@]}" "$DBG_RESTART_FILE"; do
78+
if [[ -n "$_Dbg_source_file" ]] ; then
79+
if [[ -r "$_Dbg_source_file" ]] && [[ -f "$_Dbg_source_file" ]] ; then
80+
source "$_Dbg_source_file"
8181
else
82-
_Dbg_errmsg "Unable to read shell script: ${source_file}"
82+
_Dbg_errmsg "Unable to read shell script: ${_Dbg_source_file}"
8383
fi
8484
fi
8585
done

lib/alias.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ _Dbg_alias_remove() {
3232
return 0
3333
}
3434

35-
# Expand alias $1. The result is set in variable expanded_alias which
35+
# Expand alias $1. The result is set in variable _Dbg_expanded_alias which
3636
# could be declared local in the caller.
3737
_Dbg_alias_expand() {
3838
(( $# != 1 )) && return 1
39-
expanded_alias="$1"
39+
_Dbg_expanded_alias="$1"
4040
[[ -z "$1" ]] && return 0
41-
[[ -n ${_Dbg_aliases[$1]} ]] && expanded_alias=${_Dbg_aliases[$1]}
41+
[[ -n ${_Dbg_aliases[$1]} ]] && _Dbg_expanded_alias=${_Dbg_aliases[$1]}
4242
return 0
4343
}
4444

lib/complete.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ typeset -a _Dbg_matches; _Dbg_matches=()
2626
# We get the list of completions from _Dbg._*subcmd*_cmds.
2727
# If no completion, we return the empty list.
2828
_Dbg_subcmd_complete() {
29-
subcmd=$1
30-
text=$2
29+
typeset subcmd=$1
30+
typeset text=$2
3131
_Dbg_matches=()
3232
typeset list=''
3333
if [[ $subcmd == 'set' ]] ; then

lib/help.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ function _Dbg_help_add {
4444

4545
# Add help text $3 for in subcommand $1 under key $2
4646
function _Dbg_help_add_sub {
47-
add_command=${4:-1}
47+
typeset add_command; add_command=${4:-1}
4848
(($# != 3)) && (($# != 4)) && return 1
49+
typeset -i add_command; add_command=${4:-1}
4950
eval "_Dbg_command_help_$1[$2]=\"$3\""
5051
if (( add_command )) ; then
5152
eval "_Dbg_debugger_${1}_commands[$2]=\"_Dbg_do_${1}_${2}\""

lib/info.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _Dbg_info_help() {
2828
typeset -a list
2929
_Dbg_section 'List of info subcommands:'
3030

31+
typeset thing
3132
for thing in $_Dbg_info_cmds ; do
3233
_Dbg_info_help $thing 1
3334
done

lib/processor.sh

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ function _Dbg_process_commands {
102102
_Dbg_continue_rc=-1 # Don't continue exectuion unless told to do so.
103103
_Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore"
104104

105-
typeset key
105+
typeset _Dbg_key
106106

107107
# Evaluate all hooks
108-
for key in ${!_Dbg_cmdloop_hooks[@]} ; do
109-
${_Dbg_cmdloop_hooks[$key]}
108+
for _Dbg_key in ${!_Dbg_cmdloop_hooks[@]} ; do
109+
${_Dbg_cmdloop_hooks[$_Dbg_key]}
110110
done
111111

112112
# Loop over all pending open input file descriptors
@@ -146,15 +146,15 @@ function _Dbg_process_commands {
146146
_Dbg_preloop
147147

148148
typeset _Dbg_cmd
149-
typeset args
150-
typeset rc
149+
typeset _Dbg_args
150+
typeset _Dbg_rc
151151

152152
while : ; do
153153
set -o history
154154
_Dbg_input_desc=${_Dbg_fd[_Dbg_fd_last]}
155155
if [[ $_Dbg_tty == '&1' ]] ; then
156156
echo -n "$_Dbg_prompt"
157-
if ! read _Dbg_cmd args <&$_Dbg_input_desc 2>&1; then
157+
if ! read _Dbg_cmd _Dbg_args <&$_Dbg_input_desc 2>&1; then
158158
break
159159
fi
160160
else
@@ -163,7 +163,7 @@ function _Dbg_process_commands {
163163
else
164164
_Dbg_read_fn='read'
165165
fi
166-
if ! $_Dbg_read_fn $_Dbg_edit -p "$_Dbg_prompt" _Dbg_cmd args \
166+
if ! $_Dbg_read_fn $_Dbg_edit -p "$_Dbg_prompt" _Dbg_cmd _Dbg_args \
167167
<&$_Dbg_input_desc 2>>$_Dbg_prompt_output ; then
168168
set +o history
169169
break
@@ -172,11 +172,11 @@ function _Dbg_process_commands {
172172

173173
# FIXME: until I figure out to fix builtin readc, this happens
174174
# on command completion:
175-
if [[ $_Dbg_cmd =~ ' ' && -z $args ]] ; then
176-
typeset -a ary; IFS=' ' ary=( $_Dbg_cmd )
177-
_Dbg_cmd=${ary[0]}
178-
unset ary[0]
179-
args="${ary[@]}"
175+
if [[ $_Dbg_cmd =~ ' ' && -z $_Dbg_args ]] ; then
176+
typeset -a _Dbg_ary; IFS=' ' _Dbg_ary=( $_Dbg_cmd )
177+
_Dbg_cmd=${_Dbg_ary[0]}
178+
unset _Dbg_ary[0]
179+
_Dbg_args="${_Dbg_ary[@]}"
180180
fi
181181
set +o history
182182
if (( _Dbg_brkpt_commands_defining )) ; then
@@ -200,14 +200,14 @@ function _Dbg_process_commands {
200200
continue
201201
;;
202202
*)
203-
_Dbg_brkpt_commands[${#_Dbg_brkpt_commands[@]}]="$_Dbg_cmd $args"
203+
_Dbg_brkpt_commands[${#_Dbg_brkpt_commands[@]}]="$_Dbg_cmd $_Dbg_args"
204204
(( _Dbg_brkpt_commands_end[$_Dbg_brkpt_commands_current]++ ))
205205
continue
206206
;;
207207
esac
208-
rc=$?
208+
_Dbg_rc=$?
209209
else
210-
_Dbg_onecmd "$_Dbg_cmd" "$args"
210+
_Dbg_onecmd "$_Dbg_cmd" "$_Dbg_args"
211211
_Dbg_postcmd
212212
fi
213213
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc
@@ -238,40 +238,40 @@ _Dbg_annotation() {
238238
}
239239

240240
# Run a single command
241-
# Parameters: _Dbg_cmd and args
241+
# Parameters: _Dbg_cmd and _Dbg_args
242242
#
243243
_Dbg_onecmd() {
244-
typeset full_cmd=$@
244+
typeset _Dbg_full_cmd=$@
245245
typeset _Dbg_orig_cmd="$1"
246-
typeset expanded_alias; _Dbg_alias_expand "$_Dbg_orig_cmd"
247-
typeset _Dbg_cmd="$expanded_alias"
246+
typeset _Dbg_expanded_alias; _Dbg_alias_expand "$_Dbg_orig_cmd"
247+
typeset _Dbg_cmd="$_Dbg_expanded_alias"
248248
shift
249249
typeset _Dbg_args="$@"
250250

251251
# Set default next, step or skip command
252252
if [[ -z $_Dbg_cmd ]]; then
253253
_Dbg_cmd=$_Dbg_last_next_step_cmd
254254
_Dbg_args=$_Dbg_last_next_step_args
255-
full_cmd="$_Dbg_cmd $_Dbg_args"
255+
_Dbg_full_cmd="$_Dbg_cmd $_Dbg_args"
256256
fi
257257

258258
# If "set trace-commands" is "on", echo the the command
259259
if [[ $_Dbg_set_trace_commands == 'on' ]] ; then
260-
_Dbg_msg "+$full_cmd"
260+
_Dbg_msg "+$_Dbg_full_cmd"
261261
fi
262262

263-
local dq_cmd=$(_Dbg_esc_dq "$_Dbg_cmd")
264-
local dq_args=$(_Dbg_esc_dq "$_Dbg_args")
263+
local _Dbg_dq_cmd=$(_Dbg_esc_dq "$_Dbg_cmd")
264+
local _Dbg_dq_args=$(_Dbg_esc_dq "$_Dbg_args")
265265

266266
# _Dbg_write_journal_eval doesn't work here. Don't really understand
267267
# how to get it to work. So we do this in two steps.
268268
_Dbg_write_journal \
269-
"_Dbg_history[${#_Dbg_history[@]}]=\"$dq_cmd $dq_args\""
269+
"_Dbg_history[${#_Dbg_history[@]}]=\"$_Dbg_dq_cmd $_Dbg_dq_args\""
270270

271271
_Dbg_history[${#_Dbg_history[@]}]="$_Dbg_cmd $_Dbg_args"
272272

273273
_Dbg_hi=${#_Dbg_history[@]}
274-
history -s -- "$full_cmd"
274+
history -s -- "$_Dbg_full_cmd"
275275

276276
typeset -i _Dbg_redo=1
277277
while (( _Dbg_redo )) ; do
@@ -280,25 +280,25 @@ _Dbg_onecmd() {
280280

281281
[[ -z $_Dbg_cmd ]] && _Dbg_cmd=$_Dbg_last_cmd
282282
if [[ -n $_Dbg_cmd ]] ; then
283-
typeset -i found=0
284-
typeset found_cmd
283+
typeset -i _Dbg_found=0
284+
typeset _Dbg_found_cmd
285285
if [[ -n ${_Dbg_debugger_commands[$_Dbg_cmd]} ]] ; then
286-
found=1
287-
found_cmd=$_Dbg_cmd
286+
_Dbg_found=1
287+
_Dbg_found_cmd=$_Dbg_cmd
288288
else
289289
# Look for a unique abbreviation
290-
typeset -i count=0
291-
typeset list; list="${!_Dbg_debugger_commands[@]}"
292-
for try in $list ; do
290+
typeset -i _Dbg_count=0
291+
typeset _Dbg_list; _Dbg_list="${!_Dbg_debugger_commands[@]}"
292+
for try in $_Dbg_list ; do
293293
if [[ $try =~ ^$_Dbg_cmd ]] ; then
294-
found_cmd=$try
295-
((count++))
294+
_Dbg_found_cmd=$try
295+
((_Dbg_count++))
296296
fi
297297
done
298-
((found=(count==1)))
298+
((_Dbg_found=(_Dbg_count==1)))
299299
fi
300-
if ((found)); then
301-
${_Dbg_debugger_commands[$found_cmd]} $_Dbg_args
300+
if ((_Dbg_found)); then
301+
${_Dbg_debugger_commands[$_Dbg_found_cmd]} $_Dbg_args
302302
IFS=$_Dbg_space_IFS;
303303
eval "_Dbg_prompt=$_Dbg_prompt_str"
304304
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc

lib/sig.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ _Dbg_save_handler() {
7979
_Dbg_subst_handler_var() {
8080
typeset -i i
8181
typeset result=''
82+
typeset arg
8283
for arg in $* ; do
8384
case $arg in
8485
'$LINENO' )

test/unit/test-alias.sh.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
test_alias()
44
{
55
_Dbg_alias_add u up
6-
typeset expanded_alias=''; _Dbg_alias_expand u
7-
assertEquals 'up' $expanded_alias
6+
typeset _Dbg_expanded_alias=''; _Dbg_alias_expand u
7+
assertEquals 'up' $_Dbg_expanded_alias
88

99
_Dbg_alias_add q quit
10-
expanded_alias=''; _Dbg_alias_expand q
11-
assertEquals 'quit' $expanded_alias
10+
_Dbg_expanded_alias=''; _Dbg_alias_expand q
11+
assertEquals 'quit' $_Dbg_expanded_alias
1212

1313
typeset aliases_found=''
1414
_Dbg_alias_find_aliased quit
@@ -19,14 +19,14 @@ test_alias()
1919
assertEquals 'exit, q' "$aliases_found"
2020

2121
_Dbg_alias_remove q
22-
expanded_alias=''; _Dbg_alias_expand q
23-
assertEquals 'q' $expanded_alias
22+
_Dbg_expanded_alias=''; _Dbg_alias_expand q
23+
assertEquals 'q' $_Dbg_expanded_alias
2424

2525
_Dbg_alias_find_aliased quit
2626
assertEquals 'exit' "$aliases_found"
2727

28-
expanded_alias=''; _Dbg_alias_expand u
29-
assertEquals 'up' $expanded_alias
28+
_Dbg_expanded_alias=''; _Dbg_alias_expand u
29+
assertEquals 'up' $_Dbg_expanded_alias
3030
}
3131

3232
if [ '@abs_top_srcdir@' = '' ] ; then

0 commit comments

Comments
 (0)