Discussion:
cppawk now mentioned in GNU Awk manual.
(too old to reply)
Kaz Kylheku
2023-06-10 05:54:56 UTC
Permalink
Cool!

https://www.kylheku.com/cgit/cppawk/about/

cppawk preprocesses your Awk code with the C preprocessor
and executes it or optionally captures it.

This has benefits:

- modularization: making a big Awk program out of include
files.
- #include nicely searches relative to the directory
of the file in which the #include appears. Bye-bye AWKPATH.

- #define constants, efficiently propagated where you want them.

- macros for inlining code; avoid call overhead.

- syntactic macros! including ones that come with cppawk
- cppawk provides a case macro which translates to GNU Awk
switch syntax or to portable Awk.
- cppawk provides a loop macro with numerous useful clauses.
- parallel and cross-product iteration.
- cppawk has some macros for dealing with

- conditional code. E.g. #if ... we are targeting this awk,
do this, #else do that.
- parametrize your code and conditionally generate;
#if THIS_FEATURE ... #endif

cppawk is rigorously developed, covered by 149 test cases.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @***@mstdn.ca
Kpop 2GM
2023-07-06 22:29:50 UTC
Permalink
here's an easy way to do (some form of) var-arg without any special preprocessor :

BEGIN {
. . CONVFMT = OFMT = "%.250g"
. . srand() srand()
}

($++NF = _______(__ARGV__[$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11,
. . . . . . . . . . . . . . . . . . . . . . . . $12, $13, $14, $15, $16, $17] = FNR "_" NR "_" NF "_" (1 + int(3^3^3 *
rand()))))^_ {
. . print
}


function _______(__, ___, _, ____, _____, ________, _________,
__________, ___________)
{
. . for (_ in __ARGV__) {
. . . . if ((_____ = __ARGV__[_]) == __) {
. . . . . . delete __ARGV__[_]
. . . . . . break
. . . . }
. . }
. . print __ = +___[_ ^= (_____ = split(_, ___, SUBSEP)) < _____]
. . ___________ = (++_^_^_ * _)^(_ + (__________ = _ * _ * _--))
. . * __________--
. . while (_++ < _____) {
. . . . print __ = (____ = ( (________ = ___[_]) * __) < ___________) \
. . . . ? ____ : (length(________) <= __________) ? int((________ = \
. . . . +________) * substr(__ = __ "", !!_, _________ = length(__) \
. . . . - __________) + (____ = int((__ = substr(__, ++_________) * \
. . . . ________) / (_________ = (!!_ !_)^__________)))) sprintf("%.*d",
. . . . __________, __ - _________ * ____) : (________ * substr(__,
. . . . !!_, ________ = match(__, "[^0][0]*$"))) substr(__, ++________)
. . }
. . return __
}

when I fed in

echo ' 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 '

as the input, then run the output through gnu-factor, it looks like :

2: 2
6: 2 3
30: 2 3 5
210: 2 3 5 7
2310: 2 3 5 7 11
30030: 2 3 5 7 11 13
510510: 2 3 5 7 11 13 17
9699690: 2 3 5 7 11 13 17 19
223092870: 2 3 5 7 11 13 17 19 23
6469693230: 2 3 5 7 11 13 17 19 23 29
200560490130: 2 3 5 7 11 13 17 19 23 29 31
7420738134810: 2 3 5 7 11 13 17 19 23 29 31 37
304250263527210: 2 3 5 7 11 13 17 19 23 29 31 37 41
13082761331670030: 2 3 5 7 11 13 17 19 23 29 31 37 41 43
614889782588491410: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
32589158477190044730: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53
1922760350154212639070: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59

worked in gawk 5.2.2, mawk 1.3.4, mawk2 - 1.9.9.6, and nawk 20200816
Kenny McCormack
2023-07-06 23:15:54 UTC
Permalink
Post by Kpop 2GM
BEGIN {
. . CONVFMT = OFMT = "%.250g"
. . srand() srand()
}
Thank you for sharing.
--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Snicker
Loading...