From: "Marshall Deppe"
First, I'd like to say thanks for the cool little kit,
and that it works very well 90% of the time.
I've just tested it today really and even the network
stuff works well..
This piece of code caused it to die though..
----------------------------------
function swap(arra,i,m) {
tmp = arra[i]
arra[i] = arra[m]
arra[m] = tmp
}
function bump(array,n,max,val) {
tmp = array[n + 1]
array[n + 1] = val
n++
if (n < max) {
bump(array,n,max,tmp)
}
}
function parray(array,max) {
while (i <= max) {
i++
print array[i]
}
}
BEGIN {
print ARGV[1]
while ((getline arr[a++] < ARGV[1]) > 0) {
print a
}
close(ARGV[1])
print "First: " ,arr[1], "Second to last: ",
arr[a - 2]
swap(arr,1,(a - 2))
bump(arr,1,(a + 1),arr[a - 2])
parray(arr,a)
}
-------------------------------------------------------------------------
Compiled using awka -f filename -X -o filename.awka
Awka has an issue (I think) correctly initialising local variables in functions when they are not correctly defined.
"Correctly defined" meaning as per the spec, where local variables are part of the argument list.
The problem seems to show up in the recursive calling of functions, so
bump()is causing the error.Change the function definition to
function bump(array,n,max,val, tmp) {which defines the tmp var as being a local variable (the extra space just for readability and differentiating between parameters and local vars),