"Fossies" - the Fresh Open Source Software Archive

Member "xxgdb-1.12/dialog.c" (19 Jun 1995, 13269 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  *****************************************************************************/
   60 
   61 /*  dialog.c
   62  *
   63  *    Create the dialogue window where the user enter dbx commands, and
   64  *    provide action procs to make a text widget behave like a terminal.
   65  *
   66  *    InsertSpace():    Prevent user from deleting past the prompt (action proc
   67  *          for DELETE or BACKSPACE).
   68  *    DeleteWord(): Word delete in dialog window. (action proc for Ctrl-w).
   69  *    DeleteLine(): Line delete in dialog window. (action proc for Ctrl-u).
   70  *    Dispatch():   Send an input command line to dbx. (action proc for CR).
   71  *    SigInt():     Send SIGINT to dbx (action proc for Ctrl-C).
   72  *    SigEof():     Send an EOF signal to dbx (action proc for Ctrl-D).
   73  *    SigQuit():    Send SIGQUIT to dbx (action proc for Ctrl-\).
   74  *    CreateDialogWindow(): Create dialog window and install action table.
   75  *    AppendDialogText():       Append string to dialog window.
   76  */
   77 
   78 #include <signal.h>
   79 #include "global.h"
   80 
   81 #define DIALOGSIZE  100000      /* max size of dialogue window buffer */
   82 
   83 Widget  dialogWindow;           /* text window as a dbx terminal */
   84 Boolean FalseSignal = FALSE;        /* set to TRUE before self-generated
   85                        interrupt/quit signals */
   86 static char DialogText[DIALOGSIZE]; /* text buffer for widget */
   87 static XawTextPosition  StartPos;       /* starting position of input text */
   88 
   89 
   90 /*  This procedure prevents the user from deleting past the prompt, or
   91  *  any text appended by AppendDialogText() to the dialog window.
   92  *  It checks the last position of text, if it matches StartPos, set
   93  *  by AppendDialogText(), it inserts a space so that delete-previous-
   94  *  character() can only delete the space character.
   95  */
   96 /* ARGSUSED */
   97 static void InsertSpace(w, event, params, num_params)
   98     Widget w;
   99     XEvent *event;
  100     String *params;
  101     Cardinal *num_params;
  102 {
  103     XawTextBlock    textblock;
  104     XawTextPosition lastPos;
  105 
  106     if (XawTextGetInsertionPoint(w) <= StartPos) {
  107         lastPos = TextGetLastPos(w);
  108     if (lastPos == StartPos) {
  109         textblock.firstPos = 0;
  110         textblock.length   = 1;
  111         textblock.ptr      = " ";
  112         XawTextReplace(w, lastPos, lastPos, &textblock);
  113         XawTextSetInsertionPoint(w, lastPos+1);
  114     }
  115     }
  116 }
  117 
  118 /*  Erases the preceding word.
  119  *  Simulates the action of the WERASE character (ctrl-W).
  120  */
  121 /* ARGSUSED */
  122 void DeleteWord(w, event, params, num_params)
  123     Widget w;
  124     XEvent *event;
  125     String *params;
  126     Cardinal *num_params;
  127 {
  128     XawTextBlock        textblock;
  129     XawTextPosition pos;
  130     Cardinal        i;
  131 
  132     textblock.firstPos = 0;
  133     textblock.length   = 0;
  134     textblock.ptr      = "";
  135 
  136     pos = XawTextGetInsertionPoint(w); 
  137     if (pos <= StartPos)
  138         pos = TextGetLastPos(w); 
  139     for (i=pos; i > StartPos && DialogText[i-1] == ' '; i--);
  140     for (; i > StartPos && DialogText[i-1] != ' '; i--);
  141     XawTextReplace(w, i, pos, &textblock);
  142     XawTextSetInsertionPoint(w, i);
  143 }
  144 
  145 
  146 /*  Deletes the entire current input line.
  147  *  simulates the action of the KILL character (ctrl-U).
  148  */
  149 /* ARGSUSED */
  150 void DeleteLine(w, event, params, num_params)
  151     Widget w;
  152     XEvent *event;
  153     String *params;
  154     Cardinal *num_params;
  155 {
  156     XawTextBlock        textblock;
  157     XawTextPosition     pos, beginPos;
  158     Cardinal        i;
  159     char        *s;
  160 
  161     textblock.firstPos = 0;
  162     textblock.length   = 0;
  163     textblock.ptr      = "";
  164 
  165     pos = XawTextGetInsertionPoint(w); 
  166     if (w == dialogWindow) {
  167     s = DialogText;
  168     beginPos = StartPos;
  169     if (pos <= beginPos)
  170             pos = TextGetLastPos(w);
  171     } else {
  172         return;
  173     }
  174     for (i=pos; i > beginPos && s[i-1] != '\n'; i--);
  175     XawTextReplace(w, i, pos, &textblock);
  176     XawTextSetInsertionPoint(w, i);
  177 }
  178 
  179 
  180 /*  Dispatch() is invoked on every <CR>.
  181  *  It collects text from the dialog window and sends it to dbx.
  182  *  If the string is a command to dbx (Prompt would be TRUE),
  183  *  it is stored in the global variable, Command.
  184  */
  185 /* ARGSUSED */
  186 static void Dispatch(w, event, params, num_params)
  187     Widget w;
  188     XEvent *event;
  189     String *params;
  190     Cardinal *num_params; 
  191 {
  192 #ifdef GDB
  193     /* 
  194     For GDB, '\n' means exec previous command again.
  195     default command is space+CR, so that we never send
  196     CR to gdb (the repeat is managed here)
  197     */
  198     static char gdb_command[LINESIZ] = " \n";
  199 #endif
  200 char s[LINESIZ];
  201 
  202     strcpy(s, DialogText + StartPos);
  203 #if 1
  204     /* (PW)18DEC90 : bug xdbx : without the following line,
  205     xdbx sends several times the same lines when Prompt is false */
  206     StartPos = TextGetLastPos(dialogWindow);
  207 #endif
  208 
  209     if (Prompt)
  210         {
  211 #ifdef GDB
  212         /* When we send \n to gdb, it executes the last command,
  213         so better tell xxgdb what gdb is doing */
  214         if (strcmp(s, "\n"))
  215             strcpy(gdb_command,s);  /* if not "\n" ! */
  216         else
  217             {
  218             /* copy previous command in new command, and
  219             echo the command in the dialog window. */
  220             strcpy(s,gdb_command);
  221             AppendDialogText(gdb_command);
  222             }
  223 #endif /* GDB */
  224         send_command (s);
  225         }
  226     else
  227         /* this string is for the application, not for gdb */
  228         write_dbx(s);
  229 }
  230 
  231 /*  Sends an interrupt signal, SIGINT, to dbx.
  232  *  Simulates the action of the INTR character (ctrl-C).
  233  */
  234 void signal_interrupt_dbx()
  235 {
  236 #ifndef GDB
  237     FalseSignal = TRUE;
  238 #ifdef SYSV /* (PW)13AUG92:  change SVR4 into SYSV */ /* (MJH) */
  239    kill(-(dbxpid), SIGINT);
  240 #else
  241    killpg(dbxpid, SIGINT);
  242 #endif /* SYSV */
  243 #else      
  244     write_dbx("\003");  /* (PW)18FEB91 : seems to work better */
  245 #endif  /* GDB */
  246 }
  247 
  248 /*  Sends an interrupt signal, SIGINT, to dbx.
  249  *  Simulates the action of the INTR character (ctrl-C).
  250  */
  251 /* ARGSUSED */
  252 static void SigInt(w, event, params, num_params)
  253     Widget w;
  254     XEvent *event;
  255     String *params;
  256     Cardinal *num_params;
  257 {
  258   signal_interrupt_dbx ();
  259 }
  260 
  261 /*  Sends an EOF signal to dbx. (ctrl-D) */
  262 /* ARGSUSED */
  263 static void SigEof(w, event, params, num_params)
  264     Widget w;
  265     XEvent *event;
  266     String *params;
  267     Cardinal *num_params;
  268 {
  269     write_dbx("\04");
  270 }
  271 
  272 
  273 /*  Sends a QUIT signal, SIGQUIT, to dbx. 
  274  *  Simulates the action of the QUIT character (ctrl-\) 
  275  */
  276 /* ARGSUSED */
  277 static void SigQuit(w, event, params, num_params)
  278     Widget w;
  279     XEvent *event;
  280     String *params;
  281     Cardinal *num_params;
  282 {
  283     FalseSignal = TRUE;
  284 
  285 #ifdef SYSV /* (PW)13AUG92:  change SVR4 into SYSV */ /* (MJH) */
  286     kill(-(dbxpid), SIGQUIT);
  287 #else
  288     killpg(dbxpid, SIGQUIT);
  289 #endif /* SYSV */
  290 }
  291 
  292 
  293 /* 
  294  *  Dialog window has its own set of translations for editing.
  295  *  Special action procedures for keys Delete/Backspace, Carriage Return,
  296  *  Ctrl-U, Ctrl-C, Ctrl-D, Ctrl-\, and word selection.
  297  */
  298 void CreateDialogWindow(parent)
  299 Widget parent;
  300 {
  301     Arg     args[MAXARGS];
  302     Cardinal    n;
  303 
  304     static XtActionsRec dialog_actions[] = {
  305     {"SigInt",  (XtActionProc) SigInt},
  306     {"SigEof",  (XtActionProc) SigEof},
  307     {"SigQuit",     (XtActionProc) SigQuit},
  308     {"InsertSpace", (XtActionProc) InsertSpace},
  309     {"Dispatch",    (XtActionProc) Dispatch},
  310         {NULL, NULL}
  311     };
  312 
  313     static String translations = "#override\n\
  314     Ctrl<Key>C: SigInt()\n\
  315     Ctrl<Key>D: SigEof()\n\
  316     Ctrl<Key>|: SigQuit()\n\
  317     Ctrl<Key>W: DeleteWord()\n\
  318     Ctrl<Key>U: DeleteLine()\n\
  319     Ctrl<Key>H: InsertSpace() delete-previous-character()\n\
  320     <Key>Delete:    InsertSpace() delete-previous-character()\n\
  321     <Key>BackSpace: InsertSpace() delete-previous-character()\n\
  322     <Key>Return:    newline() Dispatch()\n\
  323     ";
  324 
  325     n = 0;
  326     XtSetArg(args[n], XtNuseStringInPlace, True);                       n++;
  327     XtSetArg(args[n], XtNstring, (XtArgVal) DialogText);        n++;
  328     XtSetArg(args[n], XtNlength, (XtArgVal) DIALOGSIZE);        n++;
  329     XtSetArg(args[n], XtNeditType, (XtArgVal) XawtextAppend);       n++;
  330     XtSetArg(args[n], XtNscrollVertical, XawtextScrollAlways);      n++;
  331     XtSetArg(args[n], XtNwrap, XawtextWrapWord);            n++;
  332     dialogWindow = XtCreateManagedWidget("dialogWindow", asciiTextWidgetClass,
  333                      parent, args, n );
  334     XtOverrideTranslations(dialogWindow, XtParseTranslationTable(translations));
  335     XtAppAddActions(app_context, dialog_actions, XtNumber(dialog_actions));
  336 }
  337 
  338 #if 0 /* never used */
  339 static void TextSetLastPos(w, lastPos)
  340 Widget w;
  341 XawTextPosition lastPos;
  342 {
  343     TextWidget ctx = (TextWidget) w;
  344     ctx->text.lastPos = lastPos;
  345 }
  346 #endif
  347  
  348 void AppendDialogText(s)
  349     char   *s;
  350 {
  351     XawTextPosition     i, lastPos;
  352     XawTextBlock        textblock, nullblock;
  353 
  354     if (!s || !strcmp(s, "")) return;
  355 
  356     if (debug) {
  357         fprintf(stderr, "AppendDialogText \"%s\"\n", s);
  358     }
  359 
  360     textblock.firstPos = 0;
  361     textblock.length   = strlen(s);
  362     textblock.ptr      = s;
  363 
  364     lastPos = TextGetLastPos(dialogWindow);
  365     if (textblock.length > DIALOGSIZE) {
  366     bell(0);
  367 #ifdef GDB
  368     fprintf(stderr, "xxgdb error: cannot display string in dialogue window\n\
  369             string has %d bytes; dialogue window size limit is %d bytes\n",
  370         textblock.length, DIALOGSIZE);
  371 #else
  372     fprintf(stderr, "xdbx error: cannot display string in dialogue window\n\
  373             string has %d bytes; dialogue window size limit is %d bytes\n",
  374         textblock.length, DIALOGSIZE);
  375 #endif
  376         return;
  377     }
  378     if (lastPos + textblock.length > DIALOGSIZE) {
  379     nullblock.firstPos = 0;
  380     nullblock.length = 0;
  381     nullblock.ptr = "";
  382 
  383     i = textblock.length - (DIALOGSIZE - lastPos);
  384     if (i < 0.9*DIALOGSIZE)
  385         i += 0.1*DIALOGSIZE;
  386         while (DialogText[i] != '\n') i++;
  387         XawTextReplace(dialogWindow, 0, i+1, &nullblock);
  388         lastPos = TextGetLastPos(dialogWindow);
  389     }
  390     XawTextReplace(dialogWindow, lastPos, lastPos, &textblock);
  391     StartPos = TextGetLastPos(dialogWindow);
  392     XawTextSetInsertionPoint(dialogWindow, StartPos);
  393 
  394 #if 0 /* no longer necessary I think */
  395 /* fix annoying bug that dialog mark is sometimes scrolled off bottom (widget bug?) */
  396     XawTextDisplay(dialogWindow);
  397 #endif
  398 
  399 #if defined(OLDSUNOS)||defined(SUNOS4)
  400 /* Have experienced bug where dialog window actually writes off bottom
  401 (does not scroll to bottom).  Seems more prevalent with Openwindows,
  402 but since it needs to debug certain programs to get this to show up.
  403 Couldn't find the problem, but this works around it: (really icky but
  404 only way I found to fix it) */
  405 
  406     if (StartPos >= ((TextWidget)dialogWindow)->text.lt.info[((TextWidget)dialogWindow)->text.lt.lines].position)
  407        XtCallActionProc(dialogWindow, "redraw-display", 0, 0, 0);
  408 #endif /* SUNOS */
  409 }
  410