Path: uunet!wuarchive!cs.utexas.edu!sun-barr!newstop!male!jethro!exodus!tce.COM
From: pierre@tce.COM (Pierre Willard)
Newsgroups: comp.sources.x
Subject: REPOST: v11i054: xxgdb - X front end for gdb, Part07/08
Message-ID: <9290@exodus.Eng.Sun.COM>
Date: 7 Mar 91 08:19:56 GMT
References: <csx-11i048:xxgdb@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 1605
Approved: argv@sun.com

Submitted-by: pierre@tce.COM (Pierre Willard)
Posting-number: Volume 11, Issue 54
Archive-name: xxgdb/part07


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 5 (of 8)."
# Contents:  gdb_parser.c handler.c xdbx.c
# Wrapped by gilbert@phi on Tue Jan 15 13:12:48 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'gdb_parser.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdb_parser.c'\"
else
echo shar: Extracting \"'gdb_parser.c'\" \(16574 characters\)
sed "s/^X//" >'gdb_parser.c' <<'END_OF_FILE'
X/*****************************************************************************
X *
X *  xdbx - X Window System interface to the dbx debugger
X *
X *  Copyright 1989 The University of Texas at Austin
X *  Copyright 1990 Microelectronics and Computer Technology Corporation
X *
X *  Permission to use, copy, modify, and distribute this software and its
X *  documentation for any purpose and without fee is hereby granted,
X *  provided that the above copyright notice appear in all copies and that
X *  both that copyright notice and this permission notice appear in
X *  supporting documentation, and that the name of The University of Texas
X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
X *  used in advertising or publicity pertaining to distribution of
X *  the software without specific, written prior permission.  The
X *  University of Texas and MCC makes no representations about the 
X *  suitability of this software for any purpose.  It is provided "as is" 
X *  without express or implied warranty.
X *
X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X *  Author:  	Po Cheung
X *  Created:   	March 10, 1989
X * 
X *****************************************************************************
X * 
X *  xxgdb - X Window System interface to the gdb debugger
X *  
X * 	Copyright 1990 Thomson Consumer Electronics, Inc.
X *  
X *  Permission to use, copy, modify, and distribute this software and its
X *  documentation for any purpose and without fee is hereby granted,
X *  provided that the above copyright notice appear in all copies and that
X *  both that copyright notice and this permission notice appear in
X *  supporting documentation, and that the name of Thomson Consumer
X *  Electronics (TCE) not be used in advertising or publicity pertaining
X *  to distribution of the software without specific, written prior
X *  permission.  TCE makes no representations about the suitability of
X *  this software for any purpose.  It is provided "as is" without express
X *  or implied warranty.
X *
X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X *  SOFTWARE.
X *
X *  Adaptation to GDB:  Pierre Willard
X *  XXGDB Created:   	December, 1990
X *
X *****************************************************************************/
X
X/*  gdb_parser.c:
X *
X *	WARNING : gdb_parser.c is included by parser.c for GDB.
X *
X *    Parse output messages from dbx using regular expression pattern matching,
X *    and take appropriate action.
X *
X *    parse():		Parse the dbx output and invoke the appropriate action
X *			handler.
X *    filter():		Modify the dbx output before it gets displayed on the
X *			dialog window.
X *    gdb_source_command():	Test for source command.
X */
X
X#include 	<string.h>
X
X/*--------------------------------------------------------------------------+
X|																			|
X|	Function to remove all 'Reading in symbols' message						|
X|	from a string.															|
X|																			|
X|	This function is used in parser() before matching the output			|
X|	because this message can happen any time.								|
X|																			|
X+--------------------------------------------------------------------------*/
Xvoid filter_reading_symbols(output)
Xchar *output;
X{
Xstruct re_registers regs;
Xint	r;
Xchar *p1;
Xchar *p2;
X
X		/* test for reading symbols message */
X	
X	while (re_match(output_pattern[O_READING_SYMBOLS].buf,output,strlen(output),0,&regs) > 0)
X		{
X		/* we found a "Reading in symbols for 	...done." pattern */
X		
X		r = output_pattern[O_READING_SYMBOLS].reg_token[TK_MESG];
X		p1=  output+regs.start[r];
X		p2 = output+regs.end[r];
X		
X		/* remove "Reading in symbols for 	...done." */
X		
X		while(*(p1++) = *(p2++));
X		}
X}
X
X/*--------------------------------------------------------------------------+
X|																			|
X| *	 This routine first parses the command string.							|
X| *	 If the command is one of run, cont, next, step, stop at, stop in,		|
X| *	 where, up, or down, it parses the dbx output to decide what action		|
X| *	 to take and dispatch it to one of the handlers.						|
X| *	 For other commands, the appropriate handler is called.					|
X| *																			|
X| *	 !!! This routine has to be re-entrant.									|
X| *																			|
X+--------------------------------------------------------------------------*/
Xvoid parse(output, command)
Xchar *output;
Xchar *command;
X{
X    int  command_type;
X    char *output_string;
X
X    if (debug) {
X	fprintf(stderr, "parse(output = %s, command = %s)\n", output, command);
X    }
X
X    /* Make a local copy of `output' and use that instead */
X    output_string = XtNewString(output);
X    if (output) strcpy(output, "");
X
X    if (!command) {
X	if (match(output_pattern, output_string, O_DEBUG) != -1)
X	    debug_handler(); 
X	debug_init();
X	XtFree(output_string);
X	return;
X    }
X    
X    if (!Parse)
X    	{
X    	XtFree(output_string);
X		return;
X		}
X
X	if (match(output_pattern, output_string, O_BELL) != -1)
X		{
X		bell(0);
X    	XtFree(output_string);
X		return;
X		}
X	
X    command_type = match(command_pattern, command, C_ANY);
X    
X    
X    /* remove all "Reading in symbols for pw.c...done."  */
X
X	filter_reading_symbols(output_string);
X        	
X    switch (command_type) {
X      	case C_EXEC: 
X		case C_FINISH:
X		{
X		char * message;
X		int signal;
X		message = 0;
X		if (match(output_pattern, output_string, O_RECEIVED_SIGNAL) != -1)
X			{
X			message = XtNewString(Token.mesg);
X			signal = Token.stop;	/* signal number received */
X			}
X			
X		/* warning : the order of the matching tests is important */
X		
X	    if ((match(output_pattern, output_string, O_EXEC_MESS_AFTER) != -1)
X	    	|| (match(output_pattern, output_string, O_EXEC_MESS_BEFORE) != -1)
X	    	|| (match(output_pattern, output_string, O_EXEC) != -1))
X			{
X			exec_handler(message,signal);
X			}
X	    else 
X	    	{
X			if (match(output_pattern, output_string, O_DONE) != -1)
X				done_handler(message,signal);
X			else
X				bell(0);
X			}
X			
X		if (message)
X			{
X			bell(0);
X			XtFree(message);
X			}
X		}
X	    break;
X	    
X	case C_UPDOWN:
X	    if (match(output_pattern, output_string, O_UPDOWN) != -1)
X		updown_handler();
X	    else
X		bell(0);
X	    break;
X	case C_SEARCH:
X	    if (match(output_pattern, output_string, O_SEARCH) != -1)
X		search_handler();
X	    else
X		bell(0);
X	    break;
X	case C_DELETE:
X	    delete_handler(); 
X	    break;
X	case C_LIST:
X	    if (match(output_pattern, output_string, O_LIST) != -1)
X	        list_handler();
X	    else
X		bell(0);
X	    break;
X	    
X	case C_BREAK: 
X	    if (match(output_pattern, output_string, O_BREAK) != -1)
X			break_handler();
X	    else
X		bell(0);
X	    break;
X	    
X	case C_INFO_DIR:
X	    if (match(output_pattern, output_string, O_INFO_DIR) != -1)
X	        info_dir_handler();
X	    else
X		bell(0);	
X		break;
X		
X	case C_DIRECTORY:
X	    directory_handler(); 
X	    break;
X	    
X	case C_INFO_LINE:
X	    if (match(output_pattern, output_string, O_INFO_LINE) != -1)
X	    	info_line_handler();		/* command was 'info line' */
X	    else
X		bell(0);
X	    break;
X	    
X	case C_INFO_BREAK:
X	    info_break_handler(output_string);
X	    break;
X
X	case C_DISPLAY:
X		{
X	    if ((strcmp(output_string, "") == NULL) ||
X	    	(match(output_pattern, output_string, O_DISPLAY) != -1))
X	    	display_handler();
X	    else
X		bell(0);
X		}
X	    break;
X	    
X	case C_UNDISPLAY:
X	    if (strcmp(output_string, "") == NULL)
X			display_handler();
X	    else
X		bell(0);
X	    break;
X
X	case C_DISPLAY_INFO:
X		{
X	    if ((strcmp(output_string, "") == NULL) ||
X	    	(match(output_pattern, output_string, O_DISPLAY_INFO) != -1))
X	    	display_info_handler();
X	    else
X		bell(0);
X		}
X	    break;
X	    
X	case C_CD:
X	    if (match(output_pattern, output_string, O_CD) != -1)
X	    	cd_handler(Token.mesg); 
X	    else
X		bell(0);
X	    break;
X	    
X	case C_PWD:
X	    if (match(output_pattern, output_string, O_PWD) != -1)
X			pwd_handler(Token.mesg);
X	    else
X		bell(0);
X	    break;
X
X	case C_FRAME_CURR:
X	    if (match(output_pattern, output_string, O_FRAME_CURR) != -1)
X		frame_curr_handler();
X	    else
X		bell(0);
X	    break;
X
X	case C_PRINT:
X		{
X		/* for GDB, the label of the popup display is the expression
X		string which is printed instead of $n */
X		char * prtname;
X		prtname = 0;
X		if ((Token.mesg) && (PopupMode))
X			prtname = XtNewString(Token.mesg);
X			
X	    if (match(output_pattern, output_string, O_PRINT) != -1)
X	    	{
X	    	if (prtname)
X	    		{
X				XtFree(Token.mesg);
X				Token.mesg = prtname;
X				prtname = 0;			/* not to XtFree twice this string */
X				}
X	    	print_handler(output_string);
X	    	}
X	    else
X		bell(0);
X		
X		/* if PopupMode was true but GDB found an error in print
X		statement (ie match() returned -1), PopupMode was never reset */
X		PopupMode = FALSE;	 
X		
X		XtFree(prtname);
X		}
X	    break;
X	    
X	case C_SYMBOL_FILE:
X		debug_handler(); 
X	    break;
X
X	case C_SOURCE:	/* WE SHOULD NEVER ARRIVE HERE */
X		break;
X
X	case C_EXEC_FILE:
X		break;
X		
X	default:
X	    break;
X    }
X    XtFree(output_string);
X}
X
X/*--------------------------------------------------------------------------+
X|																			|
X|	Function to filter all the display information in a string				|
X|																			|
X|	input : string pointer.													|
X|																			|
X|	output : none.															|
X|																			|
X|	See O_EXEC_DISPLAY in gdb_regex.h for the display pattern.				|
X|																			|
X|	Take care when GDB send some message after '\032\032...\n'				|
X|	which is not a display line.											|
X|																			|
X| (gdb) finish																|
X| Run till exit from #0	 foo (n=1) (pw.c line 9)							|
X| main () (pw.c line 41)													|
X| /usr1/gnu_sun4/xxgdb/pw.c:41:590:beg:0x232c								|
X| 1: i = 1																	|
X| Value returned is $1 = 1													|
X| (gdb)																		|
X|																			|
X+--------------------------------------------------------------------------*/
Xvoid filter_display_info(output)
Xchar *output;
X{
Xstruct re_registers regs;
Xint	r;
Xchar *p;
Xchar *p1;
Xchar *p2;
Xchar *cp_output;
Xint begin_struct;
X
X	p = cp_output = XtNewString(output);
X
X	p1 = strstr(p,"\032\032");		/* find beginning of special gdb line */
X	
X	if ((p1 == 0) || ((p2 = strchr(p1+1,'\n')) == 0))
X		{
X		AppendDialogText(p);		/* something wrong here */
X		XtFree(cp_output);
X		return;
X		}
X		
X	*p1 = 0;
X	AppendDialogText(p);			/* print everything before that line */
X	p = p2 + 1;						/* end of that line + skip \n */
X
X	/* test for beginning of a display */
X	
X	while (re_match(output_pattern[O_EXEC_DISPLAY].buf,p,strlen(p),0,&regs) > 0)
X		{
X		/* we found a "X:....\n" pattern */
X		
X		r = output_pattern[O_EXEC_DISPLAY].reg_token[TK_DISP];
X		p1=  p+regs.start[r];
X		p2 = p+regs.end[r];
X					
X		/* count number of { and } : if not equal, the next lines are part of this display */
X		begin_struct = 0;
X		while (p1 < p2)
X			{
X			switch(*(p1++))
X				{
X				case '{':
X					begin_struct++;
X					break;
X				case '}':
X					begin_struct--;
X					break;
X				}
X			}
X			
X		p1=p+regs.start[r];
X		*p1 = 0;
X		if (p != p1)
X			AppendDialogText(p);	/* print what is before display */
X		p = p2;						/* skip display text */
X					
X		if (begin_struct)
X			{
X			/* try to find end of display structure */
X			
X			while(p1 = strstr(p,"}\n"))		/* find next occurrence of "}\n" */
X				{
X				if (p1 && ((p1 == p) || (*(p1-1) == '\n')))
X					{
X					/* this line is the end of the current display */
X					p = p1 + strlen("}\n");
X					break;
X					}
X				}
X			}
X		}
X		
X	AppendDialogText(p);		/* print what is after display */
X	XtFree(cp_output);
X}
X
X/*--------------------------------------------------------------------------+
X|																			|
X| *	 This function edits the dbx output so that unnecessary information is	|
X| *	 not displayed on the dialog window.									|
X| *	 It filters away the some output returned by the execution commands;	|
X| *	 output from the search commands, and the display command.				|
X| *	 On Sun dbx, it also filters away part of the output returned by the	|
X| *	 up and down commands.													|
X| *																			|
X+--------------------------------------------------------------------------*/
Xvoid filter(string, output, command)
Xchar *string, *output, *command;
X{
X    struct re_registers regs;
X    char 		*p;
X    char 		*p2;
X    char 		*p3;
X    int			r;
X    static Boolean	deleteRest = False;
X    int			command_type = -1;
X	static unsigned int already_taken_care;	
X
X    if (output == NULL || strcmp(output, "") == NULL) 
X	return;
X
X/* for GDB, the only things we want to filter are:
X
X	- the line displayed because of the -fullname  option :
X	"\032\032/usr1/gnu_sun4/xdbx/pw.c:6:40:beg:0x22b0\n",
X	
X	- the displayed info which goes into the display window,
X	
X	- list and search outputs
X
X*/
X	if (!string)
X		string = "";
X		
X    if (command)
X    	command_type = match(command_pattern, command, C_ANY);
X    	
X    if ((command_type == C_EXEC)||(command_type == C_FINISH))
X    	{
X		if ((re_match(output_pattern[O_EXEC_MESS_AFTER].buf,string,strlen(string),0,&regs) > 0)
X			|| (re_match(output_pattern[O_EXEC_MESS_BEFORE].buf,string,strlen(string),0,&regs) > 0)
X			|| (re_match(output_pattern[O_EXEC].buf,string,strlen(string),0,&regs) > 0))
X			{
X			/* remember what was the output length was output was matched */
X			already_taken_care = strlen(output) - strlen(string);
X			
X			/* Remove display messages from output and print what is no a display */
X			
X			if (Prompt)
X				filter_display_info(output + already_taken_care);	
X		    else
X				deleteRest = True;
X				
X			return;
X			}
X		else
X			{
X			if (deleteRest)		
X				{
X				/* Remove display messages from output and print what is no a display */
X				if (Prompt)
X					{
X					filter_display_info(output + already_taken_care);	
X					deleteRest = False;
X					}
X				return;
X				}
X			}
X		}
X		
X	/* filter any line starting with \032\032 */
X	
X	p = strchr(string,'\032');
X	if (p && (*(p+1) == '\032') && (p == string || *(p-1) == '\n') && (p2 = strchr(p,'\n')))
X		{
X		while (*(p++) = *(++p2));
X		}
X		
X	if ((command_type == C_EXEC)||(command_type == C_FINISH))
X		{
X		AppendDialogText(string);
X		return;
X		}
X		
X    if (Prompt)
X    	{
X		char *s;
X
X		s = XtNewString(output);
X		switch (command_type)
X			{
X			case C_DISPLAY:
X			    if (match(output_pattern, s, O_DISPLAY) != -1)
X				strcpy(s, "");
X			    break;
X			case C_SEARCH:
X			    if (match(output_pattern, s, O_SEARCH) != -1)
X				strcpy(s, "");
X			    break;
X			case C_LIST:
X			    if (match(output_pattern, s, O_LIST) != -1)
X				strcpy(s, "");
X			    break;
X			case C_PRINT:
X				if	(PopupMode &&	/* if print goes in a window, don't display here */
X			    	(match(output_pattern, s, O_PRINT) != -1))
X				strcpy(s, "");
X				break;
X				
X			default:
X				XtFree(s);
X			    s = XtNewString(string);		/* append 'string' only */
X			    break;
X			}
X		AppendDialogText(s);
X		XtFree(s);
X	    }
X	else
X		{
X		switch (command_type)
X			{
X			case C_DISPLAY:
X			case C_SEARCH:
X			case C_LIST:
X			case C_PRINT:
X				break;
X			default:
X				AppendDialogText(string);
X				break;
X			}
X		}
X}
X
X
X/*--------------------------------------------------------------------------+
X|																			|
X|	Function to filter 'source' command										|
X|																			|
X|	input : command (from .gdbinit or source command or keyboard),			|
X|			echo is TRUE if source command must be echoed.					|
X|																			|
X|	output : TRUE if source command was recognized							|
X|																			|
X|	In case source command is recognized, it is executed here.				|
X|																			|
X+--------------------------------------------------------------------------*/
Xint gdb_source_command(command,echo)
Xchar *command;
Xint echo;
X{
X	if (command && (match(command_pattern, command, C_SOURCE) != -1))
X		{
X		if (echo)
X			AppendDialogText(command);
X		source_handler();	
X	    send_command(" \n");	/* ask GDB to redisplay its prompt */
X		return TRUE;
X		}
X		
X	return FALSE;
X}
END_OF_FILE
if test 16574 -ne `wc -c <'gdb_parser.c'`; then
    echo shar: \"'gdb_parser.c'\" unpacked with wrong size!
fi
# end of 'gdb_parser.c'
fi
if test -f 'handler.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'handler.c'\"
else
echo shar: Extracting \"'handler.c'\" \(14644 characters\)
sed "s/^X//" >'handler.c' <<'END_OF_FILE'
X/*****************************************************************************
X *
X *  xdbx - X Window System interface to the dbx debugger
X *
X *  Copyright 1989 The University of Texas at Austin
X *  Copyright 1990 Microelectronics and Computer Technology Corporation
X *
X *  Permission to use, copy, modify, and distribute this software and its
X *  documentation for any purpose and without fee is hereby granted,
X *  provided that the above copyright notice appear in all copies and that
X *  both that copyright notice and this permission notice appear in
X *  supporting documentation, and that the name of The University of Texas
X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
X *  used in advertising or publicity pertaining to distribution of
X *  the software without specific, written prior permission.  The
X *  University of Texas and MCC makes no representations about the 
X *  suitability of this software for any purpose.  It is provided "as is" 
X *  without express or implied warranty.
X *
X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X *  Author:  	Po Cheung
X *  Created:   	March 10, 1989
X * 
X *****************************************************************************
X * 
X *  xxgdb - X Window System interface to the gdb debugger
X *  
X * 	Copyright 1990 Thomson Consumer Electronics, Inc.
X *  
X *  Permission to use, copy, modify, and distribute this software and its
X *  documentation for any purpose and without fee is hereby granted,
X *  provided that the above copyright notice appear in all copies and that
X *  both that copyright notice and this permission notice appear in
X *  supporting documentation, and that the name of Thomson Consumer
X *  Electronics (TCE) not be used in advertising or publicity pertaining
X *  to distribution of the software without specific, written prior
X *  permission.  TCE makes no representations about the suitability of
X *  this software for any purpose.  It is provided "as is" without express
X *  or implied warranty.
X *
X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X *  SOFTWARE.
X *
X *  Adaptation to GDB:  Pierre Willard
X *  XXGDB Created:   	December, 1990
X *
X *****************************************************************************/
X
X/*  handler.c
X *
X *    Contain action handlers for the parser to invoke upon a dbx command.
X *
X *    TextSetTopPosition():	Set the top character position of text displayed
X *    AdjustText():		Adjust the portion of text displayed.
X *    exec_handler():		Update file, line label, arrow position.
X *    done_handler():		Progrm execution completed, clear breakpoints
X *    stop_at_handler():	Place stop sign on line specified.
X *    stop_in_handler():	Place stop sign on function specified.
X *    updown_handler():		Update file, line label, updown arrow position.
X *    delete_handler():		Remove stop sign.
X *    func_handler():		Display function, if specified.
X *    file_handler():		Display file, if specified.
X *    debug_handler():		Check directory use list, display source file.
X *    cd_handler():		Record current working directory.
X *    use_handler():		Record directory paths.
X *    search_handler():		Adjust source file to display matched line.
X *    list_handler();		Adjust source file to display result.
X *    display_handler():	Display results in display window.
X */
X
X#include <ctype.h>
X#include "global.h"
X#ifdef BSD
X#define	BRACKET	"[%d]"
X#else
X#define	BRACKET	"(%d)"
X#endif
X
XBoolean		Echo = True;		/* display dbx output if true */
Xstatic Boolean	Skip_func_handler = False;
X
X/*  Display text starting from the top position specified by pos */
X
Xvoid TextSetTopPosition(w, pos)
X    Widget w;
X    XawTextPosition pos;
X{
X    Arg args[MAXARGS];
X    Cardinal n;
X
X    n = 0;
X    XtSetArg(args[n], XtNdisplayPosition, (XtArgVal) pos);               n++;
X    XtSetValues(w, args, n);
X}
X
X/*
X *  Adjust text so that 'line' will fall into the viewable part of the
X *  source window.
X *  Arrows, stop signs, and line label are updated accordingly.
X */
Xvoid AdjustText(line)
X    int	   	line;
X{
X    FileRec 		*file;
X    int	    		nlines = 0;
X    int			i;
X    XawTextPosition 	pos;
X
X    if ((file = displayedFile) == NULL || line <= 0) return;
X    file->currentline = line;
X
X    if (line < file->topline || line > file->bottomline ) {
X	/* Position line about 30% from the top */
X	nlines = file->lines*0.3;
X	if (line < nlines)			   /* near top */
X	    file->topline = 1;
X	else if (line > file->lastline - nlines)  /* near bottom */
X	    file->topline = MAX(file->lastline - file->lines + 1, 1);
X	else
X	    file->topline = line - nlines;
X	file->bottomline = MIN(file->topline + file->lines - 1, file->lastline);
X	TextSetTopPosition(sourceWindow, file->linepos[file->topline]);
X	file->topPosition = file->linepos[file->topline];
X    }
X    XawTextSetInsertionPoint(sourceWindow, file->linepos[line]);
X
X    /* Text window might have scrolled, check topline & bottomline */
X    pos = XawTextTopPosition(sourceWindow);
X    for (i=1; pos >= file->linepos[i]; i++);
X    if (file->topline != i-1) {
X	file->topline = i-1;
X	file->bottomline = MIN (file->topline + file->lines - 1,
X				file->lastline);
X    }
X    UpdateLineLabel(line);
X    UpdateStops(file);
X    UpdateArrow(file);
X    UpdateUpdown(file);
X    UpdateBomb(file);
X}
X    
X#ifdef GDB
X
X#include "gdb_handler.c"
X
X#else /*>>>>>>>>>> ALL THE FOLLOWING IS NOT COMPILED FOR GDB <<<<<<<<<<<<<<<<<<<*/
X
X/*  Handle dbx output of run, cont, next, step, return commands.
X *  Result of output parsing is returned in a set of tokens.
X */
Xvoid exec_handler()
X{
X    int	 line, status;
X    char *func, *mesg;
X    char *segv = "signal SEGV";
X    char *segfault = "Segmentation fault";
X
X    /* Print "stopped in ..." line in message window 
X     * Adjust text displayed
X     */
X    if (Token.func == NULL || Token.line == 0) 
X	return; 
X    UpdateMessageWindow(Token.mesg);
X    line = Token.line;
X    func = XtNewString(Token.func);
X    mesg = XtNewString(Token.mesg);
X#ifdef MIPS
X    status = LoadCurrentFile();
X#else
X    if (Token.file)
X	status = LoadFile(Token.file);
X#endif
X    arrow.line = line;			/* update arrow sign position */
X    strcpy(arrow.func, func);
X    updown.line = 0;			/* remove updown, if any */
X    if (displayedFile) {
X    	strcpy(arrow.file, displayedFile->pathname);
X    }
X    /* Display bomb sign if segmentation fault occurs in source code */
X    if (status != -1 && (strncmp(mesg, segv, strlen(segv)) == NULL ||
X	strncmp(mesg, segfault, strlen(segfault)) == NULL)) {
X	arrow.line = 0;
X	bomb.line = line;
X	strcpy(bomb.func, func);
X    	if (displayedFile) strcpy(bomb.file, displayedFile->pathname);
X    }
X    else
X	bomb.line = 0;
X
X    AdjustText(line);
X#ifndef BSD
X    display_handler();
X#endif
X    XtFree(func);
X    XtFree(mesg);
X}
X
X/*  Remove all the arrow and updown signs, print message, then 
X *  change the file variable to the file name displayed.
X */
Xvoid done_handler()
X{
X    char command[LINESIZ];
X
X    arrow.line = 0;
X    updown.line = 0;
X    UpdateArrow(displayedFile);
X    UpdateUpdown(displayedFile);
X    UpdateMessageWindow("Ready for execution");
X    if (displayedFile == NULL) return;
X#ifdef MIPS
X    sprintf(command, "file %s\n", displayedFile->filename);
X#else
X    sprintf(command, "file %s\n", displayedFile->pathname);
X#endif
X    Parse = False;
X    query_dbx(command);
X}
X
X/*  Place a stop sign next to the line specified on the source file window 
X *  if it is to be viewable.
X */
Xvoid stop_at_handler()
X{
X    if (Token.stop == 0 || Token.line == 0 || displayedFile == NULL)
X	return;
X    if (Token.file == NULL)
X	stops[Token.stop].file = displayedFile->pathname;
X    else
X	stops[Token.stop].file = GetPathname(Token.file);
X    DisplayStop(displayedFile, Token.line);
X    stops[Token.stop].line = Token.line;
X    stops[Token.stop].tag = 0;
X    nstops = Token.stop;
X}
X
X
X/*
X *  Place a stop sign next to the function routine, getting the line number 
X *  by "list <func>", (or "func <func>" on a MIPS), and resetting the file 
X *  variable properly.
X */
Xvoid stop_in_handler()
X{
X    char command[LINESIZ], *file;
X    int  stop;
X    int	 line;
X
X    if (Token.stop == 0 || Token.func == NULL || displayedFile == NULL)
X	return;
X    stop = Token.stop;
X#ifdef MIPS
X    /* For mips dbx, need to use func command to locate the function */
X    Skip_func_handler = True;
X    sprintf(command, "func %s\n", Token.func);
X    query_dbx(command);
X#else
X#ifdef BSD
X    sprintf(command, "list %s\n", Token.func);
X    query_dbx(command);
X#else
X    sprintf(command, "list %s\n", Token.func);
X    query_dbx(command);
X    if (Token.line <= 0) 
X	return;
X    else 
X	Token.line += 5;
X#endif
X#endif
X
X    stops[stop].line = Token.line;
X    nstops = stop;
X    line = Token.line;
X
X    /* Check the name of the file containing Token.func */
X    query_dbx("file\n");
X    if ((file = GetPathname(CurrentFile)) && 
X        strcmp(file, displayedFile->pathname)) {   /* new file, record stop */
X	stops[nstops].file = file;
X#ifdef MIPS
X	sprintf(command, "file %s\n", displayedFile->filename);
X#else
X	sprintf(command, "file %s\n", displayedFile->pathname);
X#endif
X	Parse = False;
X	query_dbx(command);
X    }
X    else { 					   /* same file, display stop */
X	stops[nstops].file = displayedFile->pathname;
X	DisplayStop(displayedFile, line);
X    }
X}
X
X/*  
X *  Display an outlined arrow to locate the calling routine in a stack
X *  frame.  BSD and SUN dbx have slightly different output semantics here.
X *  The appropriate file with the calling routine is displayed and the
X *  file variable is set accordingly.
X */
Xvoid updown_handler()
X{
X    char command[LINESIZ], *func, *file;
X    int	 line;
X
X    line = Token.line;
X    func = XtNewString(Token.func);
X#ifdef MIPS
X    LoadCurrentFile();
X#endif
X#ifdef BSD
X    file = GetPathname(Token.file);
X#else
X    if (line <= 0) line = 1;
X    LoadCurrentFile();
X    if (displayedFile)
X	file = displayedFile->pathname;
X#endif
X
X    if (line <= 0 || func == NULL || file == NULL) 
X	return;
X    if (displayedFile && strcmp(file, displayedFile->pathname)) {
X	LoadFile(file);
X	
X	/* set dbx file variable to file */
X#ifdef MIPS
X	sprintf(command, "file %s\n", displayedFile->filename);
X#else
X	sprintf(command, "file %s\n", displayedFile->pathname);
X#endif
X	Parse = False;
X	query_dbx(command);
X    }
X    updown.line = line;
X    strcpy(updown.func, func);
X    if (displayedFile)
X    	strcpy(updown.file, displayedFile->pathname);
X    AdjustText(line);
X    XtFree(func);
X}
X
X/*
X *  Delete handler remove the stop specified and undisplayed the stopsign
X *  if it's visible.
X *  It calls the dbx status command to find out what stops are left, and
X *  then update the array of stops accordingly.
X */
X/* ARGSUSED */
Xvoid delete_handler()
X{
X    char s[LINESIZ];
X    int  i; 
X    int	 line;
X
X    write_dbx("status\n");
X    while (fgets(s, LINESIZ, dbxfp) == NULL);
X    do {
X	if (strcmp(s, dbxprompt) || strcmp(s, "")) {
X	    sscanf(s, BRACKET, &i);
X	    if (i > 0 && i <= nstops && stops[i].line > 0) 
X	    	stops[i].tag = 1;
X	}
X    } while (fgets(s, LINESIZ, dbxfp));
X
X    for (i=1; i<=nstops; i++)
X	if (stops[i].line > 0) {
X	    if (stops[i].tag)
X		stops[i].tag = 0;
X	    else {
X		line = stops[i].line;
X		stops[i].line = 0;
X		stops[i].file = NULL;
X		if (LineToStop_no(line) == 0)
X		    RemoveStop(line);
X	    }
X	}
X}
X
X/*
X *  This handler displays the function routine on the source window.
X *  It locates the function by sending the dbx command "list <func>",
X *  and loads the appropriate file accordingly.
X */
Xvoid func_handler()
X{
X    int	 line;
X    char command[LINESIZ];
X
X    if (Token.func && !Skip_func_handler) {
X#ifdef MIPS
X	line = Token.line;
X#else
X	sprintf(command, "list %s\n", Token.func);
X	query_dbx(command);
X	line = Token.line + 5;
X#endif
X	LoadCurrentFile();
X	AdjustText(line);
X    }
X    Skip_func_handler = False;
X}
X
X
X/*  File handler first queries the current file set by the user command,
X *  and then loads the file.
X */
X/* ARGSUSED */
Xvoid file_handler() 	/* Command was 'file' */
X{
X    if (Token.file)
X	strcpy(CurrentFile, Token.file);
X    else
X	strcpy(CurrentFile, "");
X}
X
X/* ARGSUSED */
Xvoid debug_handler()
X{
X    query_dbx("use\n");
X    displayedFile = NULL;		/* force reloading of source file */
X    if (LoadCurrentFile() == 0) {
X	arrow.line = 0;			/* clear arrow sign */
X	updown.line = 0;		/* clear updown sign */
X	bomb.line = 0;			/* clear bomb sign */
X	UpdateArrow(displayedFile);
X	UpdateUpdown(displayedFile);
X	UpdateBomb(displayedFile);
X	ClearStops();
X	UpdateStops(displayedFile);
X        UpdateMessageWindow("Ready for execution");
X	query_dbx("func main\n");
X#ifndef BSD
X	query_dbx("display\n");		/* clear display window */
X#endif
X    }
X}
X
X/* ARGSUSED */
Xvoid cd_handler()
X{
X    query_dbx("pwd\n");
X}
X
X/* ARGSUSED */
Xvoid pwd_handler(s)
Xchar *s;
X{
X    strcpy(cwd, (char *)strtok(s, "\n"));
X}
X
X/* ARGSUSED */
Xvoid use_handler(output)
Xchar *output;
X{
X    if (strcmp(output, "") == NULL)
X	query_dbx("use\n");
X    else
X    	MakeDirList(output);
X}
X
X/* ARGSUSED */
Xvoid search_handler()
X{
X    AdjustText(Token.line);
X}
X
X/* ARGSUSED */
Xvoid list_handler()
X{
X    int	 line;
X
X    if (Echo) {
X	line = Token.line;
X	LoadCurrentFile();
X    	AdjustText(line);
X    }
X}
X
X/* ARGSUSED */
X/*  Show output on the display window.
X *  If output is null but the display window is managed, replace contents of
X *  the display window with the null string.
X */
Xvoid display_handler()
X{
X    Arg		args[MAXARGS];
X    Cardinal	n;
X
X    if (!Token.display || strcmp(Token.display, "") == NULL) {
X	if (!XtIsManaged(displayWindow))
X	    return;
X	else {
X	    XtFree(Token.display);
X	    Token.display = XtNewString("");
X	}
X    }
X    if (!XtIsManaged(displayWindow)) {
X	XtManageChild(separator);
X	XtManageChild(displayWindow);
X    }
X    n = 0;
X    XtSetArg(args[n], XtNstring, (XtArgVal) Token.display);		n++;
X    XtSetValues(displayWindow, args, n);
X    XtFree(Token.display);
X}
X
X#endif /* NOT GDB */
END_OF_FILE
if test 14644 -ne `wc -c <'handler.c'`; then
    echo shar: \"'handler.c'\" unpacked with wrong size!
fi
# end of 'handler.c'
fi
if test -f 'xdbx.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xdbx.c'\"
else
echo shar: Extracting \"'xdbx.c'\" \(14674 characters\)
sed "s/^X//" >'xdbx.c' <<'END_OF_FILE'
X/*****************************************************************************
X *
X *  xdbx - X Window System interface to the dbx debugger
X *
X *  Copyright 1989 The University of Texas at Austin
X *  Copyright 1990 Microelectronics and Computer Technology Corporation
X *
X *  Permission to use, copy, modify, and distribute this software and its
X *  documentation for any purpose and without fee is hereby granted,
X *  provided that the above copyright notice appear in all copies and that
X *  both that copyright notice and this permission notice appear in
X *  supporting documentation, and that the name of The University of Texas
X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
X *  used in advertising or publicity pertaining to distribution of
X *  the software without specific, written prior permission.  The
X *  University of Texas and MCC makes no representations about the 
X *  suitability of this software for any purpose.  It is provided "as is" 
X *  without express or implied warranty.
X *
X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X *  Author:  	Po Cheung
X *  Created:   	March 10, 1989
X * 
X *****************************************************************************
X * 
X *  xxgdb - X Window System interface to the gdb debugger
X *  
X * 	Copyright 1990 Thomson Consumer Electronics, Inc.
X *  
X *  Permission to use, copy, modify, and distribute this software and its
X *  documentation for any purpose and without fee is hereby granted,
X *  provided that the above copyright notice appear in all copies and that
X *  both that copyright notice and this permission notice appear in
X *  supporting documentation, and that the name of Thomson Consumer
X *  Electronics (TCE) not be used in advertising or publicity pertaining
X *  to distribution of the software without specific, written prior
X *  permission.  TCE makes no representations about the suitability of
X *  this software for any purpose.  It is provided "as is" without express
X *  or implied warranty.
X *
X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X *  SOFTWARE.
X *
X *  Adaptation to GDB:  Pierre Willard
X *  XXGDB Created:   	December, 1990
X *
X *****************************************************************************/
X
X/*  xdbx.c
X *
X *    Contain main program and initialization, command line options handling,
X *    and resource database management.
X *
X *    Syntax():		Print an error message if xdbx is invoked with an
X *			incorrect number of arguments.
X *    main_init():	Initialization routine.
X *    dbxoptions():	Construct command line arguments for dbx.
X *    main():		Main program.
X */
X
X#ifdef GDB
X#define XGDBVERSION	"1.01"
X#endif
X
X#include "global.h"
X#include "bitmaps.h"
X#include "patchlevel.h"
X
X#define VERSION	"2.1"
X#define Offset(field) (XtOffset(XdbxResources *, field))
X
XXtAppContext  	app_context; 		/* application context */
XWidget  	toplevel; 		/* top level widget */
XDisplay		*display;		/* connection to X server */
XCursor		watch;			/* XC_watch cursor */
XXdbxResources 	app_resources;		/* application resources of xdbx */
Xchar 		xdbxinit[LINESIZ];	/* initialization file name */
XBoolean		Tstartup = False;	/* if True, remove xdbxinit */
XBoolean		debug = False;		/* debug mode for xdbx */
X
X
Xstatic XtResource resources[] = {
X    {"bell", "Bell", XtRBoolean, sizeof(Boolean), 
X	Offset(bell), XtRImmediate, (caddr_t)False},
X    {"displayWindow", "DisplayWindow", XtRBoolean, sizeof(Boolean), 
X	Offset(displayWindow), XtRImmediate, (caddr_t)False},
X    {"prompt", "Prompt", XtRString, sizeof(char *), 
X	Offset(prompt), XtRImmediate, (caddr_t)NULL},
X    {"delimiters", "Delimiters", XtRString, sizeof(char *), 
X	Offset(delimiters), XtRImmediate, (caddr_t)NULL},
X    {"stop_color", "StopColor", XtRPixel, sizeof(Pixel), 
X	Offset(stop_color), XtRString, "Red"},
X    {"arrow_color", "ArrowColor", XtRPixel, sizeof(Pixel), 
X	Offset(arrow_color), XtRString, "Blue"},
X    {"updown_color", "UpdownColor", XtRPixel, sizeof(Pixel), 
X	Offset(updown_color), XtRString, "Blue"},
X    {"bomb_color", "bombColor", XtRPixel, sizeof(Pixel), 
X	Offset(bomb_color), XtRString, "Red"},
X    {"dataDpyMaxHeight", "DataDpyMaxHeight", XtRDimension, sizeof(Dimension), 
X	Offset(dataDpyMaxHeight), XtRString, "300"},
X    {"dataDpyMaxWidth", "DataDpyMaxWidth", XtRDimension, sizeof(Dimension), 
X	Offset(dataDpyMaxWidth), XtRString, "600"},
X    {"bigicon", "Xdbxoptions", XtRBoolean, sizeof(Boolean), 
X	Offset(bigicon), XtRImmediate, (caddr_t)False},
X    {"debug", "Xdbxoptions", XtRBoolean, sizeof(Boolean), 
X	Offset(debug), XtRImmediate, (caddr_t)False},
X    {"dbxopt_r", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
X	Offset(dbxopt_r), XtRImmediate, (caddr_t)False},
X    {"dbxopt_i", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
X	Offset(dbxopt_i), XtRImmediate, (caddr_t)False},
X    {"includeDir", "Dbxoptions", XtRString, sizeof(char *), 
X	Offset(includeDir), XtRImmediate, (caddr_t)NULL},
X    {"dbxopt_k", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
X	Offset(dbxopt_k), XtRImmediate, (caddr_t)False},
X    {"cfile", "Dbxoptions", XtRString, sizeof(char *), 
X	Offset(cfile), XtRImmediate, (caddr_t)NULL},
X    {"dbxopt_kbd", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
X	Offset(dbxopt_kbd), XtRImmediate, (caddr_t)False},
X    {"fcount", "Dbxoptions", XtRString, sizeof(char *), 
X	Offset(fcount), XtRImmediate, (caddr_t)NULL},
X    {"startup", "Dbxoptions", XtRString, sizeof(char *), 
X	Offset(startup), XtRImmediate, (caddr_t)NULL},
X    {"tstartup", "Dbxoptions", XtRString, sizeof(char *), 
X	Offset(tstartup), XtRImmediate, (caddr_t)NULL},
X};
X
X
XString fallback_resources[] = {
X    "*allowShellResize:                 True",
X    "*borderWidth:			1",
X    "*font:                             fixed",
X    "*vpane.width:                      550",
X    "*fileWindow*font:     		variable",
X    "*fileLabel.width:     		500",
X    "*lineLabel.width:     		50",
X    "*sourceForm.preferredPaneSize:     320",
X    "*sourceWindow.leftMargin:          35",
X    "*sourceWindow.scrollHorizontal:	whenNeeded",
X    "*sourceWindow.translations:	#override \\n\
X        <Btn1Down>:             SelectStart() SelectWord() \\n\
X        Shift<Btn1Up>:          Update() SelectEnd() PrintSelection() \\n\
X        <Btn1Up>:               Update() SelectEnd() \\n",
X    "*messageWindow*font:  		variable",
X    "*messageWindow.min:  		30",
X    "*messageWindow.max:  		30",
X    "*dialogWindow.preferredPaneSize:	200",
X    "*dialogWindow.resizeToPreferred:	True",
X    "*dialogWindow.translations:	#override \\n\
X        <Btn1Down>:     SelectStart() SelectWord() \\n\
X        Shift<Btn1Up>:  SelectEnd() PrintSelection() \\n\
X        <Btn1Up>:       SelectEnd() \\n",
X    "*commandWindow.preferredPaneSize:  106",
X    "*commandWindow.skipAdjust:		True",
X    "*commandWindow.hSpace:		14",
X    "*commandWindow.vSpace:		10",
X    "*Command.height:                   20",
X    "*Command.width:                    60",
X    "*List.columnSpacing:               10",
X    "*displayWindow.preferredPaneSize:  50",
X    "*displayWindow.skipAdjust:         True",
X    "*displayWindow.scrollVertical:	whenNeeded",
X    "*displayWindow.scrollHorizontal:	whenNeeded",
X    "*displayWindow.translations:	#override \\n\
X        <Btn1Down>:             SelectStart() SelectWord() \\n\
X        Shift<Btn1Up>:          SelectEnd() PrintSelection() \\n\
X        <Btn1Up>:               SelectEnd() \\n",
X    "*popup*showGrip:  			False",
X    NULL,
X};
X
Xstatic XrmOptionDescRec options[] = {
X    {"-bigicon","bigicon",	XrmoptionNoArg, "True"},
X    {"-debug",	"debug",	XrmoptionNoArg, "True"},
X#ifdef GDB
X    {"-d",	"includeDir",	XrmoptionSepArg, NULL},
X#else
X    {"-r",	"dbxopt_r",	XrmoptionNoArg, "True"},
X    {"-i",	"dbxopt_i",	XrmoptionNoArg, "True"},
X    {"-I",	"includeDir",	XrmoptionSepArg, NULL},
X    {"-k",	"dbxopt_k",	XrmoptionNoArg, "True"},
X#ifdef BSD   /* Berkeley dbx */
X    {"-c",	"cfile",	XrmoptionSepArg, NULL},
X#else	     /* Sun dbx */
X    {"-kbd",	"dbxopt_kbd",	XrmoptionNoArg, "True"},
X    {"-f",	"fcount",	XrmoptionSepArg, NULL},
X    {"-s",	"startup",	XrmoptionSepArg, NULL},
X    {"-sr",	"tstartup",	XrmoptionSepArg, NULL},
X#endif
X#endif	/* GDB */
X#ifdef MIPS  /* Mips dbx */
X    {"-pixie",  "pixie",	XrmoptionNoArg, "True"},
X#endif
X};
X
XXtActionsRec xdbx_actions[] = {
X    {"SelectStart",	(XtActionProc) SelectStart},
X    {"SelectEnd",	(XtActionProc) SelectEnd},
X    {"SelectWord",	(XtActionProc) SelectWord},
X    {"PrintSelection",	(XtActionProc) PrintSelection},
X    {"Update",		(XtActionProc) Update},
X    {"DeleteWord",	(XtActionProc) DeleteWord},
X    {"DeleteLine",	(XtActionProc) DeleteLine},
X    {NULL, NULL}
X};
X
Xstatic void Syntax(call)
Xchar *call;
X{
X    fprintf(stderr,
X#ifdef GDB
X	    "Usage: %s [-toolkitoptions] [-gdboptions] [objfile [corefile]]\n",
X#else
X	    "Usage: %s [-toolkitoptions] [-dbxoptions] [objfile [corefile]]\n",
X#endif	/* GDB */
X	    call);
X    exit(1);
X}
X
X/*  Set window manager hints to indicate display accepts input.
X *  Initialize routines in source.c, signs.c and parser.c.
X *  Disable window resize of fileWindow.
X *  Get the name of the dbx command initialization file.
X */
Xstatic void main_init()
X{
X    XWMHints	wmhints;
X    char	title[100];
X
X    display = XtDisplay(toplevel);
X    watch = XCreateFontCursor(display, XC_watch);
X
X#ifdef GDB
X    sprintf(title, "xxgdb %s (from xdbx %s patch level %d)", XGDBVERSION,VERSION, PATCHLEVEL);
X    XStoreName(display, XtWindow(toplevel), title);
X    XSetIconName(display, XtWindow(toplevel), "xxgdb");
X#else
X    sprintf(title, "xdbx %s (patch level %d)", VERSION, PATCHLEVEL);
X    XStoreName(display, XtWindow(toplevel), title);
X    XSetIconName(display, XtWindow(toplevel), "xdbx");
X#endif	/* GDB */
X    wmhints.input = True;
X    if (app_resources.bigicon)
X	wmhints.icon_pixmap = XCreateBitmapFromData(display, XtWindow(toplevel),
X	    xdbx64_bits, xdbx64_width, xdbx64_height);
X    else
X	wmhints.icon_pixmap = XCreateBitmapFromData(display, XtWindow(toplevel),
X	    xdbx48_bits, xdbx48_width, xdbx48_height);
X    wmhints.flags = IconPixmapHint | InputHint;
X    XSetWMHints(display, XtWindow(toplevel), &wmhints);
X
X    if (!app_resources.delimiters || 
X	strcmp(app_resources.delimiters, "") == NULL)
X	app_resources.delimiters = XtNewString(DELIMITERS);
X    if (app_resources.prompt && strcmp(app_resources.prompt, "") != NULL)
X	xdbxprompt = app_resources.prompt;
X    else
X	xdbxprompt = XtNewString(XDBXPROMPT);
X    debug = app_resources.debug;
X    DisableWindowResize(fileWindow);
X
X#ifdef GDB
X    strcpy(xdbxinit, ".gdbinit");
X    if (access(xdbxinit, R_OK) == -1) {
X    	sprintf(xdbxinit, "%s/%s", (char *) getenv("HOME"), ".gdbinit");
X#else
X    strcpy(xdbxinit, ".dbxinit");
X    if (access(xdbxinit, R_OK) == -1) {
X    	sprintf(xdbxinit, "%s/%s", (char *) getenv("HOME"), ".dbxinit");
X#endif	/* GDB */
X    	if (access(xdbxinit, R_OK) == -1) {
X	    strcpy(xdbxinit, "");
X	}
X    }
X    source_init();
X    signs_init();
X    parser_init();
X}
X
X
X/*  Reconstruct command line arguments for calling dbx.
X *  Return the argument list for dbx and new value of argc.
X */
Xstatic char **dbxoptions(argc, argv, app_resources)
X    int  *argc;
X    char **argv;
X    XdbxResources *app_resources;
X{
X    char **dbxargv;
X#ifdef GDB
X    char *temp = "xxgdb.XXXXXX";
X#else
X    char *temp = "xdbx.XXXXXX";
X#endif
X    int  i=0;
X
X    dbxargv = (char **) XtMalloc (MAXARGS * sizeof(char *));
X    for (i=0; i < *argc; i++)
X	dbxargv[i] = argv[i];
X
X#ifdef GDB
X	dbxargv[i++] = "-fullname";	/* see gdb_regex.h */
X#endif	/* GDB */
X
X    if (app_resources->dbxopt_r)
X	dbxargv[i++] = "-r";
X    if (app_resources->dbxopt_i)
X	dbxargv[i++] = "-i";
X    if (app_resources->includeDir) {
X#ifdef GDB
X	dbxargv[i++] = "-d ";
X#else
X	dbxargv[i++] = "-I";
X#endif	/* GDB */
X	dbxargv[i++] = app_resources->includeDir;
X    }
X    if (app_resources->dbxopt_k)
X	dbxargv[i++] = "-k";
X    if (app_resources->cfile) {
X	dbxargv[i++] = "-c";
X	dbxargv[i++] = app_resources->cfile;
X    }
X    if (app_resources->dbxopt_kbd)
X	dbxargv[i++] = "-kbd";
X    if (app_resources->fcount) {
X	dbxargv[i++] = "-f";
X	dbxargv[i++] = app_resources->fcount;
X    }
X    /*  If .dbxinit exists in the local or home directory, include the option
X     *  -c (Berkeley dbx) or -s (Sun dbx) and a dummy filename as the option 
X     *	argument.  This will prevent dbx from reading the user's command
X     *	initialization file.  Xdbx will read each line and pass it to dbx
X     *  instead.
X     */
X     /* for GDB, just use option -nx */
X     
X    if (strcmp(xdbxinit, "")) {		/* .dbxinit or ~/.dbxinit exists */
X#ifdef GDB
X	dbxargv[i++] = "-nx";
X#else
X#ifdef BSD
X	dbxargv[i++] = "-c";
X#else
X	dbxargv[i++] = "-s";
X#endif
X	dbxargv[i++] = (char *) mktemp(temp);
X#endif	/* GDB */
X    }
X    if (app_resources->startup) {	/* overwrites dbxinit */
X	Tstartup = False;
X	strcpy(xdbxinit, app_resources->startup);
X    }
X    if (app_resources->tstartup) {	/* overwrites dbxinit */
X	Tstartup = True;
X	strcpy(xdbxinit, app_resources->tstartup);
X    }
X#ifdef MIPS
X    if (app_resources->pixie) {		/* pixie output */
X	dbxargv[i++] = "-pixie";
X    }
X#endif
X    dbxargv[i] = NULL;
X    *argc = i;
X    return dbxargv;
X}
X
Xvoid main(argc, argv)
Xint argc;
Xchar **argv;
X{
X    char 	**dbxargv;
X
X    trap_signals();
X
X    toplevel = XtAppInitialize(&app_context, "XDbx", options, XtNumber(options),
X			       &argc, argv, fallback_resources, NULL, 0);
X    if (argc > 3) Syntax(argv[0]);
X    
X    XtGetApplicationResources(toplevel, &app_resources, resources,
X                              XtNumber(resources), NULL, 0);
X    XtAppAddActions(app_context, xdbx_actions, XtNumber(xdbx_actions));
X    CreateSubWindows(toplevel);
X    XtRealizeWidget(toplevel);
X
X    main_init();
X    
X#ifdef GDB
X    AppendDialogText("XXGDB comes with ABSOLUTELY NO WARRANTY.\n");
X#endif
X   
X    dbxargv = dbxoptions(&argc, argv, &app_resources);
X    calldbx(argc, dbxargv);
X
X    XtAppMainLoop(app_context);
X}
END_OF_FILE
if test 14674 -ne `wc -c <'xdbx.c'`; then
    echo shar: \"'xdbx.c'\" unpacked with wrong size!
fi
# end of 'xdbx.c'
fi
echo shar: End of archive 5 \(of 8\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 8 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

--
Dan Heller
------------------------------------------------
O'Reilly && Associates		 Z-Code Software
Senior Writer			       President
argv@ora.com			argv@zipcode.com
