Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2010, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
/******************************************************************************
37
*
38
* cond.c: Routines for handling "cond" nodes.
39
*
40
* Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.
41
*
42
****************************************************************************/
43
44
#include "openaxiom-c-macros.h"
45
#include "debug.h"
46
#include "sockio.h"
47
#include "halloc.h"
48
#include "lex.h"
49
#include "hyper.h"
50
#include "sockio.h"
51
52
static int check_memostack(TextNode * node);
53
54
void
55
insert_cond(char *label, char *cond)
56
{
57
CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label);
58
59
/*
60
* This routine creates a new cond node and inserts it into the
61
* current cond table
62
*/
63
if (condnode) {
64
fprintf(stderr, "Error: \\%s is declared twice \n", label);
65
print_page_and_filename();
66
jump();
67
}
68
condnode = alloc_condnode();
69
condnode->label = halloc(strlen(label) + 1, "Condnode->label");
70
condnode->cond = halloc(strlen(cond) + 1, "Condnode->cond");
71
strcpy(condnode->label, label);
72
strcpy(condnode->cond, cond);
73
hash_insert(gWindow->fCondHashTable, (char *) condnode, condnode->label);
74
}
75
76
void
77
change_cond(char *label, char *newcond)
78
{
79
CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label);
80
81
if (condnode == NULL) {
82
fprintf(stderr, "Error: Tried to set an uncreated cond %s\n", label);
83
}
84
else {
85
free(condnode->cond);
86
condnode->cond = halloc(strlen(newcond) + 1, "Condnode->cond");
87
strcpy(condnode->cond, newcond);
88
}
89
}
90
91
static int
92
check_memostack(TextNode *node)
93
{
94
char *buffer;
95
int stackp = gWindow->fMemoStackIndex;
96
int found = 0;
97
HyperDocPage *page;
98
99
buffer = print_to_string(node->data.node);
100
101
/*
102
* Once we have done that much, search down the stack for the
103
* proper page
104
*/
105
106
while (!found && stackp > 0) {
107
page = gWindow->fMemoStack[--stackp];
108
if (!strcmp(page->name, buffer))
109
found = 1;
110
}
111
return found;
112
}
113
114
int
115
check_condition(TextNode *node)
116
{
117
CondNode *cond;
118
InputBox *box;
119
int ret_val;
120
121
/* checks the condition presented and returns a 1 or a 0 */
122
switch (node->type) {
123
case openaxiom_Cond_token:
124
cond = (CondNode *) hash_find(gWindow->fCondHashTable, node->data.text);
125
if (!strcmp("0", cond->cond))
126
return 0;
127
else
128
return 1;
129
case openaxiom_Boxcond_token:
130
box = (InputBox *) hash_find(gWindow->page->box_hash, node->data.text);
131
return (box->picked);
132
case openaxiom_Haslisp_token:
133
if (spad_socket != NULL) {
134
ret_val = send_int(spad_socket, TestLine);
135
return (ret_val + 1);
136
}
137
else
138
return 0;
139
case openaxiom_Hasup_token:
140
return need_up_button;
141
case openaxiom_Hasreturn_token:
142
return gWindow->fMemoStackIndex;
143
case openaxiom_Hasreturnto_token:
144
return (check_memostack(node));
145
case openaxiom_Lastwindow_token:
146
return (gSessionHashTable.num_entries == 1 || gParentWindow == gWindow);
147
default:
148
return 0;
149
}
150
}
151
152