aboutsummaryrefslogtreecommitdiffstats
path: root/awklib/eg/prog
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2018-05-27 18:43:20 +0300
committerArnold D. Robbins <arnold@skeeve.com>2018-05-27 18:43:20 +0300
commit29f1563294ac1ab19aa252f3fd5fca94c4f88516 (patch)
tree1acfaad5610df7af96bd9a2ddce1eb3d8b9304e9 /awklib/eg/prog
parent58cc32a6d4a179b3005f8e4fecbff932da681fba (diff)
downloadegawk-29f1563294ac1ab19aa252f3fd5fca94c4f88516.tar.gz
egawk-29f1563294ac1ab19aa252f3fd5fca94c4f88516.tar.bz2
egawk-29f1563294ac1ab19aa252f3fd5fca94c4f88516.zip
Bug fix to extract.awk. Rerun and update files.
Diffstat (limited to 'awklib/eg/prog')
-rw-r--r--awklib/eg/prog/extract.awk11
-rw-r--r--awklib/eg/prog/indirectcall.awk45
2 files changed, 50 insertions, 6 deletions
diff --git a/awklib/eg/prog/extract.awk b/awklib/eg/prog/extract.awk
index f5dfcf40..ff598e8e 100644
--- a/awklib/eg/prog/extract.awk
+++ b/awklib/eg/prog/extract.awk
@@ -30,7 +30,7 @@ BEGIN { IGNORECASE = 1 }
}
if ($3 != curfile) {
if (curfile != "")
- close(curfile)
+ filelist[curfile]++ # save to close later
curfile = $3
}
@@ -60,14 +60,13 @@ BEGIN { IGNORECASE = 1 }
print join(a, 1, n, SUBSEP) > curfile
}
}
+END {
+ for (f in filelist)
+ close(filelist[f])
+}
function unexpected_eof()
{
printf("extract: %s:%d: unexpected EOF or error\n",
FILENAME, FNR) > "/dev/stderr"
exit 1
}
-
-END {
- if (curfile)
- close(curfile)
-}
diff --git a/awklib/eg/prog/indirectcall.awk b/awklib/eg/prog/indirectcall.awk
index 165b022a..b2b82686 100644
--- a/awklib/eg/prog/indirectcall.awk
+++ b/awklib/eg/prog/indirectcall.awk
@@ -1,3 +1,48 @@
+# indirectcall.awk --- Demonstrate indirect function calls
+#
+# Arnold Robbins, arnold@skeeve.com, Public Domain
+# January 2009
+# average --- return the average of the values in fields $first - $last
+
+function average(first, last, sum, i)
+{
+ sum = 0;
+ for (i = first; i <= last; i++)
+ sum += $i
+
+ return sum / (last - first + 1)
+}
+
+# sum --- return the sum of the values in fields $first - $last
+
+function sum(first, last, ret, i)
+{
+ ret = 0;
+ for (i = first; i <= last; i++)
+ ret += $i
+
+ return ret
+}
+# For each record, print the class name and the requested statistics
+{
+ class_name = $1
+ gsub(/_/, " ", class_name) # Replace _ with spaces
+
+ # find start
+ for (i = 1; i <= NF; i++) {
+ if ($i == "data:") {
+ start = i + 1
+ break
+ }
+ }
+
+ printf("%s:\n", class_name)
+ for (i = 2; $i != "data:"; i++) {
+ the_function = $i
+ printf("\t%s: <%s>\n", $i, @the_function(start, NF) "")
+ }
+ print ""
+}
# num_lt --- do a numeric less than comparison
function num_lt(left, right)