"Fossies" - the Fresh Open Source Software Archive

Member "xxgdb-1.12/command.c" (23 Nov 1994, 27976 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 the dbx debugger
    4  *
    5  *  Copyright 1989 The University of Texas at Austin
    6  *  Copyright 1990 Microelectronics and Computer Technology Corporation
    7  *
    8  *  Permission to use, copy, modify, and distribute this software and its
    9  *  documentation for any purpose and without fee is hereby granted,
   10  *  provided that the above copyright notice appear in all copies and that
   11  *  both that copyright notice and this permission notice appear in
   12  *  supporting documentation, and that the name of The University of Texas
   13  *  and Microelectronics and Computer Technology Corporation (MCC) not be 
   14  *  used in advertising or publicity pertaining to distribution of
   15  *  the software without specific, written prior permission.  The
   16  *  University of Texas and MCC makes no representations about the 
   17  *  suitability of this software for any purpose.  It is provided "as is" 
   18  *  without express or implied warranty.
   19  *
   20  *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
   21  *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
   22  *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
   23  *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
   24  *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
   25  *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
   26  *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   27  *
   28  *  Author:     Po Cheung
   29  *  Created:    March 10, 1989
   30  * 
   31  *****************************************************************************
   32  * 
   33  *  xxgdb - X Window System interface to the gdb debugger
   34  *  
   35  *  Copyright 1990,1993 Thomson Consumer Electronics, Inc.
   36  *  
   37  *  Permission to use, copy, modify, and distribute this software and its
   38  *  documentation for any purpose and without fee is hereby granted,
   39  *  provided that the above copyright notice appear in all copies and that
   40  *  both that copyright notice and this permission notice appear in
   41  *  supporting documentation, and that the name of Thomson Consumer
   42  *  Electronics (TCE) not be used in advertising or publicity pertaining
   43  *  to distribution of the software without specific, written prior
   44  *  permission.  TCE makes no representations about the suitability of
   45  *  this software for any purpose.  It is provided "as is" without express
   46  *  or implied warranty.
   47  *
   48  *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
   49  *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
   50  *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
   51  *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
   52  *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
   53  *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
   54  *  SOFTWARE.
   55  *
   56  *  Adaptation to GDB:  Pierre Willard
   57  *  XXGDB Created:      December, 1990
   58  *
   59  *  AJK Changes: Apr-May 1991
   60  *  1. Added new buttons for gdb, dbx,
   61  *  2. Free strings allocated by 'XFetchBytes',
   62  *****************************************************************************/
   63 
   64 /*  command.c
   65  *
   66  *    Create the command window, the command buttons and their callbacks.
   67  *
   68  *    CreateCommandPanel() :    Create a window with command buttons
   69  *    CreateButtons() :     Create command buttons in panel
   70  *    AddButton() :     Add a command button into the command window
   71  *    ButtonSet() :     Action proc for command button translation
   72  *
   73  *    Command callbacks for the command buttons:
   74  *
   75  *    forwardSearch() :     forward string search
   76  *    reverseSearch() :     reverse string search
   77  *    Search() :        call either forwardSearch() or reverseSearch()
   78  *    PopupSearch() :       command callback for search button
   79  *    DoneSearch() :        command callback for DONE button in search panel
   80  *    CreateSearchPopup() : create search panel
   81  *
   82  *    Command queue manipulation routines:
   83  *  send_command():     send a command to dbx and record in the queue
   84  *  get_command():      read command off head of queue
   85  *  insert_command():   insert command at the head of queue
   86  *  delete_command():   delete command from head of queue
   87  */
   88  
   89 #include <stdio.h>
   90 #include <stdlib.h>
   91 #include <string.h>
   92 #include <ctype.h>
   93 #include <signal.h>
   94 #ifdef  _POSIX_SOURCE
   95 #include <sys/types.h>
   96 #endif
   97 #include <sys/wait.h>
   98 #include "global.h"
   99 
  100 #define  REVERSE    0
  101 #define  FORWARD    1
  102 
  103 Widget      commandWindow;          /* command panel with buttons */
  104 Boolean     PopupMode = False;
  105 static int  Button;
  106 static Widget   searchPopupShell, searchPopup;
  107 static Widget   AddButton();
  108 static Widget   button[30];
  109 static char SearchString[BUFSIZ] = "";  /* search string buffer */
  110 static char command[LINESIZ];
  111 static CommandRec *commandQueue = NULL;
  112 #ifndef GDB
  113 #ifdef BSD
  114 static char savedCommand[LINESIZ] = ""; 
  115 #endif
  116 #endif  /* not GDB */
  117 
  118 /* ARGSUSED */
  119 static void ButtonSet(w, event, params, num_params)
  120     Widget w;
  121     XEvent *event;
  122     String *params;
  123     Cardinal *num_params;
  124 {
  125     Button = atoi(params[0]);
  126 }
  127 
  128 /* ARGSUSED */
  129 /*  Execute the dbx command specifed in client_data
  130  */
  131 static void DoIt (w, command, call_data)
  132     Widget w;
  133     XtPointer command;
  134     XtPointer call_data;
  135 {
  136     /* run, cont, next, step, where, up, down, status */
  137     send_command(command);
  138     AppendDialogText(command);
  139 }
  140 
  141 #if !defined(GDB) && defined(BSD)   /* >>>>>>>>>> NOT USED FOR GDB <<<<<<<<<<<<<<< */
  142 
  143 /* ARGSUSED */
  144 static void Return (w, client_data, call_data)
  145     Widget w;
  146     XtPointer client_data;
  147     XtPointer call_data;
  148 {
  149     char *funcname;
  150     int  nbytes;
  151 
  152     funcname = XFetchBytes(display, &nbytes);   /* from CUT_BUFFER0 */
  153     if (nbytes == 0)
  154         strcpy(command, "return\n");
  155     else {
  156         sprintf(command, "return %s\n", funcname);
  157     XFree (funcname);                           /* AJK */
  158       }
  159     send_command(command);
  160     AppendDialogText(command);
  161 }
  162 #endif /* NOT GDB && BSD */
  163 
  164 #ifdef GDB  /* >>>>>>>>>>>>>> GDB ONLY <<<<<<<<<<<<<<<< */
  165 /*
  166     here client_data is "break" or "tbreak"
  167 
  168 */
  169 static void Break(w, client_data, call_data)
  170     Widget w;
  171     XtPointer client_data;
  172     XtPointer call_data;
  173 {
  174     XawTextPosition pos;
  175     int line;
  176     char *funcname;
  177     int  nbytes;
  178     char *s;
  179 
  180     funcname = XFetchBytes(display, &nbytes);   /* from CUT_BUFFER0 */
  181     if (nbytes) 
  182         {
  183         s = funcname;
  184         while (*s == ' ') s++;  /* skip leading spaces (if any) */
  185         if ((*s >= '0') && (*s <= '9'))
  186             sprintf(command, "%s *%s\n",client_data,funcname);
  187         else
  188             sprintf(command, "%s %s\n",client_data,funcname);
  189         XFree (funcname);   /* AJK */
  190         }
  191     else
  192         {
  193         if (displayedFile != NULL)
  194             {
  195             pos = XawTextGetInsertionPoint(sourceWindow);
  196             line = TextPositionToLine(pos);
  197             sprintf(command, "%s %d\n",client_data,line);
  198             }
  199         else
  200             {
  201             UpdateMessageWindow(BREAK_HELP, NULL);
  202             bell(0);
  203             return;
  204             }
  205         }
  206         
  207     send_command(command);
  208     AppendDialogText(command);
  209 }
  210 
  211 #else   /* >>>>>>>>>> NOT USED FOR GDB <<<<<<<<<<<<<<< */
  212 
  213 /* ARGSUSED */
  214 static void Stop_at(w, client_data, call_data)
  215     Widget w;
  216     XtPointer client_data;
  217     XtPointer call_data;
  218 {
  219     XawTextPosition pos;
  220     int line;
  221 
  222     if (displayedFile == NULL) {
  223     UpdateMessageWindow(STOP_AT_HELP, NULL);
  224     bell(0);
  225     return;
  226     }
  227     pos = XawTextGetInsertionPoint(sourceWindow);
  228     line = TextPositionToLine(pos);
  229     sprintf(command, "stop at %d\n", line);
  230     send_command(command);
  231     AppendDialogText(command);
  232 }
  233 
  234 /* ARGSUSED */
  235 static void Stop_in(w, client_data, call_data)
  236     Widget w;
  237     XtPointer client_data;
  238     XtPointer call_data;
  239 {
  240     char *funcname;
  241     int  nbytes;
  242 
  243     funcname = XFetchBytes(display, &nbytes);   /* from CUT_BUFFER0 */
  244     if (nbytes == 0) {
  245     UpdateMessageWindow(STOP_IN_HELP, NULL);
  246     bell(0);
  247     return;
  248     }
  249     sprintf(command, "stop in %s\n", funcname);
  250     send_command(command);
  251     AppendDialogText(command);
  252     XFree (funcname);          /* AJK */
  253 }
  254 
  255 #endif /* NOT GDB */
  256 
  257 /*  Delete removes the stop_no associated with a given line number.
  258  *  RemoveStop() is called to undisplay the stop sign only when there
  259  *  are no more stop_no's associated with that line number.
  260  */
  261 /* ARGSUSED */
  262 static void Delete(w, client_data, call_data)
  263     Widget w;
  264     XtPointer client_data;
  265     XtPointer call_data;
  266 {
  267     XawTextPosition pos;
  268     char        *string;
  269     int         stop_no, line, nbytes;
  270 
  271     string = XFetchBytes(display, &nbytes);
  272     if (nbytes > 0 && (stop_no = atoi(string)) > 0) {
  273         sprintf(command, "delete %d\n", stop_no);
  274     send_command(command);
  275     AppendDialogText(command);
  276     XFree (string);                             /* AJK */
  277     return;
  278     }
  279     else if (displayedFile) {
  280       if (string) {                     /* AJK: string is non-NULL, but not an int */
  281       XFree (string);
  282       string = (char *)NULL;
  283     }
  284     pos = XawTextGetInsertionPoint(sourceWindow);
  285     line = TextPositionToLine(pos);
  286     if ((stop_no = LineToStop_no(line))) {
  287         sprintf(command, "delete %d\n", stop_no);
  288         send_command(command);
  289         AppendDialogText(command);
  290         return;
  291     }
  292     }
  293     if (string) {                     /* AJK */
  294       XFree (string);
  295     }
  296     UpdateMessageWindow(DELETE_HELP, NULL);
  297     bell(0);
  298 }
  299 
  300 /* ARGSUSED */
  301 static void Print(w, client_data, call_data)
  302     Widget w;
  303     XtPointer client_data;
  304     XtPointer call_data;
  305 {
  306     char *string;
  307     int nbytes;
  308 
  309     if (Button == 3) PopupMode = True;
  310 
  311     string = XFetchBytes(display, &nbytes);
  312     if (nbytes == 0) {
  313     UpdateMessageWindow(PRINT_HELP, NULL);
  314     bell(0);
  315     return;
  316     }
  317     if (client_data == (XtPointer)0)
  318     sprintf(command, "print %s\n", string);
  319     else if (client_data == (XtPointer)1)
  320     sprintf(command, "print *%s\n", string);
  321     send_command(command);
  322 #ifdef GDB
  323     if (!PopupMode)     /* for GDB don't display print if everything goes in a window */
  324 #endif
  325     AppendDialogText(command);
  326     XFree (string);                           /* AJK */
  327 }
  328 
  329 #ifndef GDB /* >>>>>>>>>> NOT USED FOR GDB <<<<<<<<<<<<<<< */
  330 /* ARGSUSED */
  331 static void Func(w, client_data, call_data)
  332     Widget w;
  333     XtPointer client_data;
  334     XtPointer call_data;
  335 {
  336     char *funcname;
  337     int nbytes;
  338 
  339     funcname = XFetchBytes(display, &nbytes);
  340     if (nbytes == 0)
  341         strcpy(command, "func\n");
  342     else {
  343         sprintf(command, "func %s\n", funcname);
  344     XFree (funcname);                           /* AJK */
  345       }
  346     send_command(command);
  347     AppendDialogText(command);
  348 }
  349 #endif /* NOT GDB */
  350 
  351 /* CRL mod 2/19/91 GWC - an callback procedure for the "interrupt" button.
  352  * As in SigInt in dialog.c the process is 
  353  * interrupted with killpg(dbxpid, SIGINT).
  354  */
  355 /* add interrupt button that send sigint to inferior gdb,
  356 need to have gdb receive SIGINT.
  357  */
  358 static void Interrupt(w, client_data, call_data)
  359    Widget w;
  360    XtPointer client_data;
  361    XtPointer call_data;
  362 {
  363   signal_interrupt_dbx ();
  364 }
  365 
  366 #ifdef EDIT_BUTTON
  367 /* allow invocation of favorite editor from within interface. */
  368 static void EdCallback(w, client_data, call_data)
  369     Widget w;
  370     XtPointer client_data;
  371     XtPointer call_data;
  372 {
  373     StartEditor();
  374 }
  375 #endif /* EDIT_BUTTON */
  376  
  377 /* ARGSUSED */
  378 #ifndef NEW_INTERFACE
  379 static
  380 #endif
  381 void Quit(w, client_data, call_data)
  382     Widget w;
  383     XtPointer client_data;
  384     XtPointer call_data;
  385 {
  386 #ifdef SYSV 
  387     int status;
  388 #else
  389     union wait status;
  390 #endif /* SYSV */
  391 
  392     write_dbx("quit\n");
  393     XtDestroyApplicationContext(app_context);
  394     kill(dbxpid, SIGKILL);
  395 #ifdef SYSV
  396 #if 1 /* instead of ifdef SVR4 */
  397     status = waitpid(dbxpid, (int *)0, WNOHANG);    /* (MJH) */
  398 #else
  399     waitpid(&status, NULL, WNOHANG);
  400 #endif  /* SVR4 */
  401 #else   /* not SYSV */
  402     wait3(&status, WNOHANG, NULL);
  403 #endif /* SYSV */
  404     exit(0);
  405 }
  406 
  407 
  408 /* ARGSUSED */
  409 static void Display_(w, client_data, call_data)
  410     Widget w;
  411     XtPointer client_data;
  412     XtPointer call_data;
  413 {
  414     char *string;
  415     int nbytes;
  416 
  417     string = XFetchBytes(display, &nbytes);
  418     sprintf(command, "display %s\n", string);
  419     send_command(command);
  420     AppendDialogText(command);
  421     if (string)                  /* AJK */
  422       XFree (string);
  423 }
  424 
  425 #ifndef GDB
  426 
  427 /* Handle dbx commands which need a variable name (whatis,whereis,which,trace).
  428  * Command name is passed in client_data.
  429  */
  430 static void WhCmds (w, client_data, call_data)                      /* AJK */
  431     Widget    w;
  432     XtPointer client_data;
  433     XtPointer call_data;
  434 {
  435     char *string;
  436     int   nbytes;
  437 
  438     string = XFetchBytes (display, &nbytes);
  439     if (nbytes == 0) {
  440     UpdateMessageWindow (WHATIS_HELP, NULL);
  441     bell (0);
  442     return;
  443       }
  444     sprintf (command, "%s %s\n", client_data, string);
  445     send_command (command);
  446     AppendDialogText (command);
  447     XFree (string);
  448 
  449 } /* WhCmds */
  450 
  451 #endif          /* >>>>>>>>>>>>>> DBX ONLY <<<<<<<<<<<<<<<< */
  452 
  453 #ifdef GDB  /* >>>>>>>>>>>>>> GDB ONLY <<<<<<<<<<<<<<<< */
  454 /* ARGSUSED */
  455 static void Undisplay(w, client_data, call_data)
  456     Widget w;
  457     XtPointer client_data;
  458     XtPointer call_data;
  459 {
  460     char *string;
  461     int  stop_no, nbytes;
  462 
  463     string = XFetchBytes(display, &nbytes);
  464     if (nbytes != 0)
  465         {
  466         if ((stop_no = atoi(string)) > 0)
  467             sprintf(command, "undisplay %d\n", stop_no);
  468         else
  469             {
  470             UpdateMessageWindow(UNDISPLAY_HELP, NULL);
  471             bell(0);
  472             return;
  473             }
  474         XFree (string);           /* AJK */
  475         }
  476     else
  477         sprintf(command, "undisplay\n");
  478         
  479     send_command(command);
  480     AppendDialogText(command);
  481 }
  482 
  483 #else   /* >>>>>>>>>> NOT USED FOR GDB <<<<<<<<<<<<<<< */
  484 
  485 /* ARGSUSED */
  486 static void Undisplay(w, client_data, call_data)
  487     Widget w;
  488     XtPointer client_data;
  489     XtPointer call_data;
  490 {
  491     char *string;
  492     int  stop_no, nbytes;
  493 
  494     string = XFetchBytes(display, &nbytes);
  495     if (nbytes == 0) {
  496     UpdateMessageWindow(UNDISPLAY_HELP, NULL);
  497     bell(0);
  498     return;
  499     }
  500     if ((stop_no = atoi(string)) > 0)
  501     sprintf(command, "undisplay %d\n", stop_no);
  502     else
  503         sprintf(command, "undisplay %s\n", string);
  504     send_command(command);
  505     AppendDialogText(command);
  506     XFree (string);           /* AJK */
  507 }
  508 #endif /* NOT GDB */
  509 
  510 #ifndef GDB /* >>>>>>>>>> NOT USED FOR GDB <<<<<<<<<<<<<<< */
  511 /* ARGSUSED */
  512 static void Dump(w, client_data, call_data)
  513     Widget w;
  514     XtPointer client_data;
  515     XtPointer call_data;
  516 {
  517     char *funcname;
  518     int nbytes;
  519 
  520     funcname = XFetchBytes(display, &nbytes);
  521     if (nbytes == 0)
  522         strcpy(command, "dump\n");
  523     else {
  524         sprintf(command, "dump %s\n", funcname);
  525     XFree (funcname);           /* AJK */
  526       }
  527     send_command(command);
  528     AppendDialogText(command);
  529 }
  530 #endif /* NOT GDB */
  531 
  532 
  533 /*  Beginning from startpos, this routine searches text forward for 
  534  *  searchstring, and returns 1 if searchstring is found, also returning 
  535  *  the left and right positions of the matched string in left and right; 
  536  *  else 0 is returned.
  537  *  It also does wrap-around search.
  538  */
  539 static int forwardSearch(text, startpos, searchstring, left, right)
  540     char *text;
  541     int  startpos;
  542     char *searchstring;
  543     XawTextPosition  *left, *right;
  544 {
  545     int  searchlength, searchsize, i, n=0;
  546     char *s1, *s2;
  547 
  548     searchlength = strlen(searchstring);
  549     searchsize = strlen(text) - searchlength;
  550     for (i=startpos+1; i < searchsize; i++) {
  551     n = searchlength;
  552     s1 = &text[i];
  553     s2 = searchstring;
  554     while (--n >= 0 && *s1++ == *s2++);
  555     if (n < 0) break;
  556     }
  557     if (n < 0) {
  558         *left = i;
  559         *right = i+searchlength;
  560         return 1;
  561     }
  562     else {
  563     for (i=0; i <= startpos; i++) {
  564         n = searchlength;
  565         s1 = &text[i];
  566         s2 = searchstring;
  567         while (--n >= 0 && *s1++ == *s2++);
  568         if (n < 0) break;
  569     }
  570     if (n < 0) {
  571         *left = i;
  572         *right = i+searchlength;
  573         return 1;
  574     }
  575     return 0;
  576     }
  577 }
  578     
  579 
  580 /*  Similar to forwardSearch(), except that it does a reverse search
  581  */
  582 static int reverseSearch(text, startpos, searchstring, left, right)
  583     char        *text;
  584     XawTextPosition  startpos;
  585     char        *searchstring;
  586     XawTextPosition  *left, *right;
  587 {
  588     int  searchlength, i, n=0;
  589     char *s1, *s2;
  590 
  591     searchlength = strlen(searchstring);
  592     for (i=startpos; i >= searchlength; i--) {
  593     n = searchlength;
  594     s1 = &text[i];
  595     s2 = &searchstring[searchlength-1];
  596     while (--n >= 0 && *--s1 == *s2--);
  597     if (n < 0) break;
  598     }
  599     if (n < 0) {
  600         *right = i;
  601         *left = *right-searchlength;
  602         return 1;
  603     }
  604     else {
  605     for (i=strlen(text); i > startpos; i--) {
  606         n = searchlength;
  607         s1 = &text[i];
  608         s2 = &searchstring[searchlength-1];
  609         while (--n >= 0 && *--s1 == *s2--);
  610         if (n < 0) break;
  611     }
  612     if (n < 0) {
  613             *right = i;
  614             *left = *right-searchlength;
  615         return 1;
  616     }
  617     return 0;
  618     }
  619 }
  620 
  621 /* ARGSUSED */
  622 void PopupSearch(w, client_data, call_data)
  623     Widget w;
  624     XtPointer client_data;
  625     XtPointer call_data;
  626 {
  627     Arg     args[MAXARGS];
  628     Cardinal    n;
  629     Dimension   popup_width, dialog_width;
  630     Position    x, y;
  631 
  632     if (!displayedFile) {
  633     UpdateMessageWindow(SEARCH_HELP, NULL);
  634     bell(0);
  635     }
  636     else {
  637     XtRealizeWidget(searchPopupShell);
  638     n = 0;
  639     XtSetArg(args[n], XtNwidth, &popup_width);          n++;
  640     XtGetValues(searchPopupShell, args, n);
  641     n = 0;
  642     XtSetArg(args[n], XtNwidth, &dialog_width);         n++;
  643     XtGetValues(dialogWindow, args, n);
  644     XtTranslateCoords(dialogWindow, 
  645               (Position)(dialog_width - popup_width)/2, 10, &x, &y);
  646     n = 0;
  647     XtSetArg(args[n], XtNx, x);                 n++;
  648     XtSetArg(args[n], XtNy, y);                 n++;
  649     XtSetValues(searchPopupShell, args, n);
  650     XtPopup(searchPopupShell, XtGrabNone);
  651     }
  652 }
  653 
  654 
  655 /* ARGSUSED */
  656 /*  This routine handles both forward and reverse text search.
  657  *  If no text has been entered, the contents of the cut buffer are used
  658  *  for searching.
  659  */ 
  660 static void Search(w, direction, call_data)
  661     Widget w;
  662     XtPointer direction;
  663     XtPointer call_data;
  664 {
  665     XawTextBlock        textblock;
  666     XawTextPosition pos, left, right;
  667     char        *searchString;
  668 
  669     searchString = XawDialogGetValueString(searchPopup);
  670     if (strlen(searchString) == 0) {
  671     textblock.ptr = XFetchBytes(display, &textblock.length);
  672     if (!textblock.ptr) {
  673         UpdateMessageWindow("No search string selected", NULL);
  674         bell(0);
  675         return;
  676     }
  677     searchString = textblock.ptr;
  678     }
  679     pos = XawTextGetInsertionPoint(sourceWindow);
  680     if ((direction == (XtPointer)FORWARD && 
  681     forwardSearch(displayedFile->buf, pos, searchString, &left, &right)) ||
  682         (direction == (XtPointer)REVERSE && 
  683     reverseSearch(displayedFile->buf, pos, searchString, &left, &right))) {
  684         AdjustText(TextPositionToLine(left));
  685         XawTextSetSelection(sourceWindow, left, right);
  686         XawTextSetInsertionPoint(sourceWindow, left);
  687     }
  688     else {
  689         if (direction == (XtPointer)FORWARD)
  690             UpdateMessageWindow("String not found", NULL);
  691         else if (direction == (XtPointer)REVERSE)
  692             UpdateMessageWindow("String not found", NULL);
  693         else
  694 #ifdef GDB
  695             UpdateMessageWindow("xxgdb error: illegal search direction", NULL);
  696 #else
  697             UpdateMessageWindow("xdbx error: illegal search direction", NULL);
  698 #endif
  699         bell(0);
  700     }
  701 }
  702 
  703 /* ARGSUSED */
  704 static void DoneSearch(w, client_data, call_data)
  705     Widget w;
  706     XtPointer client_data;
  707     XtPointer call_data;
  708 {
  709     XtPopdown(client_data);
  710 }
  711 
  712 /* ARGSUSED */
  713 static void Activate(w, event, params, num_params)
  714     Widget w;
  715     XEvent *event;
  716     String *params;
  717     Cardinal *num_params;
  718 {
  719     Search(w, (XtPointer)FORWARD, NULL);
  720     DoneSearch(w, (XtPointer)searchPopupShell, NULL);
  721 }
  722 
  723 static void CreateSearchPopup()
  724 {
  725     Widget  dialogValue;
  726     Arg     args[MAXARGS];
  727     Cardinal    n;
  728 
  729     static XtActionsRec search_actions[] = {
  730         {"Activate", Activate},
  731         {NULL, NULL}
  732     };
  733 
  734     static String translations = "#override\n\
  735         <Key>Return:         Activate() \n\
  736     ";
  737 
  738     n = 0;
  739     XtSetArg(args[n], XtNinput, True);                  n++;
  740     XtSetArg(args[n], XtNallowShellResize, True);           n++;
  741     searchPopupShell = XtCreatePopupShell("Search", transientShellWidgetClass, 
  742     toplevel, args, n);
  743 
  744     n = 0;
  745     XtSetArg(args[n], XtNlabel, "Enter search string :");       n++;
  746     XtSetArg(args[n], XtNvalue, SearchString);              n++;
  747     searchPopup = XtCreateManagedWidget("searchPopup", dialogWidgetClass, 
  748     searchPopupShell, args, n);
  749     
  750     AddButton(searchPopup, "<<", Search, (XtPointer) REVERSE);
  751     AddButton(searchPopup, ">>", Search, (XtPointer) FORWARD);
  752     AddButton(searchPopup, "DONE", DoneSearch, (XtPointer)searchPopupShell);
  753 
  754     dialogValue = XtNameToWidget(searchPopup, "value");
  755     XtOverrideTranslations(dialogValue, XtParseTranslationTable(translations));
  756     XtAppAddActions(app_context, search_actions, XtNumber(search_actions));
  757 }
  758 
  759 
  760 
  761 static Widget AddButton(parent, name, function, client_data)
  762 Widget parent;
  763 char *name;
  764 void (*function) ();
  765 XtPointer client_data;      /* callback registered data */
  766 {
  767     Widget  button;
  768     Arg     args[MAXARGS];
  769     Cardinal    n;
  770 
  771     static XtActionsRec command_actions[] = {
  772     {"ButtonSet", (XtActionProc) ButtonSet},
  773         {NULL, NULL}
  774     };
  775 
  776     static String translations = "\
  777     <EnterWindow>:  highlight() \n\
  778     <LeaveWindow>:  reset() \n\
  779     <Btn1Down>: set()\n\
  780     <Btn1Up>:   ButtonSet(1) notify() unset() \n\
  781     <Btn3Down>: set()\n\
  782     <Btn3Up>:   ButtonSet(3) notify() unset()\n\
  783     ";
  784 
  785     n = 0;
  786     XtSetArg(args[n], XtNresize, (XtArgVal) False);         n++;
  787     if (strcmp(name, "print") == 0 || strcmp(name, "print *") == 0) {
  788     XtSetArg(args[n], XtNtranslations, 
  789         XtParseTranslationTable(translations));             n++;
  790     }
  791     button = XtCreateManagedWidget(name, commandWidgetClass, parent, args, n);
  792     XtAddCallback(button, XtNcallback, function, client_data);
  793     XtAppAddActions(app_context, command_actions, XtNumber(command_actions));
  794     return (button);
  795 }
  796 
  797 
  798 static void CreateButtons (parent)
  799 Widget parent;
  800 {
  801     int i=0;
  802 
  803 #ifdef GDB  /* >>>>>>>>>>>>>> GDB ONLY <<<<<<<<<<<<<<<< */
  804     button[i++] = AddButton (parent, "run", DoIt, "run\n");
  805     button[i++] = AddButton (parent, "cont", DoIt, "cont\n");
  806     button[i++] = AddButton (parent, "next", DoIt, "next\n");
  807     button[i++] = AddButton (parent, "step", DoIt, "step\n");
  808     button[i++] = AddButton (parent, "finish", DoIt, "finish\n");
  809     button[i++] = AddButton (parent, "break", Break, "break");
  810     button[i++] = AddButton (parent, "tbreak", Break, "tbreak");
  811     button[i++] = AddButton (parent, "delete", Delete, NULL);
  812     button[i++] = AddButton (parent, "up", DoIt, "up\n");
  813     button[i++] = AddButton (parent, "down", DoIt, "down\n");
  814     button[i++] = AddButton (parent, "print", Print, (XtPointer)0);
  815     button[i++] = AddButton (parent, "print *", Print, (XtPointer)1);
  816     button[i++] = AddButton (parent, "display", Display_, NULL);
  817     button[i++] = AddButton (parent, "undisplay", Undisplay, NULL);
  818     button[i++] = AddButton (parent, "show display", DoIt, "info display\n");     /* AJK */
  819     button[i++] = AddButton (parent, "args", DoIt, "info args\n");
  820     button[i++] = AddButton (parent, "locals", DoIt, "info locals\n");
  821     button[i++] = AddButton (parent, "stack", DoIt, "info stack\n");
  822 #ifdef EDIT_BUTTON
  823     button[i++] = AddButton (parent, "edit", EdCallback, NULL);
  824 #endif
  825     button[i++] = AddButton (parent, "search", PopupSearch, NULL);
  826     button[i++] = AddButton (parent, "interrupt", Interrupt, NULL); /* DH */
  827     button[i++] = AddButton (parent, "file", File, NULL);
  828     button[i++] = AddButton (parent, "show brkpts", DoIt, "info breakpoints\n");  /* AJK */
  829     button[i++] = AddButton (parent, "yes", DoIt, "y\n");                         /* AJK */
  830     button[i++] = AddButton (parent, "no", DoIt, "n\n");                          /* AJK */
  831     button[i++] = AddButton (parent, "quit", Quit, NULL);
  832 #else   /* >>>>>>>>>> IF NOT GDB <<<<<<<<<<<<<<< */
  833 
  834 
  835     button[i++] = AddButton (parent, "run", DoIt, "run\n");
  836     button[i++] = AddButton (parent, "rerun", DoIt, "rerun\n");               /* AJK */
  837     button[i++] = AddButton (parent, "cont", DoIt, "cont\n");
  838     button[i++] = AddButton (parent, "next", DoIt, "next\n");
  839     button[i++] = AddButton (parent, "step", DoIt, "step\n");
  840     button[i++] = AddButton (parent, "nexti", DoIt, "nexti\n");               /* AJK */
  841     button[i++] = AddButton (parent, "stepi", DoIt, "stepi\n");               /* AJK */
  842 #ifdef BSD
  843     button[i++] = AddButton (parent, "return", Return, "return\n");
  844 #endif
  845     button[i++] = AddButton (parent, "stop at", Stop_at, NULL);
  846     button[i++] = AddButton (parent, "stop in", Stop_in, NULL);
  847     button[i++] = AddButton (parent, "delete", Delete, NULL);
  848     button[i++] = AddButton (parent, "where", DoIt, "where\n");
  849     button[i++] = AddButton (parent, "up", DoIt, "up\n");
  850     button[i++] = AddButton (parent, "down", DoIt, "down\n");
  851     button[i++] = AddButton (parent, "print", Print, (XtPointer)0);
  852     button[i++] = AddButton (parent, "print *", Print, (XtPointer)1);
  853     button[i++] = AddButton (parent, "func", Func, NULL);
  854     button[i++] = AddButton (parent, "file", File, NULL);
  855     button[i++] = AddButton (parent, "status", DoIt, "status\n");
  856 #ifndef BSD
  857     button[i++] = AddButton (parent, "display", Display_, NULL);
  858     button[i++] = AddButton (parent, "undisplay", Undisplay, NULL);
  859 #endif
  860     button[i++] = AddButton (parent, "dump", Dump, NULL);
  861     button[i++] = AddButton (parent, "search", PopupSearch, NULL);
  862     button[i++] = AddButton (parent, "trace",   WhCmds, "trace");    /* AJK */
  863     button[i++] = AddButton (parent, "whereis", WhCmds, "whereis");  /* AJK */
  864     button[i++] = AddButton (parent, "whatis",  WhCmds, "whatis");   /* AJK */
  865     button[i++] = AddButton (parent, "which",   WhCmds, "which");    /* AJK */
  866     button[i++] = AddButton (parent, "dbxenv",  DoIt, "dbxenv\n");   /* AJK */
  867     button[i++] = AddButton (parent, "make",    DoIt, "make\n");     /* AJK */
  868     button[i++] = AddButton (parent, "modules", DoIt, "modules\n");  /* AJK */
  869     button[i++] = AddButton (parent, "pwd",     DoIt, "pwd\n");      /* AJK */
  870     button[i++] = AddButton (parent, "quit", Quit, NULL);
  871 #endif /* NOT GDB */
  872 
  873     button[i++] = NULL;
  874     CreateSearchPopup();
  875 }
  876 
  877 
  878 /*  Create a command widget, and the buttons.  */
  879 
  880 void CreateCommandPanel(parent)
  881 Widget parent;
  882 {
  883     Arg args[10];
  884     Cardinal n;
  885 
  886     n = 0;
  887     commandWindow = XtCreateManagedWidget("commandWindow", boxWidgetClass, 
  888                       parent, args, n);
  889     CreateButtons(commandWindow);
  890 #ifndef GDB /* (PW)12MAR93 : for gdb, use pwd command of gdb */
  891 #ifndef SYSV 
  892     getwd(cwd);
  893 #endif
  894 #endif /* not GDB */
  895 }
  896 
  897 /**************************************************************************
  898  *
  899  *  Command queue functions
  900  *
  901  **************************************************************************/
  902 
  903 /*  Append command to end of the command queue and send the command to dbx */
  904 
  905 void send_command(command)
  906 char *command;
  907 {
  908     CommandRec *p, *q, *r;
  909 
  910 #ifndef GDB 
  911 #ifdef BSD 
  912     /* Save the command if it is not a blank command; else use the 
  913        last saved command instead */
  914     if (strcspn(command, " \n"))
  915     strcpy(savedCommand, command);
  916     else
  917     strcpy(command, savedCommand);
  918 #endif
  919 #endif  /* not GDB */
  920 
  921     p = (CommandRec *)XtNew(CommandRec);
  922     p->command = XtNewString(command);
  923     p->next = NULL;
  924     if (!commandQueue)
  925     commandQueue = p;
  926     else {
  927     q = commandQueue;
  928     while ((r = q->next))
  929         q = r;
  930     q->next = p;
  931     }
  932 
  933 #ifdef GDB
  934     write_dbx_available();
  935 #else
  936     write_dbx(command);
  937 #endif /* GDB */
  938 }
  939 
  940 /*  Read command at the head of the command queue */
  941 
  942 char *get_command()
  943 {
  944     if (commandQueue) {
  945     return (commandQueue->command);
  946     }
  947     else
  948     return NULL;
  949 }
  950 
  951 /*  Delete command from the head of the command queue */
  952 
  953 void delete_command()
  954 {
  955     CommandRec *p;
  956 
  957     if ((p = commandQueue)) {
  958     commandQueue = p->next;
  959     XtFree(p->command);
  960     XtFree((void*)p);
  961     }
  962 }
  963 
  964 /*  Insert command into head of queue */
  965 
  966 void insert_command(command)
  967 char *command;
  968 {
  969     CommandRec *p;
  970 
  971     p = (CommandRec *)XtNew(CommandRec);
  972     p->command = XtNewString(command);
  973     p->next = NULL;
  974     if (!commandQueue)
  975     commandQueue = p;
  976     else {
  977     p->next = commandQueue;
  978     commandQueue = p;
  979     }
  980 }