Skip to content

Commit f5e83cc

Browse files
authored
5.2: Avoid pollution with global variables (#40)
* Avoid pollution with global variables in info commands * Don't pollute with global variable int_pat This is a global search & replace * Don't pollute with global variable _resteglob This is a global search & replace * Don't pollute with global variable _seteglob This is a global search & replace
1 parent 1daa08b commit f5e83cc

26 files changed

+111
-111
lines changed

command/break.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ _Dbg_do_clear_brkpt() {
150150
# If $1 is given just list those associated for that line.
151151
_Dbg_do_list_brkpt() {
152152

153-
eval "$_seteglob"
153+
eval "$_Dbg_seteglob"
154154
if (( $# != 0 )) ; then
155155
typeset brkpt_num="$1"
156-
if [[ $brkpt_num != $int_pat ]]; then
156+
if [[ $brkpt_num != $_Dbg_int_pat ]]; then
157157
_Dbg_errmsg "Bad breakpoint number $brkpt_num."
158158
elif [[ -z "${_Dbg_brkpt_file[$brkpt_num]}" ]] ; then
159159
_Dbg_errmsg "Breakpoint entry $brkpt_num is not set."
@@ -171,7 +171,7 @@ _Dbg_do_list_brkpt() {
171171
fi
172172
_Dbg_print_brkpt_count ${_Dbg_brkpt_count[$i]}
173173
fi
174-
eval "$_resteglob"
174+
eval "$_Dbg_resteglob"
175175
return 0
176176
elif (( ${#_Dbg_brkpt_line[@]} != 0 )); then
177177
typeset -i i

command/commands.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Type a line containing "end" to indicate the end of them. Give
3131
output is printed when it is hit, except what the commands print.'
3232

3333
_Dbg_do_commands() {
34-
eval "$_seteglob"
34+
eval "$_Dbg_seteglob"
3535
typeset num=$1
3636
typeset -i found=0
3737
case $num in
38-
$int_pat )
38+
$_Dbg_int_pat )
3939
if [[ -z "${_Dbg_brkpt_file[$num]}" ]] ; then
4040
_Dbg_errmsg "No breakpoint number $num."
4141
return 1
@@ -45,7 +45,7 @@ _Dbg_do_commands() {
4545
* )
4646
_Dbg_errmsg "Invalid entry number skipped: $num"
4747
esac
48-
eval "$_resteglob"
48+
eval "$_Dbg_resteglob"
4949
if (( found )) ; then
5050
_Dbg_brkpt_commands_defining=1
5151
_Dbg_brkpt_commands_current=$num

command/condition.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ function _Dbg_do_condition {
5252
typeset -r n=$1
5353
shift
5454

55-
eval "$_seteglob"
56-
if [[ $n != $int_pat ]]; then
57-
eval "$_resteglob"
55+
eval "$_Dbg_seteglob"
56+
if [[ $n != $_Dbg_int_pat ]]; then
57+
eval "$_Dbg_resteglob"
5858
_Dbg_errmsg "condition: Bad breakpoint number: $n"
5959
return 2
6060
fi
61-
eval "$_resteglob"
61+
eval "$_Dbg_resteglob"
6262

6363
if [[ -z "${_Dbg_brkpt_file[$n]}" ]] ; then
6464
_Dbg_msg "condition: Breakpoint entry $n is not set. Condition not changed."

command/debug.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _Dbg_do_debug() {
4848

4949
[[ -z $BASH ]] && BASH='bash'
5050

51-
eval "$_seteglob"
51+
eval "$_Dbg_seteglob"
5252
# Add appropriate bash debugging options
5353
if (( ! _Dbg_script )) ; then
5454
# Running "bash --debugger", so prepend "bash --debugger"
@@ -57,7 +57,7 @@ _Dbg_do_debug() {
5757
# Running "bashdb", so prepend "bash bashdb .."
5858
set_Dbg_debug_cmd="typeset _Dbg_debug_cmd=\"$BASH $_Dbg_orig_0 -q -L $_Dbg_libdir $script_cmd\"";
5959
fi
60-
eval "$_resteglob"
60+
eval "$_Dbg_resteglob"
6161
eval $set_Dbg_debug_cmd
6262

6363
if (( _Dbg_set_basename )) ; then

command/delete.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ _Dbg_do_delete() {
4848
fi
4949
fi
5050

51-
eval "$_seteglob"
51+
eval "$_Dbg_seteglob"
5252
for del in $to_go ; do
5353
case $del in
5454
$_Dbg_watch_pat )
5555
_Dbg_delete_watch_entry ${del:0:${#del}-1}
5656
;;
57-
$int_pat )
57+
$_Dbg_int_pat )
5858
if _Dbg_delete_brkpt_entry $del ; then
5959
_Dbg_msg "Deleted breakpoint ${del}"
6060
((tot_found++))
@@ -64,7 +64,7 @@ _Dbg_do_delete() {
6464
_Dbg_errmsg "Invalid entry number skipped: $del"
6565
esac
6666
done
67-
eval "$_resteglob"
67+
eval "$_Dbg_resteglob"
6868
return $tot_found
6969
}
7070

command/handle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ _Dbg_do_handle() {
4646
return 1
4747
fi
4848

49-
if [[ $sig == $int_pat ]]; then
49+
if [[ $sig == $_Dbg_int_pat ]]; then
5050
signame=$(_Dbg_signum2name $sig)
5151
if (( $? != 0 )) ; then
5252
_Dbg_errmsg "Bad signal number: $sig"

command/history.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ _Dbg_do_history() {
5252
# $2 is where to stop or 0 if not given.
5353
_Dbg_do_history_list() {
5454

55-
eval "$_seteglob"
56-
if [[ $1 != $int_pat ]] && [[ $1 != -$int_pat ]] && [[ -n $1 ]] ; then
55+
eval "$_Dbg_seteglob"
56+
if [[ $1 != $_Dbg_int_pat ]] && [[ $1 != -$_Dbg_int_pat ]] && [[ -n $1 ]] ; then
5757
_Dbg_msg "Invalid history number: $1"
58-
eval "$_resteglob"
58+
eval "$_Dbg_resteglob"
5959
return 1
6060
fi
61-
eval "$_resteglob"
61+
eval "$_Dbg_resteglob"
6262

6363
_Dbg_hi=${#_Dbg_history[@]}
6464
local -i n=${1:-$_Dbg_hi-1}

command/info.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,32 @@ _Dbg_complete_info() {
3636
_Dbg_do_info() {
3737

3838
if (($# > 0)) ; then
39-
typeset subcmd=$1
39+
typeset _Dbg_subcmd=$1
4040
shift
4141

42-
typeset -i found=0
42+
typeset -i _Dbg_found=0
4343

44-
if [[ -n ${_Dbg_debugger_info_commands[$subcmd]} ]] ; then
45-
${_Dbg_debugger_info_commands[$subcmd]} "$@"
44+
if [[ -n ${_Dbg_debugger_info_commands[$_Dbg_subcmd]} ]] ; then
45+
${_Dbg_debugger_info_commands[$_Dbg_subcmd]} "$@"
4646
return $?
4747
else
4848
# Look for a unique abbreviation
49-
typeset -i count=0
50-
typeset list; list="${!_Dbg_debugger_info_commands[@]}"
51-
for try in $list ; do
52-
if [[ $try =~ ^$subcmd ]] ; then
53-
subcmd=$try
54-
((count++))
49+
typeset -i _Dbg_count=0
50+
typeset _Dbg_list; _Dbg_list="${!_Dbg_debugger_info_commands[@]}"
51+
for _Dbg_try in $_Dbg_list ; do
52+
if [[ $_Dbg_try =~ ^$_Dbg_subcmd ]] ; then
53+
_Dbg_subcmd="$_Dbg_try"
54+
((_Dbg_count++))
5555
fi
5656
done
57-
((found=(count==1)))
57+
((_Dbg_found=(_Dbg_count==1)))
5858
fi
59-
if ((found)); then
60-
${_Dbg_debugger_info_commands[$subcmd]} "$@"
59+
if ((_Dbg_found)); then
60+
${_Dbg_debugger_info_commands[$_Dbg_subcmd]} "$@"
6161
return $?
6262
fi
6363

64-
_Dbg_errmsg "Unknown info subcommand: $subcmd"
64+
_Dbg_errmsg "Unknown info subcommand: $_Dbg_subcmd"
6565
msg=_Dbg_errmsg
6666
else
6767
msg=_Dbg_msg

command/info_sub/args.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ _Dbg_do_info_args() {
4646

4747
typeset -r frame_start=${1:-0}
4848

49-
eval "$_seteglob"
50-
if [[ $frame_start != $int_pat ]] ; then
49+
eval "$_Dbg_seteglob"
50+
if [[ $frame_start != $_Dbg_int_pat ]] ; then
5151
_Dbg_errmsg "Bad integer parameter: $frame_start"
52-
eval "$_resteglob"
52+
eval "$_Dbg_resteglob"
5353
return 1
5454
fi
5555

command/search.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ _Dbg_do_reverse() {
4646
typeset -i i
4747
for (( i=_Dbg_listline-1; i > 0 ; i-- )) ; do
4848
_Dbg_get_source_line $i "$_Dbg_frame_last_filename"
49-
eval "$_seteglob"
49+
eval "$_Dbg_seteglob"
5050
if [[ $_Dbg_source_line == *$_Dbg_last_search_pat* ]] ; then
51-
eval "$_resteglob"
51+
eval "$_Dbg_resteglob"
5252
_Dbg_do_list $i 1
5353
_Dbg_listline=$i
5454
_Dbg_last_cmd='search'
5555
return 0
5656
fi
57-
eval "$_resteglob"
57+
eval "$_Dbg_resteglob"
5858
done
5959
_Dbg_msg "search pattern: $_Dbg_last_search_pat not found."
6060
return 1
@@ -91,15 +91,15 @@ _Dbg_do_search() {
9191
typeset -i i
9292
for (( i=_Dbg_listline+1; i < max_line ; i++ )) ; do
9393
_Dbg_get_source_line $i "$_Dbg_frame_last_filename"
94-
eval "$_seteglob"
94+
eval "$_Dbg_seteglob"
9595
if [[ $_Dbg_source_line == *$_Dbg_last_search_pat* ]] ; then
96-
eval "$_resteglob"
96+
eval "$_Dbg_resteglob"
9797
_Dbg_do_list $i 1
9898
_Dbg_listline=$i
9999
# _Dbg_last_cmd='/'
100100
return 0
101101
fi
102-
eval "$_resteglob"
102+
eval "$_Dbg_resteglob"
103103
done
104104
_Dbg_errmsg "search pattern: $_Dbg_last_search_pat not found."
105105
return 1

command/set_sub/annotate.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ See also:
3434
' 1
3535

3636
_Dbg_do_set_annotate() {
37-
eval "$_seteglob"
37+
eval "$_Dbg_seteglob"
3838
if (( $# != 1 )) ; then
3939
_Dbg_msg "A single argument is required (got $# arguments)."
40-
elif [[ $1 == $int_pat ]] ; then
40+
elif [[ $1 == $_Dbg_int_pat ]] ; then
4141
if (( $1 > 3 )) ; then
4242
_Dbg_msg "Annotation level must be between 0 and 3. Got: ${1}."
4343
else
4444
_Dbg_write_journal_eval "_Dbg_set_annotate=$1"
4545
fi
4646
else
47-
eval "$_resteglob"
47+
eval "$_Dbg_resteglob"
4848
_Dbg_msg "Integer argument expected; got: $1"
4949
return 1
5050
fi
51-
eval "$_resteglob"
51+
eval "$_Dbg_resteglob"
5252
return 0
5353
}

command/set_sub/history.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ _Dbg_do_set_history() {
5656
esac
5757
;;
5858
si | siz | size )
59-
eval "$_seteglob"
59+
eval "$_Dbg_seteglob"
6060
if [[ -z $2 ]] ; then
6161
_Dbg_errmsg "Argument required (integer to set it to.)."
62-
elif [[ $2 != $int_pat ]] ; then
62+
elif [[ $2 != $_Dbg_int_pat ]] ; then
6363
_Dbg_errmsg "Integer argument expected; got: $2"
64-
eval "$_resteglob"
64+
eval "$_Dbg_resteglob"
6565
return 1
6666
fi
67-
eval "$_resteglob"
67+
eval "$_Dbg_resteglob"
6868
_Dbg_write_journal_eval "_Dbg_history_length=$2"
6969
;;
7070
*)

command/set_sub/linetrace.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ _Dbg_do_set_linetrace() {
4747
_Dbg_write_journal_eval "_Dbg_set_linetrace=0"
4848
;;
4949
d | de | del | dela | delay )
50-
eval "$_seteglob"
51-
if [[ $2 != $int_pat ]] ; then
50+
eval "$_Dbg_seteglob"
51+
if [[ $2 != $_Dbg_int_pat ]] ; then
5252
_Dbg_msg "Bad int parameter: $2"
53-
eval "$_resteglob"
53+
eval "$_Dbg_resteglob"
5454
return 1
5555
fi
56-
eval "$_resteglob"
56+
eval "$_Dbg_resteglob"
5757
_Dbg_write_journal_eval "_Dbg_linetrace_delay=$2"
5858
;;
5959
e | ex | exp | expa | expan | expand )

command/set_sub/listsize.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ See also:
4141
typeset -xi _Dbg_set_listsize=10
4242

4343
_Dbg_do_set_listsize() {
44-
eval "$_seteglob"
45-
if [[ $1 == $int_pat ]] ; then
44+
eval "$_Dbg_seteglob"
45+
if [[ $1 == $_Dbg_int_pat ]] ; then
4646
_Dbg_write_journal_eval "_Dbg_set_listsize=$1"
4747
else
48-
eval "$_resteglob"
48+
eval "$_Dbg_resteglob"
4949
_Dbg_errmsg "Integer argument expected; got: $1"
5050
return 1
5151
fi
52-
eval "$_resteglob"
52+
eval "$_Dbg_resteglob"
5353
return 0
5454
}

command/set_sub/width.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Set maximum width of lines to *width*.
3535
typeset -i _Dbg_set_linewidth; _Dbg_set_linewidth=${COLUMNS:-80}
3636

3737
_Dbg_do_set_width() {
38-
if [[ $1 == $int_pat ]] ; then
38+
if [[ $1 == $_Dbg_int_pat ]] ; then
3939
_Dbg_write_journal_eval "_Dbg_set_linewidth=$1"
4040
else
4141
_Dbg_errmsg "Integer argument expected; got: $1"

command/show_sub/commands.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ _Dbg_do_show_commands() {
3636
if ((default_hi_start < 0)) ; then default_hi_start=0 ; fi
3737
typeset hi_start=${2:-$default_hi_start}
3838

39-
eval "$_seteglob"
39+
eval "$_Dbg_seteglob"
4040
case $hi_start in
4141
"+" )
4242
((hi_start=_Dbg_hi_last_stop-1))
4343
;;
44-
$int_pat | -$int_pat)
44+
$_Dbg_int_pat | -$_Dbg_int_pat)
4545
:
4646
;;
4747
* )
4848
_Dbg_msg "Invalid parameter $hi_start. Need an integer or '+'"
4949
esac
50-
eval "$_resteglob"
50+
eval "$_Dbg_resteglob"
5151

5252
typeset -i hi_stop=hi_start-10
5353
_Dbg_do_history_list $hi_start $hi_stop

command/signal.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ _Dbg_do_signal() {
4040
return 1
4141
fi
4242

43-
eval "$_seteglob"
44-
if [[ $sig == $int_pat ]]; then
45-
eval "$_resteglob"
43+
eval "$_Dbg_seteglob"
44+
if [[ $sig == $_Dbg_int_pat ]]; then
45+
eval "$_Dbg_resteglob"
4646
signame=$(_Dbg_signum2name $sig)
4747
if (( $? != 0 )) ; then
4848
_Dbg_msg "Bad signal number: $sig"
4949
return 1
5050
fi
5151
signum=sig
5252
else
53-
eval "$_resteglob"
53+
eval "$_Dbg_resteglob"
5454
typeset signum;
5555
signum=$(_Dbg_name2signum $sig)
5656
if (( $? != 0 )) ; then

init/vars.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ typeset _Dbg_last_printe='' # expression on last print expression command
4747

4848
# strings to save and restore the setting of `extglob' in debugger functions
4949
# that need it
50-
typeset _seteglob='local __eopt=-u ; shopt -q extglob && __eopt=-s ; shopt -s extglob'
51-
typeset _resteglob='shopt $__eopt extglob'
50+
typeset _Dbg_seteglob='local __eopt=-u ; shopt -q extglob && __eopt=-s ; shopt -s extglob'
51+
typeset _Dbg_resteglob='shopt $__eopt extglob'
5252

53-
typeset int_pat='[0-9]*([0-9])'
53+
typeset _Dbg_int_pat='[0-9]*([0-9])'
5454
typeset _Dbg_signed_int_pat='?([-+])+([0-9])'
5555

5656
# Set tty to use for output.

0 commit comments

Comments
 (0)