/* GNUPLOT - datablock.c */
/*[
* Copyright Ethan A Merritt 2012
*
* Gnuplot license:
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
*
* Alternative license:
*
* As an alternative to distributing code in this file under the gnuplot license,
* you may instead comply with the terms below. In this case, redistribution and
* use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. Redistributions in binary
* form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
]*/
#include "gp_types.h"
#include "alloc.h"
#include "command.h"
#include "datablock.h"
#include "datafile.h"
#include "eval.h"
#include "misc.h"
#include "util.h"
#ifdef USE_FUNCTIONBLOCKS
/* Set by "return" command and pushed onto the evaluation stack by f_eval */
struct value eval_return_value;
/* Used by f_eval to pass parameters to a function block */
struct value eval_parameters[9];
/* Non-zero to allow values to remain on the evaluation stack across
* a call to f_eval(). Set on entry to f_eval; cleared when control returns
* to the LFS depth just above that. If you're not using function blocks
* then this is never set.
*/
int evaluate_inside_functionblock = 0;
#endif
/* static function prototypes */
static int enlarge_datablock(struct value *datablock_value, int extra);
static void new_block( enum DATA_TYPES type );
/*
* In-line data blocks are implemented as a here-document:
* $FOO udv_value.type = FUNCTIONBLOCK;
datablock->udv_value.v.functionblock.parnames = NULL;
datablock->udv_value.v.functionblock.data_array = NULL;
if (equals(c_token, "(")) {
int dummy_num = 0;
datablock->udv_value.v.functionblock.parnames
= gp_alloc( 10*sizeof(char *), "function block");
memset(datablock->udv_value.v.functionblock.parnames, 0, 10*sizeof(char *));
do {
c_token++;
m_capture(&(datablock->udv_value.v.functionblock.parnames[dummy_num++]),
c_token, c_token);
} while (equals(++c_token, ",") && (dummy_num < 9));
if (!equals(c_token, ")"))
int_error(c_token, "expecting ')'");
c_token++;
}
} else {
/* Must be a datablock */
datablock->udv_value.type = DATABLOCK;
datablock->udv_value.v.data_array = NULL;
}
if (!equals(c_token, "