"Fossies" - the Fresh Open Source Software Archive

Member "xxgdb-1.12/windows.c" (29 Apr 1994, 13525 Bytes) of package /linux/misc/old/xxgdb-1.12.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*****************************************************************************
    2  *
    3  *  xdbx - X Window System interface to dbx
    4  *
    5  *  Copyright 1989, 1990 The University of Texas at Austin
    6  *
    7  *  Permission to use, copy, modify, and distribute this software and its
    8  *  documentation for any purpose and without fee is hereby granted,
    9  *  provided that the above copyright notice appear in all copies and that
   10  *  both that copyright notice and this permission notice appear in
   11  *  supporting documentation, and that the name of The University of Texas
   12  *  not be used in advertising or publicity pertaining to distribution of
   13  *  the software without specific, written prior permission.  The
   14  *  University of Texas makes no representations about the suitability of
   15  *  this software for any purpose.  It is provided "as is" without express
   16  *  or implied warranty.
   17  *
   18  *  THE UNIVERSITY OF TEXAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
   19  *  SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
   20  *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS BE LIABLE FOR ANY
   21  *  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
   22  *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
   23  *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
   24  *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   25  *
   26  *  Author:     Po Cheung, The University of Texas at Austin
   27  *  Created:    March 10, 1989
   28  *
   29  *****************************************************************************
   30  * 
   31  *  xxgdb - X Window System interface to the gdb debugger
   32  *  
   33  *  Copyright 1990,1993 Thomson Consumer Electronics, Inc.
   34  *  
   35  *  Permission to use, copy, modify, and distribute this software and its
   36  *  documentation for any purpose and without fee is hereby granted,
   37  *  provided that the above copyright notice appear in all copies and that
   38  *  both that copyright notice and this permission notice appear in
   39  *  supporting documentation, and that the name of Thomson Consumer
   40  *  Electronics (TCE) not be used in advertising or publicity pertaining
   41  *  to distribution of the software without specific, written prior
   42  *  permission.  TCE makes no representations about the suitability of
   43  *  this software for any purpose.  It is provided "as is" without express
   44  *  or implied warranty.
   45  *
   46  *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
   47  *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
   48  *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
   49  *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
   50  *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
   51  *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
   52  *  SOFTWARE.
   53  *
   54  *  Adaptation to GDB:  Pierre Willard
   55  *  XXGDB Created:      December, 1990
   56  *
   57  *****************************************************************************/
   58 
   59 /*  windows.c:
   60  *
   61  *    CreateTitleBar() :    Create title bar.
   62  *    CreateFileLabel() :   Create file label in file window.
   63  *    CreateLineLabel() :   Create line label in file window.
   64  *    CreateFileWindow() :  Create file window.
   65  *    CreateMessageWindow() :   Create message window.
   66  *    CreateDisplayWindow() :   Create display window.
   67  *    CreateSubWindows() :  Create the subwindows.
   68  *    UpdateFileLabel() :   Update file label.
   69  *    UpdateLineLabel() :   Update line label.
   70  *    UpdateMessageWindow() :   Update message window.
   71  */
   72 
   73 #include "global.h"
   74 
   75 Widget  fileWindow,         /* parent of fileLabel and lineLabel */
   76     messageWindow,          /* window for displaying messages */
   77     separator,          /* separator in vpane */
   78     displayWindow;          /* area for displaying variables */
   79 
   80 static Widget   fileLabel,      /* filename of displayed text */
   81         lineLabel;      /* line number of caret position */
   82 
   83 /*
   84  *  Private routines for creating various subwindows for xdbx.
   85  */
   86 
   87 static void CreateFileLabel(parent)
   88 Widget parent;
   89 {
   90     Arg     args[MAXARGS];
   91     Cardinal    n;
   92 
   93     n = 0;
   94     XtSetArg(args[n], XtNlabel, (XtArgVal) "No Source File");           n++;
   95     XtSetArg(args[n], XtNborderWidth, (XtArgVal) 0);                n++;
   96     fileLabel = XtCreateManagedWidget("fileLabel", labelWidgetClass, 
   97                       parent, args, n);
   98 }
   99 
  100 static void CreateLineLabel(parent)
  101 Widget parent;
  102 {
  103     Arg     args[MAXARGS];
  104     Cardinal    n;
  105 
  106     n = 0;
  107     XtSetArg(args[n], XtNlabel, (XtArgVal) "");                 n++;
  108     XtSetArg(args[n], XtNborderWidth, (XtArgVal) 0);                n++;
  109     XtSetArg(args[n], XtNfromHoriz, (XtArgVal) fileLabel);              n++;
  110     XtSetArg(args[n], XtNhorizDistance, (XtArgVal) 0);              n++;
  111     lineLabel = XtCreateManagedWidget("lineLabel", labelWidgetClass, 
  112                       parent, args, n);
  113 }
  114 
  115 static void CreateFileWindow(parent)
  116 Widget parent;
  117 {
  118     Arg     args[MAXARGS];
  119     Cardinal    n;
  120 
  121     n = 0;
  122     XtSetArg(args[n], XtNshowGrip, (XtArgVal) False);           n++;
  123     fileWindow = XtCreateManagedWidget("fileWindow", formWidgetClass, 
  124                        parent, args, n);
  125     CreateFileLabel(fileWindow);
  126     CreateLineLabel(fileWindow);
  127 }
  128 
  129 static void CreateMessageWindow(parent)
  130 Widget parent;
  131 {
  132     Arg     args[MAXARGS];
  133     Cardinal    n;
  134 
  135     n = 0;
  136     XtSetArg(args[n], XtNlabel, (XtArgVal) "");             n++;
  137     XtSetArg(args[n], XtNjustify, (XtArgVal) XtJustifyLeft);            n++;
  138     XtSetArg(args[n], XtNshowGrip, (XtArgVal) False);           n++;
  139     messageWindow = XtCreateManagedWidget("messageWindow", labelWidgetClass,
  140                       parent, args, n);
  141 }
  142 
  143 /*  Create a window for displaying variables as specified by the display
  144  *  command in dbx.
  145  */
  146 static void CreateDisplayWindow(parent)
  147 Widget parent;
  148 {
  149     Arg     args[MAXARGS];
  150     Cardinal    n;
  151 
  152 #ifndef NEW_INTERFACE
  153     n = 0;
  154     XtSetArg(args[n], XtNborderWidth, (XtArgVal) 0);                    n++;
  155     XtSetArg(args[n], XtNmin, (XtArgVal) 2);                n++;
  156     XtSetArg(args[n], XtNmax, (XtArgVal) 2);                n++;
  157     XtSetArg(args[n], XtNshowGrip, (XtArgVal) False);           n++;
  158     separator = XtCreateWidget("", labelWidgetClass, parent, args, n);
  159 #endif
  160     n = 0;
  161     XtSetArg(args[n], XtNeditType, (XtArgVal) XawtextRead);     n++;
  162 #ifdef NEW_INTERFACE
  163     displayWindow = XtCreateManagedWidget("displayWindow",
  164                       asciiTextWidgetClass, 
  165                       parent, args, n);
  166 #else
  167     displayWindow = XtCreateWidget("displayWindow", asciiTextWidgetClass, 
  168                    parent, args, n);
  169 #endif
  170 
  171 #ifndef NEW_INTERFACE
  172     if (app_resources.displayWindow) {
  173     XtManageChild(separator);
  174     XtManageChild(displayWindow);
  175     }
  176 #endif
  177 }
  178 
  179 #ifdef NEW_INTERFACE
  180 Widget pcWindow;
  181 Widget sourceShell;
  182 Widget sourceToggle;
  183 Widget commandShell;
  184 Widget commandToggle;
  185 Widget displayShell;
  186 Widget displayToggle;
  187 
  188 Atom   wm_delete_window;
  189 
  190 Widget MatchToggleFromShell(shell)
  191 Widget shell;
  192 {
  193   if (shell == sourceShell) return sourceToggle;
  194   if (shell == commandShell) return commandToggle;
  195   if (shell == displayShell) return displayToggle;
  196   return NULL;
  197 }
  198 
  199 void State_Transient(w, client_data, call_data)
  200      Widget w;
  201      Widget client_data;
  202      XtPointer call_data;
  203 {
  204   Arg   args[MAXARGS];
  205   Cardinal  n;
  206   Boolean       ToggleState;
  207 
  208   XtVaGetValues(w, XtNstate, &ToggleState, NULL);
  209   if (ToggleState)
  210     XtPopup(client_data, XtGrabNone);
  211   else
  212     XtPopdown(client_data);
  213 }
  214 
  215 void WMDeleteWindow(w, client_data, msg)
  216      Widget w;
  217      XtPointer client_data;
  218      XClientMessageEvent *msg;
  219 {
  220     if (msg->type == ClientMessage && msg->data.l[0] == wm_delete_window) {
  221       w = MatchToggleFromShell(client_data);
  222       if (w) XawToggleUnsetCurrent(w);
  223     }
  224 }
  225 
  226 
  227 void SetupWMProtocol(shell)
  228 Widget shell;
  229 {
  230   XtRealizeWidget(shell);
  231   XSetWMProtocols(XtDisplay(shell), XtWindow(shell), &wm_delete_window, 1);
  232   XtAddEventHandler(shell, NoEventMask, True, WMDeleteWindow, (XtPointer) shell);
  233 }
  234 
  235 void CreatePCToggle(parent, toggle, name, label, shell)
  236 Widget  parent;
  237 Widget  *toggle;
  238 char *name;
  239 XtPointer label;
  240 Widget shell;
  241 {
  242     Arg     args[MAXARGS];
  243     Cardinal    n;
  244 
  245     n = 0;
  246     XtSetArg(args[n], XtNresize, (XtArgVal) False);         n++;
  247     XtSetArg(args[n], XtNlabel, label);                     n++;
  248     XtSetArg(args[n], XtNwidth, 130);                                   n++;
  249 #ifdef OPEN_ALL_WINDOWS
  250     XtSetArg(args[n], XtNstate, True);                                   n++;
  251 #endif
  252     *toggle = XtCreateManagedWidget(name, toggleWidgetClass,
  253                    parent, args, n);
  254     XtAddCallback(*toggle, XtNcallback, State_Transient, shell);
  255 }
  256 
  257 static void CreatePopupControls(parent)
  258 Widget parent;
  259 {
  260   Widget QuitButtonTwo;
  261   Arg   args[MAXARGS];
  262   Cardinal  n;
  263   
  264   n = 0;
  265   XtSetArg(args[n], XtNshowGrip, (XtArgVal) False);         n++;
  266   pcWindow = XtCreateManagedWidget("pcWindow", boxWidgetClass, 
  267                    parent, args, n);
  268   CreatePCToggle(pcWindow, &sourceToggle , "pcSource"  ,
  269          "Source Listing"  , sourceShell );
  270   CreatePCToggle(pcWindow, &commandToggle, "pcCommand" ,
  271          "Command Buttons" , commandShell);
  272 #ifdef GDB
  273   CreatePCToggle(pcWindow, &displayToggle, "pcDisplay" ,
  274                  "Display Window"  , displayShell);
  275 #endif
  276   n = 0;
  277   QuitButtonTwo = XtCreateManagedWidget("Quit", commandWidgetClass,
  278                     pcWindow, args, n);
  279   XtAddCallback(QuitButtonTwo, XtNcallback, Quit, NULL);
  280 }
  281 
  282 #endif /* NEW_INTERFACE */
  283 
  284 /*  PUBLIC ROUTINES */
  285 /*
  286  *  Top level function for creating all the xdbx subwindows.
  287  */
  288 void CreateSubWindows(parent)
  289 Widget parent;
  290 {
  291     Widget  vpane;      /* outer widget containing various subwindows */
  292 #ifdef NEW_INTERFACE
  293     Widget      listingForm; /* file listing Shell */
  294     Widget      displayForm; /* file listing Shell */
  295 #endif
  296     Arg     args[MAXARGS];
  297     Cardinal    n;
  298 
  299     n = 0;
  300     vpane = XtCreateManagedWidget("vpane", panedWidgetClass, parent, args, n);
  301 
  302 #ifdef NEW_INTERFACE
  303     wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False);
  304 
  305     n = 0;
  306     XtSetArg(args[n], XtNtitle, "xxgdb Source Display");                n++;
  307     sourceShell = XtCreatePopupShell("sourceShell", 
  308                      transientShellWidgetClass,
  309                      toplevel, args, n);
  310     n=0;
  311     listingForm = XtCreateManagedWidget("listingForm", 
  312                     formWidgetClass,
  313                     sourceShell, args, n);
  314 
  315     CreateFileWindow(listingForm);
  316     CreateSourceWindow(listingForm);
  317     SetupWMProtocol(sourceShell);
  318 #else
  319     CreateFileWindow(vpane);
  320     CreateSourceWindow(vpane);
  321 #endif
  322     CreateMessageWindow(vpane);
  323 #ifdef NEW_INTERFACE
  324     n = 0;
  325     XtSetArg(args[n], XtNtitle, "xxgdb Commands");                n++;
  326     commandShell = XtCreatePopupShell("commandShell", 
  327                      transientShellWidgetClass,
  328                      toplevel, args, n);
  329     CreateCommandPanel(commandShell);
  330     SetupWMProtocol(commandShell);
  331 #else
  332     CreateCommandPanel(vpane);
  333 #endif
  334     CreateDialogWindow(vpane);
  335 #ifdef GDB
  336 #ifdef NEW_INTERFACE
  337     n = 0;
  338     XtSetArg(args[n], XtNtitle, "xxgdb Variable Display");                n++;
  339     displayShell = XtCreatePopupShell("displayShell", 
  340                       transientShellWidgetClass,
  341                       toplevel, args, n);
  342     n=0;
  343     displayForm = XtCreateManagedWidget("displayForm",
  344                     formWidgetClass,
  345                     displayShell, args, n);
  346 
  347     CreateDisplayWindow(displayForm);
  348     SetupWMProtocol(displayShell);
  349 #else
  350     CreateDisplayWindow(vpane);
  351 #endif
  352 #else /* not GDB */
  353 #ifndef BSD
  354     CreateDisplayWindow(vpane);
  355 #endif
  356 #endif  /* not GDB */
  357 #ifdef NEW_INTERFACE
  358     CreatePopupControls(vpane);
  359 #endif
  360 } 
  361 
  362 /*
  363  *  Routines for updating fields for the filename and line number
  364  *  in the file window, and the execution status in the message window.
  365  */
  366 
  367 void UpdateFileLabel(string)
  368 char *string;
  369 {
  370     Arg     args[MAXARGS];
  371     Cardinal    n;
  372 
  373     n = 0;
  374     XtSetArg(args[n], XtNlabel, (XtArgVal) string);             n++;
  375     XtSetValues(fileLabel, args, n);
  376 }
  377 
  378 void UpdateLineLabel(line)
  379 Cardinal line;
  380 {
  381     Arg     args[MAXARGS];
  382     Cardinal    n;
  383     char    string[10];
  384 
  385     n = 0;
  386     if (line > 0)
  387         sprintf(string, "%d", line);
  388     else
  389     strcpy(string, "");
  390     XtSetArg(args[n], XtNlabel, (XtArgVal) string);         n++;
  391     XtSetValues(lineLabel, args, n);
  392 }
  393 
  394 /*--------------------------------------------------------------------------+
  395 |                                                                           |
  396 |   Note : UpdateMessageWindow assumes that the format string               |
  397 |           can only contain one %s specifier.                              |
  398 |       arg is either NULL or is a string.                                  |
  399 |       format is a string (never NULL).                                    |
  400 |                                                                           |
  401 +--------------------------------------------------------------------------*/
  402 void UpdateMessageWindow(format, arg)
  403 char *format, *arg;
  404 {
  405     char *message;
  406     char string[LINESIZ];
  407     int fulllength;
  408     Arg     args[MAXARGS];
  409     Cardinal    n;
  410 
  411     /* fix bug where if a debugged program function arg is a string
  412 that looks like "%s", and UpdateMesssageWindow is passed that string
  413 in format (with a NULL arg), then UpdateMessageWindow expects another
  414 arg.  We fix by seeing if arg is NULL.  If so, then make format "%s"
  415 and arg whatever the format string was. */
  416 
  417     if (arg == NULL) {
  418         arg = format;
  419         format = "%s";
  420     }
  421 
  422     fulllength = strlen ("  ") + strlen (format) + 1 + ((arg == NULL) ? 0 : strlen (arg));
  423     
  424     if (fulllength > LINESIZ)
  425         message = (char*) XtMalloc (fulllength);
  426     else
  427         message = string;
  428         
  429     strcpy(message, "  ");
  430     sprintf(message + strlen(message), format, arg);
  431     
  432     n = 0;
  433     XtSetArg(args[n], XtNlabel, (XtArgVal) message);        n++;
  434     XtSetValues(messageWindow, args, n);
  435     
  436     if (fulllength > LINESIZ)
  437         XtFree(message);
  438 }
  439 
  440 void ClearMessageWindow()
  441 {
  442     Arg     args[MAXARGS];
  443     Cardinal    n;
  444 
  445     n = 0;
  446     XtSetArg(args[n], XtNlabel, (XtArgVal) "");         n++;
  447     XtSetValues(messageWindow, args, n);
  448 }
  449