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
* group.c: Routines for managing the HyperDoc group stack.
39
*
40
* Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.
41
*
42
****************************************************************************/
43
44
#include "debug.h"
45
#include "halloc.h"
46
#include "sockio.h"
47
#include "group.h"
48
#include "initx.h"
49
50
GroupItem *gTopOfGroupStack = NULL;
51
52
53
54
int
55
pop_group_stack()
56
{
57
/* This routine pops the top of the current group stack */
58
GroupItem *junk;
59
60
/*
61
* If the the stack has only a single item, then pop it anyway so the
62
* user can see the problem
63
*/
64
if (! gTopOfGroupStack->next)
65
return -1;
66
67
/* Else, Pop the thing */
68
69
junk = gTopOfGroupStack;
70
gTopOfGroupStack = gTopOfGroupStack->next;
71
junk->next = NULL;
72
73
free(junk);
74
75
/* Now change the font to the cur_font and the cur_color */
76
77
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
78
return 1;
79
80
}
81
82
void
83
push_group_stack()
84
{
85
/*
86
* This routine makes room by pushing a new item on the stack
87
*/
88
GroupItem *newgp;
89
90
newgp = (GroupItem *) halloc(sizeof(GroupItem), "Push Group Stack");
91
newgp->cur_font = gTopOfGroupStack->cur_font;
92
newgp->cur_color = gTopOfGroupStack->cur_color;
93
newgp->center = gTopOfGroupStack->center;
94
newgp->next = gTopOfGroupStack;
95
96
gTopOfGroupStack = newgp;
97
}
98
99
void
100
init_group_stack()
101
{
102
gTopOfGroupStack = (GroupItem *) halloc(sizeof(GroupItem), "Push Group Stack");
103
gTopOfGroupStack->center = 0;
104
gTopOfGroupStack->next = NULL;
105
gTopOfGroupStack->cur_color = 0;
106
gTopOfGroupStack->cur_font = NULL;
107
}
108
109
void
110
em_top_group()
111
{
112
if (! gTopOfGroupStack->next)
113
push_group_stack();
114
gTopOfGroupStack->cur_color = gEmColor;
115
gTopOfGroupStack->cur_font = gEmFont;
116
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
117
}
118
119
void
120
rm_top_group()
121
{
122
if (! gTopOfGroupStack->next)
123
push_group_stack();
124
gTopOfGroupStack->cur_color = gRmColor;
125
gTopOfGroupStack->cur_font = gRmFont;
126
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
127
128
}
129
130
void
131
line_top_group()
132
{
133
if (! gTopOfGroupStack->next)
134
push_group_stack();
135
gTopOfGroupStack->cur_color = gBorderColor;
136
gTopOfGroupStack->cur_font = gRmFont;
137
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
138
139
}
140
141
void
142
bf_top_group()
143
{
144
/*
145
* Just in case the person is tryin a \em without a grouping
146
*/
147
148
if (! gTopOfGroupStack->next)
149
push_group_stack();
150
gTopOfGroupStack->cur_color = gBfColor;
151
gTopOfGroupStack->cur_font = gBfFont;
152
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
153
}
154
155
void
156
tt_top_group()
157
{
158
if (! gTopOfGroupStack->next)
159
push_group_stack();
160
gTopOfGroupStack->cur_color = gTtColor;
161
gTopOfGroupStack->cur_font = gTtFont;
162
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
163
}
164
165
void
166
push_active_group()
167
{
168
push_group_stack();
169
gTopOfGroupStack->cur_font = gActiveFont;
170
gTopOfGroupStack->cur_color = gActiveColor;
171
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
172
}
173
174
void
175
push_spad_group()
176
{
177
push_group_stack();
178
gTopOfGroupStack->cur_font = gAxiomFont;
179
gTopOfGroupStack->cur_color = gAxiomColor;
180
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
181
}
182
183
void
184
init_top_group()
185
{
186
/* clear the group stack */
187
while (pop_group_stack() >= 0)
188
;
189
190
/* then set the colors to be normal */
191
192
gTopOfGroupStack->cur_color = gRmColor;
193
gTopOfGroupStack->cur_font = gRmFont;
194
change_text(gTopOfGroupStack->cur_color, gTopOfGroupStack->cur_font);
195
}
196
197
void
198
center_top_group()
199
{
200
push_group_stack();
201
gTopOfGroupStack->center = 1;
202
}
203
204
GroupItem *
205
copy_group_stack()
206
{
207
GroupItem *newgp = NULL;
208
GroupItem *first = NULL;
209
GroupItem *prev = NULL;
210
GroupItem *trace = gTopOfGroupStack;
211
212
while (trace) {
213
newgp = (GroupItem *) halloc(sizeof(GroupItem), "Copy Group Stack");
214
newgp->cur_font = trace->cur_font;
215
newgp->cur_color = trace->cur_color;
216
newgp->center = trace->center;
217
if (!first)
218
first = newgp;
219
else
220
prev->next = newgp;
221
prev = newgp;
222
trace = trace->next;
223
}
224
if (newgp)
225
newgp->next = NULL;
226
return first;
227
}
228
229
void
230
free_group_stack(GroupItem *g)
231
{
232
GroupItem *trace = g;
233
234
while (trace) {
235
GroupItem *junk = trace;
236
trace = trace->next;
237
free(junk);
238
}
239
}
240
241