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
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are
7
met:
8
9
- Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
12
- Redistributions in binary form must reproduce the above copyright
13
notice, this list of conditions and the following disclaimer in
14
the documentation and/or other materials provided with the
15
distribution.
16
17
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
18
names of its contributors may be used to endorse or promote products
19
derived from this software without specific prior written permission.
20
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
#include "openaxiom-c-macros.h"
35
#include <string.h>
36
#include <stdio.h>
37
#include <sys/types.h>
38
#include "edible.h"
39
40
#include "prt.h"
41
#include "edin.h"
42
43
void
44
myputchar(char c)
45
{
46
if (ECHOIT)
47
putchar(c);
48
return;
49
}
50
51
void
52
clear_buff(void)
53
{
54
int count;
55
56
/*** called when spadbuf gives me a line incase there is something already
57
on the line ****/
58
if (buff_pntr > 0) {
59
/*** backup to the beginning of the line ***/
60
for (count = curr_pntr; count > 0; count--)
61
myputchar(_BKSPC);
62
/** blank over the line ***/
63
for (count = 0; count < buff_pntr; count++) {
64
myputchar(_BLANK);
65
}
66
/** back up again ***/
67
for (count = buff_pntr; count > 0; count--)
68
myputchar(_BKSPC);
69
init_buff(buff, buff_pntr);
70
init_flag(buff_flag, buff_pntr);
71
curr_pntr = buff_pntr = 0;
72
}
73
}
74
75
76
void
77
move_end(void)
78
{
79
80
/** Moves cursor to the end of the line ***/
81
if (curr_pntr == buff_pntr) {
82
putchar(_BELL);
83
}
84
else {
85
for (; curr_pntr < buff_pntr;) {
86
myputchar(buff[curr_pntr++]);
87
}
88
}
89
fflush(stdout);
90
}
91
92
void
93
move_home(void)
94
{
95
96
/*** Moves the cursor to the front of the line ***/
97
if (curr_pntr > 0) {
98
for (; curr_pntr > 0;) {
99
myputchar(_BKSPC);
100
curr_pntr--;
101
}
102
}
103
else {
104
putchar(_BELL);
105
}
106
fflush(stdout);
107
108
}
109
110
void
111
move_fore_word(void)
112
{
113
/** move the cursor to the next blank space **/
114
if (curr_pntr != buff_pntr) {
115
myputchar(buff[curr_pntr]);
116
curr_pntr++;
117
while (curr_pntr < buff_pntr && buff[curr_pntr] != ' ') {
118
myputchar(buff[curr_pntr]);
119
curr_pntr++;
120
}
121
}
122
else
123
putchar(_BELL);
124
fflush(stdout);
125
return;
126
}
127
128
void
129
move_back_word(void)
130
{
131
/*** moves the cursor to the last blank space ***/
132
if (curr_pntr > 0) {
133
myputchar(_BKSPC);
134
curr_pntr--;
135
while (curr_pntr > 0 && buff[curr_pntr - 1] != ' ') {
136
myputchar(_BKSPC);
137
curr_pntr--;
138
}
139
140
}
141
else
142
putchar(_BELL);
143
fflush(stdout);
144
return;
145
}
146
147
void
148
delete_current_char(void)
149
{
150
/** deletes the char currently above the current_pntr, if it can be **/
151
if (curr_pntr != buff_pntr) {
152
if (buff_flag[curr_pntr] == 1 || buff_flag[curr_pntr] == 0) {
153
myputchar(_BLANK);
154
myputchar(_BKSPC);
155
strcpy(&buff[curr_pntr],
156
&buff[curr_pntr + 1]);
157
flagcpy(&buff_flag[curr_pntr],
158
&buff_flag[curr_pntr + 1]);
159
buff_pntr--;
160
del_print(curr_pntr, 1);
161
}
162
else {
163
/** lets delete two of the little buggers **/
164
myputchar(_BLANK);
165
myputchar(_BLANK);
166
myputchar(_BKSPC);
167
myputchar(_BKSPC);
168
strcpy(&buff[curr_pntr],
169
&buff[curr_pntr + 2]);
170
flagcpy(&buff_flag[curr_pntr],
171
&buff_flag[curr_pntr + 2]);
172
buff_pntr -= 2;
173
del_print(curr_pntr, 2);
174
}
175
}
176
else {
177
putchar(_BELL);
178
fflush(stdout);
179
}
180
num_proc = num_proc + 3;
181
}
182
183
void
184
delete_to_end_of_line(void)
185
{
186
int count;
187
188
/*** deletes from the curr_pntr to the end of line ***/
189
190
if (curr_pntr == buff_pntr)
191
return; /** There is nothing to do **/
192
193
/** blank over the end of the line ***/
194
for (count = curr_pntr; count < buff_pntr; count++) {
195
myputchar(_BLANK);
196
}
197
/** back up again ***/
198
for (count = buff_pntr; count > curr_pntr; count--)
199
myputchar(_BKSPC);
200
201
buff_pntr = curr_pntr;
202
fflush(stdout);
203
return;
204
205
}
206
207
void
208
delete_line(void)
209
{
210
int count;
211
212
/*** deletes the entire line *****/
213
214
if (buff_pntr == 0)
215
return; /** There is nothing to do **/
216
217
/** first I have to back up to the beginning of the line ****/
218
for (count = curr_pntr; count > 0; count--)
219
myputchar(_BKSPC);
220
221
/** blank over the end of the line ***/
222
for (count = 0; count < buff_pntr; count++) {
223
myputchar(_BLANK);
224
}
225
/** back up again ***/
226
for (count = buff_pntr; count > 0; count--)
227
myputchar(_BKSPC);
228
229
/* Also clear the buffer */
230
init_buff(buff, buff_pntr);
231
init_flag(buff_flag, buff_pntr);
232
buff_pntr = curr_pntr = 0;
233
234
fflush(stdout);
235
return;
236
237
}
238
239
void
240
printbuff(int start,int num)
241
{
242
int trace;
243
244
for (trace = start; trace < start + num; trace++)
245
if (buff[trace] != '\0')
246
myputchar(buff[trace]);
247
fflush(stdout);
248
}
249
250
void
251
del_print(int start, int num)
252
{
253
int count;
254
255
/*** move the rest of the string ***/
256
for (count = start; count < buff_pntr; count++) {
257
myputchar(buff[count]);
258
}
259
/** now blank out the number of chars we are supposed to ***/
260
for (count = 0; count < num; count++)
261
myputchar(_BLANK);
262
/*** Now back up ***/
263
for (count = buff_pntr + num; count > start; count--)
264
myputchar(_BKSPC);
265
fflush(stdout);
266
}
267
268
269
void
270
ins_print(int start,int num)
271
{
272
int count;
273
274
/** write the rest of the word ***/
275
for (count = start; count < buff_pntr + num; count++) {
276
myputchar(buff[count]);
277
}
278
/** now back up to where we should be ***/
279
for (count = buff_pntr; count > start; count--)
280
myputchar(_BKSPC);
281
fflush(stdout);
282
}
283
284
void
285
reprint(int start)
286
{
287
/** simply reprints a single character **/
288
if (buff[start] == '\0')
289
myputchar(_BLANK);
290
else
291
myputchar(buff[start]);
292
myputchar(_BKSPC);
293
fflush(stdout);
294
return;
295
}
296
297
void
298
back_up(int num_chars)
299
{
300
int cnt;
301
302
for (cnt = 0; cnt < num_chars; cnt++)
303
myputchar(_BKSPC);
304
for (cnt = 0; cnt < num_chars; cnt++)
305
myputchar(_BLANK);
306
for (cnt = 0; cnt < num_chars; cnt++)
307
myputchar(_BKSPC);
308
fflush(stdout);
309
310
}
311
312
void
313
back_it_up(int num_chars)
314
{
315
int cnt;
316
317
for (cnt = 0; cnt < num_chars; cnt++)
318
myputchar(_BKSPC);
319
fflush(stdout);
320
}
321
322
323
void
324
print_whole_buff(void)
325
{
326
int trace;
327
328
for (trace = 0; trace < buff_pntr; trace++)
329
if (buff[trace] != '\0')
330
myputchar(buff[trace]);
331
fflush(stdout);
332
}
333
334
void
335
move_ahead(void)
336
{
337
/*** simply moves the pointer ahead a single word ***/
338
if (curr_pntr == buff_pntr) {
339
putchar(_BELL);
340
}
341
else {
342
if (buff_flag[curr_pntr] == 2) {
343
myputchar(buff[curr_pntr++]);
344
}
345
myputchar(buff[curr_pntr++]);
346
}
347
fflush(stdout);
348
}
349
350
void
351
move_back(void)
352
{
353
/** simply moves the cursor back one position **/
354
if (curr_pntr == 0) {
355
putchar(_BELL);
356
}
357
else {
358
if (!buff_flag[curr_pntr - 1]) {
359
myputchar(_BKSPC);
360
curr_pntr--;
361
}
362
myputchar(_BKSPC);
363
curr_pntr--;
364
}
365
fflush(stdout);
366
}
367
368
void
369
back_over_current_char(void)
370
{
371
/*** simply backs over the character behind the cursor ***/
372
if (curr_pntr == 0) {
373
putchar(_BELL);
374
}
375
else {
376
if (!buff_flag[curr_pntr - 1]) {
377
myputchar(_BKSPC);
378
myputchar(_BKSPC);
379
myputchar(_BLANK);
380
myputchar(_BLANK);
381
myputchar(_BKSPC);
382
myputchar(_BKSPC);
383
strcpy(&buff[curr_pntr - 2],
384
&buff[curr_pntr]);
385
flagcpy(&buff_flag[curr_pntr - 2],
386
&buff_flag[curr_pntr]);
387
buff_pntr -= 2;
388
curr_pntr -= 2;
389
del_print(curr_pntr, 2);
390
}
391
else {
392
myputchar(_BKSPC);
393
myputchar(_BLANK);
394
myputchar(_BKSPC);
395
strcpy(&buff[curr_pntr - 1],
396
&buff[curr_pntr]);
397
flagcpy(&buff_flag[curr_pntr - 1],
398
&buff_flag[curr_pntr]);
399
curr_pntr--;
400
buff_pntr--;
401
del_print(curr_pntr, 1);
402
}
403
}
404
fflush(stdout);
405
return;
406
}
407
408
409