diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2018-05-27 23:14:49 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2018-05-27 23:14:49 +0300 |
commit | 25b0b016e33315857b299fbacf7c17e3d35a9e4f (patch) | |
tree | 0ca540185be200904a21a116a8de2afd14cec64b /awklib/eg/prog/indirectcall.awk | |
parent | e4c4d7bdb58cc90d8397a5d7d72d03974ad6a5fb (diff) | |
parent | a9df82701a087b45b4c6991fb0c20f6911c278ad (diff) | |
download | egawk-25b0b016e33315857b299fbacf7c17e3d35a9e4f.tar.gz egawk-25b0b016e33315857b299fbacf7c17e3d35a9e4f.tar.bz2 egawk-25b0b016e33315857b299fbacf7c17e3d35a9e4f.zip |
Merge branch 'master' into feature/fix-comments
Diffstat (limited to 'awklib/eg/prog/indirectcall.awk')
-rw-r--r-- | awklib/eg/prog/indirectcall.awk | 45 |
1 files changed, 45 insertions, 0 deletions
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) |