|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 8279 (0x2057)
Types: TextFile
Names: »source.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
└─⟦e10a7c8ba⟧ »./UNRELEASED/xgdb.tar.Z«
└─⟦ae30648b5⟧
└─⟦this⟧ »./source.c«
\f
#ifndef lint
static char rcsid[] = "$Header: source.c,v 1.1 89/07/05 15:36:35 hubbard Exp $";
#endif
/*
*
* Copyright 1988, 1989
* PCS Computer Systeme, GmbH
* Munich, West Germany
*
* All rights reserved.
*
* This is unsupported software and is subject to change without notice.
* PCS makes no representations about the suitability of this software
* for any purpose. It is supplied "as is" without express or implied
* warranty.
*
* 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, and that the name of PCS Computer Systeme not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
*/
/*
* Author: Jordan K. Hubbard
* For: PCS Computer Systems, GmbH.
* When: February 23rd, 1989.
*
* $Log: source.c,v $
* Revision 1.1 89/07/05 15:36:35 hubbard
* Initial revision
*
*
*/
#include "xgdb.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
static View *SourceView;
/*
* Everything needed to handle the source display pane.
*/
static struct {
String *list;
int nitems;
} sourceInfo;
/*
* Mapped?
*/
Boolean sourceMapped()
{
Entry("sourceMapped");
if (SourceView)
Leave(SourceView->mapped);
Leave(FALSE);
}
/*
* Highlight a source line.
*/
static void sourceHiliteLine(n)
int n;
{
Entry("sourceHiliteLine");
/* compensate for the fact that lists start at 0 */
if (n - 1 >= 0)
XtScrollListHighlight(SourceView->output, n - 1);
else
XtScrollListUnhighlight(SourceView->output);
Leave_void;
}
/*
* What to do when a source line is selected.
*/
static void sourceSelectLine(w, client_data, data)
Widget w;
caddr_t client_data, data;
{
XtScrollListReturnStruct *bpt = (XtScrollListReturnStruct *)data;
Entry("sourceSelectLine");
if (dbg_state.S_file && strcmp(dbg_state.S_file, INITIAL)) {
debuggerAddBkpt(NULL, T_LINE, bpt->list_index + 1);
sourceHiliteLine(atoi(dbg_state.S_line));
}
Leave_void;
}
/*
* Display a file in a source view.
*/
void sourceDisplayFile(s)
String s;
{
register String cp;
register char line[512];
register FILE *in;
register int i, list_size;
Entry("sourceDisplayFile");
/* Free old */
if (sourceInfo.list) {
for (i = 0; i < sourceInfo.nitems; i++)
XtFree(sourceInfo.list[i]);
XtFree(sourceInfo.list);
sourceInfo.list = (String *)NULL;
}
if (!(in = find_and_open(dbg_state.S_file_path, s, "r")))
puke("%p: Can't open file '%s'!", s);
else {
sourceInfo.list = (String *)XtMalloc(LINE_CHUNK * sizeof(String));
list_size = LINE_CHUNK;
i = 0;
while (fgets(line, 512, in)) {
if (i == list_size) {
list_size += LINE_CHUNK;
sourceInfo.list = (String *)XtRealloc(sourceInfo.list,
list_size * sizeof(String));
}
cp = (String)expand_string(line, ' ');
STASHF(sourceInfo.list[i], cp);
i++;
}
sourceInfo.nitems = i;
fclose(in);
if (!atoi(dbg_state.S_line))
XtScrollListChange(SourceView->output, sourceInfo.list,
i, 0, TRUE);
else
XtScrollListChange(SourceView->output, sourceInfo.list,
i, 0, FALSE);
}
Leave_void;
}
void sourceUpdateView()
{
static String File_name, Function, Line;
static Boolean initialized = FALSE;
FieldAttributes fla;
Entry("sourceUpdateView");
if (!initialized) {
STASH(File_name, "*");
STASH(Function, "*");
STASH(Line, "-1");
initialized = TRUE;
}
if (sourceMapped()) {
/* Has file changed? */
if (strcmp(File_name, dbg_state.S_file)) {
STASH(File_name, dbg_state.S_file);
/* make sure it's not the INITIAL value */
if (strcmp(File_name, INITIAL))
sourceDisplayFile(File_name);
/* If it's in the CWD, strip the unnecessary directory prefix */
if (!strcmp(strip_file_component(File_name), dbg_state.S_dir))
fla.label = (String)strip_directory_prefix(File_name);
else
fla.label = File_name;
changeField(nameToField("file_name", SourceView->fields),
FldLabel, &fla);
}
/* Has line changed? */
if (strcmp(Line, dbg_state.S_line)) {
STASH(Line, dbg_state.S_line);
sourceHiliteLine(atoi(Line));
fla.label = Line;
changeField(nameToField("line_number", SourceView->fields),
FldLabel, &fla);
}
/* Has function changed? */
if (strcmp(Function, dbg_state.S_function)) {
STASH(Function, dbg_state.S_function);
fla.label = Function;
changeField(nameToField("function_name", SourceView->fields),
FldLabel, &fla);
}
}
Leave_void;
}
/*
* Called when user is in a routine with no file/line information.
*/
void sourceNoLineInfo(T_PROCS_ARGS)
T_PROCS_DECL;
{
Entry("sourceNoLineInfo");
STASH(dbg_state.S_file, INITIAL);
STASH(dbg_state.S_line, "0");
Leave_void;
}
/*
* The following are invoked by the translation manager.
*/
void source_step(w, ev, av, ac)
Widget w;
XEvent *ev;
String *av;
Cardinal *ac;
{
Entry("source_step");
debuggerStep(NULL, NULL, NULL);
Leave_void;
}
void source_next(w, ev, av, ac)
Widget w;
XEvent *ev;
String *av;
Cardinal *ac;
{
Entry("source_next");
debuggerStepThrough(NULL, NULL, NULL);
Leave_void;
}
void source_finish(w, ev, av, ac)
Widget w;
XEvent *ev;
String *av;
Cardinal *ac;
{
Entry("source_finish");
debuggerStepFinish(NULL, NULL, NULL);
Leave_void;
}
/*
* Create the source view pane.
*/
void sourceCreateView(w, client_data, data)
Widget w;
caddr_t client_data, data;
{
static FormField buttons[] = {
{ { "close", viewCloseShell }, 2, FALSE, 0, 0, 0, 0 },
{ { "File:", NULL }, 0, FALSE, 0, 8, 0, 1 },
{ { "file_name", NULL }, 1, TRUE, 0, 5, 0, 2 },
{ { "Line:", NULL }, 0, FALSE, 0, 8, 0, 3 },
{ { "line_number", NULL }, 1, TRUE, 0, 5, 0, 4 },
{ { "Function:", NULL }, 0, FALSE, 0, 8, 0, 5 },
{ { "function_name", NULL }, 1, TRUE, 0, 5, 0, 6 },
{ { NULL, NULL }, 0, 0, 0, 0, 0, 0 },
};
static XtActionsRec src_actions[] = {
{ "Step", source_step },
{ "Next", source_next },
{ "Finish", source_finish },
};
static char src_trans[] =
"<Key>S: Step()\n <Key>N: Next()\n <Key>F: Finish()\n";
static XtTranslations trans = NULL;
FieldAttributes fla;
Field *flist;
String name = ((w) ? XtWidgetToName(w) : (String)data);
Entry("sourceCreateView");
if (!SourceView) {
convertFormToField(buttons, &flist);
if (!trans) {
XtAddActions(src_actions, XtNumber(src_actions));
trans = XtParseTranslationTable(src_trans);
}
ii = 0;
XtSetArg(aa[ii], XtNforceColumns, TRUE); ii++;
XtSetArg(aa[ii], XtNdefaultColumns, 1); ii++;
XtSetArg(aa[ii], XtNrepositionOnHilite, TRUE); ii++;
XtSetArg(aa[ii], XtNscrollVertical, TRUE); ii++;
if (sourceInfo.list) {
XtSetArg(aa[ii], XtNlist, sourceInfo.list); ii++;
XtSetArg(aa[ii], XtNnumberStrings, sourceInfo.nitems); ii++;
}
SourceView = viewCreateShell(name, flist,
scrollListWidgetClass,
aa, ii);
XtAddCallback(SourceView->output, XtNcallback, sourceSelectLine,
NULL);
XtAugmentTranslations(SourceView->output, trans);
debuggerQueryInitialSource();
}
XtPopup(SourceView->parent, XtGrabNone);
XRaiseWindow(XtDisplay(SourceView->parent),
XtWindow(SourceView->parent));
SourceView->mapped = TRUE;
/* Make the field that invoked us go insensitive */
fla.sensitive = FALSE;
changeField(nameToField(name, client_data), FldSensitive, &fla);
sourceUpdateView();
Leave_void;
}