Got rid of sanitize_data feature, which forces double dips into awk, instead I put hte cleaners for , and whitespace into

each awk statement. This avoids exiting awk, then looping through the array in bash, then sending the array items to the 
cleaner function, back into awk, then sending it back, and rebuilding the array.

I tried putting the gawk cleaners into a variable and using the variable, but that didn't work as expected, but I'll see 
if i can figure out how to get that working.
This commit is contained in:
inxi-svn 2008-11-06 20:32:19 +00:00
parent c2f692c068
commit 82c3d091a8

93
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 0.3.25
#### Date: November 5 2008
#### version: 0.3.26
#### Date: November 6 2008
########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif
#### As time permits functionality improvements and recoding will occur.
@ -39,20 +39,6 @@
#### VARIABLES
########################################################################
GAWK_CLEANUP='
gsub(/,/," ",$NF)
gsub(/[^ | $| \t]+/," ",$NF)
'
# fred=$( echo ' corporate graphics crap of some type ' | gawk '
# /graphics/ {
# gsub(/"graphics"/, "", $NF )
# '
# $GAWK_CLEANUP
# '}' )
# echo $fred;exit
## NOTE: we can use hwinfo if it's available in all systems, or most, to get
## a lot more data and verbosity levels going
@ -802,6 +788,9 @@ get_audio_data()
{ IGNORECASE=1 }
/multimedia audio controller|audio device/ {
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
gsub(/,/," ",$NF)
gsub(/^ +| +$/,"",$NF)
gsub(/ [ \t]+/," ",$NF)
print $NF
}' ) )
IFS="$ORIGINAL_IFS"
@ -860,10 +849,11 @@ get_cpu_data()
/^processor\t+:/ { nr = $NF }
/^model name|^cpu\t+:/ {
gsub(/,/," ",$NF)
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
gsub(/[ \t]+/," ",$NF)
gsub(/,/, " ", $NF)
gsub(/^ +| +$/, "", $NF)
gsub(/ [ \t]+/, " ", $NF)
cpu[nr, "model"] = $NF
}
@ -955,9 +945,10 @@ get_distro_data()
distro_file="issue"
distro=$( gawk '
BEGIN { RS="" } {
gsub(/\\[a-z]/,"")
gsub(/ [ ]+/," ")
gsub(/^ +| +$/,"")
gsub(/\\[a-z]/, "")
gsub(/,/, " ")
gsub(/^ +| +$/, "")
gsub(/ [ \t]+/, " ")
print
}' "/etc/${distro_file}" )
fi
@ -983,12 +974,21 @@ get_graphics_card_data()
local i=''
IFS=$'\n'
A_GFX_CARD_DATA=( $( echo "$lspci_data" | gawk -F': ' '/VGA compatible controller/ { print $NF }' ) )
A_GFX_CARD_DATA=( $( echo "$lspci_data" | gawk -F': ' '
{ IGNORECASE=1 }
/VGA compatible controller/ {
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
gsub(/,/, " ", $NF)
gsub(/^ +| +$/, "", $NF)
gsub(/ [ \t]+/, " ", $NF)
print $NF
}'
) )
IFS="$ORIGINAL_IFS"
for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
do
A_GFX_CARD_DATA[i]=$( sanitize_characters BAN_LIST_NORMAL "${A_GFX_CARD_DATA[i]}" )
done
# for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
# do
# A_GFX_CARD_DATA[i]=$( sanitize_characters BAN_LIST_NORMAL "${A_GFX_CARD_DATA[i]}" )
# done
# handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
if [[ ${#A_GFX_CARD_DATA[@]} -eq 0 ]];then
A_GFX_CARD_DATA[0]='Failed to Detect Video Card!'
@ -1090,10 +1090,12 @@ get_graphics_x_data()
BEGIN { IGNORECASE=1 }
/vendor string/ {
gsub(/the|,|inc|foundation|project|coorperation/, "", $2)
gsub(/^ +| +$/, "", $2); gsub(/ +/," ",$2)
gsub(/,/, " ", $2)
gsub(/^ +| +$/, "", $2)
gsub(/ [ \t]+/, " ", $2)
print $2
}' )
# new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
# Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
# A failover mechanism is in place. (if $x_version is empty, the release number is parsed instead)
@ -1102,8 +1104,8 @@ get_graphics_x_data()
x_version=$(xdpyinfo | gawk -F': +' '
BEGIN { IGNORECASE=1 }
/vendor release number/ {
gsub(/0+$/,"",$2)
gsub(/0+/,".",$2)
gsub(/0+$/, "", $2)
gsub(/0+/, ".", $2)
print $2
}
')
@ -1154,10 +1156,13 @@ get_hard_drive_data()
if (b[i] ~ / *type: *direct-access.*/) {
#c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
c=gensub(/^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i])
gsub(/ [ ]+/, " ", c)
gsub(/,/, " ", c)
gsub(/^ +| +$/, "", c)
#print a[i]
if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) continue
gsub(/ [ \t]+/, " ", c)
#print a[i]
if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) {
continue
}
print c
}
}
@ -1196,10 +1201,16 @@ get_hard_drive_data()
if (/^\/dev\/(mapper\/|[hs]d[a-z][0-9]+)/) {
if (NF == 1) {
getline
if (NF == 5) { c += $2 }
else next
if (NF == 5) {
c += $2
}
else {
next
}
}
else if (NF == 6) {
c += $3
}
else if (NF == 6) { c += $3 }
}
}
/^Filesystem/ { p++ }
@ -1247,14 +1258,16 @@ get_networking_data()
nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
gsub(/realtek semiconductor/, "Realtek", nic)
gsub(/davicom semiconductor/, "Davicom", nic)
gsub(/,/," ", nic)
gsub(/'"$BAN_LIST_NORMAL"'/, "", nic)
gsub(/ [ ]+/," ", nic)
gsub(/^ +| +$/,"", nic)
gsub(/,/, " ", nic)
gsub(/^ +| +$/, "", nic)
gsub(/ [ \t]+/, " ", nic)
# The doublequotes above are necessary because of the pipes in the variable.
eth[nic]++
while (getline && !/^$/) {
if (/I\/O/) ports[nic]=ports[nic]$4" "
if (/I\/O/) {
ports[nic]=ports[nic]$4" "
}
}
}