home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * xdbx - X Window System interface to dbx
- *
- * Copyright 1989 The University of Texas at Austin
- *
- * Author: Po Cheung
- * Date: March 10, 1989
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation. The University of Texas at Austin makes no
- * representations about the suitability of this software for any purpose.
- * It is provided "as is" without express or implied warranty.
- *
- ******************************************************************************/
-
-
- #include <ctype.h>
- #include "global.h"
- #ifdef BSD
- #include "bsd_regex.h"
- #else
- #include "sun_regex.h"
- #endif
-
- /* Display text starting from the top position specified by pos */
-
- static void TextSetTopPosition(w, pos)
- Widget w;
- XtTextPosition pos;
- {
- Arg args[MAXARGS];
- Cardinal n;
-
- n = 0;
- XtSetArg(args[n], XtNdisplayPosition, (XtArgVal) pos); n++;
- XtSetValues(w, args, n);
- XtTextDisplay(w);
- }
-
- /*
- * Adjust text so that 'line' will fall into the viewable part of the
- * source window.
- * Arrows, stop signs, and line label are updated accordingly.
- */
- static void AdjustText(w, line)
- Widget w;
- Line line;
- {
- FileRec *file;
-
- if ((file = displayedFile) == NULL) return;
- file->currentline = line;
- if (line < file->topline || line > file->bottomline ) {
-
- if (line < file->lines/2) /* near top */
- file->topline = 1;
- else if (line > file->lastline - file->lines/2) /* near bottom */
- file->topline = MAX(file->lastline - file->lines + 1, 1);
- else
- file->topline = line - file->lines/2;
- file->bottomline = MIN(file->topline + file->lines - 1, file->lastline);
- TextSetTopPosition (w, file->linepos[file->topline]);
- UpdateStops(file);
- }
- XtTextSetInsertionPoint(w, file->linepos[line]);
- UpdateLineLabel(line);
- UpdateArrow(file);
- UpdateUpdown(file);
- }
-
-
- /* Handle dbx output of run, cont, next, step commands.
- * Result of output parsing is returned in a set of tokens.
- * Done is a boolean which indicates completed execution of debugged program.
- */
- void exec_handler(token, done)
- Tokens *token;
- int done;
- {
- char s[LINESIZ], command[LINESIZ];
-
- /* If done, remove all the arrow and updown signs, print message, then
- * change the file variable to the file name displayed.
- */
- if (done) {
- arrow.line = 0;
- updown.line = 0;
- UpdateArrow(displayedFile);
- UpdateUpdown(displayedFile);
- UpdateMessageWindow("Ready for execution");
- if (displayedFile == NULL) return;
- sprintf(command, "file %s\n", displayedFile->filename);
- QueryDbx(command, FALSE);
- return;
- }
-
- /* Print "stopped in ..." line in meesage window
- * Adjust text displayed
- */
- if (token->func == NULL || token->line == 0)
- return;
- if (token->file)
- displayedFile = LoadFile(token->file);
- UpdateMessageWindow(token->mesg);
- arrow.line = token->line; /* update arrow sign position */
- updown.line = 0; /* remove updown, if any */
- if (displayedFile)
- strcpy(arrow.filename, displayedFile->filename);
- AdjustText(sourceWindow, token->line);
- if (displayedFile) {
- XtTextSetInsertionPoint(sourceWindow, displayedFile->linepos[token->line]);
- UpdateLineLabel(token->line);
- }
- }
-
-
- /* Place a stop sign next to the line specified on the source file window
- * if it is to be viewable.
- */
- void stop_at_handler(token)
- Tokens *token;
- {
- if (token->stop == 0 || token->line == 0 || displayedFile == NULL)
- return;
- if (token->file == NULL)
- stops[token->stop].filename = displayedFile->filename;
- else
- stops[token->stop].filename = token->file;
- DisplayStop(displayedFile, token->line);
- stops[token->stop].line = token->line;
- stops[token->stop].tag = 0;
- nstops = token->stop;
- }
-
-
- /*
- * Place a stop sign next to the function routine, getting the line number
- * by "list <func>", (which possibly changes the file variable), and
- * resetting the file variable properly.
- */
- void stop_in_handler(token)
- Tokens *token;
- {
- char command[LINESIZ], s[LINESIZ], *filename;
- int stop;
- Line line;
-
- if (token->stop == 0 || token->func == NULL || displayedFile == NULL)
- return;
- stop = token->stop;
- sprintf(command, "list %s\n", token->func);
- if (QueryDbx(command, TRUE) != O_LIST || token->line <= 0)
- return;
-
- stops[stop].line = token->line;
- nstops = stop;
- line = token->line;
-
- /* check if funcname belongs to another file */
- if ((filename = QueryFile()) && strcmp(filename, displayedFile->filename)) {
- /* new file, record stop */
- stops[nstops].filename = filename;
-
- /* restore variable file to original file */
- sprintf(command, "file %s\n", displayedFile->filename);
- QueryDbx(command, FALSE);
- }
- else { /* same file, display stop */
- stops[nstops].filename = displayedFile->filename;
- DisplayStop(displayedFile, line);
- }
- }
-
-
- /*
- * Display an outlined arrow to locate the calling routine in a stack
- * frame. BSD and SUN dbx have slightly different output semantics here.
- * The appropriate file with the calling routine is displayed and the
- * file variable is set accordingly.
- */
- void updown_handler(token)
- Tokens *token;
- {
- char s[LINESIZ], command[LINESIZ];
-
- #ifndef BSD
- displayedFile = LoadFile(QueryFile());
- if (displayedFile)
- token->file = displayedFile->filename;
- if (token->line <= 0) token->line = 1;
- #endif
-
- if (token->line <= 0 || token->func == NULL || token->file == NULL)
- return;
- if (token->file && displayedFile &&
- strcmp(token->file, displayedFile->filename)) {
- displayedFile = LoadFile(token->file);
- /* set dbx file variable to filename */
- sprintf(command, "file %s\n", token->file);
- QueryDbx(command, FALSE);
- }
- updown.line = token->line;
- if (displayedFile)
- strcpy(updown.filename, displayedFile->filename);
- AdjustText(sourceWindow, token->line);
- }
-
-
- /*
- * Delete handler remove the stop specified and undisplayed the stopsign
- * if it's visible.
- * It calls the dbx status command to find out what stops are left, and
- * then update the array of stops accordingly.
- */
- /* ARGSUSED */
- void delete_handler()
- {
- char s[LINESIZ];
- int i;
- Line line;
-
- Echo = FALSE;
- writeDbx("status\n");
- while (fgets(s, LINESIZ, dbxfp) == NULL);
- do {
- if (strcmp(s, "(dbx) ") || strcmp(s, "")) {
- sscanf(s, BRACKET, &i);
- if (i > 0 && i <= nstops && stops[i].line > 0)
- stops[i].tag = 1;
- }
- } while (fgets(s, LINESIZ, dbxfp));
- Echo = TRUE;
-
- for (i=1; i<=nstops; i++)
- if (stops[i].line > 0) {
- if (stops[i].tag)
- stops[i].tag = 0;
- else {
- line = stops[i].line;
- stops[i].line = 0;
- stops[i].filename = NULL;
- if (LineToStop_no(line) == 0)
- RemoveStop(line);
- }
- }
- }
-
- /*
- * This handler displays the function routine on the source window.
- * It locates the function by sending the dbx command "list <func>",
- * and loads the appropriate file accordingly.
- */
- void func_handler(token)
- Tokens *token;
- {
- Line line = 0;
- char s[LINESIZ], command[LINESIZ];
-
- if (token->func) {
- sprintf(command, "list %s\n", token->func);
- QueryDbx(command, TRUE);
- displayedFile = LoadFile(QueryFile());
- AdjustText(sourceWindow, token->line);
- }
- }
-
-
- /*
- * File handler first queries the current file set by the user command,
- * and then loads the file.
- */
- /* ARGSUSED */
- void file_handler(token)
- Tokens *token;
- {
- char *filename;
-
- if (token->file)
- displayedFile = LoadFile(QueryFile());
- }
-
-
- /* ARGSUSED */
- void debug_handler()
- {
- DisplayInit();
- }
-
-
- /* ARGSUSED */
- void cd_handler()
- {
- UpdateFileMenu();
- }
-