From a79fba0f20611338079e680493645c95ee677084 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 18 Mar 2022 18:33:05 -0700 Subject: Add awkloop example to man page. --- cppawk.1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cppawk.1') 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 -- cgit v1.2.3