GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/****************************************************************************1**2*W xgap.c XGAP Source Frank Celler3**4**5*Y Copyright 1995-1997, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany6*Y Copyright 1997, Frank Celler, Huerth, Germany7*/8#include "utils.h" /* utility functions */910#include "popdial.h" /* popup dialogs */11#include "gapgraph.h" /* gap graphic sheet */12#include "gaptext.h" /* gap text sheet */13#include "popdial.h" /* popup dialogs */14#include "xcmds.h"15#include "pty.h"16#include "selfile.h"1718#include "xgap.h"192021/****************************************************************************22**2324*F * * * * * * * * * * * * * * global variables * * * * * * * * * * * * * *25*/262728/****************************************************************************29**3031*V AppContext . . . . . . . . . . . . . . . . . . . . . aplication context32*/33XtAppContext AppContext;343536/****************************************************************************37**38*V GapDisplay . . . . . . . . . . . . . . . . . . . . . . . current display39*/40Display * GapDisplay;414243/****************************************************************************44**45*V GapScreen . . . . . . . . . . . . . . . . . . . . . . . . current screen46*/47long GapScreen;484950/****************************************************************************51**52*V GapState . . . . . . . . . . . . . . . . . . . . . . . . . status of gap53*/54#define GAP_NOGAP 055#define GAP_RUNNING 156#define GAP_INPUT 257#define GAP_ERROR 358#define GAP_HELP 45960Int GapState = GAP_NOGAP;616263/****************************************************************************64**65*V GapTalk . . . . . . . . . . . . . . . . . . . . . . . . . gap text window66*/67Widget GapTalk;686970/****************************************************************************71**72*V MyRootWindow . . . . . . . . . . . . . . . . . . . . current root window73*/74Drawable MyRootWindow;757677/****************************************************************************78**79*V SpyMode . . . . . . . . . . . . . . . . . . . . copy GAP output to stderr80*/81Boolean SpyMode = False;828384/****************************************************************************85**86*V WmDeleteWindowAtom . . . . . . . window manager "delete window" request87*/88Atom WmDeleteWindowAtom;899091/****************************************************************************92**93*V XGap . . . . . . . . . . . . . . . . . . . . . . . . . . toplevel shell94*/95Widget XGap;969798/****************************************************************************99**100101*F * * * * * * * * * * * * * * various symbols * * * * * * * * * * * * * * *102*/103104105106/****************************************************************************107**108109*V CheckMarkSymbol . . . . . . . . . . . . . symbol for checked menu entries110*/111Pixmap CheckMarkSymbol;112113114/****************************************************************************115**116*V CursorTL . . . . . . . . . . . . . . . . . . . . . . . . top left arrow117*/118Cursor CursorTL;119120121/****************************************************************************122**123*V EmptyMarkSymbol . . . . . . . . . . . . symbol for unchecked menu entries124*/125Pixmap EmptyMarkSymbol;126127128/****************************************************************************129**130*V ExMarkSymbol . . . . . . . . . . . . . . . . . . . . . exclamation mark131*/132Pixmap ExMarkSymbol;133134135/****************************************************************************136**137*V MenuSymbol . . . . . . . . . . . . . . . . . symbol for drop down menus138*/139Pixmap MenuSymbol;140141142/****************************************************************************143**144145*F * * * * * * * * * * * * * * local variables * * * * * * * * * * * * * * *146*/147148149/****************************************************************************150**151152*V CommandOptions . . . . . . . . . . . . . . . . . . command line options153*/154static XrmOptionDescRec CommandOptions[] =155{156{ "-colorModel", "*colorModel", XrmoptionSepArg, 0 },157{ "-colors", "*colors", XrmoptionSepArg, 0 },158{ "-huge", "*hugeFont", XrmoptionSepArg, 0 },159{ "-hugeFont", "*hugeFont", XrmoptionSepArg, 0 },160{ "-large", "*largeFont", XrmoptionSepArg, 0 },161{ "-largeFont", "*largeFont", XrmoptionSepArg, 0 },162{ "-normal", "*normalFont", XrmoptionSepArg, 0 },163{ "-normalFont", "*normalFont", XrmoptionSepArg, 0 },164{ "-positionTitle", "*titlePosition", XrmoptionSepArg, 0 },165{ "-small", "*smallFont", XrmoptionSepArg, 0 },166{ "-smallFont", "*smallFont", XrmoptionSepArg, 0 },167{ "-tiny", "*tinyFont", XrmoptionSepArg, 0 },168{ "-tinyFont", "*tinyFont", XrmoptionSepArg, 0 },169{ "-titlePosition", "*titlePosition", XrmoptionSepArg, 0 },170{ "-tp", "*titlePosition", XrmoptionSepArg, 0 },171};172173174/****************************************************************************175**176*V FallbackResources . . . . . . . . . . . . . . . . . . . default resources177*/178static char *FallbackResources[] =179{180"*menu.line.height: 10",181"*xgapMenu*shapeStyle: Oval",182"*xgapDialog*shapeStyle: Oval",183184/* gap talk window */185"*xgapTalk.height: 600",186"*xgapTalk.width: 600",187"*xgapMenu.showGrip: False",188"*xgapTalk.showGrip: False",189"*xgapTalk.quitGapCtrD: True",190"*xgapTalk.pasteGapPrompt: True",191192/* gap menu */193"*xgapMenu.gapButton.label: GAP",194"*xgapMenu.gapButton*pastePrompt.label: Paste 'gap>'",195"*xgapMenu.gapButton*quitGapCTRD.label: Quit on CTR-D",196"*xgapMenu.gapButton*editFile.label: Edit File ...",197"*xgapMenu.gapButton*readFile.label: Read File ...",198"*xgapMenu.gapButton*changeLib.label: Change Library ...",199#ifdef DEBUG_ON200"*xgapMenu.gapButton*resyncGap.label: Resync with GAP",201#endif202"*xgapMenu.gapButton*quit.label: Quit GAP",203"*xgapMenu.gapButton*kill.label: Kill GAP",204205/* run menu */206"*xgapMenu.runButton.label: Run",207"*xgapMenu.runButton*quitBreak.label: Leave Breakloop",208"*xgapMenu.runButton*contBreak.label: Continue Execution",209"*xgapMenu.runButton*interrupt.label: Interrupt",210"*xgapMenu.runButton*garbColl.label: Collect Garbage",211"*xgapMenu.runButton*garbMesg.label: Toggle GC Messages",212"*xgapMenu.runButton*infoRead.label: Toggle Library Read Mesg",213214/* help menu */215"*xgapMenu.helpButton.label: Help",216"*xgapMenu.helpButton*copyHelp.label: Copyright",217"*xgapMenu.helpButton*helpHelp.label: Helpsystem",218"*xgapMenu.helpButton*chpsHelp.label: Chapters",219"*xgapMenu.helpButton*secsHelp.label: Sections",220"*xgapMenu.helpButton*nchpHelp.label: Next Chapter",221"*xgapMenu.helpButton*pchpHelp.label: Previous Chapter",222"*xgapMenu.helpButton*nextHelp.label: Next Help Section",223"*xgapMenu.helpButton*prevHelp.label: Previous Help Section",224225/* gap graphic window */226"*xgapWindowViewport.width: 800",227"*xgapWindowViewport.height: 600",228229/* query a input file name */230#ifdef NO_FILE_SELECTOR231"*queryFileName.xgapDialog.icon: Term",232#else233"*selFileCancel*ShapeStyle: Oval",234"*selFileCancel*label: Cancel",235"*selFileOK*ShapeStyle: Oval",236"*selFileOK*label: OK",237"*selFileHome*ShapeStyle: Oval",238"*selFileHome*label: Home",239#endif2400241};242243244245/****************************************************************************246**247248*F * * * * * * * * * * * * gap talk window menus * * * * * * * * * * * * * *249*/250251252/****************************************************************************253**254255*V GapMenu . . . . . . . . . . . . . . . . . . . . . . . . xgap's "GAP" menu256**257*/258static void MenuQuitGap () { KeyboardInput( "@C@A@Kquit;\nquit;\n", 18 ); }259static void MenuKillGap () { KillGap(); }260261#ifdef DEBUG_ON262static void MenuResyncGap ()263{264ExecRunning = 0;265GapState = GAP_INPUT;266UpdateMenus(GapState);267UpdateXCMDS(True);268ProcessStoredInput(0);269}270#endif271272static void MenuPastePrompt ( item )273TypeMenuItem * item;274{275static Boolean paste = False;276277paste = !paste;278GTDropGapPrompt( GapTalk, !paste );279if ( paste )280XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)CheckMarkSymbol,281(String)NULL );282else283XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)EmptyMarkSymbol,284(String)NULL );285}286287static void MenuQuitGapCTRD ( item )288TypeMenuItem * item;289{290QuitGapCtrlD = !QuitGapCtrlD;291if ( QuitGapCtrlD )292XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)CheckMarkSymbol,293(String)NULL );294else295XtVaSetValues( item->entry, XtNrightBitmap, (XtArgVal)EmptyMarkSymbol,296(String)NULL );297}298299#ifndef NO_FILE_SELECTOR300void MenuReadFile ( item )301TypeMenuItem * item;302{303Int res;304String str;305String input;306307res = XsraSelFile( XGap, "Select a File", 0, 0, &str );308if ( res && str[0] )309{310input = XtMalloc( strlen(str)+30 );311strcpy( input, "Read( \"" );312strcat( input, str );313strcat( input, "\" );\n" );314SimulateInput(input);315XtFree(input);316XtFree(str);317}318}319#endif320321static TypeMenuItem GapMenu[] =322{323{ "pastePrompt", MenuPastePrompt, S_ALWAYS, 0 },324{ "quitGapCTRD", MenuQuitGapCTRD, S_ALWAYS, 0 },325{ "-----------", 0, 0, 0 },326#ifndef NO_FILE_SELECTOR327{ "readFile", MenuReadFile, S_NORMAL_ONLY, 0 },328#endif329{ "-----------", 0, 0, 0 },330#ifdef DEBUG_ON331{ "resyncGap", MenuResyncGap, S_ALWAYS, 0 },332#endif333{ "quit", MenuQuitGap, S_ALWAYS, 0 },334{ "kill", MenuKillGap, S_ALWAYS, 0 },335{ 0, 0, 0, 0 }336};337338339/****************************************************************************340**341*V HelpMenu . . . . . . . . . . . . . . . . . . . . . . xgap's "Help" menu342**343*/344static void MenuChapters () { SimulateInput( "?Chapters\n" ); }345static void MenuSections () { SimulateInput( "?Sections\n" ); }346static void MenuCopyright () { SimulateInput( "?Copyright\n" );}347static void MenuHelp () { SimulateInput( "?Help\n" ); }348static void MenuNextHelp () { SimulateInput( "?>\n" ); }349static void MenuNextChapter () { SimulateInput( "?>>\n" ); }350static void MenuPrevChapter () { SimulateInput( "?<<\n" ); }351static void MenuPrevHelp () { SimulateInput( "?<\n" ); }352353354static TypeMenuItem HelpMenu[] =355{356{ "copyHelp", MenuCopyright, S_INPUT_ONLY, 0 },357{ "helpHelp", MenuHelp, S_INPUT_ONLY, 0 },358{ "---------", 0, 0, 0 },359{ "chpsHelp", MenuChapters, S_INPUT_ONLY, 0 },360{ "secsHelp", MenuSections, S_INPUT_ONLY, 0 },361{ "---------", 0, 0, 0 },362{ "nchpHelp", MenuNextChapter, S_INPUT_ONLY, 0 },363{ "pchpHelp", MenuPrevChapter, S_INPUT_ONLY, 0 },364{ "nextHelp", MenuNextHelp, S_INPUT_ONLY, 0 },365{ "prevHelp", MenuPrevHelp, S_INPUT_ONLY, 0 },366{ 0, 0, 0, 0 }367};368369370/****************************************************************************371**372*V RunMenu . . . . . . . . . . . . . . . . . . . . . . . . xgap's "Run" menu373**374*/375static void MenuInterrupt () { InterruptGap(); }376static void MenuQuitBreak () { SimulateInput( "quit;\n" ); }377static void MenuContBreak () { SimulateInput( "return;\n" ); }378static void MenuGarbColl () { SimulateInput( "GASMAN(\"collect\");\n" ); }379static void MenuGarbMesg () { SimulateInput( "GASMAN(\"message\");\n" ); }380static void MenuInfoRead () { SimulateInput(381"if InfoRead1=Print then InfoRead1:=Ignore; else InfoRead1:=Print; fi;\n"); }382383static TypeMenuItem RunMenu[] =384{385{ "interrupt", MenuInterrupt, S_RUNNING_ONLY, 0 },386{ "---------", 0, 0, 0 },387{ "quitBreak", MenuQuitBreak, S_ERROR_ONLY, 0 },388{ "contBreak", MenuContBreak, S_ERROR_ONLY, 0 },389{ "---------", 0, 0, 0 },390{ "garbColl", MenuGarbColl, S_INPUT_ONLY, 0 },391{ "garbMesg", MenuGarbMesg, S_INPUT_ONLY, 0 },392{ "infoRead", MenuInfoRead, S_INPUT_ONLY, 0 },393{ 0, 0, 0, 0 }394};395396397/****************************************************************************398**399400*F CreateMenu( <button>, <items> ) . . . . . . . . . . . . create a pop menu401**402** RESOURCES403** *menu.line.height404** height of menu line separator, default 10405*/406static TypeList ListInputOnly = 0;407static TypeList ListErrorOnly = 0;408static TypeList ListNormalOnly = 0;409static TypeList ListRunningOnly = 0;410static TypeList ListHelpOnly = 0;411412static void MenuSelected ( Widget, TypeMenuItem *, caddr_t );413414415static void CreateMenu (416Widget button,417TypeMenuItem * items )418{419Widget menu;420421/* if this is the first call, create lists */422if ( ListInputOnly == 0 )423{424ListErrorOnly = List(0);425ListHelpOnly = List(0);426ListInputOnly = List(0);427ListNormalOnly = List(0);428ListRunningOnly = List(0);429}430431/* create new simple menu */432menu = XtCreatePopupShell( "menu", simpleMenuWidgetClass, button, 0, 0 );433434/* and add menu buttons */435for ( ; items->label != 0; items++ )436{437if ( *(items->label) == '-' )438(void) XtVaCreateManagedWidget( "line",439smeLineObjectClass, menu, (String)NULL );440else441{442items->entry = XtVaCreateManagedWidget(443items->label, smeBSBObjectClass, menu,444XtNrightMargin, (XtArgVal)14,445XtNrightBitmap, (XtArgVal)EmptyMarkSymbol,446(String)NULL );447XtAddCallback( items->entry, XtNcallback,448(XtCallbackProc)MenuSelected, items );449switch ( items->sensitive )450{451case S_INPUT_ONLY:452AddList( ListInputOnly, items->entry );453XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,454(String)NULL );455break;456case S_ERROR_ONLY:457AddList( ListErrorOnly, items->entry );458XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,459(String)NULL );460break;461case S_NORMAL_ONLY:462AddList( ListNormalOnly, items->entry );463XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,464(String)NULL );465break;466case S_RUNNING_ONLY:467AddList( ListRunningOnly, items->entry );468XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,469(String)NULL );470break;471case S_HELP_ONLY:472AddList( ListHelpOnly, items->entry );473XtVaSetValues( items->entry, XtNsensitive, (XtArgVal)False,474(String)NULL );475break;476case S_ALWAYS:477break;478}479}480}481}482483static void MenuSelected (484Widget w,485TypeMenuItem * item,486caddr_t dummy )487{488if ( item->click != 0 )489(*(item->click))(item);490else491{492fputs( "Warning: menu item ", stderr );493fputs( XtName(w), stderr );494fputs( " has been selected.\n", stderr );495}496}497498499/****************************************************************************500**501*F UpdateMenus( <state> ) . . . . . . update menus in case of state change502*/503void UpdateMenus ( state )504Int state;505{506TypeList l;507Int i;508509/* menu entry active only in break loop */510l = ListErrorOnly;511for ( i = 0; i < l->len; i++ )512{513if ( state == GAP_ERROR )514XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,515(String)NULL );516else517XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,518(String)NULL );519}520521/* menu entry active only during input */522l = ListInputOnly;523for ( i = 0; i < l->len; i++ )524{525if ( state == GAP_ERROR || state == GAP_INPUT )526XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,527(String)NULL );528else529XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,530(String)NULL );531}532533/* menu entry active only during normal input */534l = ListNormalOnly;535for ( i = 0; i < l->len; i++ )536{537if ( state == GAP_INPUT )538XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,539(String)NULL );540else541XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,542(String)NULL );543}544545/* menu entry active only while gap is running */546l = ListRunningOnly;547for ( i = 0; i < l->len; i++ )548{549if ( state == GAP_RUNNING )550XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,551(String)NULL );552else553XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,554(String)NULL );555}556557/* menu entry active only while gap is helping */558l = ListHelpOnly;559for ( i = 0; i < l->len; i++ )560{561if ( state == GAP_HELP )562XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)True,563(String)NULL );564else565XtVaSetValues( (Widget)l->ptr[i], XtNsensitive, (XtArgVal)False,566(String)NULL );567}568}569570571/****************************************************************************572**573574*F * * * * * * * * * * * * * * gap talk window * * * * * * * * * * * * * * *575*/576577578/****************************************************************************579**580581*F UpdateMemoryInfo( <type>, <val> ) . . . . . . . . . update memory usage582*/583static Widget LabelLiveObjects;584static Widget LabelLiveKB;585static Widget LabelTotalKBytes;586587void UpdateMemoryInfo ( type, val )588Int type;589Int val;590{591char tmp[30];592593594switch ( type )595{596case 1:597sprintf( tmp, "Objects: %-5d ", val );598XtVaSetValues( LabelLiveObjects, XtNlabel, (XtArgVal)tmp,599(String)NULL );600break;601case 2:602sprintf( tmp, "KB used: %-5d ", val );603XtVaSetValues( LabelLiveKB, XtNlabel, (XtArgVal)tmp,604(String)NULL );605break;606case 6:607sprintf( tmp, "MBytes total: %-4d ", val/1024 );608XtVaSetValues( LabelTotalKBytes, XtNlabel, (XtArgVal)tmp,609(String)NULL );610break;611}612}613614615/****************************************************************************616**617*F GapTalkResized( <talk>, <cd>, <evt>, <ctd> ) . . . . . . resize callback618*/619static void GapTalkResized (620Widget talk,621XtPointer cd,622XEvent * evt,623Boolean * ctd )624{625Int i;626String ptr;627Widget snk;628XFontStruct * font;629char buf[128];630static UInt h, h1 = 0;631static UInt w, w1 = 0;632633/* is this a resize event */634if ( evt->type == ConfigureNotify )635{636637/* compute a sensible size */638XtVaGetValues( talk, XtNtextSink, (XtArgVal)&snk, (String)NULL );639XtVaGetValues( snk, XtNfont, (XtArgVal)&font, (String)NULL );640w = evt->xconfigure.width / font->max_bounds.width - 3;641h = evt->xconfigure.height / ( font->max_bounds.ascent642+ font->max_bounds.descent ) - 2;643if ( w < 2 ) w = 2;644if ( h < 2 ) h = 2;645if ( w == w1 && h == h1 )646return;647w1 = w;648h1 = h;649650/* construct gap command */651strcpy( buf, "SizeScreen([ " );652ptr = buf + strlen(buf);653for ( i = 3; 0 <= i; i--, w = w / 10 )654ptr[i] = w%10 + '0';655ptr += 4;656*ptr++ = ',';657*ptr++ = ' ';658for ( i = 3; 0 <= i; i--, h = h / 10 )659ptr[i] = h%10 + '0';660ptr += 4;661strcpy( ptr, " ]);;\n" );662663/* if gap is waiting for input, do it */664if ( GapState == GAP_INPUT || GapState == GAP_ERROR )665SimulateInput( buf );666else667strcpy( ScreenSizeBuffer, buf );668}669}670671672/****************************************************************************673**674*F CreateGapWindow() . . . . . . . . . . . . . . create communication window675**676** RESOURCES677** *xgapMenu*shapeStyle678** style of the menu buttons, default "Oval"679** *xgap.height680** *xgap.width681** start size of the communication text window682*/683static void CreateGapWindow ( void )684{685Widget paned;686Widget box;687Widget button;688Pixmap symbol;689Display * display;690Boolean flag;691Int i;692693/* create a "paned" for the menu and text window */694paned = XtVaCreateManagedWidget( "paned", panedWidgetClass,695XGap, (String)NULL );696697/* create a menu box for the menu buttons */698box = XtVaCreateManagedWidget( "xgapMenu", boxWidgetClass,699paned,700XtNx, (XtArgVal)0,701XtNy, (XtArgVal)0,702XtNresizeToPreferred, (XtArgVal)True,703(String)NULL );704705/* create a menu button drop down symbol */706display = XtDisplay(box);707symbol = XCreateBitmapFromData( display,708DefaultRootWindow(display),709"\376\3\2\2\2\6\162\6\2\6\162\6\2\6\162\6\2\6\2\6\376\7\370\7",71012, 12 );711712/* create file menu button and file menu */713button = XtVaCreateManagedWidget( "gapButton", menuButtonWidgetClass,714box,715XtNleftBitmap, (XtArgVal)symbol,716XtNx, (XtArgVal)0,717(String)NULL );718CreateMenu( button, GapMenu );719720/* create run menu button and run menu */721button = XtVaCreateManagedWidget( "runButton", menuButtonWidgetClass,722box,723XtNleftBitmap, (XtArgVal)symbol,724XtNx, (XtArgVal)10,725(String)NULL );726CreateMenu( button, RunMenu );727728/* create help menu button and help menu */729button = XtVaCreateManagedWidget( "helpButton", menuButtonWidgetClass,730box,731XtNleftBitmap, (XtArgVal)symbol,732XtNx, (XtArgVal)10,733(String)NULL );734CreateMenu( button, HelpMenu );735736/* create the communication window */737GapTalk = XtVaCreateManagedWidget( "xgapTalk", gapTextWidgetClass,738paned,739XtNinputCallback, (XtArgVal)KeyboardInput,740XtNcheckCaretPos, (XtArgVal)CheckCaretPos,741XtNscrollHorizontal, (XtArgVal)XawtextScrollWhenNeeded,742XtNscrollVertical, (XtArgVal)XawtextScrollAlways,743XtNeditType, (XtArgVal)XawtextEdit,744XtNbottomMargin, (XtArgVal)15,745XtNx, (XtArgVal)0,746XtNy, (XtArgVal)10,747XtNdisplayCaret, (XtArgVal)True,748(String)NULL );749XtAddEventHandler(GapTalk,StructureNotifyMask,False,GapTalkResized,0);750GTDropGapPrompt( GapTalk, True );751752/* to quit or not do quit on CTR-D */753XtVaGetValues( GapTalk, XtNquitGapCtrD, (XtArgVal)&flag, (String)NULL );754if ( flag )755{756for ( i = 0; GapMenu[i].label; i++ )757if ( !strcmp( GapMenu[i].label, "quitGapCTRD" ) )758break;759if ( GapMenu[i].label && GapMenu[i].click )760GapMenu[i].click(&(GapMenu[i]));761}762763/* paste GAP prompt into talk window? */764XtVaGetValues( GapTalk, XtNpasteGapPrompt, &flag, NULL );765if ( flag )766{767for ( i = 0; GapMenu[i].label; i++ )768if ( !strcmp( GapMenu[i].label, "pastePrompt" ) )769break;770if ( GapMenu[i].label && GapMenu[i].click )771GapMenu[i].click(&(GapMenu[i]));772}773774/* create a box and labels for garbage info */775box = XtVaCreateManagedWidget( "xgapInfo", boxWidgetClass,776paned,777XtNx, (XtArgVal)0,778XtNy, (XtArgVal)20,779XtNskipAdjust, (XtArgVal)True,780XtNresizeToPreferred, (XtArgVal)True,781(String)NULL );782LabelLiveObjects = XtVaCreateManagedWidget( "liveObjects",783labelWidgetClass, box,784XtNborderWidth, (XtArgVal)0,785(String)NULL );786LabelLiveKB = XtVaCreateManagedWidget( "liveBytes",787labelWidgetClass, box,788XtNborderWidth, (XtArgVal)0,789(String)NULL );790LabelTotalKBytes = XtVaCreateManagedWidget( "totalBytes",791labelWidgetClass, box,792XtNborderWidth, (XtArgVal)0,793(String)NULL );794UpdateMemoryInfo( 1, 0 );795UpdateMemoryInfo( 2, 0 );796UpdateMemoryInfo( 6, 0 );797}798799800/****************************************************************************801**802803*F * * * * * * * * * * * * * * error handler * * * * * * * * * * * * * * * *804*/805806807/****************************************************************************808**809810*F MyErrorHandler(<dis>) . . . . . . . . . . . . kill gap in case of X error811*/812static int (*OldErrorHandler)();813814static int MyErrorHandler ( dis, evt )815Display * dis;816XErrorEvent evt;817{818# ifdef DEBUG_ON819fputs( "killing gap because of X error\n", stderr );820# endif821KillGap();822return OldErrorHandler( dis, evt );823}824825826/****************************************************************************827**828*F MyIOErrorHandler(<dis>) . . . . . . . . . . . kill gap in case of X error829*/830static int (*OldIOErrorHandler)();831832static int MyIOErrorHandler ( dis )833Display * dis;834{835# ifdef DEBUG_ON836fputs( "killing gap because of X IO error\n", stderr );837# endif838KillGap();839return OldIOErrorHandler(dis);840}841842843/****************************************************************************844**845*F MySignalHandler() . . . . . . . . . . . . . . kill gap in case of signal846*/847#ifdef DEBUG_ON848849static void (*OldSignalHandlerHUP)();850static void (*OldSignalHandlerINT)();851static void (*OldSignalHandlerQUIT)();852static void (*OldSignalHandlerILL)();853static void (*OldSignalHandlerIOT)();854static void (*OldSignalHandlerBUS)();855static void (*OldSignalHandlerSEGV)();856857static void MySignalHandlerHUP ()858{859fputs( "killing gap because of signal HUP\n", stderr );860KillGap();861OldSignalHandlerHUP();862exit(1);863}864static void MySignalHandlerINT ()865{866fputs( "killing gap because of signal INT\n", stderr );867KillGap();868OldSignalHandlerINT();869exit(1);870}871static void MySignalHandlerQUIT ()872{873fputs( "killing gap because of signal QUIT\n", stderr );874KillGap();875OldSignalHandlerQUIT();876exit(1);877}878static void MySignalHandlerILL ()879{880fputs( "killing gap because of signal ILL\n", stderr );881KillGap();882OldSignalHandlerILL();883exit(1);884}885static void MySignalHandlerIOT ()886{887fputs( "killing gap because of signal IOT\n", stderr );888KillGap();889OldSignalHandlerIOT();890exit(1);891}892static void MySignalHandlerBUS ()893{894fputs( "killing gap because of signal BUS\n", stderr );895KillGap();896OldSignalHandlerBUS();897exit(1);898}899900static void MySignalHandlerSEGV ()901{902fputs( "killing gap because of signal SEGV\n", stderr );903KillGap();904OldSignalHandlerSEGV();905exit(1);906}907908#else909910static void MySignalHandler ()911{912KillGap();913exit(1);914}915916#endif917918919/****************************************************************************920**921922*F * * * * * * * * * * * * * * * main program * * * * * * * * * * * * * * *923*/924925926/****************************************************************************927**928929*F ParseArgs( <argc>, <argv> ) . . . create argument arry for gap subprocess930*/931static char * nargv[1024];932933static void ParseArgs ( argc, argv )934Int argc;935char ** argv;936{937Int nargc;938Int i, j;939String p;940941/* at first assume that "gap" is started with "gap", append "-p" */942nargc = 0;943nargv[nargc++] = "gap";944nargv[nargc++] = "-p";945946/* parse XGAP arguments till we see '--' */947for ( argv++, argc--; 0 < argc; argv++, argc-- ) {948949/* start of an argument */950if ( *argv[0] == '-' ) {951952/* don't group any options */953if ( strlen(*argv) != 2 ) {954fputs("XGAP: sorry options must not be grouped '", stderr);955fputs(*argv, stderr);956fputs("'.\n", stderr);957goto usage;958}959switch( argv[0][1] ) {960961/* catch unknown arguments */962default:963fputs("XGAP: unknown option '", stderr);964fputs(*argv, stderr);965fputs("'.\n", stderr);966goto usage;967968/* start of GAP options */969case '-':970argv++;971argc--;972goto gap;973974/* print a help */975case 'h':976goto fullusage;977978/* toggle debug */979case 'D':980# ifdef DEBUG_ON981if ( argc-- < 2 ) {982fputs( "XGAP: option '-D' must have an argument.\n",983stderr );984goto usage;985}986Debug = atoi(*++argv);987# else988fputs( "XGAP: compile XGAP using 'COPTS=-DDEBUG_ON'.\n",989stderr );990goto usage;991# endif992break;993994/* broken window manager */995case 'W':996PopupDialogBrokenWM();997break;998999/* copy GAP output to stderr */1000case 'E':1001SpyMode = !SpyMode;1002break;10031004/* get name of gap subprocess */1005case 'G':1006if ( argc-- < 2 ) {1007fputs( "XGAP: option '-G' must have an argument.\n",1008stderr );1009goto usage;1010}1011p = *++argv;1012nargv[0] = p;1013j = 0;1014while ( *++p ) {1015if ( *p == ' ' )1016{1017*p = '\0';1018j = j + 1;1019}1020}1021if ( 0 < j ) {1022for ( i = nargc-1; 0 < i; i-- )1023nargv[i+j] = nargv[i];1024nargc = nargc + j;1025while ( 0 < j )1026{1027while ( *--p ) ;1028nargv[j--] = p+1;1029}1030}1031break;1032}1033}10341035/* non-arguments are not allowed here */1036else {1037goto usage;1038}1039}10401041/* copy any remaining arguments */1042gap:1043for ( ; 0 < argc; argv++, argc-- )1044nargv[nargc++] = *argv;1045nargv[nargc] = 0;1046return;10471048/* print a usage message */1049usage:1050fputs("usage: xgap [OPTIONS] -- [GAP OPTIONS]\n",stderr);1051fputs(" run the X-Windows front-end for GAP,\n",stderr);1052fputs(" use '-h' option to get help.\n",stderr);1053fputs("\n",stderr);1054exit(1);10551056fullusage:1057fputs("usage: xgap [OPTIONS] -- [GAP OPTIONS]\n",stderr);1058fputs(" run the X-Windows front-end for GAP,\n",stderr);1059fputs("\n",stderr);1060fputs(" -h print this help message\n",stderr);1061fputs(" -D <num> set debug level\n",stderr);1062fputs(" -W try to workaround broken wm\n",stderr);1063fputs(" -E toggle spy mode\n",stderr);1064fputs(" -G <file> filename of the GAP executable\n",stderr);1065exit(1);1066}106710681069/****************************************************************************1070**1071*F main( <argc>, <argv> ) . . . . . . . . . . . . . . . . main event loop1072*/1073#include "bitmaps/checksym.bm"1074#include "bitmaps/emptymk.bm"1075#include "bitmaps/exmark.bm"1076#include "bitmaps/menusym.bm"10771078int main ( argc, argv )1079int argc;1080char ** argv;1081{1082String color;1083String colors;1084int fromGap;1085Int mod = -1;1086Int len;1087Int i;1088Int j;108910901091/* options after '--' are for gap */1092for ( i = 0; i < argc; i++ )1093if ( ! strcmp( argv[i], "--" ) )1094break;1095len = i;10961097/* create a new top level shell and an applictation context */1098XGap = XtVaAppInitialize( &AppContext, "XGap",1099CommandOptions, XtNumber(CommandOptions),1100&i, argv, FallbackResources, (String)NULL );1101for ( j = len; j <= argc; j++ ) {1102argv[i+(j-len)] = argv[j];1103}1104argc = argc + (i-len);1105GapDisplay = XtDisplay(XGap);1106GapScreen = DefaultScreen(GapDisplay);1107MyRootWindow = RootWindow( GapDisplay, GapScreen );11081109/* parse remaining arguments */1110ParseArgs( argc, argv );1111fromGap = StartGapProcess( nargv[0], nargv );11121113/* create top left arrow cusor */1114CursorTL = XCreateFontCursor( XtDisplay(XGap), XC_top_left_arrow );11151116/* create menu symbol */1117MenuSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,1118menusym_bits, menusym_width,1119menusym_height );11201121/* create check mark and empty mark */1122CheckMarkSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,1123checksym_bits, checksym_width,1124checksym_height );1125EmptyMarkSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,1126emptymk_bits, emptymk_width,1127emptymk_height );11281129/* exclamation mark */1130ExMarkSymbol = XCreateBitmapFromData( GapDisplay, MyRootWindow,1131exmark_bits, exmark_width,1132exmark_height );11331134/* WM_DELETE_WINDOW atom */1135WmDeleteWindowAtom = XInternAtom(GapDisplay, "WM_DELETE_WINDOW", False);11361137/* install our error handler, we have to kill gap in this case */1138OldIOErrorHandler = XSetIOErrorHandler( MyIOErrorHandler );1139OldErrorHandler = XSetErrorHandler ( MyErrorHandler );11401141/***************WIN32 CYGWIN fix***************/1142/* SIGIOT not defined in CYGWIN signal.h unless !defined(SIGTRAP)1143there may be a way to get ...? */1144#ifdef __CYGWIN__1145# define SIGIOT 6 /* IOT instruction */1146# define SIGABRT 6 /* used by abort, replace SIGIOT in the future */1147#endif1148/***************WIN32 CYGWIN fix***************/114911501151/* install your signal handler, we have to kill gap in this case */1152# ifdef DEBUG_ON1153OldSignalHandlerHUP = signal( SIGHUP, MySignalHandlerHUP );1154OldSignalHandlerINT = signal( SIGINT, MySignalHandlerINT );1155OldSignalHandlerQUIT = signal( SIGQUIT, MySignalHandlerQUIT );1156OldSignalHandlerILL = signal( SIGILL, MySignalHandlerILL );1157OldSignalHandlerIOT = signal( SIGIOT, MySignalHandlerIOT );1158OldSignalHandlerBUS = signal( SIGBUS, MySignalHandlerBUS );1159OldSignalHandlerSEGV = signal( SIGSEGV, MySignalHandlerSEGV );1160# else1161signal( SIGHUP, MySignalHandler );1162signal( SIGINT, MySignalHandler );1163signal( SIGQUIT, MySignalHandler );1164signal( SIGILL, MySignalHandler );1165signal( SIGIOT, MySignalHandler );1166signal( SIGBUS, MySignalHandler );1167signal( SIGSEGV, MySignalHandler );1168# endif11691170/* create the gap talk window */1171CreateGapWindow();1172XtRealizeWidget(XGap);11731174/* initialize window commands */1175InitXCMDS();11761177/* get color model */1178XtVaGetValues( GapTalk, XtNcolorModel, (XtArgVal)&color, (String)NULL );1179len = strlen(color);1180if ( !strncmp( color, "black&white", len ) )1181mod = CM_BW;1182else if ( !strncmp( color, "monochrome", len ) )1183mod = CM_BW;1184else if ( !strncmp( color, "grey", len ) )1185mod = CM_GRAY;1186else if ( !strncmp( color, "gray", len ) )1187mod = CM_GRAY;1188else if ( !strncmp( color, "color5", len ) )1189mod = CM_COLOR5;1190else if ( !strncmp( color, "color3", len ) )1191mod = CM_COLOR3;1192else if ( !strncmp( color, "default", len ) )1193mod = -1;1194else1195{1196fputs( "XGAP: unkown color model '", stderr );1197fputs( color, stderr );1198fputs( "'\n", stderr );1199mod = -1;1200}1201if ( mod != -1 ) {1202XtVaGetValues( GapTalk, XtNcolors, (XtArgVal)&colors, (String)NULL );1203GCSetColorModel( GapDisplay, mod, colors );1204}12051206/* add callback for output from gap*/1207XtAppAddInput( AppContext, fromGap, (XtPointer) XtInputReadMask,1208(XtInputCallbackProc) GapOutput, (XtPointer) 0 );12091210StoreInput( "LoadPackage(\"xgap\");;\n",22 );12111212/* force a garbage collection in the beginning */1213StoreInput( "GASMAN(\"collect\");\n", 19 );12141215/* talk window is drawn only partial during start up otherwise (why?) */1216/*XFlush( GapDisplay );1217sleep(1);1218XFlush( GapDisplay );1219sleep(1);1220XFlush( GapDisplay );1221sleep(1);*/1222/* FIXME: No longer necessary??? */12231224/* enter main read-eval loop */1225XtAppMainLoop(AppContext);1226return 0;1227}12281229/****************************************************************************1230**12311232*E xgap.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here1233*/123412351236