Skip to content

Commit

Permalink
5.2: Fix more pollution with global variables, improve handling of pa…
Browse files Browse the repository at this point in the history
…ths with whitespace (#46)

* Don't pollute global variables with "fullname"
Also wraps the assigned value in quotes for better whitespace handling

* Don't pollute global variables with "opt"

* Don't pollute global variables with "prefix"
Function declaration and call are on a single line because the line number is referenced by tests

* Better handling of spaces in paths
  • Loading branch information
jansorg authored Oct 9, 2024
1 parent ce225ef commit 206b2b5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
18 changes: 9 additions & 9 deletions bashdb-main.inc.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ typeset _Dbg_release='@PACKAGE_VERSION@'
typeset _Dbg_bashdb_main='@DBGR_MAIN@'

# The short shell name. Helps keep code common in bash, zsh, and ksh debuggers.
typeset _Dbg_shell_name=${_Dbg_shell##*/} # Equivalent to basename(_Dbg_shell)
typeset _Dbg_shell_name="${_Dbg_shell##*/}" # Equivalent to basename(_Dbg_shell)

# Original $0. Note we can't set this in an include.
typeset _Dbg_orig_0=$0
typeset _Dbg_orig_0="$0"

# Equivalent to basename $0; the short program name
typeset _Dbg_pname=${0##*/}
typeset _Dbg_pname="${0##*/}"

## Stuff set by autoconf/configure ###
typeset prefix=@prefix@ # @PKGDATADIR@ often uses $prefix
typeset _Dbg_libdir=@PKGDATADIR@
# @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable
_Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; _Dbg_assign_libdir
###

# We agonize a bit over _Dbg_libdir: the root directory for where
# debugger code is stored.
[[ -d $_Dbg_libdir ]] || _Dbg_libdir=${_Dbg_bashdb_main%/*} # dirname(_Dbg_bashdb_main)
[[ -d $_Dbg_libdir ]] || _Dbg_libdir='.'
[[ -d "$_Dbg_libdir" ]] || _Dbg_libdir="${_Dbg_bashdb_main%/*}" # dirname(_Dbg_bashdb_main)
[[ -d "$_Dbg_libdir" ]] || _Dbg_libdir='.'

typeset _Dbg_main="$_Dbg_libdir/dbg-main.sh"
if [[ ! -r $_Dbg_main ]] ; then
if [[ ! -r "$_Dbg_main" ]] ; then
echo "${_Dbg_pname}: Can't read debugger library file '${_Dbg_main}'."
echo "${_Dbg_pname}: Perhaps @PACKAGE@ is installed wrong (if its installed)." >&2
echo "${_Dbg_pname}: Try running @PACKAGE@ using -L (with a different directory)." >&2
Expand All @@ -57,6 +57,6 @@ if [[ ! -r $_Dbg_main ]] ; then
fi

# Pull in the rest of the debugger code.
. $_Dbg_main
. "$_Dbg_main"

trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG
4 changes: 2 additions & 2 deletions bashdb.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ typeset _Dbg_orig_0=$0
typeset _Dbg_pname=${0##*/}

## Stuff set by autoconf/configure ###
typeset prefix=@prefix@ # @PKGDATADIR@ often uses $prefix
typeset _Dbg_libdir="@PKGDATADIR@"
# @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable
_Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; _Dbg_assign_libdir
###

# We agonize a bit over _Dbg_libdir: the root directory for where
Expand Down
1 change: 1 addition & 0 deletions command/info_sub/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function _Dbg_info_variables_parse_options {

typeset -i _Dbg_rc=0
typeset OPTLIND=''
typeset opt
while getopts_long irxaAtp opt \
integer no_argument \
readonly no_argument \
Expand Down
3 changes: 2 additions & 1 deletion lib/filecache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ function _Dbg_readin {
if [[ -z "$filename" ]] || [[ "$filename" == "$_Dbg_bogus_file" ]] ; then
eval "${_Dbg_source_array_var}[0]=\"$Dbg_EXECUTION_STRING\""
else
fullname=$(_Dbg_resolve_expand_filename "$filename")
typeset fullname
fullname="$(_Dbg_resolve_expand_filename "$filename")"
if [[ -r "$fullname" ]] ; then
typeset -r progress_prefix="Reading $filename"
_Dbg_file2canonic["$filename"]="$fullname"
Expand Down

0 comments on commit 206b2b5

Please sign in to comment.