home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-09-09 | 39.9 KB | 1,315 lines |
- Newsgroups: alt.sources
- Path: wupost!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!think.com!news.bbn.com!mips2!bubba!jtsillas
- From: jtsillas@bubba.ma30.bull.com (James Tsillas)
- Subject: mxgdb 1.0.3 (part 3/10)
- Organization: Bull HN, Worldwide Information Systems, Billerica, Mass., USA
- Distribution: alt
- Date: 6 Sep 91 14:22:25
- Message-ID: <JTSILLAS.91Sep6142225@bubba.ma30.bull.com>
- Sender: news@mips2.ma30.bull.com (Usenet News Manager)
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # this is mxgdb.03 (part 3 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file mxgdb/source.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 3; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping mxgdb/source.c'
- else
- echo 'x - continuing file mxgdb/source.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'mxgdb/source.c' &&
- 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
- /* source.c
- X *
- X * Create the source window and handle display of file.
- X *
- X * source_init(): Initialization routine.
- X * Update(): Action proc to update source window on scrollbar action.
- X * NotifyResize(): Action proc to update source window on resize.
- X * CreateSourceWindow(): Create the source window.
- X * BuildLinePos(): Build an array of starting text position of each line.
- X * LookUpFileTable():Check out source file info from a file table.
- X * SaveDisplayedFileInfo(): records displayed file info into file table.
- X * DisplayFile(): Display a file on the source window
- X * LoadFile(): Search for a file and open it for display.
- X */
- X
- #include <X11/Xos.h>
- #include <sys/stat.h>
- #include <pwd.h>
- #include "global.h"
- #include "bitmaps.h"
- #ifdef SYSV
- #if defined(SCO)
- # include <fcntl.h>
- #endif
- #if defined(Mips)
- # include <unistd.h>
- #endif
- #endif /* SYSV */
- X
- #include <Xm/Xm.h>
- #include <Xm/Form.h>
- #include <Xm/Text.h>
- #include <Xm/ScrolledW.h>
- #include <Xm/ScrollBar.h>
- #include <Xm/ArrowB.h>
- #include <Xm/PushB.h>
- X
- #define MAXDIRS 256 /* max number of dirs in dirList */
- X
- char CurrentFile[MAXNAME]; /* current contents of file variable */
- Widget sourceWindow, /* text window for source file */
- X sourceScroll,
- X scrollV,
- X sourceForm,
- X pageRbutton, pageLbutton,
- X breakbutton, stepbutton, nextbutton, printbutton,
- X downbutton, upbutton, stackbutton, contbutton, finishbutton,
- X runbutton, dispbutton, undispbutton, clearbutton, printsbutton,
- X argsbutton, localsbutton, commandDialog;
- X
- FileRec *displayedFile; /* pointer to table entry of currently
- X displayed file */
- X
- static FileRec **fileTable; /* table of file records */
- static int fileTableSize; /* size of file table */
- static char *dirList[MAXDIRS]; /* list of dirs for searching files */
- static short maxcol;
- static short currvalue;
- X
- void source_init()
- {
- X dirList[0] = NULL;
- }
- X
- /*
- X * Update topline, bottomline, arrow sign, updown sign, stop signs, and
- X * line label.
- X */
- /* ARGSUSED */
- void Update(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X XmTextPosition pos;
- X int topline;
- X FileRec *file;
- X int Py;
- X Arg args[5];
- X
- X if (displayedFile) {
- X file = displayedFile;
- X pos = XmTextGetTopCharacter(sourceWindow);
- X file->topPosition = pos;
- X topline = TextPositionToLine(pos);
- X /* Update the symbols only if the text scrolls */
- X if (file->topline != topline) {
- X file->topline = topline;
- X file->bottomline = MIN (file->topline + file->lines - 1,
- X file->lastline);
- X if (*num_params == 1 && strcmp(params[0], "warp") == 0)
- X {
- X XmTextSetInsertionPosition(sourceWindow,
- X file->linepos[file->topline]);
- X }
- X
- X UpdateLineLabel(file->topline);
- X UpdateStops(file, -1);
- X UpdateArrow(file);
- X UpdateUpdown(file);
- X UpdateBomb(file);
- X Py = TextPositionToLine(XmTextGetTopCharacter(sourceWindow));
- X XtSetArg(args[0], XmNvalue, Py);
- X XtSetValues(scrollV, args, 1);
- X
- X }
- X else {/* Update caret position only */
- X pos = XmTextGetInsertionPosition(sourceWindow);
- X UpdateLineLabel(TextPositionToLine(pos));
- X }
- X }
- }
- X
- void UpdateSigns(reason)
- X int reason;
- {
- X int pos;
- X FileRec *file;
- X Arg args[MAXARGS];
- X
- X file = displayedFile;
- X pos = XmTextGetTopCharacter(sourceWindow);
- X file->topline = TextPositionToLine(pos);
- X
- X file->bottomline = MIN (file->topline + file->lines - 1,
- X file->lastline);
- X UpdateStops(file, reason);
- X UpdateArrow(file);
- X UpdateUpdown(file);
- X UpdateBomb(file);
- X
- }
- X
- X
- /* Update the position of the caret */
- /* ARGSUSED */
- void UpdateLine(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X XmTextPosition pos;
- X int line;
- X
- X pos = XmTextGetInsertionPosition(w);
- X line = TextPositionToLine(pos);
- X UpdateLineLabel(line);
- }
- X
- X
- /* My select-start routine that cancels the effect of automatic scrolling
- X * near the bottom of an Athena text widget window.
- X */
- /* ARGSUSED */
- void SelectStart(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X XtCallActionProc(w, "set-insertion-point", event, params, num_params);
- X XtCallActionProc(w, "grab-focus", event, params, num_params);
- }
- X
- /* My select-end routine to store the text selection into both the PRIMARY
- X * selection and cut buffer 0.
- X */
- /* ARGSUSED */
- void SelectEnd(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X XtCallActionProc(w, "extend-end", event, params, num_params);
- }
- 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 */
- /* ARGSUSED */
- void SelectWord(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X XmTextPosition left, right, center, last;
- X char *valuestring;
- X
- X XtCallActionProc(w, "set-insertion-point", event, params, num_params);
- X center = XmTextGetInsertionPosition(w);
- X valuestring = XmTextGetString(w);
- X last = XmTextGetLastPosition(w);
- X
- X if(strchr(DELIMITERS, valuestring[center])) return;
- X left = center;
- X right = center;
- X
- X while(left>0 && !strchr(DELIMITERS, valuestring[left-1])) left--;
- X while(right<last && !strchr(DELIMITERS, valuestring[right])) right++;
- X
- X XmTextSetSelection(w, left, right, 0);
- X XtFree(valuestring);
- }
- X
- void SelectAdjust(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X XtCallActionProc(w, "extend-adjust", event, params, num_params);
- }
- X
- void ScrollTxt(w, client_data, call_data)
- X Widget w;
- X XtPointer client_data;
- X XmScrollBarCallbackStruct *call_data;
- {
- X Arg args[5];
- X int Py;
- X
- X if(!displayedFile) return;
- X
- X switch((unsigned int) client_data)
- X {
- X case _PAGERIGHT:
- X XtCallActionProc(sourceWindow, "page-right", call_data->event,
- X NULL, 0);
- X break;
- X case _PAGELEFT:
- X XtCallActionProc(sourceWindow, "page-left", call_data->event,
- X NULL, 0);
- X break;
- X case _SCROLLUPPAGE:
- X XtCallActionProc(sourceWindow, "next-page", call_data->event, NULL, 0);
- X Py = TextPositionToLine(XmTextGetTopCharacter(sourceWindow));
- X XtSetArg(args[0], XmNvalue, Py);
- X XtSetValues(scrollV, args, 1);
- X break;
- X case _SCROLLDOWNPAGE:
- X XtCallActionProc(sourceWindow, "previous-page", call_data->event,
- X NULL, 0);
- X Py = TextPositionToLine(XmTextGetTopCharacter(sourceWindow));
- X XtSetArg(args[0], XmNvalue, Py);
- X XtSetValues(scrollV, args, 1);
- X break;
- X default:
- X XmTextSetTopCharacter(sourceWindow,
- X displayedFile->linepos[call_data->value]);
- X }
- X UpdateSigns(call_data->reason);
- }
- X
- void resetLineBounds(w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X Arg args[MAXARGS];
- X short file_lines;
- X
- X if(displayedFile)
- X {
- X XtSetArg(args[0], XmNrows, &file_lines);
- X XtGetValues(sourceWindow, args, 1);
- X displayedFile->lines = file_lines;
- X displayedFile->bottomline = MIN (displayedFile->topline +
- X displayedFile->lines - 1,
- X displayedFile->lastline);
- X UpdateSigns(SASH_MOTION);
- X }
- }
- X
- #define BUTTONSNUM 18 /* Number of buttons */
- #define NCOLUMNS 2 /* Should divide BUTTONSNUM evenly */
- #define SPACEFACTOR 32 /* These number can be diddled. */
- #define BUTTONWIDTH 32
- #define FRACTIONBASE ((BUTTONSNUM * SPACEFACTOR) / NCOLUMNS)
- X
- void CreateCommandButtons(parent)
- Widget parent;
- {
- X static buttonstruct commandbuttons[] = {
- X { NULL, "stackbutton", stack_bits, stack_width, stack_height, DoIt,
- X "info stack\n" },
- X { NULL, "runbutton", run_bits, run_width, run_height, DoIt, "run\n" },
- X { NULL, "upbutton", up_bits, up_width, up_height, DoIt, "up\n" },
- X { NULL, "localsbutton", locals_bits, locals_width, locals_height, DoIt,
- X "info locals\n" },
- X { NULL, "downbutton", down_bits, down_width, down_height, DoIt, "down\n" },
- X { NULL, "argsbutton", args_bits, args_width, args_height, DoIt,
- X "info args\n" },
- X { NULL, "printbutton", print_bits, print_width, print_height, Print,
- X NULL },
- X { NULL, "printsbutton", prints_bits, prints_width, prints_height, Print,
- X 1 },
- X { NULL, "nextbutton", next_bits, next_width, next_height, DoIt, "next\n" },
- X { NULL, "contbutton", cont_bits, cont_width, cont_height, DoIt, "cont\n" },
- X { NULL, "stepbutton", step_bits, step_width, step_height, DoIt, "step\n" },
- X { NULL, "finishbutton", finish_bits, finish_width, finish_height, DoIt,
- X "finish\n" },
- X { NULL, "breakbutton", stop_bits, stop_width, stop_height, Break,
- X "break" },
- X { NULL, "clearbutton", clear_bits, clear_width, clear_height, Clear,
- X NULL },
- X { NULL, "dispbutton", disp_bits, disp_width, disp_height, Display_, NULL },
- X { NULL, "undispbutton", undisp_bits, undisp_width, undisp_height,
- X Undisplay,
- X NULL },
- X { NULL, "pageRbutton", pageR_bits, pageR_width, pageR_height,
- X ScrollTxt, _PAGERIGHT},
- X { NULL, "pageLbutton", pageL_bits, pageL_width, pageL_height,
- X ScrollTxt, _PAGELEFT },
- X };
- X
- X Pixel bg;
- X int screen;
- X Display *topdisplay;
- X int window1;
- X int depth1;
- X int buttonindex;
- X XtCallbackList buttoncalls;
- X Arg args[10];
- X
- X static Arg buttonargs[] = {
- X { XmNbottomAttachment, XmATTACH_POSITION },
- X { XmNtopAttachment, XmATTACH_POSITION },
- X { XmNrightAttachment, XmATTACH_FORM },
- X { XmNwidth, BUTTONWIDTH },
- X { XmNlabelType, XmPIXMAP },
- X { XmNhighlightOnEnter, True },
- X { 0, 0 },
- X { 0, 0 },
- X { 0, 0 },
- X };
- X
- X XtSetArg(args[0], XmNbackground, &bg);
- X XtGetValues(sourceForm, args, 1);
- X topdisplay = XtDisplay(toplevel);
- X screen = DefaultScreen(topdisplay);
- X window1 = DefaultRootWindow(topdisplay);
- X depth1 = DefaultDepth(topdisplay, screen);
- X
- X for (buttonindex = 0; buttonindex < BUTTONSNUM; buttonindex++)
- X {
- X XtSetArg(buttonargs[6], XmNlabelPixmap,
- X XCreatePixmapFromBitmapData(topdisplay, window1,
- X commandbuttons[buttonindex].labelbits,
- X commandbuttons[buttonindex].labelwidth,
- X commandbuttons[buttonindex].labelheight,
- X app_resources.stop_color, bg,
- X depth1));
- X
- X XtSetArg(buttonargs[7], XmNrightOffset,
- X (buttonindex%NCOLUMNS)?(BUTTONWIDTH*(buttonindex%NCOLUMNS)):0);
- X XtSetArg(buttonargs[8], XmNtopPosition,
- X ((buttonindex/NCOLUMNS) * SPACEFACTOR));
- X XtSetArg(buttonargs[9], XmNbottomPosition,
- X (((buttonindex/NCOLUMNS) + 1) * SPACEFACTOR));
- X commandbuttons[buttonindex].button =
- X XtCreateManagedWidget(commandbuttons[buttonindex].buttonname,
- X xmPushButtonWidgetClass, parent,
- X buttonargs, 10);
- X XtAddCallback(commandbuttons[buttonindex].button,
- X XmNactivateCallback, commandbuttons[buttonindex].CB,
- X commandbuttons[buttonindex].CBarg);
- X }
- }
- /*
- X * On top of a form widget, we have a text widget, label
- X * widgets for the stop sign, arrow sign, and updown signs.
- X */
- void CreateSourceWindow(parent)
- Widget parent;
- {
- X Arg args[10];
- X
- X static XtActionsRec command_actions[] = {
- X { "SelectStart", (XtActionProc) SelectStart },
- X { "SelectWord", (XtActionProc) SelectWord },
- X { "SelectEnd", (XtActionProc) SelectEnd },
- X { "SelectAdjust", (XtActionProc) SelectAdjust },
- X { "Update", (XtActionProc) Update },
- X { "resetLineBounds", (XtActionProc) resetLineBounds },
- X { NULL, NULL }
- X };
- X
- X static Arg sourcewindowargs[] = {
- X { XmNeditMode, XmMULTI_LINE_EDIT },
- X { XmNrightAttachment, XmATTACH_FORM },
- X { XmNbottomAttachment, XmATTACH_FORM },
- X { XmNtopAttachment, XmATTACH_FORM },
- X { XmNleftAttachment, XmATTACH_FORM },
- X { XmNeditable, False },
- X { XmNhighlightOnEnter, True },
- X { XmNleftOffset, 50 },
- X { 0, 0 },
- X };
- X
- X static Arg sourcescrollargs[] = {
- X { XmNscrollingPolicy, XmAPPLICATION_DEFINED },
- X { XmNscrollBarPlacement, XmBOTTOM_LEFT },
- X };
- X
- X static Arg commanddialogargs[] = {
- X { XmNfractionBase, FRACTIONBASE },
- X { XmNautoUnmanage, False },
- X };
- X
- X sourceScroll = XtCreateManagedWidget("sourceScroll",
- X xmScrolledWindowWidgetClass,
- X parent, sourcescrollargs, 2);
- X
- X scrollV = XtCreateWidget("scrollV", xmScrollBarWidgetClass, sourceScroll,
- X args, 0);
- X
- X XtSetArg(args[0], XmNfractionBase, FRACTIONBASE);
- X sourceForm = XtCreateManagedWidget("sourceForm", xmFormWidgetClass,
- X sourceScroll, args, 1);
- X
- X XmScrolledWindowSetAreas(sourceScroll, NULL, scrollV, sourceForm);
- X
- X XtAddCallback(scrollV, XmNdecrementCallback, ScrollTxt, _SCROLLDOWN);
- X XtAddCallback(scrollV, XmNincrementCallback, ScrollTxt, _SCROLLUP);
- X XtAddCallback(scrollV, XmNpageIncrementCallback, ScrollTxt, _SCROLLUPPAGE);
- X XtAddCallback(scrollV, XmNpageDecrementCallback,
- X ScrollTxt, _SCROLLDOWNPAGE);
- X XtAddCallback(scrollV, XmNdragCallback, ScrollTxt, _SCROLLDRAG);
- X if(!app_resources.useCommandDialog)
- X XtSetArg(sourcewindowargs[8], XmNrightOffset, BUTTONWIDTH * NCOLUMNS);
- X sourceWindow = XtCreateManagedWidget("sourceWindow", xmTextWidgetClass,
- X sourceForm, sourcewindowargs, 9);
- X XtAppAddActions(app_context, command_actions, XtNumber(command_actions));
- X if(app_resources.useCommandDialog)
- X {
- X commandDialog = XmCreateFormDialog(parent, "commandDialog",
- X commanddialogargs, 2);
- X CreateCommandButtons(commandDialog);
- X }
- X else
- X CreateCommandButtons(sourceForm);
- }
- X
- /*
- X * Popup the commandDialog Box if we are using it.
- X *
- X */
- X
- void PopupCommands(w, client_data, call_data)
- X Widget w;
- X XtPointer client_data;
- X XmPushButtonCallbackStruct *call_data;
- {
- X if(app_resources.useCommandDialog)
- X XtManageChild(commandDialog);
- X else
- X {
- X UpdateMessageWindow("Not using command button dialog", NULL);
- X bell(0);
- X }
- }
- X
- /*
- X * Build the array which gives the starting text position of each line.
- X * > Estimate the number of lines in the file and allocate memory buffer.
- X * > Starting position of line #1 is 0, and is stored in linepos[1].
- X * > Search for '\n' till end of buffer.
- X */
- static void BuildLinePos(file)
- FileRec *file;
- {
- X char *p;
- X int line, nlines;
- X
- X nlines = MAX(2, file->filesize/CHARS_PER_LINE);
- X file->linepos = (XmTextPosition *)
- X XtMalloc ((nlines+1) * sizeof(XmTextPosition));
- X p = file->buf;
- X
- X file->linepos[0] = 0;
- X file->linepos[1] = 0;
- X line = 2;
- X
- X while (*p) {
- X if (*p++ == '\n') {
- X if (line == nlines) { /* buffer full, need more memory */
- X file->linepos = (XmTextPosition *) XtRealloc (file->linepos,
- X (nlines + ADD_LINES) * sizeof(XmTextPosition));
- X nlines += ADD_LINES;
- X }
- X file->linepos[line++] = p - file->buf;
- X }
- X }
- X file->lastline = line - 2;
- X file->linepos = (XmTextPosition *) XtRealloc /* shrink to min size */
- X (file->linepos, line * sizeof(XmTextPosition));
- }
- 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 */
- static LookUpFileTable(pathname, filename, file)
- char *pathname, *filename;
- FileRec **file;
- {
- X struct stat fileinfo;
- X int fd;
- X int i, j, n;
- X
- X for (i=0; fileTable && fileTable[i] && i<fileTableSize; i++) {
- X if (!strcmp(fileTable[i]->pathname, pathname)) { /* file found */
- X if (stat(pathname, &fileinfo) == -1) {
- X UpdateMessageWindow("Error: cannot stat file %s", pathname);
- X *file = fileTable[i];
- X return 0;
- X }
- X if (fileinfo.st_mtime > fileTable[i]->mtime) { /* file modified */
- X XtFree((char *)fileTable[i]->buf);
- X XtFree((char *)fileTable[i]->linepos);
- X XtFree((char *)fileTable[i]);
- X displayedFile = NULL;
- X break;
- X }
- X else if (displayedFile && /* same as displayed file */
- X strcmp(pathname, displayedFile->pathname) == 0) {
- X *file = NULL;
- X return 0;
- X }
- X else {
- X *file = fileTable[i];
- X return 0;
- X }
- X }
- X }
- X
- X /* Record file into file table */
- X
- X if (i == fileTableSize) { /* file table full, enlarge it */
- X fileTableSize += ADD_SIZE;
- X fileTable = (FileRec **)
- X XtRealloc (fileTable, fileTableSize * sizeof(FileRec *));
- X for (j=i; j<fileTableSize; j++)
- X fileTable[j] = NULL;
- X }
- X if ((fd = open(pathname, O_RDONLY)) == -1) {
- X UpdateMessageWindow("Error: cannot open file %s", pathname);
- X return -1;
- X }
- X if (fstat(fd, &fileinfo) == -1) {
- X UpdateMessageWindow("Error: cannot fstat file %s", pathname);
- X close(fd);
- X return -1;
- X }
- X fileTable[i] = (FileRec *) XtMalloc (sizeof(FileRec));
- X fileTable[i]->filesize = fileinfo.st_size + 1;
- X fileTable[i]->mtime = fileinfo.st_mtime;
- X fileTable[i]->buf = XtMalloc((int)fileTable[i]->filesize);
- X if ((n = read(fd, fileTable[i]->buf, (int) fileTable[i]->filesize)) == -1) {
- X UpdateMessageWindow("Error: cannot read file %s", pathname);
- X XtFree(fileTable[i]->buf);
- X XtFree(fileTable[i]);
- X fileTable[i] = NULL;
- X close(fd);
- X return -1;
- X }
- X fileTable[i]->buf[n] = '\0';
- X fileTable[i]->pathname = XtNewString(pathname);
- X fileTable[i]->filename = XtNewString(filename);
- 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 close(fd);
- X *file = fileTable[i];
- X return 0;
- }
- X
- /*
- X * Remember file position and current line before closing.
- X */
- static void SaveDisplayedFileInfo()
- {
- X XmTextPosition pos;
- X Arg args[MAXARGS];
- X
- X if (displayedFile) {
- X XtSetArg(args[0], XmNtopPosition, &(displayedFile->topPosition));
- X XtGetValues(sourceWindow, args, 1);
- X XtSetArg(args[0], XmNcursorPosition, &pos);
- X XtGetValues(sourceWindow, args, 1);
- X displayedFile->currentline = TextPositionToLine(pos);
- X }
- }
- X
- 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 */
- static void DisplayFile(file)
- FileRec *file;
- {
- X Arg args[MAXARGS];
- X short columns, rows, rowcount;
- X int slidersize;
- X Dimension height, width;
- X
- X XtSetArg(args[0], XmNeditable, False);
- X XtSetArg(args[1], XmNvalue, file->buf);
- X XtSetValues(sourceWindow, args, 2);
- X
- X XtSetArg(args[0], XmNrows, &rows);
- X XtSetArg(args[1], XmNcolumns, &columns);
- X XtGetValues(sourceWindow, args, 2);
- X
- X file->lines = rows;
- X file->bottomline = MIN (file->topline + file->lines - 1, file->lastline);
- X
- X if(file->lastline < rows)
- X {
- X if(XtIsManaged(scrollV))
- X XtUnmanageChild(scrollV);
- X }
- X else
- X {
- X XtSetArg(args[0], XmNheight, &height);
- X XtGetValues(scrollV, args, 1);
- X slidersize = ((int)rows * (int)height)/(int)file->lastline;
- X XmScrollBarSetValues(scrollV, 1, slidersize, 1, 0, True);
- X XtSetArg(args[0], XmNmaximum, file->lastline+slidersize);
- X XtSetArg(args[1], XmNminimum, 0);
- X XtSetValues(scrollV, args, 2);
- X XtManageChild(scrollV);
- X }
- }
- X
- X
- /* Given a filename starting with a tilde (`~'), it expands ~[user] to
- X * the home directory of that user, or to the login home directory if user
- X * is not specified.
- X */
- static char *expand(filename)
- char *filename;
- {
- X struct passwd *pwd;
- X char *string, *name, newfile[MAXNAME];
- X
- X string = XtNewString(filename+1);
- X if (*string == '\0' || *string == '/')
- X name = (char *) getlogin();
- X else
- X name = (char *) strtok(string, "/");
- X if (name == NULL)
- X return filename;
- X pwd = (struct passwd *) getpwnam(name);
- X if (pwd && pwd->pw_dir) {
- X sprintf(newfile, "%s%s", pwd->pw_dir, filename+strlen(name)+1);
- X return XtNewString(newfile);
- X }
- X else
- X return filename;
- }
- X
- X
- /* Create a list of directories for searching source files.
- X * It reads the list of directories specified by the user, adding
- X * the current directory into the list if it is not already there.
- X *
- X * With fix from Dave Gagne (daveg@fs1.ee.ubc.ca) 7/30/90
- X */
- void MakeDirList(output)
- char *output;
- {
- X char *s, list[BUFSIZ], command[LINESIZ];
- X int i, use_cwd;
- X
- X for (i=0; dirList[i]; i++) /* remove old list */
- X XtFree(dirList[i]);
- X i = 0;
- X use_cwd = TRUE;
- X if (output) { /* create list */
- X s = (char *) strtok(output, ": \n");
- X while (s) {
- X dirList[i] = XtNewString(s);
- X
- X if (dirList[i][0] == '~') /* expand '~' */
- X dirList[i] = expand(dirList[i]);
- X if (LASTCH(dirList[i]) == '/') /* remove last '/' */
- X LASTCH(dirList[i]) = '\0';
- X if (!strcmp(dirList[i], ".")) /* watch for "." */
- X use_cwd = FALSE;
- X
- X ++i;
- X s = (char *) strtok(NULL, " \n");
- X }
- X dirList[i] = NULL;
- X }
- X
- X if (use_cwd) { /* include current dir */
- X dirList[i++] = XtNewString(".");
- X dirList[i] = NULL;
- X }
- X strcpy(list, ""); /* tell dbx our new list */
- X for (i=0; dirList[i]; i++) {
- X strcat(list, dirList[i]);
- X strcat(list, " ");
- X }
- X sprintf(command, "directory %s\n", list);
- X Parse = False;
- X query_dbx(command);
- }
- X
- X
- /* Returns the full pathname of a given file.
- X * It searches for the file from a list of directories.
- X */
- char *GetPathname(filename)
- char *filename;
- {
- X char pathname[LINESIZ];
- X int i;
- X
- X if (filename == NULL || !strcmp(filename, ""))
- X return NULL;
- X for (i=0; dirList[i]; i++) {
- X if (*filename == '/' && access(filename, R_OK) == -1) {
- X /* this handles the exceptional case of sun4 dbx output */
- X strcpy(filename, &filename[1]);
- X }
- X if (*filename == '/' || *filename == '~')
- X strcpy(pathname, filename);
- X else if (!strcmp(dirList[i], "."))
- X sprintf(pathname, "%s/%s", cwd, filename);
- X else if (*dirList[i] == '/' || *dirList[i] == '~')
- X sprintf(pathname, "%s/%s", dirList[i], filename);
- X else
- X sprintf(pathname, "%s/%s/%s", cwd, dirList[i], filename);
- X if (access(pathname, R_OK) == 0)
- X return XtNewString(pathname);
- X }
- X UpdateMessageWindow("File not found: %s", filename);
- X return NULL;
- }
- X
- /*
- X * Given a file name, LoadFile attempts to open it and displays it onto
- X * the source window:
- X * 1. get the full pathname of the file
- X * 2. LookUpFileTable() returns a pointer to the file's entry if it's
- X * already in the table; else, creates an entry and return a pointer.
- X * 3. save the current displayedFile info
- X * 4. display the file
- X * 5. update the file label and the various signs on the source window.
- X * LoadFile returns 0 upon successful completion, -1 otherwise.
- X */
- int LoadFile(filename)
- char *filename;
- {
- X FileRec *file;
- X char *pathname;
- X Arg args[5];
- X Position Py;
- X
- X
- X pathname = GetPathname(filename);
- X if (pathname == NULL) {
- X return -1;
- X }
- X if (LookUpFileTable(pathname, filename, &file) != -1) {
- X if (file) { /* load new file */
- X SaveDisplayedFileInfo();
- X DisplayFile(file);
- X UpdateFileLabel(pathname);
- X XmTextClearSelection(sourceWindow,0);
- X XmTextSetInsertionPosition(sourceWindow,
- X file->linepos[file->currentline]);
- X UpdateLineLabel(file->currentline);
- X UpdateStops(file, -1);
- X UpdateArrow(file);
- X UpdateUpdown(file);
- X UpdateBomb(file);
- X displayedFile = file;
- X }
- X return 0;
- X }
- X else { /* LookUpFileTable() fails */
- X return -1;
- X }
- }
- X
- int LoadCurrentFile()
- {
- X query_dbx("info line\n");
- X return LoadFile(CurrentFile);
- }
- X
- X
- SHAR_EOF
- echo 'File mxgdb/source.c is complete' &&
- chmod 0664 mxgdb/source.c ||
- echo 'restore of mxgdb/source.c failed'
- Wc_c="`wc -c < 'mxgdb/source.c'`"
- test 27029 -eq "$Wc_c" ||
- echo 'mxgdb/source.c: original size 27029, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= mxgdb/signs.c ==============
- if test -f 'mxgdb/signs.c' -a X"$1" != X"-c"; then
- echo 'x - skipping mxgdb/signs.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting mxgdb/signs.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/signs.c' &&
- static char rcsid[] = "$Id: signs.c,v 1.4 1991/08/07 21:30:42 jtsillas Exp $";
- 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
- /* signs.c
- 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 * bomb - a bomb symbol to indicate the point of segmentation fault.
- 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
- #include "global.h"
- #include "bitmaps.h"
- #include <Xm/Xm.h>
- #include <Xm/Label.h>
- X
- #define MAXSTOPS 256 /* max number of stops */
- #define MAXSIGNS 256 /* max number of signs */
- #define OFFSET 0 /* offset for displaying signs */
- X
- ArrowSign arrowsign[MAXSIGNS];
- UpdownSign updownsign[MAXSIGNS];
- StopSign stopsign[MAXSIGNS];
- BombSign bombsign[MAXSIGNS];
- X
- Arrow arrow;
- Updown updown;
- Stops stops[MAXSTOPS]; /* array of stops */
- Bomb bomb;
- Cardinal nstops; /* number of stops */
- X
- /* Initialize data structures */
- X
- void signs_init()
- {
- 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.file, "");
- X updown.i = 0;
- X updown.line = 0;
- X strcpy(updown.file, "");
- X nstops = 0;
- X bomb.i = 0;
- X bomb.line = 0;
- X strcpy(bomb.file, "");
- }
- 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 */
- static Widget CreateSign(parent, textW, sign, i)
- X Widget parent;
- X Widget textW;
- X char *sign;
- X Cardinal i;
- {
- 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 int screen;
- X
- X if (displayedFile == NULL) return NULL;
- X
- X /* Get height and background pixel values of parent window */
- X XtSetArg(args[0], XmNheight, &source_height);
- X XtSetArg(args[1], XmNbackground, &bg);
- X XtGetValues(textW, args, 2);
- X
- X height_per_line = source_height/displayedFile->lines;
- X vertDistance = OFFSET + (i * height_per_line);
- X
- X screen = DefaultScreen(display);
- 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.arrow_color;
- 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.updown_color;
- 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.stop_color;
- X }
- X else if (sign && !strcmp(sign, "bomb")) {
- X bits = bomb_bits;
- X width = bomb_width;
- X height = bomb_height;
- X horizDistance = 0;
- X fg = app_resources.bomb_color;
- X };
- X
- X n = 0;
- X XtSetArg(args[n], XmNborderWidth, 0); n++;
- X XtSetArg(args[n], XmNwidth, (XtArgVal) width); n++;
- X XtSetArg(args[n], XmNheight, (XtArgVal) height); n++;
- X XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
- X XtSetArg(args[n], XmNlabelPixmap, XCreatePixmapFromBitmapData (
- X display, DefaultRootWindow(display), bits, width, height,
- X fg, bg, DefaultDepth(display, screen))); n++;
- X
- X XtSetArg(args[n], XmNx, (XtArgVal) horizDistance+5);
- X n++;
- X XtSetArg(args[n], XmNy, (XtArgVal) vertDistance+3); n++;
- X XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
- X
- X return XtCreateManagedWidget(sign, xmLabelWidgetClass, parent, args, n);
- }
- 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 */
- void DisplayStop(file, line)
- FileRec *file;
- int line;
- {
- X Cardinal i;
- X Arg args[MAXARGS];
- 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
- X stopsign[i].w = CreateSign(sourceForm, sourceWindow, "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 * Unmap all stop signs and then display only those stops that are viewable.
- X */
- void UpdateStops(file, reason)
- FileRec *file;
- int reason;
- {
- X Cardinal i;
- X int line;
- X Position vert;
- X Dimension source_height;
- X Arg args[1];
- X
- 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].file && !strcmp(stops[i].file, file->pathname) &&
- X (line=stops[i].line) && line >= file->topline &&
- X line <= file->bottomline) {
- X DisplayStop(file, line);
- X }
- }
- X
- /*
- X * Given a line number, unmap the stop sign associated with that line.
- X */
- void RemoveStop(line)
- int line;
- {
- X Cardinal i;
- X char command[30];
- 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 sprintf(command, "clear %d\n", line);
- X send_command(command);
- X Echo = False;
- X Parse = False;
- X Prompt = False;
- X while(!Prompt) read_dbx();
- X
- X }
- X }
- }
- X
- void ClearStops()
- {
- X int i;
- X
- X for (i=1; i<=nstops; i++) {
- X stops[i].file = NULL;
- X stops[i].line = 0;
- X }
- }
- X
- /* Unmap the current arrow sign.
- X * Display a new arrow sign if it is viewable.
- X */
- void UpdateArrow(file)
- FileRec *file;
- {
- X Cardinal i;
- X int 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.file && !strcmp(arrow.file, file->pathname) &&
- 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(sourceForm, sourceWindow, "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
- /* 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 */
- void UpdateUpdown(file)
- FileRec *file;
- {
- X Cardinal i;
- X int line;
- X
- X if (file == NULL) return;
- X if (updown.file && !strcmp(updown.file, arrow.file) &&
- X !strcmp(updown.func, arrow.func) && (updown.line == arrow.line)) {
- X updown.line = 0;
- X strcpy(updown.file, "");
- 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.file && !strcmp(updown.file, file->pathname) &&
- 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(sourceForm, sourceWindow, "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
- /* Unmap the current bomb sign, if any.
- X * Display a new bomb sign.
- X */
- void UpdateBomb(file)
- FileRec *file;
- {
- X Cardinal i;
- X int line;
- X
- X if (file == NULL) return;
- X i = bomb.i;
- X if (i>=0 && i<file->lines)
- X if (bombsign[i].w && bombsign[i].mapped) {
- X XtUnmapWidget(bombsign[i].w);
- X bombsign[i].mapped = 0;
- X }
- X line = bomb.line;
- X if (bomb.file && !strcmp(bomb.file, file->pathname) &&
- X line >= file->topline && line <= file->bottomline) {
- X i = line - file->topline;
- X bomb.i = i;
- X if (bombsign[i].w == NULL) {
- X bombsign[i].w = CreateSign(sourceForm, sourceWindow, "bomb", i);
- X XtMapWidget(bombsign[i].w);
- X bombsign[i].mapped = TRUE;
- X }
- X else if (!bombsign[i].mapped) {
- X XtMapWidget(bombsign[i].w);
- X bombsign[i].mapped = TRUE;
- X }
- X }
- }
- SHAR_EOF
- chmod 0644 mxgdb/signs.c ||
- echo 'restore of mxgdb/signs.c failed'
- Wc_c="`wc -c < 'mxgdb/signs.c'`"
- test 10834 -eq "$Wc_c" ||
- echo 'mxgdb/signs.c: original size 10834, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= mxgdb/windows.c ==============
- if test -f 'mxgdb/windows.c' -a X"$1" != X"-c"; then
- echo 'x - skipping mxgdb/windows.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting mxgdb/windows.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/windows.c' &&
- static char rcsid[] = "$Id: windows.c,v 1.17 1991/08/23 16:34:46 jtsillas Exp $";
- X
- /*****************************************************************************
- X *
- X * xdbx - X Window System interface to dbx
- X *
- X * Copyright 1989, 1990 The University of Texas at Austin
- 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
- SHAR_EOF
- true || echo 'restore of mxgdb/windows.c failed'
- fi
- echo 'End of part 3'
- echo 'File mxgdb/windows.c is continued in part 4'
- echo 4 > _shar_seq_.tmp
- exit 0
-