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 <signal.h>
- #include <ctype.h>
- #include <X11/Xos.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #ifdef sparc
- #include <dirent.h>
- #else
- #include <sys/dir.h>
- #endif
- #include "global.h"
-
- char Command[LINESIZ] = ""; /* xdbx command string */
-
- static String filelist[MAXFILES]; /* list of file names in fileMenu */
- static int nfiles = 0; /* number of files in filelist */
- static Widget fileMenu = NULL, /* list widget as file menu */
- popupshell; /* parent of fileMenu */
-
-
- /* ARGSUSED */
- static void DoIt (w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- /* run, cont, next, step, where, up, down, status */
- strcpy(Command, client_data);
- AppendDialogText(Command);
- writeDbx(Command);
- }
-
- /* ARGSUSED */
- static void Stop_at(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- XtTextPosition pos;
- Line line;
-
- if (displayedFile == NULL) {
- Bell(0);
- return;
- }
- pos = XtTextGetInsertionPoint(sourceWindow);
- line = TextPositionToLine(pos);
- sprintf(Command, "stop at %d\n", line);
- AppendDialogText(Command);
- writeDbx(Command);
- }
-
- /* ARGSUSED */
- static void Stop_in(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- char *funcname;
- int nbytes;
-
- funcname = XFetchBytes(XtDisplay(w), &nbytes); /* from CUT_BUFFER0 */
- if (nbytes == 0) {
- XBell(XtDisplay(w), 0);
- return;
- }
- sprintf(Command, "stop in %s\n", funcname);
- AppendDialogText(Command);
- writeDbx(Command);
- }
-
- /*
- * Delete removes the stop_no associated with a given line number.
- * RemoveStop() is called to undisplay the stop sign only when there
- * are no more stop_no's associated with that line number.
- */
- /* ARGSUSED */
- static void Delete(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- XtTextPosition pos;
- Line line;
- Cardinal i;
-
- if (displayedFile == NULL) {
- XBell(XtDisplay(w), 0);
- return;
- }
- pos = XtTextGetInsertionPoint(sourceWindow);
- line = TextPositionToLine(pos);
- if (i = LineToStop_no(line)) {
- sprintf(Command, "delete %d\n", i);
- AppendDialogText(Command);
- writeDbx(Command);
- }
- else
- XBell(XtDisplay(w), 0);
- }
-
- /* ARGSUSED */
- static void Print(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- char *string;
- int nbytes;
-
- string = XFetchBytes(XtDisplay(w), &nbytes);
- if (nbytes == 0) {
- XBell(XtDisplay(w), 0);
- return;
- }
- if ((int)client_data == 0)
- sprintf(Command, "print %s\n", string);
- else if ((int)client_data == 1)
- sprintf(Command, "print *%s\n", string);
- AppendDialogText(Command);
- writeDbx(Command);
- }
-
- /* ARGSUSED */
- static void Func(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- char *funcname;
- int nbytes;
-
- funcname = XFetchBytes(XtDisplay(w), &nbytes);
- sprintf(Command, "func %s\n", funcname);
- AppendDialogText(Command);
- writeDbx(Command);
- }
-
- /* ARGSUSED */
- /* Callback for the fileMenu list widget, display the file selected in the
- * menu on the source window.
- */
- static void DisplayMenuFile(w, client_data, call_data)
- Widget w;
- Widget client_data;
- XtListReturnStruct *call_data;
- {
- XtPopdown(client_data);
- if (call_data->string == NULL ||
- strcmp(call_data->string, CANCEL) == NULL) return;
- displayedFile = LoadFile(call_data->string);
- sprintf(Command, "file %s\n", call_data->string);
- AppendDialogText(Command);
- writeDbx(Command);
- }
-
-
- /* A directory entry is included in the display list if it is a regular
- * file but not an executable file.
- */
- static int InList(entry)
- Directory *entry;
- {
- char buffer[16];
- int i, n;
- FILE *fp;
-
- if ((fp = fopen(entry->d_name, "r")) == NULL)
- return False;
- if (n = fread(buffer, sizeof(char), sizeof(buffer), fp)) {
- fclose(fp);
- for (i=0; i<n && (isprint(buffer[i]) || isspace(buffer[i])); i++);
- return ((i-sizeof(buffer)) ? False : True);
- }
- fclose(fp);
- return False;
- }
-
- /* Scans the working directory for files selected by InList(), sorted
- * alphabetically, and stored in an array of pointers to directory
- * entries called namelist.
- * The names of the selected files are stored in filelist.
- */
- static void ScanDir()
- {
- extern alphasort();
- Directory **namelist;
- char *dir, message[LINESIZ];
- int i;
-
- i = 0;
- filelist[i++] = "";
- dir = dbxpwd();
- nfiles = scandir(dir, &namelist, InList, alphasort);
- for (i=1; i<nfiles; i++) {
- filelist[i] = XtNewString(namelist[i]->d_name);
- }
- filelist[0] = CANCEL;
- filelist[i] = NULL;
- return;
- }
-
- /* Creates a popup shell with its child being a list widget containing
- * file names returned from ScanDir().
- * When an item in the list is selected, DisplayMenuFile will be called.
- */
- static void SetUpFileMenu()
- {
- Arg args[MAXARGS];
- Cardinal n;
- int ncolumns;
-
- static String translations = "\
- <Btn1Down>,<Btn1Up>: Set() Notify() Unset()";
-
- n = 0;
- popupshell = XtCreatePopupShell("popup", overrideShellWidgetClass,
- toplevel, args, n);
-
- ScanDir();
- n = 0;
- ncolumns = nfiles/app_resources.filesPerColumn + 1;
- XtSetArg(args[n], XtNlist, filelist); n++;
- XtSetArg(args[n], XtNverticalList, True); n++;
- XtSetArg(args[n], XtNcolumnSpacing, app_resources.columnSpacing); n++;
- XtSetArg(args[n], XtNdefaultColumns, (XtArgVal) ncolumns); n++;
- XtSetArg(args[n], XtNtranslations, XtParseTranslationTable(translations));
- n++;
- fileMenu = XtCreateManagedWidget("fileMenu", listWidgetClass,
- popupshell, args, n);
- XtAddCallback(fileMenu, XtNcallback, DisplayMenuFile, popupshell);
- }
-
- /* Destroy the existing popup shell and creates another one. */
- void UpdateFileMenu()
- {
- XtDestroyWidget(popupshell);
- SetUpFileMenu();
- }
-
- /* ARGSUSED */
- static void File(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- Arg args[MAXARGS];
- Cardinal n;
- Position x, y, x_offset;
- Dimension fileMenu_width, border_width, source_width;
-
- n = 0;
- XtSetArg(args[n], XtNwidth, &fileMenu_width); n++;
- XtSetArg(args[n], XtNborderWidth, &border_width); n++;
- XtGetValues(fileMenu, args, n);
-
- n = 0;
- XtSetArg(args[n], XtNwidth, &source_width); n++;
- XtGetValues(sourceWindow, args, n);
-
- x_offset = (Position) (source_width - fileMenu_width - 2*border_width);
- XtTranslateCoords(sourceWindow, x_offset, 0, &x, &y);
- x = MAX(0, x);
- y = MAX(0, y);
- XtMoveWidget(popupshell, x, y);
- XtPopup(popupshell, XtGrabNonexclusive);
- }
-
-
- /* ARGSUSED */
- static void Quit(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- union wait status;
-
- writeDbx("quit\n");
- XtDestroyWidget(toplevel);
- wait3(&status, WNOHANG, NULL);
- exit(0);
- }
-
- static void AddButton (parent, name, function, client_data)
- Widget parent;
- char *name;
- void (*function) ();
- caddr_t client_data; /* callback registered data */
- {
- Widget button;
- Arg args[10];
- Cardinal n;
-
- n = 0;
- XtSetArg(args[n], XtNwidth, (XtArgVal) app_resources.buttonWidth); n++;
- XtSetArg(args[n], XtNresize, (XtArgVal) False); n++;
- button = XtCreateManagedWidget(name, commandWidgetClass, parent, args, n);
- XtAddCallback(button, XtNcallback, function, client_data);
- }
-
- static void CreateButtons (parent)
- Widget parent;
- {
- AddButton (parent, "run", DoIt, "run\n");
- AddButton (parent, "cont", DoIt, "cont\n");
- AddButton (parent, "next", DoIt, "next\n");
- AddButton (parent, "step", DoIt, "step\n");
-
- AddButton (parent, "stop at", Stop_at, NULL);
- AddButton (parent, "stop in", Stop_in, NULL);
- AddButton (parent, "delete", Delete, NULL);
- AddButton (parent, "status", DoIt, "status\n");
-
- AddButton (parent, "where", DoIt, "where\n");
- AddButton (parent, "up", DoIt, "up\n");
- AddButton (parent, "down", DoIt, "down\n");
-
- AddButton (parent, "print", Print, 0);
- AddButton (parent, "print*", Print, 1);
-
- AddButton (parent, "func", Func, NULL);
- AddButton (parent, "file", File, NULL);
-
- AddButton (parent, "quit", Quit, NULL);
- }
-
- /* Create a command widget, and the buttons, and set up the file menu. */
- void CreateCommandPanel(parent)
- Widget parent;
- {
- Arg args[10];
- Cardinal n;
-
- n = 0;
- XtSetArg(args[n], XtNhSpace, app_resources.commandHSpace); n++;
- XtSetArg(args[n], XtNvSpace, app_resources.commandVSpace); n++;
- XtSetArg(args[n], XtNmax, app_resources.commandMaxHeight); n++;
- XtSetArg(args[n], XtNmin, app_resources.commandMinHeight); n++;
- XtSetArg(args[n], XtNallowResize, (XtArgVal) True); n++;
- commandWindow = XtCreateManagedWidget("commandWindow", boxWidgetClass,
- parent, args, n);
- CreateButtons(commandWindow);
- SetUpFileMenu();
- }
-