/*1Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2010, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical Algorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435/******************************************************************************36*37* cond.c: Routines for handling "cond" nodes.38*39* Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.40*41****************************************************************************/4243#include "openaxiom-c-macros.h"44#include "debug.h"45#include "sockio.h"46#include "halloc.h"47#include "lex.h"48#include "hyper.h"49#include "sockio.h"5051static int check_memostack(TextNode * node);5253void54insert_cond(char *label, char *cond)55{56CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label);5758/*59* This routine creates a new cond node and inserts it into the60* current cond table61*/62if (condnode) {63fprintf(stderr, "Error: \\%s is declared twice \n", label);64print_page_and_filename();65jump();66}67condnode = alloc_condnode();68condnode->label = halloc(strlen(label) + 1, "Condnode->label");69condnode->cond = halloc(strlen(cond) + 1, "Condnode->cond");70strcpy(condnode->label, label);71strcpy(condnode->cond, cond);72hash_insert(gWindow->fCondHashTable, (char *) condnode, condnode->label);73}7475void76change_cond(char *label, char *newcond)77{78CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label);7980if (condnode == NULL) {81fprintf(stderr, "Error: Tried to set an uncreated cond %s\n", label);82}83else {84free(condnode->cond);85condnode->cond = halloc(strlen(newcond) + 1, "Condnode->cond");86strcpy(condnode->cond, newcond);87}88}8990static int91check_memostack(TextNode *node)92{93char *buffer;94int stackp = gWindow->fMemoStackIndex;95int found = 0;96HyperDocPage *page;9798buffer = print_to_string(node->data.node);99100/*101* Once we have done that much, search down the stack for the102* proper page103*/104105while (!found && stackp > 0) {106page = gWindow->fMemoStack[--stackp];107if (!strcmp(page->name, buffer))108found = 1;109}110return found;111}112113int114check_condition(TextNode *node)115{116CondNode *cond;117InputBox *box;118int ret_val;119120/* checks the condition presented and returns a 1 or a 0 */121switch (node->type) {122case openaxiom_Cond_token:123cond = (CondNode *) hash_find(gWindow->fCondHashTable, node->data.text);124if (!strcmp("0", cond->cond))125return 0;126else127return 1;128case openaxiom_Boxcond_token:129box = (InputBox *) hash_find(gWindow->page->box_hash, node->data.text);130return (box->picked);131case openaxiom_Haslisp_token:132if (spad_socket != NULL) {133ret_val = send_int(spad_socket, TestLine);134return (ret_val + 1);135}136else137return 0;138case openaxiom_Hasup_token:139return need_up_button;140case openaxiom_Hasreturn_token:141return gWindow->fMemoStackIndex;142case openaxiom_Hasreturnto_token:143return (check_memostack(node));144case openaxiom_Lastwindow_token:145return (gSessionHashTable.num_entries == 1 || gParentWindow == gWindow);146default:147return 0;148}149}150151152