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
extern int contNum;
35
extern struct termios childbuf; /** the childs normal operating termio ***/
36
37
/*** the terminals mapping of the function keys ***/
38
extern unsigned char _INTR, _QUIT, _ERASE, _KILL, _EOF, _EOL, _RES1, _RES2;
39
extern short INS_MODE ; /** Flag for insert mode **/
40
extern short ECHOIT; /** Flag for echoing **/
41
extern short PTY; /* A flag which lets me know whether or not I am
42
talking to a socket or a pty. If I am not
43
talking to a PTY then I have to do things like echo
44
back newlines, and send interuppts with an eoln
45
*/
46
/***************************************************************************
47
Here are the key mapping my routines need
48
****************************************************************************/
49
50
51
#define _ESC 0X1B /** A character sent before every arrow key ***/
52
#define _LBRACK 0X5B /** [ **/
53
#define _EOLN '\n' /** eoln **/
54
#define _CR 0X0D /** cr **/
55
#define _BLANK 0X20 /** blank **/
56
#define _BKSPC 0X08 /** backspace **/
57
#define _DEL 0X7F /** delete **/
58
#define _BELL 0X07 /*** ring the bell **/
59
#define _INT 0X7F /*** interrupt **/
60
#define _SQUASH 0X03 /** kill my process **/
61
#define _CNTRL_W 0X17 /** cntrl-w, to back up a word **/
62
#define _CARROT 0X5E /** circumflex **/
63
#define _TAB 0X09 /** tab forward **/
64
65
#ifndef WCT
66
#define _A 0X41 /** A **/
67
#define _B 0X42 /** B **/
68
#define _C 0X43 /** C **/
69
#define _D 0X44 /** D **/
70
#define _Z 0X5A /** Z **/
71
#define _H 0X48 /** H **/
72
#define _M 0X4D /** M **/
73
#define _x 0X78 /** x **/
74
#define _z 0X7A /*** z **/
75
#define _twiddle 0X7E /*** ~ **/
76
#define _P 0X50 /*** P **/
77
#define _1 0X31 /*** 1 **/
78
#define _2 0X32 /*** 2 **/
79
#define _3 0X33 /*** 3 **/
80
#define _4 0X34 /*** 4 **/
81
#define _5 0X35 /*** 5 **/
82
#define _6 0X36 /*** 6 **/
83
#define _7 0X37 /*** 7 **/
84
#define _8 0X38 /*** 8 **/
85
#define _9 0X39 /*** 9 **/
86
#define _0 0X30 /*** 0 **/
87
#define _q 0X71 /*** q **/
88
#endif
89
90
91
92
#define MAXLINE 1024 /** maximum chars. on a line ***/
93
#define MAXBUFF 64 /** maximum lines saved in the buffer
94
queue ***/
95
96
/*** Here are the constants for my three different modes. ******/
97
#define CLEFRAW 0
98
#define CLEFCANONICAL 1
99
#define CLEFCBREAK 2
100
101
extern int mode; /** One of the above # defines *****/
102
103
/** Here is the structure for storing bound pf-keys ***/
104
typedef struct Fkey
105
{
106
const char *str;
107
short type;
108
} fkey;
109
110
extern fkey function_key[13] ; /** strings which replace function
111
keys when a key is hit ***/
112
113
114
extern char editorfilename[];
115
116
/**** Here are a bunch of constant, variable and function defs for edin.c */
117
#define UP 0 /** Tells the replace buffer command ***/
118
#define DOWN 1 /** to look up or down **/
119
120
#define inc(x) ((x+1)%MAXBUFF) /** returns the increment of the presented
121
pointer ***/
122
#define dec(x) ( ((x-1) < 0) ?(MAXBUFF - 1):(x-1))/** ibid for decrementing */
123
124
#define flip(x) (x?(x=0):(x=1)) /*** flip the bit ***/
125
126
/*
127
All the previous commands will now be stored in a double linked list.
128
This way when I type a command I just have to circle through this list
129
*/
130
typedef struct que_struct {
131
char buff[1024];
132
int flags[1024];
133
struct que_struct *prev, *next;
134
} QueStruct;
135
136
typedef struct wct {
137
char *fname;
138
off_t fsize;
139
time_t ftime;
140
char *fimage;
141
int wordc;
142
char **wordv;
143
144
struct wct *next;
145
} Wct;
146
147
typedef struct wix {
148
Wct *pwct;
149
int word;
150
} Wix;
151
152
153
extern QueStruct *ring;
154
extern QueStruct *current;
155
extern int ring_size;
156
extern int prev_check;
157
extern int MAXRING;
158
159
extern char buff[MAXLINE]; /** Buffers for collecting input and **/
160
extern int buff_flag[MAXLINE]; /** flags for whether buff chars
161
are printing
162
or non-printing **/
163
164
extern char in_buff[1024]; /** buffer for characters read until they are
165
processed **/
166
extern int num_read;
167
extern int num_proc; /** num chars processed after a read **/
168
extern int buff_pntr; /** present length of buff **/
169
extern int curr_pntr; /** the current position in buff **/
170
171
/** Here are a bunch of macros for edin.c. They are mostly just charcter
172
comparison stuff ***/
173
#define back_word(x) (((*(x) == _5) && (*(x+1) == _9) && \
174
(*(x+2) == _q))?(1):(0))
175
176
#define fore_word(x) (((*(x) == _6) && (*(x+1) == _8) && \
177
(*(x+2) == _q))?(1):(0))
178
179
#define alt_f1(x) (((*(x) == _3) && (*(x+1) == _7) && \
180
(*(x+2) == _q))?(1):(0))
181
182
#define cntrl_end(x) (((*(x) == _4) && (*(x+1) == _8) && \
183
(*(x+2) == _q))?(1):(0))
184
185
#define insert_toggle(x) (((*(x) == _3) && (*(x+1) == _9) && \
186
(*(x+2) == _q))?(1):(0))
187
188
#define end_key(x) (((*(x) == _4) && (*(x+1) == _6) && \
189
(*(x+2) == _q))?(1):(0))
190
191
#define control_char(x) \
192
(((x >= 0x01) && (x <= 0x1a))?(1):(0))
193
194
195
196
/***
197
Some global defs needed for emulating a pty. This was taken from guru.h
198
***/
199
200
201
202
/* Return an integer that is represented by a character string */
203
#define ciret(x) ((cintu.c4[0]=(x)[0]), (cintu.c4[1]=(x)[1]), \
204
(cintu.c4[2]=(x)[2]), (cintu.c4[3]=(x)[3]), cintu.i4)
205
206
/* move an integer (x) to a character string (y) */
207
208
#define icmove(x, y) ((cintu.i4=(x)), ((y)[0]=cintu.c4[0]), \
209
((y)[1]=cintu.c4[1]), ((y)[2]=cintu.c4[2]), \
210
((y)[3]=cintu.c4[3]))
211
212
/* Return an integer that may not be on an integer boundary */
213
#define iiret(x) ciret(((char *)&(x)))
214
215
/* Min of two expressions */
216
#define min(x, y) ((x)<(y)?(x):(y))
217
218
/* Max of two expressions */
219
#define max(x, y) ((x)>(y)?(x):(y))
220
221
222
223
224