diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-03-18 18:33:05 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-03-18 18:33:05 -0700 |
commit | a79fba0f20611338079e680493645c95ee677084 (patch) | |
tree | 8d5e2df0798f9bc5a7c3ff28355386a8879a6b20 /cppawk.1 | |
parent | 57f350cf16b45ff02bbad16b96599891049ae41c (diff) | |
download | cppawk-a79fba0f20611338079e680493645c95ee677084.tar.gz cppawk-a79fba0f20611338079e680493645c95ee677084.tar.bz2 cppawk-a79fba0f20611338079e680493645c95ee677084.zip |
Add awkloop example to man page.
Diffstat (limited to 'cppawk.1')
-rw-r--r-- | cppawk.1 | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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 |