summaryrefslogtreecommitdiff
path: root/extension/testarg.c
blob: 4d012db5c33934fcd0ba94f8f0f145061744adb1 (plain)
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
#include "awk.h"

int plugin_is_GPL_compatible;

static NODE *
do_check_arg(int nargs)
{
	int ret = 0;
	NODE *arg1, *arg2, *arg3;

	printf("arg count: defined = 3, supplied = %d\n", nargs);

	arg1 = get_scalar_argument(0, FALSE);
	arg2 = get_array_argument(1, FALSE);
	arg3 = get_scalar_argument(2, TRUE);	/* optional */
	if (nargs > 3) {
		/* try to use an extra arg */
		NODE *arg4;
		arg4 = get_array_argument(3, TRUE);
		printf("Shouldn't see this line\n");
	}
	if (arg3 != NULL) {
		printf("3rd arg present\n");
		if (arg3->type != Node_val)
			printf("3nd arg type = %s (*** NOT OK ***)\n", nodetype2str(arg3->type));
	} else
		printf("no 3rd arg\n");

	if (arg2 != NULL) {
		if (arg2->type != Node_var_array)
			printf("2nd arg type = %s (*** NOT OK ***)\n", nodetype2str(arg2->type));
	} else
		printf("2nd arg missing (NULL) (*** NOT OK ***)\n");

	if (arg1 != NULL) {
		if (arg1->type != Node_val)
			printf("1st arg type = %s (*** NOT OK ***)\n", nodetype2str(arg1->type));
	} else
		printf("1st arg missing (NULL) (*** NOT OK ***)\n");
	printf("\n");

	/* Set the return value */
	return make_number((AWKNUM) ret);
}

/* dlload --- load new builtins in this library */

NODE *
dlload(tree, dl)
NODE *tree;
void *dl;
{
        make_builtin("check_arg", do_check_arg, 3);
        return make_number((AWKNUM) 0);
}