1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
1:
$cppawk '
#include <narg.h>
BEGIN { print narg(x), narg(x, y), narg(x, y, z), narg(x, y, z, w) }'
:
1 2 3 4
--
2:
$cppawk '
#include <narg.h>
BEGIN { print narg(a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a) }'
:
32
--
3:
$cppawk '
#include <narg.h>
BEGIN { print narg(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) }'
:
ERR
--
4:
$cppawk '
#include <narg.h>
#define first(x) x
#define rest(prev, x) prev : x
#define colonize(...) [varexpand(first, rest, __VA_ARGS__)]
#define str(x) #x
#define xstr(x) str(x)
#define scolonize(...) xstr(colonize(__VA_ARGS__))
BEGIN { print scolonize(1), scolonize(1,2), scolonize(1, 2, 3) }'
:
[1] [1 : 2] [1 : 2 : 3]
--
5:
$cppawk '
#include <narg.h>
#define str(x) #x
#define xstr(x) str(x)
#define srev(...) xstr((revarg(__VA_ARGS__)))
BEGIN { print srev(1), srev(1,2), srev(1, 2, 3) }'
:
(1) (2, 1) (3, 2, 1)
--
5:
$cppawk '
#include <narg.h>
#define first(x) x
#define rest(prev, x) prev : x
#define colonize(...) [varexpand(first, rest, __VA_ARGS__)]
#define str(x) #x
#define xstr(x) str(x)
#define scolonize(...) xstr(colonize(__VA_ARGS__))
#define scol(x, rest) scolonize(x, splice(rest))
BEGIN { print scol(1, (2, 3)) }'
:
[1 : 2 : 3]
--
6:
x=2
args=1
revargs=1
while [ $x -lt 33 ] ; do
args="$args, $x"
revargs="$x $revargs"
[ "$($cppawk "#include <narg.h>
BEGIN { print revarg($args) }")" = "$revargs" ] || exit 1
x=$((x + 1))
done
echo okay
:
okay
--
7:
$cppawk '
#include <narg.h>
#define first(x, i) x ## i
#define rest(prev, x, i) prev : x ## i
#define colonize(...) [variexpand(first, rest, __VA_ARGS__)]
#define str(x) #x
#define xstr(x) str(x)
#define scolonize(...) xstr(colonize(__VA_ARGS__))
BEGIN { print scolonize(a), scolonize(a, b), scolonize(a, b, c) }'
:
[a1] [a1 : b2] [a1 : b2 : c3]
|