Main Page | Class List | Directories | File List | Class Members | File Members

arrayparm.c

Go to the documentation of this file.
00001 /*
00002  * arrayparm.c --- figure out how to make a parameter be an array
00003  *
00004  * Arnold Robbins
00005  * arnold@skeeve.com
00006  * 10/2001
00007  *
00008  * Revised 7/2003
00009  */
00010 
00011 /*
00012  * Copyright (C) 2001, 2003 the Free Software Foundation, Inc.
00013  * 
00014  * This file is part of GAWK, the GNU implementation of the
00015  * AWK Programming Language.
00016  * 
00017  * GAWK is free software; you can redistribute it and/or modify
00018  * it under the terms of the GNU General Public License as published by
00019  * the Free Software Foundation; either version 2 of the License, or
00020  * (at your option) any later version.
00021  * 
00022  * GAWK is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  * GNU General Public License for more details.
00026  * 
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00030  */
00031 
00032 #include "awk.h"
00033 
00034 /*  do_mkarray --- turn a variable into an array */
00035 
00036 /*
00037  * From awk, call
00038  *
00039  *      mkarray(var, sub, val)
00040  */
00041 
00042 static NODE *
00043 do_mkarray(tree)
00044 NODE *tree;
00045 {
00046         int ret = -1;
00047         NODE *var, *sub, *val;
00048         NODE **elemval;
00049 
00050         if  (do_lint && tree->param_cnt > 3)
00051                 lintwarn("mkarray: called with too many arguments");
00052 
00053         var = get_argument(tree, 0);
00054         if (var == NULL)
00055                 var = stack_ptr[0];
00056 
00057         var = get_array(var);
00058         sub = get_argument(tree, 1);
00059         val = get_argument(tree, 2);
00060 
00061         printf("var->type = %s\n", nodetype2str(var->type));
00062         printf("sub->type = %s\n", nodetype2str(sub->type));
00063         printf("val->type = %s\n", nodetype2str(val->type));
00064 
00065         assoc_clear(var);
00066 
00067         elemval = assoc_lookup(var, sub, 0);
00068         *elemval = dupnode(val);
00069         ret = 0;
00070 
00071 
00072         /* Set the return value */
00073         set_value(tmp_number((AWKNUM) ret));
00074 
00075         /* Just to make the interpreter happy */
00076         return tmp_number((AWKNUM) 0);
00077 }
00078 
00079 /* dlload --- load new builtins in this library */
00080 
00081 NODE *
00082 dlload(tree, dl)
00083 NODE *tree;
00084 void *dl;
00085 {
00086         make_builtin("mkarray", do_mkarray, 3);
00087 
00088         return tmp_number((AWKNUM) 0);
00089 }

© sourcejam.com 2005-2008