refactored more, rearranged utility functions

This commit is contained in:
inxi-svn 2008-10-28 06:45:56 +00:00
parent cde859ac3b
commit 6779d27964

71
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.1.22 #### version: 0.1.23
#### Date: October 27 2008 #### Date: October 27 2008
######################################################################## ########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif #### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -122,26 +122,9 @@ HN=$(hostname)
#### UTILITY FUNCTIONS #### UTILITY FUNCTIONS
######################################################################## ########################################################################
# inxi speaks through here. When run by Konversation, use DCOP #### -------------------------------------------------------------------
print_screen_output() #### error handler and debugger
{ #### -------------------------------------------------------------------
if (( DEBUG > 5 ))
then
if ((KONVI))
then
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
else
echo "konvi='$konvi' saying : '$@'"
fi
fi
#((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
if (( KONVI ))
then
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1"
else
echo -ne "$1\n"
fi
}
# Error handling # Error handling
error_handler() error_handler()
@ -199,6 +182,31 @@ script_debugger()
fi fi
} }
#### -------------------------------------------------------------------
#### print / output cleaners
#### -------------------------------------------------------------------
# inxi speaks through here. When run by Konversation, use DCOP
print_screen_output()
{
if (( DEBUG > 5 ))
then
if ((KONVI))
then
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
else
echo "konvi='$konvi' saying : '$@'"
fi
fi
#((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
if (( KONVI ))
then
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1"
else
echo -ne "$1\n"
fi
}
remove_erroneous_chars() remove_erroneous_chars()
{ {
## this removes newline and pipes ## this removes newline and pipes
@ -217,6 +225,18 @@ remove_erroneous_chars()
# gawk 'BEGIN { RS="" } { gsub(/\n$/,""); gsub(/\n/," "); gsub(/^ *| *$/, ""); gsub(/ +/, " "); printf $0 }' "$1" # gawk 'BEGIN { RS="" } { gsub(/\n$/,""); gsub(/\n/," "); gsub(/^ *| *$/, ""); gsub(/ +/, " "); printf $0 }' "$1"
# } # }
# Enforce boilerplate and buzzword filters
sanitize()
{
# Cannot use strong quotes to unquote a string with pipes in it! bash will interpret the |'s as usual and try to run a subshell!
# Using weak quotes instead, or use '"..."'
echo "$2" | gawk "BEGIN { IGNORECASE=1 } { gsub(/${!1}/,\"\"); gsub(/ [ ]+/,\" \"); gsub(/^ +| +$/,\"\"); print }"
}
#### -------------------------------------------------------------------
#### basic tests
#### -------------------------------------------------------------------
# Determine if any of the absolutely necessary tools are absent # Determine if any of the absolutely necessary tools are absent
check_script_depends() check_script_depends()
{ {
@ -500,15 +520,6 @@ get_parameters()
done done
} }
# Enforce boilerplate and buzzword filters
sanitize()
{
# Cannot use strong quotes to unquote a string with pipes in it! bash will interpret the |'s as usual and try to run a subshell!
# Using weak quotes instead, or use '"..."'
echo "$2" | gawk "BEGIN { IGNORECASE=1 } { gsub(/${!1}/,\"\"); gsub(/ [ ]+/,\" \"); gsub(/^ +| +$/,\"\"); print }"
}
######################################################################## ########################################################################
#### MAIN FUNCTIONS #### MAIN FUNCTIONS
######################################################################## ########################################################################