v03i054: x interface to dbx, Part02/03

Mike Wexler mikew at wyse.wyse.com
Wed Mar 15 08:01:06 AEST 1989


Submitted-by: po at volta.ece.utexas.edu (Po Ling Cheung)
Posting-number: Volume 3, Issue 54
Archive-name: xdbx/part02

#! /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 2 (of 3)."
# Contents:  dialog.c global.h handler.c patchlevel.h regex.h signs.c
#   source.c xdbx.man
# Wrapped by mikew at wyse on Tue Mar 14 13:59:00 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'dialog.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dialog.c'\"
else
echo shar: Extracting \"'dialog.c'\" \(7337 characters\)
sed "s/^X//" >'dialog.c' <<'END_OF_FILE'
X/****************************************************************************** 
X *
X *  xdbx - X Window System interface to dbx
X *
X *  Copyright 1989 The University of Texas at Austin
X *
X *  Author:	Po Cheung
X *  Date:	March 10, 1989
X *
X *  Permission to use, copy, modify, and distribute this software and
X *  its 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.  The University of Texas at Austin makes no 
X *  representations about the suitability of this software for any purpose.  
X *  It is provided "as is" without express or implied warranty.
X *
X ******************************************************************************/
X
X
X#include <signal.h>
X#include "global.h"
X
Xchar 	DialogText[DIALOGSIZE];		/* text buffer for widget */
X
X/*  This is my own select word routine to replace the standard action
X *  procedure provided by the Text widget.
X *  It selects a word delimited by DELIMITERS, not whitespace.
X */
X/* ARGSUSED */
XXtActionProc MySelectWord(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    XtTextPosition pos, left, right;
X    TextWidget 	ctx = (TextWidget) w;
X    char 	s[LINESIZ];
X    char 	*p, *ls, *rs;
X    char 	*delimiter = DELIMITERS;
X
X    pos = XtTextGetInsertionPoint(w);
X    left = (*ctx->text.source->Scan)(
X	ctx->text.source, pos, XtstWhiteSpace, XtsdLeft, 1, FALSE);
X    right = (*ctx->text.source->Scan)(
X	ctx->text.source, left, XtstWhiteSpace, XtsdRight, 1, FALSE);
X    
X    if (left == right) return;
X    if (w == dialogWindow) {
X    	strncpy(s, DialogText+left, right-left+1);
X    }
X    else if (w == sourceWindow && displayedFile) {
X    	strncpy(s, displayedFile->buf+left, right-left+1);
X    }
X
X    if (!strcmp(s, "")) return;
X    p = s+pos-left;
X    ls = (char *) strtok(s, delimiter);
X    rs = (char *) strtok(NULL, delimiter);
X    while (rs<=p && rs!=NULL) {
X	ls = rs;
X	rs = (char *) strtok(NULL, delimiter);
X    }
X    left = left + ls - s;
X    right = left + strlen(ls) - 1; 
X
X    XtTextUnsetSelection(w);
X    XStoreBytes(XtDisplay(w), ls, strlen(ls));
X    XtTextSetSelection(w, left, right+1);
X}
X
X
X/*  Clicking the left mouse button in the source or dialog window
X *  invokes this action procedure to clear the cut buffer0 contenst.
X */
X/* ARGSUSED */
Xstatic XtActionProc ClearCutBuffer0(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    XStoreBytes(XtDisplay(w), NULL, 0);
X}
X
X
X/*  This is a special character delete procedure that will not
X *  delete past StartPos set by AppendDialogText.
X */
X/* ARGSUSED */
Xstatic XtActionProc MyDelete(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    XtTextBlock    textblock;
X    XtTextPosition lastPos;
X
X    lastPos = TextGetLastPos(w);
X    XtTextSetInsertionPoint(w, lastPos);
X    if (lastPos == StartPos) {
X	textblock.firstPos = 0;
X	textblock.length   = 1;
X	textblock.ptr      = " ";
X	XtTextReplace(dialogWindow, lastPos, lastPos, &textblock);
X    }
X}
X
X/*  Dispatch() is invoked on every <CR>.
X *  It collects text from the dialog window and sends it to dbx.
X *  If the string is a command to dbx (EnterCommand would be TRUE),
X *  it is stored in the global variable, Command.
X */
X/* ARGSUSED */
Xstatic XtActionProc Dispatch(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params; 
X{
X    char *s;
X
X    s = DialogText + StartPos;
X    if (EnterCommand) {
X	strcpy(Command, s);
X    	writeDbx(Command);
X    }
X    else {
X    	writeDbx(XtNewString(s));
X    }
X}
X
X
X/*  This action procedure is called when the user hits Ctrl-U.  It does
X *  what Ctrl-U ususally does in a terminal.
X/* ARGSUSED */
Xstatic XtActionProc DeleteLine(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    XtTextBlock    	textblock;
X    XtTextPosition 	lastPos;
X    Cardinal	 	i;
X
X    lastPos = TextGetLastPos(w);
X    textblock.firstPos = 0;
X    textblock.length   = 0;
X    textblock.ptr      = "";
X
X    for (i=lastPos; i > StartPos && DialogText[i-1] != '\n'; i--);
X    XtTextReplace(dialogWindow, i, lastPos, &textblock);
X    lastPos = TextGetLastPos(w);
X    XtTextSetInsertionPoint(w, lastPos);
X}
X
X
X/*  Sends an interrupt signal, Ctrl-C, to dbx. */
X/* ARGSUSED */
Xstatic XtActionProc SigInt(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    writeDbx("\03");
X    kill(dbxpid, SIGINT);
X}
X
X
X/*  Sends an EOF signal, Ctrl-D, to dbx. */
X/* ARGSUSED */
Xstatic XtActionProc SigEof(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    writeDbx("\04");
X}
X
X
X/*  Sends a QUIT signal, Ctrl-\, to dbx. */
X/* ARGSUSED */
Xstatic XtActionProc SigQuit(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    kill(dbxpid, SIGQUIT);
X}
X
X
X/* 
X *  Dialog window has its own set of translations for editing.
X *  Special action procedures for keys Delete/Backspace, Carriage Return,
X *  Ctrl-U, Ctrl-C, Ctrl-D, Ctrl-\, and word selection.
X */
Xvoid CreateDialogWindow(parent)
XWidget parent;
X{
X    Arg 	args[MAXARGS];
X    Cardinal 	n;
X
X    static XtActionsRec actionTable[] = {
X	{"DeleteLine", (XtActionProc) DeleteLine},
X	{"MyDelete", (XtActionProc) MyDelete},
X	{"Dispatch", (XtActionProc) Dispatch},
X	{"MySelectWord", (XtActionProc) MySelectWord},
X	{"ClearCutBuffer0", (XtActionProc) ClearCutBuffer0},
X	{"SigInt", (XtActionProc) SigInt},
X	{"SigEof", (XtActionProc) SigEof},
X	{"SigQuit", (XtActionProc) SigQuit},
X        {NULL, NULL}
X    };
X
X    static String translations = "\
X 	Ctrl<Key>U:	DeleteLine()\n\
X 	Ctrl<Key>C:	SigInt()\n\
X 	Ctrl<Key>D:	SigEof()\n\
X 	Ctrl<Key>|:	SigQuit()\n\
X 	Ctrl<Key>H:	MyDelete() delete-previous-character()\n\
X 	<Key>Delete:	MyDelete() delete-previous-character()\n\
X 	<Key>BackSpace:	MyDelete() delete-previous-character()\n\
X 	<Key>Return:	end-of-file() newline() Dispatch()\n\
X 	<Key>:		end-of-file() insert-char()\n\
X	<FocusIn>:	focus-in()\n\
X	<FocusOut>:	focus-out()\n\
X	<Btn1Down>:	select-start() ClearCutBuffer0()\n\
X	<Btn1Motion>:	extend-adjust()\n\
X	<Btn1Up>:	extend-end(PRIMARY, CUT_BUFFER0)\n\
X	<Btn2Down>:	end-of-file() insert-selection(PRIMARY, CUT_BUFFER0)\n\
X	<Btn3Down>:	extend-start()\n\
X	<Btn3Motion>:	extend-adjust()\n\
X	<Btn3Up>:	extend-end(PRIMARY, CUT_BUFFER0)\n\
X	<Btn1Up>(2):	MySelectWord()";
X
X
X    n = 0;
X    XtSetArg(args[n], XtNmin, app_resources.dialogMinHeight);		n++;
X    XtSetArg(args[n], XtNheight, app_resources.dialogHeight);		n++;
X    XtSetArg(args[n], XtNtranslations, XtParseTranslationTable(translations));
X    n++;
X    XtSetArg(args[n], XtNstring, (XtArgVal) DialogText);		n++;
X    XtSetArg(args[n], XtNlength, (XtArgVal) DIALOGSIZE);		n++;
X    XtSetArg(args[n], XtNeditType, (XtArgVal) XttextEdit);		n++;
X    XtSetArg(args[n], XtNtextOptions, scrollVertical | wordBreak);	n++;
X
X    dialogWindow = XtCreateManagedWidget("dialogWindow", 
X					 asciiStringWidgetClass,
X					 parent, args, n );
X
X    XtAddActions(actionTable, XtNumber(actionTable));
X}
END_OF_FILE
if test 7337 -ne `wc -c <'dialog.c'`; then
    echo shar: \"'dialog.c'\" unpacked with wrong size!
fi
# end of 'dialog.c'
fi
if test -f 'global.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'global.h'\"
else
echo shar: Extracting \"'global.h'\" \(4824 characters\)
sed "s/^X//" >'global.h' <<'END_OF_FILE'
X/****************************************************************************** 
X *
X *  xdbx - X Window System interface to dbx
X *
X *  Copyright 1989 The University of Texas at Austin
X *
X *  Author:	Po Cheung
X *  Date:	March 10, 1989
X *
X *  Permission to use, copy, modify, and distribute this software and
X *  its 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.  The University of Texas at Austin makes no 
X *  representations about the suitability of this software for any purpose.  
X *  It is provided "as is" without express or implied warranty.
X *
X ******************************************************************************/
X
X
X#include "defs.h"
X
X/* source.c */
X
Xextern void		source_init();		/* init routine */
Xextern void 		CreateSourceWindow();
Xextern char 		*QueryFile();		/* get dbx file variable */
Xextern FileRec 		*LoadFile();		/* display source file */
X
X/* command.c */
X
Xextern void		CreateCommandPanel();
X
X/* dialog.c */
X
Xextern XtActionProc	MySelectWord();		/* double click select word */
Xextern void		CreateDialogWindow();
X
X/* windows.c */
X
Xextern void 		CreateSubWindows();	/* all subwindows of xdbx */
Xextern void 		UpdateFileLabel();	/* update current file name */
Xextern void 		UpdateLineLabel();	/* update current line num */
Xextern void 		UpdateMessageWindow();	/* update xdbx message */
X
X/* sign.c */
X
Xextern void		signs_init();		/* initilalize routine */
Xextern void 		DisplayStop();		/* show stop sign */
Xextern void 		UpdateStops();		/* update position of stops */
Xextern void 		RemoveStop();		/* undisplay stop sign */
Xextern void 		UpdateArrow();		/* update position of arrow */
Xextern void 		UpdateUpdown();		/* update position of updown */
X
X/* parser.c */
X
Xextern void		parser_init();		/* compile patterns */
Xextern void		parse();		/* parse dbx output */
Xextern void		filter();		/* modify dbx output */
Xextern int		QueryDbx();		/* ask dbx for info */
X
X/* handler.c */
X
Xextern void 		exec_handler();		/* run, cont, next, step */
Xextern void 		stop_at_handler();	/* stop at line */
Xextern void 		stop_in_handler();	/* stop in function */
Xextern void 		updown_handler();	/* move up/down the stack */
Xextern void 		list_handler();		/* list source code */
Xextern void 		delete_handler();	/* delete stop signs */
Xextern void 		func_handler();		/* display function */
Xextern void 		file_handler();		/* display file */
Xextern void 		debug_handler();	/* debug program */
Xextern void 		cd_handler();		/* change directory */
X
X/* dbx.c */
Xextern void		DisplayInit();		/* initial source display */
Xextern XtInputCallbackProc readDbx();		/* get data from dbx */
X
X/* calldbx.c */
Xextern void		calldbx();		/* fork child, exec dbx */
X
X/* signals.c */
Xextern void		trap_signals();		/* signal handling for xdbx */
X
X/* utils.c */
X
Xextern void 		writeDbx();		/* send data to dbx */
Xextern char 		*dbxpwd();		/* get working dir of dbx */
Xextern XtTextPosition	TextGetLastPos();	/* get last pos of text */
Xextern void 		AppendDialogText();	/* append text to buffer */
Xextern Line 		TextPositionToLine();	/* convert line # to text pos */
Xextern int		LineToStop_no();	/* convert line # to stop # */
Xextern void 		DisableWindowResize();  /* do not allow window resize */
Xextern void 		Bell();			/* sound bell */
X
X
X/* extern variables */
X
Xextern Widget	toplevel, vpane, titleBar, fileWindow, fileLabel, lineLabel,
X        	sourceWidget, sourceWindow, messageWindow, commandWindow, 
X		dialogWindow;
X
Xextern XdbxResources app_resources;	/* application resources */
Xextern char	*xdbxinit;		/* temporary init filename */
Xextern Boolean	Homedir;		/* .dbxinit or ~/.dbxinit */
X
Xextern XtTextPosition 	StartPos;	/* start pos of inserted text */
Xextern FileRec   	*displayedFile;	/* pointer to current file info */
Xextern Tokens		token;		/* token structure */
X
Xextern Boolean 	Echo;			/* echo dbx output onto window ? */
Xextern Boolean	EnterCommand;		/* command or program input ? */
Xextern int 	outputsize;		/* size of buffer for dbx output */
Xextern int      nfiles;			/* number of files in file menu */
Xextern int	dbxpid;			/* dbx process id */
Xextern int	dbxInputId;		/* input id for input procedure */
Xextern FILE	*dbxfp;			/* file pointer to dbx process */
X
Xextern char	DialogText[];		/* buffer for dialog window widget */
Xextern char	*output;		/* buffer for dbx output */
Xextern char 	Command[];		/* string for xdbx command entered */
Xextern char     *filelist[];		/* list of files in file menu */
X
Xextern Arrow    arrow;			/* arrow widget and mapped info */
Xextern Updown   updown;			/* updown widget and mapped info */
Xextern Stops    stops[];		/* stop widget and mapped info */
Xextern Cardinal nstops;			/* number of stops */
END_OF_FILE
if test 4824 -ne `wc -c <'global.h'`; then
    echo shar: \"'global.h'\" unpacked with wrong size!
fi
# end of 'global.h'
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'\" \(7955 characters\)
sed "s/^X//" >'handler.c' <<'END_OF_FILE'
X/****************************************************************************** 
X *
X *  xdbx - X Window System interface to dbx
X *
X *  Copyright 1989 The University of Texas at Austin
X *
X *  Author:	Po Cheung
X *  Date:	March 10, 1989
X *
X *  Permission to use, copy, modify, and distribute this software and
X *  its 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.  The University of Texas at Austin makes no 
X *  representations about the suitability of this software for any purpose.  
X *  It is provided "as is" without express or implied warranty.
X *
X ******************************************************************************/
X
X
X#include <ctype.h>
X#include "global.h"
X#ifdef BSD
X#include "bsd_regex.h"
X#else
X#include "sun_regex.h"
X#endif
X
X/*  Display text starting from the top position specified by pos */
X
Xstatic void TextSetTopPosition(w, pos)
X    Widget w;
X    XtTextPosition 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    XtTextDisplay(w);
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 */
Xstatic void AdjustText(w, line)
X    Widget w;
X    Line   line;
X{
X    FileRec *file;
X
X    if ((file = displayedFile) == NULL) return;
X    file->currentline = line;
X    if (line < file->topline || line > file->bottomline ) {
X
X	if (line < file->lines/2)			   /* near top */
X	    file->topline = 1;
X	else if (line > file->lastline - file->lines/2)  /* near bottom */
X	    file->topline = MAX(file->lastline - file->lines + 1, 1);
X	else
X	    file->topline = line - file->lines/2;
X	file->bottomline = MIN(file->topline + file->lines - 1, file->lastline);
X	TextSetTopPosition (w, file->linepos[file->topline]);
X    	UpdateStops(file);
X    }
X    XtTextSetInsertionPoint(w, file->linepos[line]);
X    UpdateLineLabel(line);
X    UpdateArrow(file);
X    UpdateUpdown(file);
X}
X    
X
X/*  Handle dbx output of run, cont, next, step commands.
X *  Result of output parsing is returned in a set of tokens.
X *  Done is a boolean which indicates completed execution of debugged program.
X */
Xvoid exec_handler(token, done)
X    Tokens 	*token;
X    int  	done;
X{
X    char s[LINESIZ], command[LINESIZ];
X
X    /*  If done, remove all the arrow and updown signs, print message, then 
X     *  change the file variable to the file name displayed.
X     */
X    if (done) {
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	sprintf(command, "file %s\n", displayedFile->filename);
X	QueryDbx(command, FALSE);
X	return;
X    }
X
X    /* Print "stopped in ..." line in meesage window 
X     * Adjust text displayed
X     */
X    if (token->func == NULL || token->line == 0) 
X	return; 
X    if (token->file)
X	displayedFile = LoadFile(token->file);
X    UpdateMessageWindow(token->mesg);
X    arrow.line = token->line;		/* update arrow sign position */
X    updown.line = 0;			/* remove updown, if any */
X    if (displayedFile)
X    	strcpy(arrow.filename, displayedFile->filename);
X    AdjustText(sourceWindow, token->line);
X    if (displayedFile) {
X    	XtTextSetInsertionPoint(sourceWindow, displayedFile->linepos[token->line]);
X	UpdateLineLabel(token->line);
X    }
X}
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(token)
X    Tokens *token;
X{
X    if (token->stop == 0 || token->line == 0 || displayedFile == NULL)
X	return;
X    if (token->file == NULL)
X	stops[token->stop].filename = displayedFile->filename;
X    else
X	stops[token->stop].filename = 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>", (which possibly changes the file variable), and 
X *  resetting the file variable properly.
X */
Xvoid stop_in_handler(token)
X    Tokens *token;
X{
X    char command[LINESIZ], s[LINESIZ], *filename;
X    int  stop;
X    Line line;
X
X    if (token->stop == 0 || token->func == NULL || displayedFile == NULL)
X	return;
X    stop = token->stop;
X    sprintf(command, "list %s\n", token->func);
X    if (QueryDbx(command, TRUE) != O_LIST || token->line <= 0) 
X	return;
X
X    stops[stop].line = token->line;
X    nstops = stop;
X    line = token->line;
X
X    /* check if funcname belongs to another file */
X    if ((filename = QueryFile()) && strcmp(filename, displayedFile->filename)) {
X	/* new file, record stop */
X	stops[nstops].filename = filename;
X
X	/* restore variable file to original file */
X	sprintf(command, "file %s\n", displayedFile->filename);
X	QueryDbx(command, FALSE);
X    }
X    else { /* same file, display stop */
X	stops[nstops].filename = displayedFile->filename;
X	DisplayStop(displayedFile, line);
X    }
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(token)
X    Tokens *token;
X{
X    char s[LINESIZ], command[LINESIZ];
X
X#ifndef BSD
X    displayedFile = LoadFile(QueryFile());
X    if (displayedFile)
X	token->file = displayedFile->filename;
X    if (token->line <= 0) token->line = 1;
X#endif
X
X    if (token->line <= 0 || token->func == NULL || token->file == NULL) 
X	return;
X    if (token->file && displayedFile && 
X	strcmp(token->file, displayedFile->filename)) {
X	displayedFile = LoadFile(token->file);
X	/* set dbx file variable to filename */
X	sprintf(command, "file %s\n", token->file);
X	QueryDbx(command, FALSE);
X    }
X    updown.line = token->line;
X    if (displayedFile)
X    	strcpy(updown.filename, displayedFile->filename);
X    AdjustText(sourceWindow, token->line);
X}
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    Line line;
X
X    Echo = FALSE;
X    writeDbx("status\n");
X    while (fgets(s, LINESIZ, dbxfp) == NULL);
X    do {
X	if (strcmp(s, "(dbx) ") || 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    Echo = TRUE;
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].filename = 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(token)
X    Tokens 	*token;
X{
X    Line line = 0;
X    char s[LINESIZ], command[LINESIZ];
X
X    if (token->func) {
X	sprintf(command, "list %s\n", token->func);
X	QueryDbx(command, TRUE);
X	displayedFile = LoadFile(QueryFile());
X	AdjustText(sourceWindow, token->line);
X    }
X}
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(token)
X    Tokens 	*token;
X{
X    char *filename;
X
X    if (token->file)
X	displayedFile = LoadFile(QueryFile());
X}
X
X
X/* ARGSUSED */
Xvoid debug_handler()
X{
X    DisplayInit();
X}
X
X
X/* ARGSUSED */
Xvoid cd_handler()
X{
X    UpdateFileMenu();
X}
END_OF_FILE
if test 7955 -ne `wc -c <'handler.c'`; then
    echo shar: \"'handler.c'\" unpacked with wrong size!
fi
# end of 'handler.c'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL 0
END_OF_FILE
if test 21 -ne `wc -c <'patchlevel.h'`; then
    echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
fi
if test -f 'regex.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'regex.h'\"
else
echo shar: Extracting \"'regex.h'\" \(10832 characters\)
sed "s/^X//" >'regex.h' <<'END_OF_FILE'
X/* Definitions for data structures callers pass the regex library.
X   Copyright (C) 1985 Free Software Foundation, Inc.
X
X		       NO WARRANTY
X
X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1985 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more extensive
X    warranty protection to some or all third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X  3. You may copy and distribute this program (or a portion or derivative
Xof it, under Paragraph 2) in object code or executable form under the terms
Xof Paragraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal
X    shipping charge) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
X
X#ifndef RE_NREGS
X#define RE_NREGS 10
X#endif
X
X/* This data structure is used to represent a compiled pattern. */
X
Xstruct re_pattern_buffer
X  {
X    char *buffer;	/* Space holding the compiled pattern commands. */
X    int allocated;	/* Size of space that  buffer  points to */
X    int used;		/* Length of portion of buffer actually occupied */
X    char *fastmap;	/* Pointer to fastmap, if any, or zero if none. */
X			/* re_search uses the fastmap, if there is one,
X			   to skip quickly over totally implausible characters */
X    char *translate;	/* Translate table to apply to all characters 
X                           before comparing.
X			   Or zero for no translation.
X			   The translation is applied to a pattern when it is compiled
X			   and to data when it is matched. */
X    char fastmap_accurate;
X			/* Set to zero when a new pattern is stored,
X			   set to one when the fastmap is updated from it. */
X    char can_be_null;   /* Set to one by compiling fastmap
X			   if this pattern might match the null string.
X			   It does not necessarily match the null string
X			   in that case, but if this is zero, it cannot.
X			   2 as value means can match null string
X			   but at end of range or before a character
X			   listed in the fastmap.  */
X  };
X
X/* Structure to store "register" contents data in.
X
X   Pass the address of such a structure as an argument to re_match, etc.,
X   if you want this information back.
X
X   start[i] and end[i] record the string matched by \( ... \) grouping i,
X   for i from 1 to RE_NREGS - 1.
X   start[0] and end[0] record the entire string matched. */
X
Xstruct re_registers
X  {
X    int start[RE_NREGS];
X    int end[RE_NREGS];
X  };
X
X/* These are the command codes that appear in compiled regular expressions, 
X  one per byte.
X  Some command codes are followed by argument bytes.
X  A command code can specify any interpretation whatever for its arguments.
X  Zero-bytes may appear in the compiled regular expression. */
X
Xenum regexpcode
X  {
X    unused,
X    exactn,    /* followed by one byte giving n, and then by n literal bytes */
X    begline,   /* fails unless at beginning of line */
X    endline,   /* fails unless at end of line */
X    jump,	 /* followed by two bytes giving relative address to jump to */
X    on_failure_jump,	 /* followed by two bytes giving relative address of place
X		            to resume at in case of failure. */
X    finalize_jump,	 /* Throw away latest failure point and then 
X			    jump to address. */
X    maybe_finalize_jump, /* Like jump but finalize if safe to do so.
X			    This is used to jump back to the beginning
X			    of a repeat.  If the command that follows
X			    this jump is clearly incompatible with the
X			    one at the beginning of the repeat, such that
X			    we can be sure that there is no use backtracking
X			    out of repetitions already completed,
X			    then we finalize. */
X    dummy_failure_jump,  /* jump, and push a dummy failure point.
X			    This failure point will be thrown away
X			    if an attempt is made to use it for a failure.
X			    A + construct makes this before the first repeat.  */
X    anychar,	 /* matches any one character */
X    charset,     /* matches any one char belonging to specified set.
X		    First following byte is # bitmap bytes.
X		    Then come bytes for a bit-map saying which chars are in.
X		    Bits in each byte are ordered low-bit-first.
X		    A character is in the set if its bit is 1.
X		    A character too large to have a bit in the map
X		    is automatically not in the set */
X    charset_not, /* similar but match any character that is NOT one 
X                    of those specified */
X    start_memory, /* starts remembering the text that is matched
X		    and stores it in a memory register.
X		    followed by one byte containing the register number.
X		    Register numbers must be in the range 0 through NREGS. */
X    stop_memory, /* stops remembering the text that is matched
X		    and stores it in a memory register.
X		    followed by one byte containing the register number.
X		    Register numbers must be in the range 0 through NREGS. */
X    duplicate,    /* match a duplicate of something remembered.
X		    Followed by one byte containing the index of the memory register. */
X    before_dot,	 /* Succeeds if before dot */
X    at_dot,	 /* Succeeds if at dot */
X    after_dot,	 /* Succeeds if after dot */
X    begbuf,      /* Succeeds if at beginning of buffer */
X    endbuf,      /* Succeeds if at end of buffer */
X    wordchar,    /* Matches any word-constituent character */
X    notwordchar, /* Matches any char that is not a word-constituent */
X    wordbeg,	 /* Succeeds if at word beginning */
X    wordend,	 /* Succeeds if at word end */
X    wordbound,   /* Succeeds if at a word boundary */
X    notwordbound, /* Succeeds if not at a word boundary */
X    syntaxspec,  /* Matches any character whose syntax is specified.
X		    followed by a byte which contains a syntax code, Sword 
X	            or such like */
X    notsyntaxspec /* Matches any character whose syntax differs from 
X                     the specified. */
X  };
X
Xextern char *re_compile_pattern ();
X/* Is this really advertised? */
Xextern void re_compile_fastmap ();
Xextern int re_search (), re_search_2 ();
Xextern int re_match (), re_match_2 ();
X
X/* 4.2 bsd compatibility (yuck) */
Xextern char *re_comp ();
Xextern int re_exec ();
X
X#ifdef SYNTAX_TABLE
Xextern char *re_syntax_table;
X#endif
END_OF_FILE
if test 10832 -ne `wc -c <'regex.h'`; then
    echo shar: \"'regex.h'\" unpacked with wrong size!
fi
# end of 'regex.h'
fi
if test -f 'signs.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'signs.c'\"
else
echo shar: Extracting \"'signs.c'\" \(8833 characters\)
sed "s/^X//" >'signs.c' <<'END_OF_FILE'
X/****************************************************************************** 
X *
X *  xdbx - X Window System interface to dbx
X *
X *  Copyright 1989 The University of Texas at Austin
X *
X *  Author:	Po Cheung
X *  Date:	March 10, 1989
X *
X *  Permission to use, copy, modify, and distribute this software and
X *  its 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.  The University of Texas at Austin makes no 
X *  representations about the suitability of this software for any purpose.  
X *  It is provided "as is" without express or implied warranty.
X *
X ******************************************************************************/
X
X
X#include "global.h"
X#include "arrow.bits"
X#include "updown.bits"
X#include "stop.bits"
X
X/*
X *  This file contains all the routines for the creation and manipulation of 
X *  symbols used in xdbx.  There are 3 different signs:
X *    arrow  - a solid right arrow to indicate the current execution point.
X *    updown - an outlined right arrow to indicate position in stack trace.
X *    stop   - a stop hand symbol to indicate a breakpoint is set.
X *
X *  To display a sign on a given line in the source window, it is first
X *  created and mapped.  To undisplay it, the sign is unmapped.  It can
X *  be mapped again when the sign is needed.  Note that the sign is never
X *  moved, so that there can be as many signs created (but not mapped) as
X *  the number of lines in the source window.
X *  For arrow and updown, there can be at most one of each mapped at a time.
X *  For stop, there can be more than one mapped at the same time.
X */
X
Xtypedef struct {
X    Widget      w;
X    Boolean     mapped;
X} ArrowSign;
X
Xtypedef struct {
X    Widget      w;
X    Boolean     mapped;
X} UpdownSign;
X
Xtypedef struct {
X    Widget      w;
X    Boolean     mapped;
X} StopSign;
X
Xstatic ArrowSign 	arrowsign[MAXSIGNS];
Xstatic UpdownSign 	updownsign[MAXSIGNS];
Xstatic StopSign		stopsign[MAXSIGNS];
X
XArrow 		arrow;
XUpdown 		updown;
XStops		stops[MAXSTOPS];	/* array of stops */
XCardinal	nstops;			/* number of stops */
X
X/* Initialize data structures */
X
Xvoid signs_init()
X{
X    int i;
X
X    for (i=0; i<MAXSIGNS; i++) {
X	arrowsign[i].w = NULL;
X	arrowsign[i].mapped = FALSE;
X    }
X    for (i=0; i<MAXSIGNS; i++) {
X	stopsign[i].w = NULL;
X	stopsign[i].mapped = FALSE;
X    }
X    arrow.i = 0;
X    arrow.line = 0;
X    strcpy(arrow.filename, "");
X    updown.i = 0;
X    updown.line = 0;
X    strcpy(updown.filename, "");
X    nstops = 0;
X}
X
X
X/*  Create an arrow symbol, updown symbol or stop symbol:
X *    calculate the position of the symbol based on i, the number of lines
X *    from the top line.
X *    create the pixmap of the symbol
X *    display the symbol as a bitmap in a label widget.
X */
Xstatic Widget CreateSign(parent, sign, i)
X    Widget	parent;
X    char	*sign;
X    Cardinal 	i;
X{
X    TextWidget 	ctx = (TextWidget) sourceWindow;
X    Arg 	args[15];
X    Cardinal 	n;
X    Dimension 	source_height, height, width; 
X    char	*bits;
X    Pixel       fg, bg;
X    int 	horizDistance, vertDistance, height_per_line;
X    Display     *dpy;
X    int         screen;
X
X    if (displayedFile == NULL) return NULL;
X
X    /* Get height and background pixel values of parent window */
X    n = 0;
X    XtSetArg(args[n], XtNheight, &source_height);			n++;
X    XtSetArg(args[n], XtNbackground, &bg);				n++;
X    XtGetValues(parent, args, n);
X
X    height_per_line = source_height/displayedFile->lines;
X    vertDistance = OFFSET + (i * height_per_line); 
X
X    dpy = XtDisplay(parent);
X    screen = DefaultScreen(dpy);
X
X    if (sign && !strcmp(sign, "arrow")) {
X	bits = arrow_bits;
X	width = arrow_width;
X	height = arrow_height;
X	horizDistance = 0;
X	fg = app_resources.arrowForeground;
X    }
X    else if (sign && !strcmp(sign, "updown")) {
X	bits = updown_bits;
X	width = updown_width;
X	height = updown_height;
X	horizDistance = 0;
X	fg = app_resources.updownForeground;
X    }
X    else if (sign && !strcmp(sign, "stop")) {
X	bits = stop_bits;
X	width = stop_width;
X	height = stop_height;
X	horizDistance = arrow_width;
X	fg = app_resources.stopForeground;
X    };
X
X    n = 0;
X    XtSetArg(args[n], XtNborderWidth, 0);				n++;
X    XtSetArg(args[n], XtNwidth, (XtArgVal) width);			n++;
X    XtSetArg(args[n], XtNheight, (XtArgVal) height);			n++;
X    XtSetArg(args[n], XtNresize, (XtArgVal) False);			n++;
X    XtSetArg(args[n], XtNmappedWhenManaged, (XtArgVal) False);		n++;
X    XtSetArg(args[n], XtNbitmap, XCreatePixmapFromBitmapData (
X        dpy, DefaultRootWindow(dpy), bits, width, height,
X        fg, bg, DefaultDepth(dpy, screen)));				n++;
X
X    XtSetArg(args[n], XtNfromVert, (XtArgVal) NULL);			n++;
X    XtSetArg(args[n], XtNfromHoriz, (XtArgVal) ctx->text.sbar);		n++;
X    XtSetArg(args[n], XtNhorizDistance, (XtArgVal) horizDistance);	n++;
X    XtSetArg(args[n], XtNvertDistance, (XtArgVal) vertDistance);	n++;
X    XtSetArg(args[n], XtNtop, (XtArgVal) XtChainTop);			n++;
X    XtSetArg(args[n], XtNleft, (XtArgVal) XtChainLeft);			n++;
X    XtSetArg(args[n], XtNbottom, (XtArgVal) XtChainTop);		n++;
X    XtSetArg(args[n], XtNright, (XtArgVal) XtChainLeft);		n++;
X
X    return XtCreateManagedWidget(sign, labelWidgetClass, parent, args, n);
X}
X
X/*
X *  Given a line number, displays a stop sign if that line is viewable.
X *  If the stop widget for that line does not exist, create one and map it.
X *  If the stop widget exists but not mapped, map it.
X */
Xvoid DisplayStop(file, line)
XFileRec *file;
XLine line;
X{
X    Cardinal i;
X
X    if (line >= file->topline && line <= file->bottomline) {
X	i = line - file->topline;
X	if (stopsign[i].w == NULL) {	/* widget does not exist */
X	    stopsign[i].w = CreateSign(sourceWidget, "stop", i);
X	    XtMapWidget(stopsign[i].w);
X	    stopsign[i].mapped = 1;
X	}
X	else if (!stopsign[i].mapped) { /* widget not mapped */
X	    XtMapWidget(stopsign[i].w);
X	    stopsign[i].mapped = 1;
X	}
X    }
X}
X
X/*
X *  Unmap all stop signs and then display only those stops that are viewable.
X */
Xvoid UpdateStops(file)
XFileRec *file;
X{
X    Cardinal i;
X    Line line;
X
X    if (file == NULL) return;
X    for (i=0; i<file->lines; i++)
X	if (stopsign[i].w && stopsign[i].mapped) {
X	    XtUnmapWidget(stopsign[i].w);
X	    stopsign[i].mapped = 0;
X	}
X
X    for (i=1; i<=nstops; i++)
X	if (stops[i].filename && !strcmp(stops[i].filename, file->filename) &&
X	    (line=stops[i].line) && line >= file->topline &&
X	    line <= file->bottomline) {
X	    DisplayStop(file, line);
X	}
X}
X
X/*
X * Given a line number, unmap the stop sign associated with that line.
X */
Xvoid RemoveStop(line)
XLine line;
X{
X    Cardinal i;
X
X    if (displayedFile && line >= displayedFile->topline && 
X			 line <= displayedFile->bottomline) {
X	i = line - displayedFile->topline;
X	if (stopsign[i].w && stopsign[i].mapped) {
X	    XtUnmapWidget(stopsign[i].w);
X	    stopsign[i].mapped = 0;
X	}
X    }
X}
X
X
X/*  Unmap the current arrow sign.
X *  Display a new arrow sign if it is viewable.
X */
Xvoid UpdateArrow(file)
XFileRec *file;
X{
X    Cardinal i;
X    Line     line;
X
X    if (file == NULL) return;
X    i = arrow.i;
X    if (i>=0 && i<file->lines)
X	if (arrowsign[i].w && arrowsign[i].mapped) {
X	    XtUnmapWidget(arrowsign[i].w);
X	    arrowsign[i].mapped = 0;
X	}
X    line = arrow.line;
X    if (arrow.filename && !strcmp(arrow.filename, file->filename) &&
X    	line >= file->topline && line <= file->bottomline) {
X        i = line - file->topline;
X	arrow.i = i;
X	if (arrowsign[i].w == NULL) {
X	    arrowsign[i].w = CreateSign(sourceWidget, "arrow", i);
X	    XtMapWidget(arrowsign[i].w);
X	    arrowsign[i].mapped = TRUE;
X	}
X	else if (!arrowsign[i].mapped) {
X	    XtMapWidget(arrowsign[i].w);
X	    arrowsign[i].mapped = TRUE;
X	}
X    }
X}
X
X
X/*  If the new updown is on the same line as the arrow, remove the updown.
X *  Unmap current updown sign.
X *  Display the updown if it is viewable.
X */
Xvoid UpdateUpdown(file)
XFileRec *file;
X{
X    Cardinal i;
X    Line     line;
X
X    if (file == NULL) return;
X    if (updown.filename && !strcmp(updown.filename, arrow.filename) && 
X	updown.line == arrow.line) {
X	updown.line = 0;
X	strcpy(updown.filename, "");
X    }
X    i = updown.i;
X    if (i>=0 && i<file->lines)
X	if (updownsign[i].w && updownsign[i].mapped) {
X	    XtUnmapWidget(updownsign[i].w);
X	    updownsign[i].mapped = 0;
X	}
X    line = updown.line;
X    if (updown.filename && !strcmp(updown.filename, file->filename) &&
X    	line >= file->topline && line <= file->bottomline) {
X        i = line - file->topline;
X	updown.i = i;
X	if (updownsign[i].w == NULL) {
X	    updownsign[i].w = CreateSign(sourceWidget, "updown", i);
X	    XtMapWidget(updownsign[i].w);
X	    updownsign[i].mapped = TRUE;
X	}
X	else if (!updownsign[i].mapped) {
X	    XtMapWidget(updownsign[i].w);
X	    updownsign[i].mapped = TRUE;
X	}
X    }
X}
END_OF_FILE
if test 8833 -ne `wc -c <'signs.c'`; then
    echo shar: \"'signs.c'\" unpacked with wrong size!
fi
# end of 'signs.c'
fi
if test -f 'source.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'source.c'\"
else
echo shar: Extracting \"'source.c'\" \(10760 characters\)
sed "s/^X//" >'source.c' <<'END_OF_FILE'
X/****************************************************************************** 
X *
X *  xdbx - X Window System interface to dbx
X *
X *  Copyright 1989 The University of Texas at Austin
X *
X *  Author:	Po Cheung
X *  Date:	March 10, 1989
X *
X *  Permission to use, copy, modify, and distribute this software and
X *  its 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.  The University of Texas at Austin makes no 
X *  representations about the suitability of this software for any purpose.  
X *  It is provided "as is" without express or implied warranty.
X *
X ******************************************************************************/
X
X
X#include "global.h"
X#include <X11/Xos.h>
X#include <sys/stat.h>
X
Xstatic FileRec	fileTable[MAXFILES];	/* table of file records */
XFileRec  	*displayedFile;		/* pointer to table entry of currently
X					   displayed file */
XBoolean		Echo = True;		/* to intercept dbx output */
X
X
Xvoid source_init()
X{
X    int i;
X
X    for (i=0; i<MAXFILES; i++) {
X	fileTable[i].filename = XtNewString("");
X    }
X}
X
X/*
X *  Update topline, bottomline, arrow sign, updown sign, stop signs, and
X *  line label.  Invoked by scrollbar action.
X */
X/* ARGSUSED */
Xstatic XtActionProc Update(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    TextWidget  	ctx = (TextWidget) sourceWindow;
X    XtTextPosition      pos;
X    Line		line;
X    FileRec 		*file;
X
X    if (displayedFile) {
X    	file = displayedFile;
X	pos = ctx->text.lt.top;
X	for(line=1; pos >= file->linepos[line]; line++);
X	if (file->topline != line-1) {
X	    file->topline = line-1;
X	    file->bottomline = MIN (file->topline + file->lines - 1, 
X				    file->lastline);
X	    XtTextSetInsertionPoint(sourceWindow, file->linepos[file->topline]);
X	    UpdateLineLabel(file->topline);
X    	    UpdateStops(file);
X    	    UpdateArrow(file);
X    	    UpdateUpdown(file);
X	}
X    }
X}
X
X/*  Invoked by left mouse button down, update the line label. 
X */
X/* ARGSUSED */
Xstatic XtActionProc UpdateLine(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    XtTextPosition pos;
X    Line line;
X
X    pos = XtTextGetInsertionPoint(sourceWindow);
X    line = TextPositionToLine(pos);
X    UpdateLineLabel(line);
X}
X
X/*
X *  Update bottomline, arrow sign, updown sign and stop signs
X *  Invoked by ConfigureNotify event.
X *  Note that topline never changes with resize, only bottomline gets changed.
X */
X/* ARGSUSED */
Xstatic XtActionProc NotifyResize(w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    TextWidget  ctx = (TextWidget) sourceWindow;
X    FileRec	*file;
X
X    if (file = displayedFile) {
X	file->lines = ctx->text.lt.lines;
X        file->bottomline = MIN (file->topline + file->lines - 1, 
X				file->lastline);
X        UpdateStops(file);
X        UpdateArrow(file);
X        UpdateUpdown(file);
X    }
X}
X
X
X/* 
X *  On top of a form widget, we have a text widget with scrollbar, a label
X *  widget for the arrow sign, one for the updown sign and some for stop signs.
X */
Xvoid CreateSourceWindow(parent)
XWidget parent;
X{
X    TextWidget ctx;
X    Arg args[MAXARGS];
X    Cardinal n;
X
X    static XtActionsRec actionTable[] = {
X        {"NotifyResize",   (XtActionProc) NotifyResize},
X        {"MySelectWord", (XtActionProc) MySelectWord},
X        {"UpdateLine", (XtActionProc) UpdateLine},
X        {"Update", 	   (XtActionProc) Update},
X        {NULL, NULL}
X    };
X
X    static String translations = "\
X        <Btn1Down>:     select-start() ClearCutBuffer0() UpdateLine()\n\
X        <Btn1Up>(2):    MySelectWord()";
X
X    static String sbarTranslations = "\
X        <Configure>:    NotifyResize() \n\
X        <Btn2Down>:     StartScroll(Continuous) MoveThumb() NotifyThumb() \
X                        Update() \n\
X        <Btn2Motion>:   MoveThumb() NotifyThumb() Update() \n\
X        <BtnUp>:        NotifyScroll(Proportional) EndScroll() Update()";
X
X
X    n = 0;
X    XtSetArg(args[n], XtNdefaultDistance, 0);                           n++;
X    sourceWidget = XtCreateManagedWidget("sourceWidget", formWidgetClass, 
X					 parent, args, n);
X
X    n = 0;
X    XtSetArg(args[n], XtNheight, app_resources.sourceHeight); 		n++;
X    XtSetArg(args[n], XtNleftMargin, app_resources.leftMargin);		n++;
X    XtSetArg(args[n], XtNborderWidth, 0);				n++;
X    XtSetArg(args[n], XtNtextOptions, (XtArgVal) scrollVertical);	n++;
X
X    sourceWindow = XtCreateManagedWidget("sourceWindow", asciiStringWidgetClass,
X					  sourceWidget, args, n);
X    ctx = (TextWidget) sourceWindow;
X    XtOverrideTranslations(sourceWindow, 
X			   XtParseTranslationTable(translations));
X    XtOverrideTranslations(ctx->text.sbar, 
X			   XtParseTranslationTable(sbarTranslations));
X    XtAddActions(actionTable, XtNumber(actionTable));
X}
X
X
X/*
X * Build the array which gives the starting text position of each line
X *   look for CR, get the position, add 1, which becomes the starting
X *   position of next line.
X */
Xstatic void BuildLinePos (file)
XFileRec *file;
X{
X    char *s;
X    Line line, nlines;
X
X    nlines = file->filesize/CHARS_PER_LINE;
X    file->linepos = (XtTextPosition *)XtMalloc(nlines * sizeof(XtTextPosition));
X    s = file->buf;
X    line = 0;
X    file->linepos[line++] = 0;
X    file->linepos[line++] = 0;
X    while (*s) {
X	if (*s++ == '\n') {
X	    if (line == nlines) {
X                file->linepos = (XtTextPosition *) XtRealloc (file->linepos, 
X			  (nlines + ADD_LINES) * sizeof(XtTextPosition));
X		nlines += ADD_LINES;
X            }
X            file->linepos[line++] = s - file->buf;
X	}
X    }
X    file->lastline = line - 2;
X    file->linepos = (XtTextPosition *) XtRealloc 
X			(file->linepos, line * sizeof(XtTextPosition));
X}
X
X
Xstatic long GetFileSize(fd)
Xint  fd;
X{
X    struct stat fileinfo;
X
X    if (fstat(fd, &fileinfo))
X	return -1;
X    return (fileinfo.st_size + 1);
X}
X
X/*
X * Look up the file table for an entry with "filename"
X * If not found, create an entry and initialize proper fields,
X * else, return pointer to entry found.
X */
Xstatic FileRec *LookUpFileTable(filename, fd)
Xchar *filename;
Xint  fd;
X{
X    int i, c1, c2;
X    char message[LINESIZ];
X
X    for (i=0; fileTable[i].filename &&
X	      (c1 = strcmp(fileTable[i].filename, "")) && 
X	      (c2 = strcmp(fileTable[i].filename, filename)) &&
X	      i < MAXFILES; i++);
X
X    if (i >= MAXFILES) {		/* too many files */
X	i = 0;
X	c1 = 0;
X	XtFree(fileTable[i].buf);
X    }
X    if (c1 == 0) {			/* file does not exist in table */
X	if ((fileTable[i].filesize = GetFileSize(fd)) == -1)
X	    return NULL ;
X	fileTable[i].buf = XtMalloc(fileTable[i].filesize);
X	if (read(fd, fileTable[i].buf, fileTable[i].filesize) == -1) {
X	    sprintf(message, "Can't read %s: read error\n", filename);
X	    UpdateMessageWindow(message);
X	    XtFree(fileTable[i].buf);
X	    return NULL;
X        }
X	fileTable[i].filename = XtNewString(filename);
X	strcpy(fileTable[i].funcname, "");
X	fileTable[i].currentline = 1;
X	fileTable[i].topline = 1;
X	fileTable[i].bottomline = 0;
X	fileTable[i].topPosition = 0;
X	BuildLinePos(&fileTable[i]);
X	return &fileTable[i];
X    }
X    if (c2 == 0) {			/* file exists in table */
X    	return &fileTable[i];
X    }
X}
X
X
X/*
X * Get the name of the file returned by the 'file' command to dbx
X * If no source file is specified, QueryFile returns NULL
X */
Xchar *QueryFile()
X{
X    char *string, s[LINESIZ], t[LINESIZ];
X
X    Echo = FALSE;
X    writeDbx("file\n");
X    while (fgets(s, LINESIZ, dbxfp) == NULL);
X    if (string = (char *) strtok(s, " \n")) {
X	if (strtok(NULL, " \n"))
X	    string = NULL;
X    }
X    while (fgets(t, LINESIZ, dbxfp));
X    Echo = TRUE;
X    if (string) 
X	return XtNewString(string);
X    else
X	return NULL;
X}
X
X/*  
X *  Remember file position before closing.
X *  Clear field funcname for proper operation of parse() & UpdateFuncLabel()
X */
Xstatic void SaveDisplayedFileInfo()
X{
X    XtTextPosition pos;
X
X    if (displayedFile) {
X    	displayedFile->topPosition = XtTextTopPosition(sourceWindow);
X	pos = XtTextGetInsertionPoint(sourceWindow);
X	displayedFile->currentline = TextPositionToLine(pos);
X	strcpy(displayedFile->funcname, "");
X    }
X}
X
X
Xstatic void DisplayFile(file)
XFileRec *file;
X{
X    Arg args[MAXARGS];
X    Cardinal n;
X    TextWidget ctx = (TextWidget) sourceWindow;
X
X    n = 0;
X    XtSetArg(args[n], XtNstring, (XtArgVal) file->buf);			n++;
X    XtSetArg(args[n], XtNlength, (XtArgVal) file->filesize);		n++;
X    XtSetArg(args[n], XtNeditType, (XtArgVal) XttextRead);		n++;
X
X    XtTextSetSource(sourceWindow, 
X		    XtStringSourceCreate(sourceWindow, args, n),
X		    file->topPosition);
X    file->lines = ctx->text.lt.lines;
X    file->bottomline = MIN (file->topline + file->lines - 1, file->lastline);
X}
X
X
Xstatic void FullPath(filename, path)
Xchar *filename, *path;
X{
X    char *dir;
X
X    dir = dbxpwd();
X    if (dir) {
X    	strcpy(path, dir);
X    	strcat(path, "/");
X    	strcat(path, filename);
X    	XtFree(dir);
X    }
X    else 
X	strcpy(path, filename);
X}
X
X/*
X * Given a file name, LoadFile attempts to open it and displays it onto
X * the source window.  
X *   LookUpFileTable checks if the file is already in the file table.
X *     if it exists, a pointer to the file structure is retured;
X *     otherwise, an entry is created and its info initialized;
X *     returns NULL only if file table full.
X *   SaveDisplayedFileInfo saves important information about the file
X *     back in the file table; they include: topPosition, breakpoints.
X *   DisplayFile displays the file onto the source window.  It
X *     uses topPosition to remember where it was last opened.  But it
X *     must recalculate bottomline because the window size might be
X *     different.
X */
XFileRec *LoadFile(filename)
Xchar *filename;
X{
X    FileRec 	*file;
X    int 	fd;
X    char	message[LINESIZ];
X    char	pathname[LINESIZ];
X
X    if (filename == NULL)
X	return displayedFile;
X    if (displayedFile && strcmp(filename, displayedFile->filename) == 0)
X	return displayedFile;
X    FullPath(filename, pathname);
X    if ((fd = open(pathname, O_RDONLY)) == -1) {
X	sprintf(message, "open: file not found : %s", pathname);
X	UpdateMessageWindow(message);
X	return displayedFile;
X    }
X    else if (file = LookUpFileTable(filename, fd)) {
X    	SaveDisplayedFileInfo();
X    	DisplayFile(file);
X	UpdateFileLabel(file->filename);
X	XtTextSetInsertionPoint(sourceWindow, file->linepos[file->currentline]);
X	UpdateLineLabel(file->currentline);
X	UpdateStops(file);
X	UpdateArrow(file);
X	UpdateUpdown(file);
X    	close(fd);
X    	return file;
X    }
X    else {
X    	close(fd);
X    	return displayedFile;
X    }
X}
END_OF_FILE
if test 10760 -ne `wc -c <'source.c'`; then
    echo shar: \"'source.c'\" unpacked with wrong size!
fi
# end of 'source.c'
fi
if test -f 'xdbx.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xdbx.man'\"
else
echo shar: Extracting \"'xdbx.man'\" \(8336 characters\)
sed "s/^X//" >'xdbx.man' <<'END_OF_FILE'
X.TH XDBX 1 "10 February 1989" "X Version 11"
X.SH NAME
Xxdbx \- X window interface to the dbx debugger.
X.SH SYNOPSIS
X.B xdbx
X[ \fI-toolkitoption ... \fP] [\fI-dbxoption ... \fP] [\fIobjfile\fP 
X[ \fIcorefile\fP ]]
X.SH DESCRIPTION
X\fIXdbx\fP is a graphical interface to the \fIdbx\fP debugger under 
Xthe X Window System.  It provides visual feedback and mouse input for 
Xthe user to examine program execution, set and remove breakpoints, 
Xexamine variables and data structures, and view source files 
Xand functions.
X.LP
X\fIXdbx\fP supports both Berkeley dbx and Sun dbx.  Sun dbx
Xis an extended and debugged version of Berkeley dbx.
X.LP
X\fIXdbx\fP allows initial dbx commands stored in the file \fI.dbxinit\fP
Xto be executed immediately after the symbolic information is read.
XIf \fI.dbxinit\fP does not exist in the current directory, the user's
Xhome directory is searched (\fI~/.dbxinit\fP).
X.LP
X\fIObjfile\fP is an object file produced by a compiler with the 
Xappropriate option (\fB\-g\fP) specified to produce symbol table 
Xinformation for dbx.  For Sun dbx, if no \fIobjfile\fP is specified, 
Xthe \fBdebug\fP command can be used later to specify the program to be 
Xdebugged.
X.LP
XIf a file named \fIcore\fP exists in the current directory or a
X\fIcorefile\fP is specified, \fIxdbx\fP can be used to examine the 
Xstate of the program when the core dump occurred.
X.SH OPTIONS
X\fIXdbx\fP accepts all of the standard X Toolkit command line options 
X(see \fIX\fP(1)), and all the dbx options (see \fIdbx\fP(1)).  
X.SH SUBWINDOWS
X\fIXdbx\fP is made up of the following subwindows:
X.IP "Title Bar" 20
XDisplay the current version of \fIxdbx\fP.
X.IP "File Window"
XDisplay the name of file displayed in the source window, and 
Xthe line number of the caret.
X.IP "Source Window"
XDisplay the contents of a source file.
X.IP "Message Window"
XDisplay the execution status and error messages of \fIxdbx\fP .
X.IP "Command Window"
XProvide a list of the common dbx commands which are invoked by simply
Xclicking the left mouse button.
X.IP "Dialog Window"
XProvide a typing interface to dbx.
X.LP
XThe relative sizes of the source window, command window, and the dialog
Xwindow can be adjusted by dragging the grip (a small square near the
Xright edge of a horizontal border) with the left mouse button down.
X.SH SELECTION
XTo select some text, click the left mouse button at the starting position, 
Xthen click the right mouse button at the ending position.  The selected text 
Xis highlighted in reverse-video.  It can be pasted into the dialog window
Xby clicking the middle mouse button or unselected by the left mouse button.
X.LP
XAn expression or function name can be selected by double clicking the
Xleft mouse button.  Also, clicking the left mouse button in the source window
Xplaces the caret at that line, and updates the line label accordingly.
X.SH SCROLLBAR
XPressing the left mouse button scrolls the text forward, whereas pressing
Xthe right mouse button scrolls the text backward.  The amount of scrolling
Xdepends on the distance of the pointer button away from the top of the
Xscrollbar.  If the button is pressed at the top of the scrollbar, only
Xone line of text is scrolled.  If the button is pressed at the bottom of the
Xscrollbar, one screenful of text is scrolled.
X.LP
XPressing the middle mouse button changes the thumb position of the 
Xscrollbar.  Dragging the middle mouse button down moves the thumb
Xalong and changes the text displayed.
X.SH COMMAND BUTTONS
X.SS "Execution Commands"
X.IP "\fBrun\fP" 10
XBegin program execution.
X.IP "\fBcont\fP"
XContinue execution from where it stopped.
X.IP "\fBstep\fP"
XExecute one source line, stepping into a function if the source line
Xcontains a function call.
X.IP "\fBnext\fP"
XExecute one source line, without stepping into any function call.
X
X.LP 
X.SS "Breakpoint Commands"
X.IP "\fBstop at\fP" 10
XStop program execution at the line selected.  To set a breakpoint in the 
Xprogram, place the caret on the source line and click the \fBstop at\fP 
Xbutton.  A stop sign will appear next to the source line.
X.IP "\fBstop in\fP"
XStop program execution in the function selected.  To set a breakpoint
Xin a function, select the function name and click the \fBstop in\fP 
Xbutton.  A stop sign will be placed near the first executable line of 
Xthe function.
X.IP "\fBdelete\fP"
XRemove the breakpoint on the source line selected.  The stop sign will 
Xdisappear.
X.IP "\fBstatus\fP"
XShow the current breakpoints and traces.
X
X.LP 
X.SS "Stack Commands"
X.IP "\fBwhere\fP" 10
XShow a stack trace of the functions called.
X.IP "\fBup\fP"
XMove up one level on the stack.
X.IP "\fBdown\fP"
XMove down one level on the stack.
X
X.LP
X.SS "Miscellaneous Commands"
X.IP "\fBprint\fP" 10
XPrint the value of the expression selected.
X.IP "\fBprint *\fP"
XPrint the value of the object the selected expression is pointing to.
X.IP "\fBfunc\fP"
XDisplay a selected function on the source window, and change the scope for
Xvariable name resolution to the selected function.  The file scope is changed 
Xto the file containing the function.
X.IP "\fBfile\fP"
XPop up a file menu to select a source file to be displayed, and
Xchange the file scope to the selected file.
X.IP "\fBquit\fP"
XExit \fIxdbx\fP.
X
X.SH X DEFAULTS
XTo change the default values of widget resources used in \fIxdbx\fP, you
Xneed to reference the widgets by name or by class.  The widget classes used
Xin \fIxdbx\fP are \fBLabel\fP, \fBText\fP, \fBCommand\fP, \fBBox\fP, and
X\fBScrollbar\fP.  The names of the widgets are:
X.IP \fBvpane\fP 20
XThe vpaned widget containing all the subwindows.
X.IP \fBtitleBar\fP
XThe label widget showing the \fIxdbx\fP title.
X.IP \fBfileLabel\fP
XThe label widget showing the name of the source file.
X.IP \fBlineLabel\fP
XThe label widget showing the line number of the caret in the source window.
X.IP \fBsourceWindow\fP
XThe text widget displaying the source file.
X.IP \fBcommandWindow\fP
XThe box widget containing the command buttons.
X.IP \fBdialogWindow\fP
XThe text widget acting as a terminal interface to dbx.
X.IP \fBfileMenu\fP
XThe list widget as a file menu.
X.LP
X
XIn addition to the standard X resources, \fIxdbx\fP uses the following
Xapplication-specific resources for user customization:
X.IP \fBshellWidth\fP 20
XWidth of \fIxdbx\fP window.
X.IP \fBlineLabelWidth\fP
XWidth of line label.
X.IP \fBsourceHeight\fP
XHeight of source window.
X.IP \fBleftMargin\fP
XSize of left margin of source window.
X.IP \fBdialogHeight\fP
XHeight of dialog window.
X.IP \fBdialogMinHeight\fP
XMinimum height of dialog window.
X.IP \fBmessageHeight\fP
XHeight of message window.
X.IP \fBbuttonWidth\fP
XWidth of a command button.
X.IP \fBcommandHSpace\fP
XHorizontal spacing among the command buttons.
X.IP \fBcommandVSpace\fP
XVertical spacing among the command buttons.
X.IP \fBcommandMinHeight\fP
XMinimum height of command window.
X.IP \fBcommandMaxHeight\fP
XMaximum height of command window.
X.IP \fBcolumnSpacing\fP
XSpacing between columns in the file menu.
X.IP \fBfilesPerColumn\fP
XNumber of files per column in the file menu.
X.IP \fBnoTitleBar\fP
XIf True, no title bar will be displayed.
X.IP \fBstopForeground\fP
XForeground color of the stop sign.
X.IP \fBarrowForeground\fP
XForeground color of the arrow sign.
X.IP \fBupdownForeground\fP
XForeground color of the updown sign.
X.LP
X
X.SH FILES
X.nf
Xa.out 		default object file
Xcore 		default core file
X\&.dbxinit 		local initial commands file
X~/.dbxinit 	user's initial commands file
X.SH SEE ALSO
XX(1), dbx(1), dbxtool(1)
X.SH LIMITATIONS
X\fIXdbx\fP is developed primarily for C program debugging.  Other languages are 
Xnot fully supported.
X.SH BUGS
XTyping control-C in the dialog window fails to interrupt dbx.
X.LP
XThe \fBfile\fP button command does not unhighlight the button border.
X.LP
XStuffing text to a window outside the \fIxdbx\fP window will sometimes give
Xsuch message: 
X.ce
X"X Toolkit Error: AtomPtr was not initialized"
X.LP
X\fIXdbx\fP does not work under SunOS 4.0 due to a problem in disabling the 
Xpacket mode (TIOCPKT) of the pseudo-terminal.  If the packet mode is not 
Xdisabled, each read from the master will return data written previously to 
Xthe slave (dbx commands entered would reappear), and each newline character 
Xis incorrectly mapped to a carriage return and a newline during text display.
X.LP
X.SH COPYRIGHT
XCopyright 1989 The University of Texas at Austin
X.SH AUTHOR
XPo Cheung, The University of Texas at Austin
END_OF_FILE
if test 8336 -ne `wc -c <'xdbx.man'`; then
    echo shar: \"'xdbx.man'\" unpacked with wrong size!
fi
# end of 'xdbx.man'
fi
echo shar: End of archive 2 \(of 3\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 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
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x



More information about the Comp.sources.x mailing list