📄 source.c
字号:
/***************************************************************************** * * xdbx - X Window System interface to the dbx debugger * * Copyright 1989 The University of Texas at Austin * Copyright 1990 Microelectronics and Computer Technology Corporation * * 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 The University of Texas * and Microelectronics and Computer Technology Corporation (MCC) not be * used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. The * University of Texas and MCC makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Po Cheung * Created: March 10, 1989 * ***************************************************************************** * * xxgdb - X Window System interface to the gdb debugger * * Copyright 1990,1993 Thomson Consumer Electronics, Inc. * * 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 Thomson Consumer * Electronics (TCE) not be used in advertising or publicity pertaining * to distribution of the software without specific, written prior * permission. TCE makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. * * TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT * SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. * * Adaptation to GDB: Pierre Willard * XXGDB Created: December, 1990 * *****************************************************************************//* source.c * * Create the source window and handle display of file. * * source_init(): Initialization routine. * Update(): Action proc to update source window on scrollbar action. * NotifyResize(): Action proc to update source window on resize. * CreateSourceWindow(): Create the source window. * BuildLinePos(): Build an array of starting text position of each line. * LookUpFileTable():Check out source file info from a file table. * SaveDisplayedFileInfo(): records displayed file info into file table. * DisplayFile(): Display a file on the source window * StartEditor(): Start a child process editor on the displayed file. * LoadFile(): Search for a file and open it for display. */#ifndef NeXT#include <malloc.h>#endif#include <stdlib.h>#include <X11/Xos.h>#include <sys/stat.h>#include <pwd.h>#include "global.h"#ifdef SYSV #ifdef sco# include <fcntl.h>#endif#endif /* SYSV */#ifdef GDB#include <string.h>#endif#define MAXDIRS 256 /* max number of dirs in dirList */char CurrentFile[MAXNAME]; /* current contents of file variable */Widget sourceForm, /* parent of sourceWindow */ sourceWindow; /* text window for source file */FileRec *displayedFile; /* pointer to table entry of currently displayed file */static FileRec **fileTable; /* table of file records */static int fileTableSize; /* size of file table */static char *dirList[MAXDIRS]; /* list of dirs for searching files */void source_init(){ dirList[0] = NULL;}/* * Update topline, bottomline, arrow sign, updown sign, stop signs, and * line label. *//* ARGSUSED */void Update(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ XawTextPosition pos; int topline; FileRec *file; if (displayedFile) { file = displayedFile; pos = XawTextTopPosition(sourceWindow); file->topPosition = pos; topline = TextPositionToLine(pos); /* Update the symbols only if the text scrolls */ if (file->topline != topline) { file->topline = topline; file->bottomline = MIN (file->topline + file->lines - 1, file->lastline); /* 03/26/91 mod 7 GWC Fixed a bug where the special margin symbols (arrows, stop signs, etc.) did not scroll when one moved the text with keyboard commands such as Ctrl<Key>n. To do this the Update action procedure should be called after text widget actions such as next-line. Unfortunately Update needed to be enhanced a bit not to always warp the cursor to the top of the window. You can now call Update with a parameter "warp" to warp the cursor to the top of the screen; the default is not to warp. */ if (*num_params == 1 && strcmp(params[0], "warp") == 0) { XawTextSetInsertionPoint(sourceWindow, file->linepos[file->topline]); } UpdateLineLabel(file->topline); UpdateStops(file); UpdateArrow(file); UpdateUpdown(file); UpdateBomb(file); } else {/* Update caret position only */ pos = XawTextGetInsertionPoint(sourceWindow); UpdateLineLabel(TextPositionToLine(pos)); } }}/* * Update bottomline, arrow sign, updown sign and stop signs on resize. * Invoked by ConfigureNotify event. *//* ARGSUSED */static void NotifyResize(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ XawTextPosition pos; TextWidget ctx = (TextWidget) sourceWindow; FileRec *file; if ((file = displayedFile)) { file->lines = ctx->text.lt.lines; pos = XawTextTopPosition(sourceWindow); file->topline = TextPositionToLine(pos); file->bottomline = MIN (file->topline + file->lines - 1, file->lastline); UpdateStops(file); UpdateArrow(file); UpdateUpdown(file); UpdateBomb(file); }}/* Update the position of the caret *//* ARGSUSED */#ifdef notdefvoid UpdateLine(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ XawTextPosition pos; int line; pos = XawTextGetInsertionPoint(w); line = TextPositionToLine(pos); UpdateLineLabel(line);}#endif/* My select-start routine that cancels the effect of automatic scrolling * near the bottom of an Athena text widget window. *//* ARGSUSED */void SelectStart(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ XawTextPosition topPosition; /* remember the top display position before automatic scrolling */ /* displayedFile->topPosition = XawTextTopPosition(w); */ topPosition = XawTextTopPosition(w); XtCallActionProc(w, "select-start", event, params, *num_params); /* reset to remembered position if top position changed */ /* if (XawTextTopPosition(w) != displayedFile->topPosition) TextSetTopPosition(w, displayedFile->topPosition); */ if (XawTextTopPosition(w) != topPosition) TextSetTopPosition(w, topPosition);}/* My select-end routine to store the text selection into both the PRIMARY * selection and cut buffer 0. *//* ARGSUSED */void SelectEnd(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ XawTextPosition begin, end, start; Widget textsrc; XawTextBlock buffer; char s_storage[LINESIZ]; /* fix bug where if selection is past 10k, xxgdb crashes */ char* s = &s_storage[0]; int nchars; XawTextGetSelectionPos(w, &begin, &end); XawTextSetSelection(w, begin, end); if (begin == end) return; if (end - begin > LINESIZ) s = (char*)malloc(end - begin + LINESIZ); textsrc = XawTextGetSource(w); strcpy(s, ""); for (start=begin, nchars=end-begin; nchars > 0; start=begin+buffer.length, nchars-=buffer.length) { XawTextSourceRead(textsrc, start, &buffer, nchars); strncat(s, buffer.ptr, buffer.length); } XStoreBytes(display, s, strlen(s)); if (end - begin > LINESIZ) free(s);}/* This is my own select word routine to replace the standard action * procedure provided by the Text widget. * It selects a word delimited by DELIMITERS, not whitespace. *//* ARGSUSED */void SelectWord(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ XawTextPosition pos, left, right, start; XawTextBlock buffer; Widget textsrc; char s[LINESIZ]; char *p, *ls, *rs; int nchars; pos = XawTextGetInsertionPoint(w); textsrc = XawTextGetSource(w); XawTextSourceRead(textsrc, pos, &buffer, 1); if (buffer.length == 0 || (buffer.length == 1 && strchr(app_resources.delimiters, (int)*(buffer.ptr)) != NULL)) { XStoreBytes(display, NULL, 0); return; } left = XawTextSourceScan(textsrc, pos+1, XawstWhiteSpace, XawsdLeft, 1, FALSE); right = XawTextSourceScan(textsrc, left, XawstWhiteSpace, XawsdRight, 1, FALSE); strcpy(s, ""); for (start=left, nchars=right-left; nchars > 0; start=left+buffer.length, nchars-=buffer.length) { XawTextSourceRead(textsrc, start, &buffer, nchars); strncat(s, buffer.ptr, buffer.length); } if (!strcmp(s, "")) return; p = s+pos-left; ls = (char *) strtok(s, app_resources.delimiters); rs = (char *) strtok(NULL, app_resources.delimiters); if (!ls) return; while (rs<=p && rs!=NULL) { ls = rs; rs = (char *) strtok(NULL, app_resources.delimiters); } left = left + ls - s; right = left + strlen(ls) - 1; XawTextUnsetSelection(w); XStoreBytes(display, ls, strlen(ls)); XawTextSetSelection(w, left, right+1);}/* Print the value of the expression in cut buffer 0. *//* ARGSUSED */void PrintSelection(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ char command[LINESIZ]; char *string; int nbytes; string = XFetchBytes(display, &nbytes); if (nbytes == 0) { UpdateMessageWindow(PRINT_HELP, NULL); bell(0); return; } sprintf(command, "print %s\n", string); send_command(command); AppendDialogText(command);}#ifdef EDIT_BUTTON/* allow invocation of favorite editor from within interface */extern void StartEditor();void EdAction(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ StartEditor();}#endif /* EDIT_BUTTON *//* fixes keybindings in source window */extern PopupSearch();void Search(w, event, params, num_params) Widget w;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -