SCOPE_BLOCK * lookup_data_scope_from_parameter (SCRIPT_NODE *node) { SCOPE_BLOCK *scope_block; if (node) if ((node-> type == GG_OPERAND) || (node-> type == GG_SYMBOL)) { if (evaluate_script_node (node-> op2) != 0) return NULL; if (node-> op1) { gg_report_error ('E', "Invalid scope."); return NULL; } scope_block = lookup_scope_block (string_result (node-> op2)); if (! scope_block) { gg_report_error ('E', "Unknown data scope: %s", node-> op2-> result_s); return NULL; } } else if (node-> type == GG_NUMBER) { if (evaluate_script_node (node) != 0) return NULL; scope_block = lookup_scope_block (string_result (node)); if (! scope_block) { gg_report_error ('E', "Unknown data scope: %s", node-> result_s); return NULL; } } else { gg_report_error ('E', "Argument must be a legal identifier."); return NULL; } else { FORLIST (scope_block, scope_stack) if (scope_block-> children) break; if ((void *) scope_block == & scope_stack) { gg_report_error ('E', "No data scope."); return NULL; } } return scope_block; }
int method_evaluate (SCRIPT_NODE *node) { int min = 0, max, chop = 0, cmp = -1, argc, rc; char *name = NULL; GSL_OBJECT *object; GSL_FUNCTION *function; SCRIPT_NODE **argv = NULL; if (node-> op1) { if (evaluate_script_node (node-> op1) != 0) return -1; name = string_result (node-> op1); FORLIST (object, object_list) if (object-> name ? streq (object-> name, name) : FALSE) break; } else
static int eval_macro (int argc, SCRIPT_NODE **argv, SCRIPT_NODE *result) { SCRIPT_NODE *name = argc > 0 ? argv [0] : NULL; if (evaluate_script_node (name) != 0) return -1; result-> result_type = TYPE_NUMBER; if (sym_lookup_symbol (macros, string_result (name))) result-> result_n = 1; else result-> result_n = 0; return 0; }
static int eval_count (int argc, SCRIPT_NODE **argv, SCRIPT_NODE *result) { long item, n; SCRIPT_NODE *identifier = argc > 0 ? argv [0] : NULL, *condition = argc > 1 ? argv [1] : NULL; char *name, *xml_name; SCOPE_BLOCK *for_block; SCOPE_ITEM *scope_item; XML_ITEM *from_xml, *xml_item; Bool error = FALSE; if (identifier-> type == GG_SYMBOL) { if ((evaluate_script_node (identifier-> op1) != 0) || (evaluate_script_node (identifier-> op2) != 0)) return -1; from_xml = lookup_from_xml (identifier-> op1); if (! from_xml) return -1; name = (identifier-> op2) ? string_result (identifier-> op2) : NULL; } else { gg_report_error ('E', "Function argument must be an identifier."); return -1; } n = 0; if (from_xml) { for_block = create_scope_block ("count"); for_block-> children = TRUE; xml_item = xml_first_child (from_xml); item = 0; while (xml_item) { while (xml_item) { xml_name = xml_item_name (xml_item); if (xml_name && name) { if (ignorecase) { if (lexcmp (xml_name, name) == 0) break; } else { if (streq (xml_name, name)) break; } } else /* Take all named children; others are part of value */ if (xml_name && (! name)) break; xml_item = xml_next_sibling (xml_item); } item++; if (xml_item) { if (condition) { scope_item = create_scope_item (for_block, xml_item, item); for_block-> scope_item = scope_item; for_block-> xml_item = xml_item; if (evaluate_script (condition) != 0) { error = TRUE; break; } number_result (condition); if ((condition-> result_type == TYPE_NUMBER) && (condition-> result_n != 0)) n++; gg_clean (condition); } else n++; xml_item = xml_next_sibling (xml_item); } } destroy_scope_block (); if (error) return -1; } result-> result_type = TYPE_NUMBER; result-> result_n = n; return 0; }