(change version)

Fixed debugger for real this time, now it actually works as intended. The infobash debugger never worked at all, unless 
you explicitly turned it on with debugging flag. Now it does.

Pre script up errors will be stored in the error array, and printed out if found automatically no matter what the 
debugging flag is set to.

This is a perfect example of why using highly compressed code with no explicit variable declarations is ALWAYS a bad 
idea.
This commit is contained in:
inxi-svn 2008-12-14 17:20:02 +00:00
parent 1ea30c905a
commit 61f9f89744

77
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.8.7 #### version: 0.8.8
#### Date: December 13 2008 #### Date: December 14 2008
######################################################################## ########################################################################
#### inxi is a fork of infobash 3.02, the original bash sys info script by locsmif #### inxi is a fork of infobash 3.02, the original bash sys info script by locsmif
#### As time permits functionality improvements and recoding will occur. #### As time permits functionality improvements and recoding will occur.
@ -101,6 +101,7 @@ A_AUDIO_DATA=''
A_CMDL='' A_CMDL=''
A_CPU_CORE_DATA='' A_CPU_CORE_DATA=''
A_CPU_DATA='' A_CPU_DATA=''
A_DEBUG_BUFFER=''
A_GFX_CARD_DATA='' A_GFX_CARD_DATA=''
A_GLX_DATA='' A_GLX_DATA=''
A_HDD_DATA='' A_HDD_DATA=''
@ -124,6 +125,8 @@ B_SHOW_DISK='false'
B_HANDLE_CORRUPT_DATA='false' B_HANDLE_CORRUPT_DATA='false'
# Running in a shell? Defaults to false, and is determined later. # Running in a shell? Defaults to false, and is determined later.
B_RUNNING_IN_SHELL='false' B_RUNNING_IN_SHELL='false'
# this sets the debug buffer
B_SCRIPT_UP='false'
# Show sound card data # Show sound card data
B_SHOW_AUDIO='false' B_SHOW_AUDIO='false'
B_SHOW_CPU='false' B_SHOW_CPU='false'
@ -303,31 +306,37 @@ error_handler()
exit $1 exit $1
} }
# note: this debugger is largely useless in its current condition, but # prior to script up set, pack the data into an array
# we'll leave this up for now. I dumped the all-up debugging variable # then we'll print it out later.
# args: $1 - $@ debugging string text; $2 - type: missing-app/all-up # args: $1 - $@ debugging string text
script_debugger() script_debugger()
{ {
local a_debug_buffer='' if [[ $B_SCRIPT_UP == 'true' ]];then
# only return if debugger is off and no pre start up errors have occured
if [[ $2 == 'all-up' || $2 == 'missing-app' ]];then if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
# only return if not app missing or no debugger return 0
if [[ $DEBUG -eq 0 && $2 != 'missing-app' ]];then # print out the stored debugging information if errors occured
return elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#a_debug_buffer[@]}; DEBUG_BUFFER_INDEX++ )) do
do print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
print_screen_output "${a_debug_buffer[$DEBUG_BUFFER_INDEX]}" done
done DEBUG_BUFFER_INDEX=0
DEBUG_BUFFER_INDEX=0 fi
print_screen_output "$1" # or print out normal debugger messages if debugger is on
fi if [[ $DEBUG -gt 0 ]];then
print_screen_output "$1"
fi
else else
if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
error_handler 2 error_handler 2
else # this case stores the data for later printout, will print out only
a_debug_buffer[DEBUG_BUFFER_INDEX++]="$1" # at B_SCRIPT_UP == 'true' if array index > 0
fi else
A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
# increment count for next pre script up debugging error
(( DEBUG_BUFFER_INDEX++ ))
fi
fi fi
} }
@ -427,7 +436,7 @@ check_script_depends()
do do
app_data=$( type -p $app_name ) app_data=$( type -p $app_name )
if [[ -z $app_data ]];then if [[ -z $app_data ]];then
script_debugger "Resuming in non X mode: $app_name not found in path" 'missing-app' script_debugger "Resuming in non X mode: $app_name not found in path"
B_X_RUNNING='false' B_X_RUNNING='false'
break break
fi fi
@ -2695,13 +2704,21 @@ print_system_data()
######################################################################## ########################################################################
#### SCRIPT EXECUTION #### SCRIPT EXECUTION
######################################################################## ########################################################################
# first two functions must be set first for colors etc. Remember, no debugger
# stuff works on these first two functions unless you set the debugging flag
# manually. Debugging flag -@ [number] will not work until get_parameters runs.
set_calculated_variables set_calculated_variables
# Check for dependencies before running anything else except above function
check_script_depends
## this needs to run before the KONVI stuff is set below ## this needs to run before the KONVI stuff is set below
get_start_client get_start_client
# "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
# must be here to allow debugger and other flags to be set.
get_parameters "$@"
# Check for dependencies before running anything else except above functions
check_script_depends
# note: this only works if it's run from inside konversation as a script builtin or something # note: this only works if it's run from inside konversation as a script builtin or something
# only do this if inxi has been started as a konversation script, otherwise bypass this # only do this if inxi has been started as a konversation script, otherwise bypass this
if [[ $KONVI -eq 1 ]];then if [[ $KONVI -eq 1 ]];then
@ -2726,16 +2743,14 @@ fi
# print_screen_output "DCSERVER: $DCSERVER" # print_screen_output "DCSERVER: $DCSERVER"
# print_screen_output "DCTARGET: $DCTARGET" # print_screen_output "DCTARGET: $DCTARGET"
# "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
get_parameters "$@"
# If no colorscheme was set in the parameter handling routine, then set the default scheme # If no colorscheme was set in the parameter handling routine, then set the default scheme
if [[ $COLOR_SCHEME_SET != 'true' ]];then if [[ $COLOR_SCHEME_SET != 'true' ]];then
set_color_scheme "$DEFAULT_SCHEME" set_color_scheme "$DEFAULT_SCHEME"
fi fi
# all the pre-start stuff is in place now # all the pre-start stuff is in place now
script_debugger "Debugger: inxi is up and running..." 'all-up' B_SCRIPT_UP='true'
script_debugger "Debugger: $SCRIPT_NAME is up and running..."
# then create the output # then create the output
print_it_out print_it_out