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

89
inxi
View file

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