aboutsummaryrefslogtreecommitdiffstats
path: root/testdir/p.table
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2019-06-23 03:13:57 -0600
committerArnold D. Robbins <arnold@skeeve.com>2019-06-23 03:13:57 -0600
commitd6c466c3671aeecf5e64b5bf9692f44517aefb46 (patch)
tree82cb4d461a702fac42d20e145fa846064c3d0cd6 /testdir/p.table
parentae99b752af2f72bae5d4948f5b2e31dac0409601 (diff)
downloadplatform_external_one-true-awk-d6c466c3671aeecf5e64b5bf9692f44517aefb46.tar.gz
platform_external_one-true-awk-d6c466c3671aeecf5e64b5bf9692f44517aefb46.tar.bz2
platform_external_one-true-awk-d6c466c3671aeecf5e64b5bf9692f44517aefb46.zip
Extract testdir.
Diffstat (limited to 'testdir/p.table')
-rw-r--r--testdir/p.table33
1 files changed, 33 insertions, 0 deletions
diff --git a/testdir/p.table b/testdir/p.table
new file mode 100644
index 0000000..68509c6
--- /dev/null
+++ b/testdir/p.table
@@ -0,0 +1,33 @@
+# table - simple table formatter
+
+BEGIN {
+ FS = "\t"; blanks = sprintf("%100s", " ")
+ number = "^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$"
+}
+
+{ row[NR] = $0
+ for (i = 1; i <= NF; i++) {
+ if ($i ~ number)
+ nwid[i] = max(nwid[i], length($i))
+ wid[i] = max(wid[i], length($i))
+ }
+}
+
+END {
+ for (r = 1; r <= NR; r++) {
+ n = split(row[r], d)
+ for (i = 1; i <= n; i++) {
+ sep = (i < n) ? " " : "\n"
+ if (d[i] ~ number)
+ printf("%" wid[i] "s%s", numjust(i,d[i]), sep)
+ else
+ printf("%-" wid[i] "s%s", d[i], sep)
+ }
+ }
+}
+
+function max(x, y) { return (x > y) ? x : y }
+
+function numjust(n, s) { # position s in field n
+ return s substr(blanks, 1, int((wid[n]-nwid[n])/2))
+}