| 1 | /*
|
|---|
| 2 | * arrayparm.c --- figure out how to make a parameter be an array
|
|---|
| 3 | *
|
|---|
| 4 | * Arnold Robbins
|
|---|
| 5 | * [email protected]
|
|---|
| 6 | * 10/2001
|
|---|
| 7 | *
|
|---|
| 8 | * Revised 7/2003
|
|---|
| 9 | * Revised 6/2004
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | /*
|
|---|
| 13 | * Copyright (C) 2001, 2003, 2004 the Free Software Foundation, Inc.
|
|---|
| 14 | *
|
|---|
| 15 | * This file is part of GAWK, the GNU implementation of the
|
|---|
| 16 | * AWK Programming Language.
|
|---|
| 17 | *
|
|---|
| 18 | * GAWK is free software; you can redistribute it and/or modify
|
|---|
| 19 | * it under the terms of the GNU General Public License as published by
|
|---|
| 20 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 21 | * (at your option) any later version.
|
|---|
| 22 | *
|
|---|
| 23 | * GAWK is distributed in the hope that it will be useful,
|
|---|
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 26 | * GNU General Public License for more details.
|
|---|
| 27 | *
|
|---|
| 28 | * You should have received a copy of the GNU General Public License
|
|---|
| 29 | * along with this program; if not, write to the Free Software
|
|---|
| 30 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | #include "awk.h"
|
|---|
| 34 |
|
|---|
| 35 | /* do_mkarray --- turn a variable into an array */
|
|---|
| 36 |
|
|---|
| 37 | /*
|
|---|
| 38 | * From awk, call
|
|---|
| 39 | *
|
|---|
| 40 | * mkarray(var, sub, val)
|
|---|
| 41 | */
|
|---|
| 42 |
|
|---|
| 43 | static NODE *
|
|---|
| 44 | do_mkarray(tree)
|
|---|
| 45 | NODE *tree;
|
|---|
| 46 | {
|
|---|
| 47 | int ret = -1;
|
|---|
| 48 | NODE *var, *sub, *val;
|
|---|
| 49 | NODE **elemval;
|
|---|
| 50 |
|
|---|
| 51 | if (do_lint && get_curfunc_arg_count() > 3)
|
|---|
| 52 | lintwarn("mkarray: called with too many arguments");
|
|---|
| 53 |
|
|---|
| 54 | var = get_argument(tree, 0);
|
|---|
| 55 | if (var == NULL)
|
|---|
| 56 | var = stack_ptr[0];
|
|---|
| 57 |
|
|---|
| 58 | var = get_array(var);
|
|---|
| 59 | sub = get_argument(tree, 1);
|
|---|
| 60 | val = get_argument(tree, 2);
|
|---|
| 61 |
|
|---|
| 62 | printf("var->type = %s\n", nodetype2str(var->type));
|
|---|
| 63 | printf("sub->type = %s\n", nodetype2str(sub->type));
|
|---|
| 64 | printf("val->type = %s\n", nodetype2str(val->type));
|
|---|
| 65 |
|
|---|
| 66 | assoc_clear(var);
|
|---|
| 67 |
|
|---|
| 68 | elemval = assoc_lookup(var, sub, 0);
|
|---|
| 69 | *elemval = dupnode(val);
|
|---|
| 70 | ret = 0;
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | /* Set the return value */
|
|---|
| 74 | set_value(tmp_number((AWKNUM) ret));
|
|---|
| 75 |
|
|---|
| 76 | /* Just to make the interpreter happy */
|
|---|
| 77 | return tmp_number((AWKNUM) 0);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | /* dlload --- load new builtins in this library */
|
|---|
| 81 |
|
|---|
| 82 | NODE *
|
|---|
| 83 | dlload(tree, dl)
|
|---|
| 84 | NODE *tree;
|
|---|
| 85 | void *dl;
|
|---|
| 86 | {
|
|---|
| 87 | make_builtin("mkarray", do_mkarray, 3);
|
|---|
| 88 |
|
|---|
| 89 | return tmp_number((AWKNUM) 0);
|
|---|
| 90 | }
|
|---|