Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

610987 views
1
/****************************************************************************
2
**
3
*W xgap.c XGAP Source Frank Celler
4
**
5
**
6
*Y Copyright 1995-1997, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany
7
*Y Copyright 1997, Frank Celler, Huerth, Germany
8
*/
9
#include "utils.h" /* utility functions */
10
11
#include "popdial.h" /* popup dialogs */
12
#include "gapgraph.h" /* gap graphic sheet */
13
#include "gaptext.h" /* gap text sheet */
14
#include "popdial.h" /* popup dialogs */
15
#include "xcmds.h"
16
#include "pty.h"
17
#include "selfile.h"
18
19
#include "xgap.h"
20
21
22
/****************************************************************************
23
**
24
25
*F * * * * * * * * * * * * * * global variables * * * * * * * * * * * * * *
26
*/
27
28
29
/****************************************************************************
30
**
31
32
*V AppContext . . . . . . . . . . . . . . . . . . . . . aplication context
33
*/
34
XtAppContext AppContext;
35
36
37
/****************************************************************************
38
**
39
*V GapDisplay . . . . . . . . . . . . . . . . . . . . . . . current display
40
*/
41
Display * GapDisplay;
42
43
44
/****************************************************************************
45
**
46
*V GapScreen . . . . . . . . . . . . . . . . . . . . . . . . current screen
47
*/
48
long GapScreen;
49
50
51
/****************************************************************************
52
**
53
*V GapState . . . . . . . . . . . . . . . . . . . . . . . . . status of gap
54
*/
55
#define GAP_NOGAP 0
56
#define GAP_RUNNING 1
57
#define GAP_INPUT 2
58
#define GAP_ERROR 3
59
#define GAP_HELP 4
60
61
Int GapState = GAP_NOGAP;
62
63
64
/****************************************************************************
65
**
66
*V GapTalk . . . . . . . . . . . . . . . . . . . . . . . . . gap text window
67
*/
68
Widget GapTalk;
69
70
71
/****************************************************************************
72
**
73
*V MyRootWindow . . . . . . . . . . . . . . . . . . . . current root window
74
*/
75
Drawable MyRootWindow;
76
77
78
/****************************************************************************
79
**
80
*V SpyMode . . . . . . . . . . . . . . . . . . . . copy GAP output to stderr
81
*/
82
Boolean SpyMode = False;
83
84
85
/****************************************************************************
86
**
87
*V WmDeleteWindowAtom . . . . . . . window manager "delete window" request
88
*/
89
Atom WmDeleteWindowAtom;
90
91
92
/****************************************************************************
93
**
94
*V XGap . . . . . . . . . . . . . . . . . . . . . . . . . . toplevel shell
95
*/
96
Widget XGap;
97
98
99
/****************************************************************************
100
**
101
102
*F * * * * * * * * * * * * * * various symbols * * * * * * * * * * * * * * *
103
*/
104
105
106
107
/****************************************************************************
108
**
109
110
*V CheckMarkSymbol . . . . . . . . . . . . . symbol for checked menu entries
111
*/
112
Pixmap CheckMarkSymbol;
113
114
115
/****************************************************************************
116
**
117
*V CursorTL . . . . . . . . . . . . . . . . . . . . . . . . top left arrow
118
*/
119
Cursor CursorTL;
120
121
122
/****************************************************************************
123
**
124
*V EmptyMarkSymbol . . . . . . . . . . . . symbol for unchecked menu entries
125
*/
126
Pixmap EmptyMarkSymbol;
127
128
129
/****************************************************************************
130
**
131
*V ExMarkSymbol . . . . . . . . . . . . . . . . . . . . . exclamation mark
132
*/
133
Pixmap ExMarkSymbol;
134
135
136
/****************************************************************************
137
**
138
*V MenuSymbol . . . . . . . . . . . . . . . . . symbol for drop down menus
139
*/
140
Pixmap MenuSymbol;
141
142
143
/****************************************************************************
144
**
145
146
*F * * * * * * * * * * * * * * local variables * * * * * * * * * * * * * * *
147
*/
148
149
150
/****************************************************************************
151
**
152
153
*V CommandOptions . . . . . . . . . . . . . . . . . . command line options
154
*/
155
static XrmOptionDescRec CommandOptions[] =
156
{
157
{ "-colorModel", "*colorModel", XrmoptionSepArg, 0 },
158
{ "-colors", "*colors", XrmoptionSepArg, 0 },
159
{ "-huge", "*hugeFont", XrmoptionSepArg, 0 },
160
{ "-hugeFont", "*hugeFont", XrmoptionSepArg, 0 },
161
{ "-large", "*largeFont", XrmoptionSepArg, 0 },
162
{ "-largeFont", "*largeFont", XrmoptionSepArg, 0 },
163
{ "-normal", "*normalFont", XrmoptionSepArg, 0 },
164
{ "-normalFont", "*normalFont", XrmoptionSepArg, 0 },
165
{ "-positionTitle", "*titlePosition", XrmoptionSepArg, 0 },
166
{ "-small", "*smallFont", XrmoptionSepArg, 0 },
167
{ "-smallFont", "*smallFont", XrmoptionSepArg, 0 },
168
{ "-tiny", "*tinyFont", XrmoptionSepArg, 0 },
169
{ "-tinyFont", "*tinyFont", XrmoptionSepArg, 0 },
170
{ "-titlePosition", "*titlePosition", XrmoptionSepArg, 0 },
171
{ "-tp", "*titlePosition", XrmoptionSepArg, 0 },
172
};
173
174
175
/****************************************************************************
176
**
177
*V FallbackResources . . . . . . . . . . . . . . . . . . . default resources
178
*/
179
static char *FallbackResources[] =
180
{
181
"*menu.line.height: 10",
182
"*xgapMenu*shapeStyle: Oval",
183
"*xgapDialog*shapeStyle: Oval",
184
185
/* gap talk window */
186
"*xgapTalk.height: 600",
187
"*xgapTalk.width: 600",
188
"*xgapMenu.showGrip: False",
189
"*xgapTalk.showGrip: False",
190
"*xgapTalk.quitGapCtrD: True",
191
"*xgapTalk.pasteGapPrompt: True",
192
193
/* gap menu */
194
"*xgapMenu.gapButton.label: GAP",
195
"*xgapMenu.gapButton*pastePrompt.label: Paste 'gap>'",
196
"*xgapMenu.gapButton*quitGapCTRD.label: Quit on CTR-D",
197
"*xgapMenu.gapButton*editFile.label: Edit File ...",
198
"*xgapMenu.gapButton*readFile.label: Read File ...",
199
"*xgapMenu.gapButton*changeLib.label: Change Library ...",
200
#ifdef DEBUG_ON
201
"*xgapMenu.gapButton*resyncGap.label: Resync with GAP",
202
#endif
203
"*xgapMenu.gapButton*quit.label: Quit GAP",
204
"*xgapMenu.gapButton*kill.label: Kill GAP",
205
206
/* run menu */
207
"*xgapMenu.runButton.label: Run",
208
"*xgapMenu.runButton*quitBreak.label: Leave Breakloop",
209
"*xgapMenu.runButton*contBreak.label: Continue Execution",
210
"*xgapMenu.runButton*interrupt.label: Interrupt",
211
"*xgapMenu.runButton*garbColl.label: Collect Garbage",
212
"*xgapMenu.runButton*garbMesg.label: Toggle GC Messages",
213
"*xgapMenu.runButton*infoRead.label: Toggle Library Read Mesg",
214
215
/* help menu */
216
"*xgapMenu.helpButton.label: Help",
217
"*xgapMenu.helpButton*copyHelp.label: Copyright",
218
"*xgapMenu.helpButton*helpHelp.label: Helpsystem",
219
"*xgapMenu.helpButton*chpsHelp.label: Chapters",
220
"*xgapMenu.helpButton*secsHelp.label: Sections",
221
"*xgapMenu.helpButton*nchpHelp.label: Next Chapter",
222
"*xgapMenu.helpButton*pchpHelp.label: Previous Chapter",
223
"*xgapMenu.helpButton*nextHelp.label: Next Help Section",
224
"*xgapMenu.helpButton*prevHelp.label: Previous Help Section",
225
226
/* gap graphic window */
227
"*xgapWindowViewport.width: 800",
228
"*xgapWindowViewport.height: 600",
229
230
/* query a input file name */
231
#ifdef NO_FILE_SELECTOR
232
"*queryFileName.xgapDialog.icon: Term",
233
#else
234
"*selFileCancel*ShapeStyle: Oval",
235
"*selFileCancel*label: Cancel",
236
"*selFileOK*ShapeStyle: Oval",
237
"*selFileOK*label: OK",
238
"*selFileHome*ShapeStyle: Oval",
239
"*selFileHome*label: Home",
240
#endif
241
0
242
};
243
244
245
246
/****************************************************************************
247
**
248
249
*F * * * * * * * * * * * * gap talk window menus * * * * * * * * * * * * * *
250
*/
251
252
253
/****************************************************************************
254
**
255
256
*V GapMenu . . . . . . . . . . . . . . . . . . . . . . . . xgap's "GAP" menu
257
**
258
*/
259
static void MenuQuitGap () { KeyboardInput( "@C@A@Kquit;\nquit;\n", 18 ); }
260
static void MenuKillGap () { KillGap(); }
261
262
#ifdef DEBUG_ON
263
static void MenuResyncGap ()
264
{
265
ExecRunning = 0;
266
GapState = GAP_INPUT;
267
UpdateMenus(GapState);
268
UpdateXCMDS(True);
269
ProcessStoredInput(0);
270
}
271
#endif
272
273
static void MenuPastePrompt ( item )
274
TypeMenuItem * item;
275
{
276
static Boolean paste = False;
277
278
paste = !paste;
279
GTDropGapPrompt( GapTalk, !paste );
280
if ( paste )
281
XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)CheckMarkSymbol,
282
(String)NULL );
283
else
284
XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)EmptyMarkSymbol,
285
(String)NULL );
286
}
287
288
static void MenuQuitGapCTRD ( item )
289
TypeMenuItem * item;
290
{
291
QuitGapCtrlD = !QuitGapCtrlD;
292
if ( QuitGapCtrlD )
293
XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)CheckMarkSymbol,
294
(String)NULL );
295
else
296
XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)EmptyMarkSymbol,
297
(String)NULL );
298
}
299
300
#ifndef NO_FILE_SELECTOR
301
void MenuReadFile ( item )
302
TypeMenuItem * item;
303
{
304
Int res;
305
String str;
306
String input;
307
308
res = XsraSelFile( XGap, "Select a File", 0, 0, &str );
309
if ( res && str[0] )
310
{
311
input = XtMalloc( strlen(str)+30 );
312
strcpy( input, "Read( \"" );
313
strcat( input, str );
314
strcat( input, "\" );\n" );
315
SimulateInput(input);
316
XtFree(input);
317
XtFree(str);
318
}
319
}
320
#endif
321
322
static TypeMenuItem GapMenu[] =
323
{
324
{ "pastePrompt", MenuPastePrompt, S_ALWAYS, 0 },
325
{ "quitGapCTRD", MenuQuitGapCTRD, S_ALWAYS, 0 },
326
{ "-----------", 0, 0, 0 },
327
#ifndef NO_FILE_SELECTOR
328
{ "readFile", MenuReadFile, S_NORMAL_ONLY, 0 },
329
#endif
330
{ "-----------", 0, 0, 0 },
331
#ifdef DEBUG_ON
332
{ "resyncGap", MenuResyncGap, S_ALWAYS, 0 },
333
#endif
334
{ "quit", MenuQuitGap, S_ALWAYS, 0 },
335
{ "kill", MenuKillGap, S_ALWAYS, 0 },
336
{ 0, 0, 0, 0 }
337
};
338
339
340
/****************************************************************************
341
**
342
*V HelpMenu . . . . . . . . . . . . . . . . . . . . . . xgap's "Help" menu
343
**
344
*/
345
static void MenuChapters () { SimulateInput( "?Chapters\n" ); }
346
static void MenuSections () { SimulateInput( "?Sections\n" ); }
347
static void MenuCopyright () { SimulateInput( "?Copyright\n" );}
348
static void MenuHelp () { SimulateInput( "?Help\n" ); }
349
static void MenuNextHelp () { SimulateInput( "?>\n" ); }
350
static void MenuNextChapter () { SimulateInput( "?>>\n" ); }
351
static void MenuPrevChapter () { SimulateInput( "?<<\n" ); }
352
static void MenuPrevHelp () { SimulateInput( "?<\n" ); }
353
354
355
static TypeMenuItem HelpMenu[] =
356
{
357
{ "copyHelp", MenuCopyright, S_INPUT_ONLY, 0 },
358
{ "helpHelp", MenuHelp, S_INPUT_ONLY, 0 },
359
{ "---------", 0, 0, 0 },
360
{ "chpsHelp", MenuChapters, S_INPUT_ONLY, 0 },
361
{ "secsHelp", MenuSections, S_INPUT_ONLY, 0 },
362
{ "---------", 0, 0, 0 },
363
{ "nchpHelp", MenuNextChapter, S_INPUT_ONLY, 0 },
364
{ "pchpHelp", MenuPrevChapter, S_INPUT_ONLY, 0 },
365
{ "nextHelp", MenuNextHelp, S_INPUT_ONLY, 0 },
366
{ "prevHelp", MenuPrevHelp, S_INPUT_ONLY, 0 },
367
{ 0, 0, 0, 0 }
368
};
369
370
371
/****************************************************************************
372
**
373
*V RunMenu . . . . . . . . . . . . . . . . . . . . . . . . xgap's "Run" menu
374
**
375
*/
376
static void MenuInterrupt () { InterruptGap(); }
377
static void MenuQuitBreak () { SimulateInput( "quit;\n" ); }
378
static void MenuContBreak () { SimulateInput( "return;\n" ); }
379
static void MenuGarbColl () { SimulateInput( "GASMAN(\"collect\");\n" ); }
380
static void MenuGarbMesg () { SimulateInput( "GASMAN(\"message\");\n" ); }
381
static void MenuInfoRead () { SimulateInput(
382
"if InfoRead1=Print then InfoRead1:=Ignore; else InfoRead1:=Print; fi;\n"); }
383
384
static TypeMenuItem RunMenu[] =
385
{
386
{ "interrupt", MenuInterrupt, S_RUNNING_ONLY, 0 },
387
{ "---------", 0, 0, 0 },
388
{ "quitBreak", MenuQuitBreak, S_ERROR_ONLY, 0 },
389
{ "contBreak", MenuContBreak, S_ERROR_ONLY, 0 },
390
{ "---------", 0, 0, 0 },
391
{ "garbColl", MenuGarbColl, S_INPUT_ONLY, 0 },
392
{ "garbMesg", MenuGarbMesg, S_INPUT_ONLY, 0 },
393
{ "infoRead", MenuInfoRead, S_INPUT_ONLY, 0 },
394
{ 0, 0, 0, 0 }
395
};
396
397
398
/****************************************************************************
399
**
400
401
*F CreateMenu( <button>, <items> ) . . . . . . . . . . . . create a pop menu
402
**
403
** RESOURCES
404
** *menu.line.height
405
** height of menu line separator, default 10
406
*/
407
static TypeList ListInputOnly = 0;
408
static TypeList ListErrorOnly = 0;
409
static TypeList ListNormalOnly = 0;
410
static TypeList ListRunningOnly = 0;
411
static TypeList ListHelpOnly = 0;
412
413
static void MenuSelected ( Widget, TypeMenuItem *, caddr_t );
414
415
416
static void CreateMenu (
417
Widget button,
418
TypeMenuItem * items )
419
{
420
Widget menu;
421
422
/* if this is the first call, create lists */
423
if ( ListInputOnly == 0 )
424
{
425
ListErrorOnly = List(0);
426
ListHelpOnly = List(0);
427
ListInputOnly = List(0);
428
ListNormalOnly = List(0);
429
ListRunningOnly = List(0);
430
}
431
432
/* create new simple menu */
433
menu = XtCreatePopupShell( "menu", simpleMenuWidgetClass, button, 0, 0 );
434
435
/* and add menu buttons */
436
for ( ; items->label != 0; items++ )
437
{
438
if ( *(items->label) == '-' )
439
(void) XtVaCreateManagedWidget( "line",
440
smeLineObjectClass, menu, (String)NULL );
441
else
442
{
443
items->entry = XtVaCreateManagedWidget(
444
items->label, smeBSBObjectClass, menu,
445
XtNrightMargin, (XtArgVal)14,
446
XtNrightBitmap, (XtArgVal)EmptyMarkSymbol,
447
(String)NULL );
448
XtAddCallback( items->entry, XtNcallback,
449
(XtCallbackProc)MenuSelected, items );
450
switch ( items->sensitive )
451
{
452
case S_INPUT_ONLY:
453
AddList( ListInputOnly, items->entry );
454
XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,
455
(String)NULL );
456
break;
457
case S_ERROR_ONLY:
458
AddList( ListErrorOnly, items->entry );
459
XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,
460
(String)NULL );
461
break;
462
case S_NORMAL_ONLY:
463
AddList( ListNormalOnly, items->entry );
464
XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,
465
(String)NULL );
466
break;
467
case S_RUNNING_ONLY:
468
AddList( ListRunningOnly, items->entry );
469
XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,
470
(String)NULL );
471
break;
472
case S_HELP_ONLY:
473
AddList( ListHelpOnly, items->entry );
474
XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,
475
(String)NULL );
476
break;
477
case S_ALWAYS:
478
break;
479
}
480
}
481
}
482
}
483
484
static void MenuSelected (
485
Widget w,
486
TypeMenuItem * item,
487
caddr_t dummy )
488
{
489
if ( item->click != 0 )
490
(*(item->click))(item);
491
else
492
{
493
fputs( "Warning: menu item ", stderr );
494
fputs( XtName(w), stderr );
495
fputs( " has been selected.\n", stderr );
496
}
497
}
498
499
500
/****************************************************************************
501
**
502
*F UpdateMenus( <state> ) . . . . . . update menus in case of state change
503
*/
504
void UpdateMenus ( state )
505
Int state;
506
{
507
TypeList l;
508
Int i;
509
510
/* menu entry active only in break loop */
511
l = ListErrorOnly;
512
for ( i = 0; i < l->len; i++ )
513
{
514
if ( state == GAP_ERROR )
515
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,
516
(String)NULL );
517
else
518
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,
519
(String)NULL );
520
}
521
522
/* menu entry active only during input */
523
l = ListInputOnly;
524
for ( i = 0; i < l->len; i++ )
525
{
526
if ( state == GAP_ERROR || state == GAP_INPUT )
527
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,
528
(String)NULL );
529
else
530
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,
531
(String)NULL );
532
}
533
534
/* menu entry active only during normal input */
535
l = ListNormalOnly;
536
for ( i = 0; i < l->len; i++ )
537
{
538
if ( state == GAP_INPUT )
539
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,
540
(String)NULL );
541
else
542
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,
543
(String)NULL );
544
}
545
546
/* menu entry active only while gap is running */
547
l = ListRunningOnly;
548
for ( i = 0; i < l->len; i++ )
549
{
550
if ( state == GAP_RUNNING )
551
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,
552
(String)NULL );
553
else
554
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,
555
(String)NULL );
556
}
557
558
/* menu entry active only while gap is helping */
559
l = ListHelpOnly;
560
for ( i = 0; i < l->len; i++ )
561
{
562
if ( state == GAP_HELP )
563
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,
564
(String)NULL );
565
else
566
XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,
567
(String)NULL );
568
}
569
}
570
571
572
/****************************************************************************
573
**
574
575
*F * * * * * * * * * * * * * * gap talk window * * * * * * * * * * * * * * *
576
*/
577
578
579
/****************************************************************************
580
**
581
582
*F UpdateMemoryInfo( <type>, <val> ) . . . . . . . . . update memory usage
583
*/
584
static Widget LabelLiveObjects;
585
static Widget LabelLiveKB;
586
static Widget LabelTotalKBytes;
587
588
void UpdateMemoryInfo ( type, val )
589
Int type;
590
Int val;
591
{
592
char tmp[30];
593
594
595
switch ( type )
596
{
597
case 1:
598
sprintf( tmp, "Objects: %-5d ", val );
599
XtVaSetValues( LabelLiveObjects, XtNlabel, (XtArgVal)tmp,
600
(String)NULL );
601
break;
602
case 2:
603
sprintf( tmp, "KB used: %-5d ", val );
604
XtVaSetValues( LabelLiveKB, XtNlabel, (XtArgVal)tmp,
605
(String)NULL );
606
break;
607
case 6:
608
sprintf( tmp, "MBytes total: %-4d ", val/1024 );
609
XtVaSetValues( LabelTotalKBytes, XtNlabel, (XtArgVal)tmp,
610
(String)NULL );
611
break;
612
}
613
}
614
615
616
/****************************************************************************
617
**
618
*F GapTalkResized( <talk>, <cd>, <evt>, <ctd> ) . . . . . . resize callback
619
*/
620
static void GapTalkResized (
621
Widget talk,
622
XtPointer cd,
623
XEvent * evt,
624
Boolean * ctd )
625
{
626
Int i;
627
String ptr;
628
Widget snk;
629
XFontStruct * font;
630
char buf[128];
631
static UInt h, h1 = 0;
632
static UInt w, w1 = 0;
633
634
/* is this a resize event */
635
if ( evt->type == ConfigureNotify )
636
{
637
638
/* compute a sensible size */
639
XtVaGetValues( talk, XtNtextSink, (XtArgVal)&snk, (String)NULL );
640
XtVaGetValues( snk, XtNfont, (XtArgVal)&font, (String)NULL );
641
w = evt->xconfigure.width / font->max_bounds.width - 3;
642
h = evt->xconfigure.height / ( font->max_bounds.ascent
643
+ font->max_bounds.descent ) - 2;
644
if ( w < 2 ) w = 2;
645
if ( h < 2 ) h = 2;
646
if ( w == w1 && h == h1 )
647
return;
648
w1 = w;
649
h1 = h;
650
651
/* construct gap command */
652
strcpy( buf, "SizeScreen([ " );
653
ptr = buf + strlen(buf);
654
for ( i = 3; 0 <= i; i--, w = w / 10 )
655
ptr[i] = w%10 + '0';
656
ptr += 4;
657
*ptr++ = ',';
658
*ptr++ = ' ';
659
for ( i = 3; 0 <= i; i--, h = h / 10 )
660
ptr[i] = h%10 + '0';
661
ptr += 4;
662
strcpy( ptr, " ]);;\n" );
663
664
/* if gap is waiting for input, do it */
665
if ( GapState == GAP_INPUT || GapState == GAP_ERROR )
666
SimulateInput( buf );
667
else
668
strcpy( ScreenSizeBuffer, buf );
669
}
670
}
671
672
673
/****************************************************************************
674
**
675
*F CreateGapWindow() . . . . . . . . . . . . . . create communication window
676
**
677
** RESOURCES
678
** *xgapMenu*shapeStyle
679
** style of the menu buttons, default "Oval"
680
** *xgap.height
681
** *xgap.width
682
** start size of the communication text window
683
*/
684
static void CreateGapWindow ( void )
685
{
686
Widget paned;
687
Widget box;
688
Widget button;
689
Pixmap symbol;
690
Display * display;
691
Boolean flag;
692
Int i;
693
694
/* create a "paned" for the menu and text window */
695
paned = XtVaCreateManagedWidget( "paned", panedWidgetClass,
696
XGap, (String)NULL );
697
698
/* create a menu box for the menu buttons */
699
box = XtVaCreateManagedWidget( "xgapMenu", boxWidgetClass,
700
paned,
701
XtNx, (XtArgVal)0,
702
XtNy, (XtArgVal)0,
703
XtNresizeToPreferred, (XtArgVal)True,
704
(String)NULL );
705
706
/* create a menu button drop down symbol */
707
display = XtDisplay(box);
708
symbol = XCreateBitmapFromData( display,
709
DefaultRootWindow(display),
710
"\376\3\2\2\2\6\162\6\2\6\162\6\2\6\162\6\2\6\2\6\376\7\370\7",
711
12, 12 );
712
713
/* create file menu button and file menu */
714
button = XtVaCreateManagedWidget( "gapButton", menuButtonWidgetClass,
715
box,
716
XtNleftBitmap, (XtArgVal)symbol,
717
XtNx, (XtArgVal)0,
718
(String)NULL );
719
CreateMenu( button, GapMenu );
720
721
/* create run menu button and run menu */
722
button = XtVaCreateManagedWidget( "runButton", menuButtonWidgetClass,
723
box,
724
XtNleftBitmap, (XtArgVal)symbol,
725
XtNx, (XtArgVal)10,
726
(String)NULL );
727
CreateMenu( button, RunMenu );
728
729
/* create help menu button and help menu */
730
button = XtVaCreateManagedWidget( "helpButton", menuButtonWidgetClass,
731
box,
732
XtNleftBitmap, (XtArgVal)symbol,
733
XtNx, (XtArgVal)10,
734
(String)NULL );
735
CreateMenu( button, HelpMenu );
736
737
/* create the communication window */
738
GapTalk = XtVaCreateManagedWidget( "xgapTalk", gapTextWidgetClass,
739
paned,
740
XtNinputCallback, (XtArgVal)KeyboardInput,
741
XtNcheckCaretPos, (XtArgVal)CheckCaretPos,
742
XtNscrollHorizontal, (XtArgVal)XawtextScrollWhenNeeded,
743
XtNscrollVertical, (XtArgVal)XawtextScrollAlways,
744
XtNeditType, (XtArgVal)XawtextEdit,
745
XtNbottomMargin, (XtArgVal)15,
746
XtNx, (XtArgVal)0,
747
XtNy, (XtArgVal)10,
748
XtNdisplayCaret, (XtArgVal)True,
749
(String)NULL );
750
XtAddEventHandler(GapTalk,StructureNotifyMask,False,GapTalkResized,0);
751
GTDropGapPrompt( GapTalk, True );
752
753
/* to quit or not do quit on CTR-D */
754
XtVaGetValues( GapTalk, XtNquitGapCtrD, (XtArgVal)&flag, (String)NULL );
755
if ( flag )
756
{
757
for ( i = 0; GapMenu[i].label; i++ )
758
if ( !strcmp( GapMenu[i].label, "quitGapCTRD" ) )
759
break;
760
if ( GapMenu[i].label && GapMenu[i].click )
761
GapMenu[i].click(&(GapMenu[i]));
762
}
763
764
/* paste GAP prompt into talk window? */
765
XtVaGetValues( GapTalk, XtNpasteGapPrompt, &flag, NULL );
766
if ( flag )
767
{
768
for ( i = 0; GapMenu[i].label; i++ )
769
if ( !strcmp( GapMenu[i].label, "pastePrompt" ) )
770
break;
771
if ( GapMenu[i].label && GapMenu[i].click )
772
GapMenu[i].click(&(GapMenu[i]));
773
}
774
775
/* create a box and labels for garbage info */
776
box = XtVaCreateManagedWidget( "xgapInfo", boxWidgetClass,
777
paned,
778
XtNx, (XtArgVal)0,
779
XtNy, (XtArgVal)20,
780
XtNskipAdjust, (XtArgVal)True,
781
XtNresizeToPreferred, (XtArgVal)True,
782
(String)NULL );
783
LabelLiveObjects = XtVaCreateManagedWidget( "liveObjects",
784
labelWidgetClass, box,
785
XtNborderWidth, (XtArgVal)0,
786
(String)NULL );
787
LabelLiveKB = XtVaCreateManagedWidget( "liveBytes",
788
labelWidgetClass, box,
789
XtNborderWidth, (XtArgVal)0,
790
(String)NULL );
791
LabelTotalKBytes = XtVaCreateManagedWidget( "totalBytes",
792
labelWidgetClass, box,
793
XtNborderWidth, (XtArgVal)0,
794
(String)NULL );
795
UpdateMemoryInfo( 1, 0 );
796
UpdateMemoryInfo( 2, 0 );
797
UpdateMemoryInfo( 6, 0 );
798
}
799
800
801
/****************************************************************************
802
**
803
804
*F * * * * * * * * * * * * * * error handler * * * * * * * * * * * * * * * *
805
*/
806
807
808
/****************************************************************************
809
**
810
811
*F MyErrorHandler(<dis>) . . . . . . . . . . . . kill gap in case of X error
812
*/
813
static int (*OldErrorHandler)();
814
815
static int MyErrorHandler ( dis, evt )
816
Display * dis;
817
XErrorEvent evt;
818
{
819
# ifdef DEBUG_ON
820
fputs( "killing gap because of X error\n", stderr );
821
# endif
822
KillGap();
823
return OldErrorHandler( dis, evt );
824
}
825
826
827
/****************************************************************************
828
**
829
*F MyIOErrorHandler(<dis>) . . . . . . . . . . . kill gap in case of X error
830
*/
831
static int (*OldIOErrorHandler)();
832
833
static int MyIOErrorHandler ( dis )
834
Display * dis;
835
{
836
# ifdef DEBUG_ON
837
fputs( "killing gap because of X IO error\n", stderr );
838
# endif
839
KillGap();
840
return OldIOErrorHandler(dis);
841
}
842
843
844
/****************************************************************************
845
**
846
*F MySignalHandler() . . . . . . . . . . . . . . kill gap in case of signal
847
*/
848
#ifdef DEBUG_ON
849
850
static void (*OldSignalHandlerHUP)();
851
static void (*OldSignalHandlerINT)();
852
static void (*OldSignalHandlerQUIT)();
853
static void (*OldSignalHandlerILL)();
854
static void (*OldSignalHandlerIOT)();
855
static void (*OldSignalHandlerBUS)();
856
static void (*OldSignalHandlerSEGV)();
857
858
static void MySignalHandlerHUP ()
859
{
860
fputs( "killing gap because of signal HUP\n", stderr );
861
KillGap();
862
OldSignalHandlerHUP();
863
exit(1);
864
}
865
static void MySignalHandlerINT ()
866
{
867
fputs( "killing gap because of signal INT\n", stderr );
868
KillGap();
869
OldSignalHandlerINT();
870
exit(1);
871
}
872
static void MySignalHandlerQUIT ()
873
{
874
fputs( "killing gap because of signal QUIT\n", stderr );
875
KillGap();
876
OldSignalHandlerQUIT();
877
exit(1);
878
}
879
static void MySignalHandlerILL ()
880
{
881
fputs( "killing gap because of signal ILL\n", stderr );
882
KillGap();
883
OldSignalHandlerILL();
884
exit(1);
885
}
886
static void MySignalHandlerIOT ()
887
{
888
fputs( "killing gap because of signal IOT\n", stderr );
889
KillGap();
890
OldSignalHandlerIOT();
891
exit(1);
892
}
893
static void MySignalHandlerBUS ()
894
{
895
fputs( "killing gap because of signal BUS\n", stderr );
896
KillGap();
897
OldSignalHandlerBUS();
898
exit(1);
899
}
900
901
static void MySignalHandlerSEGV ()
902
{
903
fputs( "killing gap because of signal SEGV\n", stderr );
904
KillGap();
905
OldSignalHandlerSEGV();
906
exit(1);
907
}
908
909
#else
910
911
static void MySignalHandler ()
912
{
913
KillGap();
914
exit(1);
915
}
916
917
#endif
918
919
920
/****************************************************************************
921
**
922
923
*F * * * * * * * * * * * * * * * main program * * * * * * * * * * * * * * *
924
*/
925
926
927
/****************************************************************************
928
**
929
930
*F ParseArgs( <argc>, <argv> ) . . . create argument arry for gap subprocess
931
*/
932
static char * nargv[1024];
933
934
static void ParseArgs ( argc, argv )
935
Int argc;
936
char ** argv;
937
{
938
Int nargc;
939
Int i, j;
940
String p;
941
942
/* at first assume that "gap" is started with "gap", append "-p" */
943
nargc = 0;
944
nargv[nargc++] = "gap";
945
nargv[nargc++] = "-p";
946
947
/* parse XGAP arguments till we see '--' */
948
for ( argv++, argc--; 0 < argc; argv++, argc-- ) {
949
950
/* start of an argument */
951
if ( *argv[0] == '-' ) {
952
953
/* don't group any options */
954
if ( strlen(*argv) != 2 ) {
955
fputs("XGAP: sorry options must not be grouped '", stderr);
956
fputs(*argv, stderr);
957
fputs("'.\n", stderr);
958
goto usage;
959
}
960
switch( argv[0][1] ) {
961
962
/* catch unknown arguments */
963
default:
964
fputs("XGAP: unknown option '", stderr);
965
fputs(*argv, stderr);
966
fputs("'.\n", stderr);
967
goto usage;
968
969
/* start of GAP options */
970
case '-':
971
argv++;
972
argc--;
973
goto gap;
974
975
/* print a help */
976
case 'h':
977
goto fullusage;
978
979
/* toggle debug */
980
case 'D':
981
# ifdef DEBUG_ON
982
if ( argc-- < 2 ) {
983
fputs( "XGAP: option '-D' must have an argument.\n",
984
stderr );
985
goto usage;
986
}
987
Debug = atoi(*++argv);
988
# else
989
fputs( "XGAP: compile XGAP using 'COPTS=-DDEBUG_ON'.\n",
990
stderr );
991
goto usage;
992
# endif
993
break;
994
995
/* broken window manager */
996
case 'W':
997
PopupDialogBrokenWM();
998
break;
999
1000
/* copy GAP output to stderr */
1001
case 'E':
1002
SpyMode = !SpyMode;
1003
break;
1004
1005
/* get name of gap subprocess */
1006
case 'G':
1007
if ( argc-- < 2 ) {
1008
fputs( "XGAP: option '-G' must have an argument.\n",
1009
stderr );
1010
goto usage;
1011
}
1012
p = *++argv;
1013
nargv[0] = p;
1014
j = 0;
1015
while ( *++p ) {
1016
if ( *p == ' ' )
1017
{
1018
*p = '\0';
1019
j = j + 1;
1020
}
1021
}
1022
if ( 0 < j ) {
1023
for ( i = nargc-1; 0 < i; i-- )
1024
nargv[i+j] = nargv[i];
1025
nargc = nargc + j;
1026
while ( 0 < j )
1027
{
1028
while ( *--p ) ;
1029
nargv[j--] = p+1;
1030
}
1031
}
1032
break;
1033
}
1034
}
1035
1036
/* non-arguments are not allowed here */
1037
else {
1038
goto usage;
1039
}
1040
}
1041
1042
/* copy any remaining arguments */
1043
gap:
1044
for ( ; 0 < argc; argv++, argc-- )
1045
nargv[nargc++] = *argv;
1046
nargv[nargc] = 0;
1047
return;
1048
1049
/* print a usage message */
1050
usage:
1051
fputs("usage: xgap [OPTIONS] -- [GAP OPTIONS]\n",stderr);
1052
fputs(" run the X-Windows front-end for GAP,\n",stderr);
1053
fputs(" use '-h' option to get help.\n",stderr);
1054
fputs("\n",stderr);
1055
exit(1);
1056
1057
fullusage:
1058
fputs("usage: xgap [OPTIONS] -- [GAP OPTIONS]\n",stderr);
1059
fputs(" run the X-Windows front-end for GAP,\n",stderr);
1060
fputs("\n",stderr);
1061
fputs(" -h print this help message\n",stderr);
1062
fputs(" -D <num> set debug level\n",stderr);
1063
fputs(" -W try to workaround broken wm\n",stderr);
1064
fputs(" -E toggle spy mode\n",stderr);
1065
fputs(" -G <file> filename of the GAP executable\n",stderr);
1066
exit(1);
1067
}
1068
1069
1070
/****************************************************************************
1071
**
1072
*F main( <argc>, <argv> ) . . . . . . . . . . . . . . . . main event loop
1073
*/
1074
#include "bitmaps/checksym.bm"
1075
#include "bitmaps/emptymk.bm"
1076
#include "bitmaps/exmark.bm"
1077
#include "bitmaps/menusym.bm"
1078
1079
int main ( argc, argv )
1080
int argc;
1081
char ** argv;
1082
{
1083
String color;
1084
String colors;
1085
int fromGap;
1086
Int mod = -1;
1087
Int len;
1088
Int i;
1089
Int j;
1090
1091
1092
/* options after '--' are for gap */
1093
for ( i = 0; i < argc; i++ )
1094
if ( ! strcmp( argv[i], "--" ) )
1095
break;
1096
len = i;
1097
1098
/* create a new top level shell and an applictation context */
1099
XGap = XtVaAppInitialize( &AppContext, "XGap",
1100
CommandOptions, XtNumber(CommandOptions),
1101
&i, argv, FallbackResources, (String)NULL );
1102
for ( j = len; j <= argc; j++ ) {
1103
argv[i+(j-len)] = argv[j];
1104
}
1105
argc = argc + (i-len);
1106
GapDisplay = XtDisplay(XGap);
1107
GapScreen = DefaultScreen(GapDisplay);
1108
MyRootWindow = RootWindow( GapDisplay, GapScreen );
1109
1110
/* parse remaining arguments */
1111
ParseArgs( argc, argv );
1112
fromGap = StartGapProcess( nargv[0], nargv );
1113
1114
/* create top left arrow cusor */
1115
CursorTL = XCreateFontCursor( XtDisplay(XGap), XC_top_left_arrow );
1116
1117
/* create menu symbol */
1118
MenuSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,
1119
menusym_bits, menusym_width,
1120
menusym_height );
1121
1122
/* create check mark and empty mark */
1123
CheckMarkSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,
1124
checksym_bits, checksym_width,
1125
checksym_height );
1126
EmptyMarkSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,
1127
emptymk_bits, emptymk_width,
1128
emptymk_height );
1129
1130
/* exclamation mark */
1131
ExMarkSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,
1132
exmark_bits, exmark_width,
1133
exmark_height );
1134
1135
/* WM_DELETE_WINDOW atom */
1136
WmDeleteWindowAtom = XInternAtom(GapDisplay, "WM_DELETE_WINDOW", False);
1137
1138
/* install our error handler, we have to kill gap in this case */
1139
OldIOErrorHandler = XSetIOErrorHandler( MyIOErrorHandler );
1140
OldErrorHandler = XSetErrorHandler ( MyErrorHandler );
1141
1142
/***************WIN32 CYGWIN fix***************/
1143
/* SIGIOT not defined in CYGWIN signal.h unless !defined(SIGTRAP)
1144
there may be a way to get ...? */
1145
#ifdef __CYGWIN__
1146
# define SIGIOT 6 /* IOT instruction */
1147
# define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
1148
#endif
1149
/***************WIN32 CYGWIN fix***************/
1150
1151
1152
/* install your signal handler, we have to kill gap in this case */
1153
# ifdef DEBUG_ON
1154
OldSignalHandlerHUP = signal( SIGHUP, MySignalHandlerHUP );
1155
OldSignalHandlerINT = signal( SIGINT, MySignalHandlerINT );
1156
OldSignalHandlerQUIT = signal( SIGQUIT, MySignalHandlerQUIT );
1157
OldSignalHandlerILL = signal( SIGILL, MySignalHandlerILL );
1158
OldSignalHandlerIOT = signal( SIGIOT, MySignalHandlerIOT );
1159
OldSignalHandlerBUS = signal( SIGBUS, MySignalHandlerBUS );
1160
OldSignalHandlerSEGV = signal( SIGSEGV, MySignalHandlerSEGV );
1161
# else
1162
signal( SIGHUP, MySignalHandler );
1163
signal( SIGINT, MySignalHandler );
1164
signal( SIGQUIT, MySignalHandler );
1165
signal( SIGILL, MySignalHandler );
1166
signal( SIGIOT, MySignalHandler );
1167
signal( SIGBUS, MySignalHandler );
1168
signal( SIGSEGV, MySignalHandler );
1169
# endif
1170
1171
/* create the gap talk window */
1172
CreateGapWindow();
1173
XtRealizeWidget(XGap);
1174
1175
/* initialize window commands */
1176
InitXCMDS();
1177
1178
/* get color model */
1179
XtVaGetValues( GapTalk, XtNcolorModel, (XtArgVal)&color, (String)NULL );
1180
len = strlen(color);
1181
if ( !strncmp( color, "black&white", len ) )
1182
mod = CM_BW;
1183
else if ( !strncmp( color, "monochrome", len ) )
1184
mod = CM_BW;
1185
else if ( !strncmp( color, "grey", len ) )
1186
mod = CM_GRAY;
1187
else if ( !strncmp( color, "gray", len ) )
1188
mod = CM_GRAY;
1189
else if ( !strncmp( color, "color5", len ) )
1190
mod = CM_COLOR5;
1191
else if ( !strncmp( color, "color3", len ) )
1192
mod = CM_COLOR3;
1193
else if ( !strncmp( color, "default", len ) )
1194
mod = -1;
1195
else
1196
{
1197
fputs( "XGAP: unkown color model '", stderr );
1198
fputs( color, stderr );
1199
fputs( "'\n", stderr );
1200
mod = -1;
1201
}
1202
if ( mod != -1 ) {
1203
XtVaGetValues( GapTalk, XtNcolors, (XtArgVal)&colors, (String)NULL );
1204
GCSetColorModel( GapDisplay, mod, colors );
1205
}
1206
1207
/* add callback for output from gap*/
1208
XtAppAddInput( AppContext, fromGap, (XtPointer) XtInputReadMask,
1209
(XtInputCallbackProc) GapOutput, (XtPointer) 0 );
1210
1211
StoreInput( "LoadPackage(\"xgap\");;\n",22 );
1212
1213
/* force a garbage collection in the beginning */
1214
StoreInput( "GASMAN(\"collect\");\n", 19 );
1215
1216
/* talk window is drawn only partial during start up otherwise (why?) */
1217
/*XFlush( GapDisplay );
1218
sleep(1);
1219
XFlush( GapDisplay );
1220
sleep(1);
1221
XFlush( GapDisplay );
1222
sleep(1);*/
1223
/* FIXME: No longer necessary??? */
1224
1225
/* enter main read-eval loop */
1226
XtAppMainLoop(AppContext);
1227
return 0;
1228
}
1229
1230
/****************************************************************************
1231
**
1232
1233
*E xgap.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
1234
*/
1235
1236