Hi Juanito
I spent some time researching awk and I have some answers for you. The scripts set FS (field separator) to the equal sign.
When you do this:
Exec=env XDG_SESSION_TYPE=x11 adriconf
awk sees 3 fields due to the extra = sign and only grabs field #2. I formatted the flwm_topside_menu_common script
so I could follow what was going on and to add some comments:
#!/bin/sh
# (c) Robert Shingledecker 2010
# Called from tc-config to setup initial flwm system menu & tce menu
writeFLWMitem()
{
busybox awk -v output="$TARGET" ' # $TARGET is set by calling program.
BEGIN # This block of code gets executed once before any input is read.
{
FS = "=" # Sets the field separator.
name = ""
exec = ""
}
{ # This block of code gets executed on each line read from the file.
# In this context, $1 and $2 are the fields of the line being read.
if ( $1 == "Name" && name == "") # Match on the Name= line.
{
name = $2
gsub(/ /, "", name) # Removes all space characters (not tabs) from name.
}
else if ( $1 == "Exec" && exec == "") # Match on the Exec= line.
{
#exec = $2
exec = substr($0, index($0, $2)) # index returns character # $2 starts on. substr copies from that
# character # to end of $0 into exec.
test = match(exec,"%") # Return the position of the first % character found.
if ( test )
exec = substr(exec,0,test-1) # Remove all text from the % character to the end of string.
}
else if ( $1 == "Terminal" ) # Match on the Terminal= line.
{
terminal = $2 # Flag used by the END block.
}
}
END # This block of code gets executed once after all input is read.
{ # In awk, the first print "blah blah" > filename creates the file.
# Further print "blah blah" > filename commands append to the file.
print "#!/bin/sh" > output"/"name
if ( terminal == "true" )
{
print "exec aterm +tr +sb -T \""name"\" -e " exec > output"/"name
}
else
{
print "exec " exec > output"/"name
}
system("chmod +x "output"/"name)
} ' "$1" # $1 is the file name to be parsed.
}
I did the same for the wbar_update.sh script:
#!/bin/sh
# (c) Robert Shingledecker 2010
# Called from desktop.sh to update wbar icons.
writeWBARitem()
{
busybox awk -v output="$TMP" -v target="$TARGET" -v wbaricons="$TCEWBAR" '
BEGIN # This block of code gets executed once before any input is read.
{
FS = "=" # Sets the field separator.
name = ""
exec = ""
}
function rtrim(s) { sub(/[ \t]+$/, "", s); return s } # Removes all space characters and tabs from end of string.
{ # This block of code gets executed on each line read from the file.
# In this context, $1 and $2 are the fields of the line being read.
if ( $1 == "Name" && name == "") # Match on the Name= line.
{
name = rtrim($2)
gsub(/ /, "", name) # Removes all space characters (not tabs) from name.
}
else if ( $1 == "Exec" && exec == "") # Match on the Exec= line.
{
#exec = $2
exec = substr($0, index($0, $2)) # index returns character # $2 starts on. substr copies from that
# character # to end of $0 into exec.
test = match(exec,"%") # Return the position of the first % character found.
if ( test )
exec = substr(exec,0,test-1) # Remove all text from the % character to the end of string.
}
else if ( $1 == "X-FullPathIcon" ) # Match on the X-FullPathIcon= line.
{
icon = $2
}
else if ( $1 == "Terminal" ) # Match on the Terminal= line.
{
terminal = $2 # Flag used by the END block.
}
}
END # This block of code gets executed once after all input is read.
{
found = 0
while (( getline item < wbaricons ) > 0 ) # Reading /usr/local/tce.icons.
{
if ( index(item, target) > 0 ) # Check for "$APPNAME".img (why???).
{
found = 1
print "i: " icon >> output # Save to /tmp/wbar.$$.
print "t: " name > output
if ( terminal == "true" )
{
print "c: exec aterm +tr +sb -T \""name"\" -e " exec > output
}
else
{
print "c: exec " exec > output
}
getline item < wbaricons # Purge the next 2 lines.
getline item < wbaricons
}
else
{
print item > output # Save to /tmp/wbar.$$.
}
}
if ( found == 0 ) # found == 0 means this is a new wbar entry.
{
print "i: " icon >> output
print "t: " name > output
if ( terminal == "true" )
{
print "c: exec aterm +tr +sb -T \""name"\" -e " exec > output
}
else
{
print "c: exec " exec > output
}
}
close(wbaricons)
} ' "$1"
sudo mv "$TMP" "$TCEWBAR" # Replace the old /usr/local/tce.icons file with the newly created one.
sudo chmod g+w "$TCEWBAR"
}
# Script starts here.
TCEWBAR="/usr/local/tce.icons"
TCEDIR=/etc/sysconfig/tcedir
APPNAME="$1"
#OnDemand xwbar check
if grep -qw "^t: *${APPNAME}$" "${TCEDIR}"/xwbar.lst 2>/dev/null; then exit 0; fi
TMP=/tmp/wbar.$$
#
FREEDESK=/usr/local/share/applications/"$APPNAME".desktop
if [ -e "$FREEDESK" ]; then
ICONCHECK="$(awk 'BEGIN{FS = "="}$1=="X-FullPathIcon"{print $2}' "$FREEDESK")"
NAMECHECK="$(awk 'BEGIN{FS = "="}$1=="Name"{print $2; exit 0}' "$FREEDESK")"
if grep -qw "^t: *${NAMECHECK// /}$" "${TCEDIR}"/xwbar.lst 2>/dev/null; then exit 0; fi
TARGET="$APPNAME".img
[ -f "$ICONCHECK" ] && writeWBARitem "$FREEDESK" && [ -G /tmp/.X11-unix/X0 ] && wbar.sh
fi
The fix for both files is here:
#exec = $2
exec = substr($0, index($0, $2)) # index returns character # $2 starts on. substr copies from that
# character # to end of $0 into exec.
The exec = line needs to be changed so it copies from the start of field #2 to the end of $0 (the entire line).