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-2008, 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
#ifndef OPENAXIOM_NODE
37
#define OPENAXIOM_NODE
38
39
#include "open-axiom.h"
40
#include "hash.h"
41
42
#ifndef X_DISPLAY_MISSING
43
# include <X11/Xlib.h>
44
# include <X11/Xutil.h>
45
# include <X11/Xos.h>
46
typedef Window openaxiom_window;
47
typedef Pixmap openaxiom_pixmap;
48
typedef XImage openaxiom_image;
49
typedef GC openaxiom_graphic_context;
50
typedef XFontStruct openaxiom_font;
51
typedef Cursor openaxiom_cursor;
52
#else /* X_DISPLAY_MISSING */
53
typedef OpenAxiom::Handle openaxiom_window;
54
typedef OpenAxiom::Handle openaxiom_pixmap;
55
typedef OpenAxiom::Handle openaxiom_image;
56
typedef OpenAxiom::Handle openaxiom_graphic_context;
57
typedef OpenAxiom::Handle openaxiom_cursor;
58
typedef OpenAxiom::Handle openaxiom_font;
59
#endif /* X_DISPLAY_MISSING */
60
61
/* Struct forward declarations */
62
63
struct TextNode;
64
struct InputBox;
65
struct InputItem;
66
struct paste_node;
67
struct RadioBoxes;
68
struct GroupItem;
69
struct PasteNode;
70
71
#define Scrollupbutton 1
72
#define Scrolldownbutton 2
73
#define Noopbutton 6
74
75
#define Scrolling 1
76
#define Header 2
77
#define Footer 3
78
#define Title 4
79
80
81
82
/** I am implementing a state node stack, this is the structure I store **/
83
84
struct StateNode {
85
int last_ch, last_token;
86
SourceInputKind input_type;
87
long fpos, keyword_fpos;
88
long page_start_fpos;
89
Token token;
90
char *input_string;
91
FILE *cfile;
92
int keyword;
93
StateNode *next;
94
};
95
96
/** pointer to the top of the state node graph **/
97
extern StateNode *top_state_node;
98
99
100
/* structure for a hyper text link */
101
struct HyperLink {
102
int type; /* Memolink, Spadlink, Downlink etc. */
103
openaxiom_window win; /* X11 window containing active area */
104
union {
105
TextNode *node; /* ID of link to which link refers */
106
InputBox *box;
107
InputItem *string;
108
PasteNode *paste; /* the paste node area */
109
} reference;
110
int x,y; /* relative position inside page */
111
};
112
113
114
struct IfNode {
115
TextNode *cond; /* the condition nodes*/
116
TextNode *thennode;
117
TextNode *elsenode;
118
};
119
120
struct ItemStack {
121
int indent;
122
int item_indent;
123
int in_item;
124
ItemStack *next;
125
};
126
127
struct PasteNode {
128
char *name;
129
SourceInputKind where; /* where should I be parsing from? */
130
short int hasbutton;
131
short int haspaste;
132
GroupItem *group;
133
ItemStack *item_stack;
134
TextNode *arg_node;
135
TextNode *end_node;
136
TextNode *begin_node;
137
InputItem *paste_item;
138
};
139
140
/* Structure for formatted hypertext */
141
142
struct TextNode {
143
short type; /* type of node (text, link, etc.) */
144
int x,y, width, height; /* relative location on screen */
145
int space; /* was there space in front of me ? */
146
union {
147
char *text; /* piece of text to display */
148
TextNode *node; /* argument text */
149
IfNode *ifnode;
150
} data;
151
HyperLink *link; /* link for active text */
152
union {
153
openaxiom_pixmap pm; /* pixmap for bit images */
154
openaxiom_image *xi; /* pixmap image */
155
} image;
156
TextNode *next; /* next node in formatted text */
157
};
158
159
/** Structure used to store pixmaps and bitmaps **/
160
161
struct ImageStruct {
162
int width,height; /** It's width and height **/
163
union {
164
openaxiom_pixmap pm;
165
openaxiom_image *xi;
166
} image;
167
char *filename; /** The filename used to reference it **/
168
};
169
170
/* Structure for locating HyperDoc pages in a source file */
171
172
struct FilePosition {
173
char *name; /* file name */
174
long pos; /* position in file */
175
int ln; /* the line number */
176
};
177
178
/*** The structure needed for storing a macro **/
179
180
struct MacroStore {
181
short int loaded;
182
FilePosition fpos;
183
char *name;
184
char *macro_string;
185
short number_parameters;
186
};
187
188
/** Structure needed for storing a patch **/
189
struct PatchStore {
190
short int loaded;
191
FilePosition fpos;
192
char *name;
193
char *string;
194
};
195
196
/* Here are the structures needed for doing input to HyperDoc windows. */
197
198
struct LineStruct {
199
char *buffer;
200
int changed; /* Has the line changed */
201
int line_number;
202
int buff_pntr;
203
int len;
204
LineStruct *prev, *next;
205
};
206
207
struct InputItem {
208
char *name; /* symbol name **/
209
int size; /* the length of the window **/
210
int cursor_x; /* x-coordinate for the cursor **/
211
int entered; /* tells me whether I have typed here
212
before */
213
int num_lines; /* number of lines needed to store
214
buffer */
215
LineStruct *lines;
216
LineStruct *curr_line; /* the current line on which the cursor */
217
openaxiom_window win;
218
InputItem *next;
219
};
220
221
222
/* structure for storing input boxes **/
223
struct InputBox {
224
char *name;
225
ImageStruct *selected, *unselected;
226
short int picked;
227
InputBox *next;
228
RadioBoxes *rbs;
229
openaxiom_window win;
230
};
231
232
struct RadioBoxes {
233
char *name;
234
InputBox *boxes;
235
ImageStruct *selected, *unselected;
236
int width, height;
237
RadioBoxes *next;
238
};
239
240
/* Structure for spadcommand dependencies hash table entries */
241
struct SpadcomDepend {
242
char *label; /* dependency label */
243
TextNode *spadcom; /* spadcommand defining the label */
244
short executed; /* true iff spadcommand has benn executed */
245
} ;
246
247
struct ButtonList {
248
int x0,y0,x1,y1;
249
HyperLink *link;
250
openaxiom_window win;
251
ButtonList *next;
252
};
253
254
/* Stucture for unformatted hyper text page */
255
256
struct HyperDocPage {
257
short type; /* Normal, Quitbutton, Upbutton etc. */
258
const char *name; /* ID of page */
259
char *filename; /* The name of the file in which the page
260
occurs, Null if not */
261
int scroll_off; /* The offset in the scrolling region */
262
int bot_scroll_margin; /* bottom of the scrolling region */
263
int top_scroll_margin; /* top of the scrolling region */
264
TextNode *title; /* the title of the page */
265
TextNode *header; /* formatted version of page */
266
TextNode *scrolling; /* Top of scrolling region */
267
TextNode *footer; /* top of non-scrolling region at bottom */
268
OpenAxiom::openaxiom_sio *sock; /* socket connection for spad buffer */
269
HashTable *fLinkHashTable; /* active link hash table */
270
ButtonList *s_button_list; /* active buttons on page */
271
ButtonList *button_list; /* active buttons on page */
272
HashTable *depend_hash; /* Hash tables of spadcommand dependencies */
273
InputItem *input_list; /* List of input structures */
274
InputItem *current_item; /* a pntr to the currently active item */
275
HashTable *box_hash; /* place where all the boxes are stored */
276
RadioBoxes *radio_boxes; /* a linked list of radio boxes */
277
short page_flags; /* A list of flags for the page */
278
char *helppage; /* the name of the helppage */
279
};
280
281
/* Structure for an unloaded page */
282
283
struct UnloadedPage {
284
short type; /* indicator of unloaded page */
285
char *name; /* name of page */
286
FilePosition fpos; /* where to find the page */
287
};
288
289
/* Structure for a HyperDoc Window */
290
291
struct HDWindow {
292
openaxiom_window fMainWindow; /* The main text field window. */
293
openaxiom_window fScrollWindow; /* The scrolling area of the window. */
294
openaxiom_window fDisplayedWindow; /* The current window of the above two,*/
295
/* being filled by display */
296
297
openaxiom_window fScrollUpWindow; /* Window for scrolling up a line. */
298
openaxiom_window fScrollDownWindow; /* Window for scrolling down a line. */
299
300
openaxiom_window scrollbar; /* the window for scrolling. */
301
openaxiom_window scroller; /* the scroller window. */
302
303
openaxiom_window fTitleBarButton1; /* 1st titlebar bitmap button. */
304
openaxiom_window fTitleBarButton2; /* 2nd titlebar bitmap button. */
305
openaxiom_window fTitleBarButton3; /* 3rd titlebar bitmap button. */
306
openaxiom_window fTitleBarButton4; /* 4th titlebar bitmap button. */
307
308
int fScrollerTopPos; /* where the top of the scroller is */
309
int fScrollerHeight; /* the height of the scroller */
310
int fScrollBarHeight; /* the height for the scrollbar */
311
312
int scrollwidth; /* the width of the scrolling area */
313
int scrollheight; /* the height of the scrolling area */
314
int scrollupy; /* Current y position of the scroll up */
315
/* button */
316
int scrolldowny; /* Current y position of the scroll */
317
/* downbutton */
318
int scrollbary; /* Current y position of teh scrollbar */
319
int scrollx; /* X coordinates for all of the above */
320
int border_width; /* Width of the border */
321
HyperDocPage *page; /* currently displayed page */
322
int width, height; /* in pixels */
323
int columns; /* Width in characters, only setable */
324
/* for form pages */
325
HyperDocPage **fMemoStack; /* stack of memo links */
326
HyperDocPage **fDownLinkStack;/* stack of down links */
327
328
int *fDownLinkStackTop; /* stack of down links */
329
int fMemoStackIndex; /* memo stack pointer */
330
int fDownLinkStackIndex; /* downlink stack pointer */
331
332
HashTable *fWindowHashTable; /* hash table of active subwindows */
333
HashTable *fPageHashTable; /* hash table of HyperDoc pages */
334
HashTable *fPasteHashTable; /* hash table for paste in areas */
335
HashTable *fMacroHashTable; /* hash table of HyperDoc macros */
336
HashTable *fCondHashTable; /* hash table for values */
337
HashTable *fPatchHashTable; /* hash table for patch locations */
338
339
int fAxiomFrame; /* Axiom frame number initializing window */
340
openaxiom_graphic_context fStandardGC; /* Graphics context for window */
341
openaxiom_graphic_context fInputGC; /* Graphics context for the input windows */
342
openaxiom_graphic_context fCursorGC; /* Graphics context for the cursors */
343
openaxiom_graphic_context fControlGC; /* Graphics context for the buttons */
344
openaxiom_cursor fDisplayedCursor; /* The currently displayed cursor */
345
};
346
347
/* Structure for identifying appropriate link hash tables */
348
349
struct LinkHashID {
350
int code; /* code of active area */
351
HyperDocPage *page; /* page for which hash table applies */
352
};
353
354
355
356
struct GroupItem {
357
int cur_color;
358
openaxiom_font *cur_font;
359
int center;
360
GroupItem *next;
361
};
362
363
364
struct CondNode {
365
char *label;
366
char *cond;
367
};
368
369
struct parameter_list_type {
370
char **list; /** The parameters in string form **/
371
short number; /** How many parameters are there **/
372
parameter_list_type *next;
373
};
374
375
using ParameterList = parameter_list_type*;
376
377
/*** Flags for the page ***/
378
379
#define NOLINES 0000001 /* Ibid, for the bottom of the page ***/
380
381
/* Here are some of the functions and constants declared and needed in
382
htadd.c ******/
383
384
#define NoChar -9999
385
#define db_file_name "ht.db"
386
387
388
/* Types of HyperDoc pages */
389
390
#define UlUnknownPage 9993 /*I hate this hack, but I have to know whether*/
391
#define UnknownPage 9994 /*this page has been loaded or not. */
392
#define ErrorPage 9995
393
#define Unixfd 9996
394
#define SpadGen 9997
395
#define Normal 9998
396
#define UnloadedPageType 9999
397
398
/* Commands from Axiom */
399
400
#define EndOfPage 99
401
#define SendLine 98
402
#define StartPage 97 /* A normal HyperDoc page */
403
#define LinkToPage 96
404
#define PopUpPage 95 /* A pop-up page */
405
#define PopUpNamedPage 94
406
#define KillPage 93
407
#define ReplacePage 92
408
#define ReplaceNamedPage 91
409
#define SpadError 90
410
411
/* Constants declaring size of page stacks */
412
413
#define MaxMemoDepth 25 /* max nesting level for memolinks */
414
#define MaxDownlinkDepth 50 /* max downlink nesting depth */
415
416
/* Constants defining the size of various hash tables */
417
418
#define PageHashSize 1000
419
#define FileHashSize 30
420
#define SessionHashSize 10
421
#define MacroHashSize 100
422
#define ImageHashSize 100
423
#define CondHashSize 100
424
#define BoxHashSize 20
425
#define PasteHashSize 100
426
#define PatchHashSize 100
427
428
/* A couple of macros for memo and down links */
429
430
#define need_up_button \
431
(gWindow->fMemoStackIndex ? gWindow->fDownLinkStackIndex >= \
432
gWindow->fDownLinkStackTop[gWindow->fMemoStackIndex-1] \
433
: gWindow->fDownLinkStackIndex)
434
435
#define need_return_button (gWindow->fMemoStackIndex)
436
437
#define need_help_button (gWindow->page->helppage != NULL)
438
439
#define openaxiom_max(x,y) ((x) > (y) ? (x) : (y))
440
441
442
#define pick_box(box) fill_box(box->win, box->selected)
443
#define unpick_box(box) fill_box(box->win, box->unselected)
444
445
#define TopLevelHelpPage "ugHyperPage"
446
#define NoMoreHelpPage "NoMoreHelpPage"
447
#define KeyDefsHelpPage "ugHyperKeysPage"
448
#define InputAreaHelpPage "ugHyperInputPage"
449
450
/* definitions for connecting to the Axiom server */
451
452
#define Connected 0
453
#define NotConnected 1
454
#define SpadBusy 2
455
456
/* some GUI-dependent stuff */
457
458
#define BeepAtTheUser() /* (XBell(gXDisplay, 5)) */
459
#define LoudBeepAtTheUser() /* (XBell(gXDisplay, 50)) */
460
461
462
463
#endif /* OPENAXIOM_NODE */
464
465