aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-18 18:33:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-18 18:33:05 -0700
commita79fba0f20611338079e680493645c95ee677084 (patch)
tree8d5e2df0798f9bc5a7c3ff28355386a8879a6b20
parent57f350cf16b45ff02bbad16b96599891049ae41c (diff)
downloadcppawk-a79fba0f20611338079e680493645c95ee677084.tar.gz
cppawk-a79fba0f20611338079e680493645c95ee677084.tar.bz2
cppawk-a79fba0f20611338079e680493645c95ee677084.zip
Add awkloop example to man page.
-rw-r--r--cppawk.125
1 files changed, 25 insertions, 0 deletions
diff --git a/cppawk.1 b/cppawk.1
index 1f9589a..42902a6 100644
--- a/cppawk.1
+++ b/cppawk.1
@@ -104,6 +104,31 @@ Print the larger of field 1 or 2:
#define max(a, b) ((a) > (b) ? (a) : (b))
{ print max($1, $2) /* C comment */ } #awk comment'
+Implement awk-like processing loop within function, to process
+/proc/mounts:
+
+ #include "awkloop.h"
+
+ function main()
+ {
+ awkloop ("/proc/mounts") {
+ rule ($3 != "ext4") { nextrec }
+ rule ($2 == "/") { print $1 }
+ }
+ }
+
+ BEGIN {
+ main()
+ }
+
+Where
+.BI awkloop.h
+contains:
+
+ #define awkloop(file) for (; getline < file || (close(file) && 0); )
+ #define nextrec continue
+ #define rule(cond) if (cond)
+
.SH "SEE ALSO"
awk(1), cpp(6)
.SH BUGS