aboutsummaryrefslogtreecommitdiffstats
path: root/extension/testarg.c
blob: 747dd515a5888ae7e1bc4cc824c830db1b9a13d7 (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
#include "awk.h"

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

        argc = get_curfunc_arg_count();
        printf("arg count: defined = %d, supplied = %d\n", tree->param_cnt, argc);

        arg1 = get_scalar_argument(tree, 0, FALSE);
        arg2 = get_array_argument(tree, 1, FALSE);
        arg3 = get_scalar_argument(tree, 2, TRUE);	/* optional */
        if (argc > 3) {	/* try to use an extra arg */
                NODE *arg4;
                arg4 = get_array_argument(tree, 3, TRUE);
        }
        if (arg3 != NULL)
                printf("3rd arg present\n\n");
        else
                printf("no 3rd arg\n\n");
        /* Set the return value */
        set_value(tmp_number((AWKNUM) ret));

        /* Just to make the interpreter happy */
        return tmp_number((AWKNUM) 0);
}

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

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