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 "global.h"
-
- Boolean EnterCommand; /* To differntiate between xdbx command
- input and debugged program input */
- static char *output = NULL; /* buffer for dbx output */
- static int outputsize = 0; /* size of buffer */
- static Boolean continueFlag; /* read flag for dbxinit commands */
-
- static void Dbxinit(fp)
- FILE *fp;
- {
- char s[LINESIZ];
-
- while (fgets(s, LINESIZ, fp)) {
- strcpy(Command, s);
- AppendDialogText(Command);
- writeDbx(Command);
- continueFlag = TRUE;
- while (continueFlag)
- readDbx();
- }
- close(fp);
- }
-
- /*
- * Called only once to display the source file, if any, right after
- * xdbx is started up.
- */
- void DisplayInit()
- {
- FILE *fp;
- char *path;
-
- displayedFile = LoadFile(QueryFile());
- UpdateMessageWindow("Ready for execution");
- if (fp = fopen(xdbxinit, "r")) {
- if (displayedFile)
- Dbxinit(fp);
- if (Homedir)
- rename(xdbxinit, "~/.dbxinit");
- else
- rename(xdbxinit, ".dbxinit");
- }
- }
-
- /*
- * This is a callback procedure invoked everytime input is pending
- * on the file descriptor to dbx.
- * It reads all the data available on the descriptor line by line
- * into 'string', and write it to the dialog window.
- * Once the dbx prompt is read in, it calls parse() to take appropriate
- * action.
- */
- XtInputCallbackProc readDbx(client_data, source, id)
- caddr_t client_data;
- int *source;
- XtInputId *id;
- {
- char s[LINESIZ], *string;
- int stringsize;
- static Boolean initialFlag = TRUE,
- displayFlag = FALSE;
-
- /* allocate one block to 'output' to begin with */
- if (outputsize == 0) {
- outputsize = BUFSIZ;
- output = XtMalloc(outputsize);
- strcpy(output, "");
- }
- stringsize = BUFSIZ;
- string = XtMalloc(stringsize);
- strcpy(string, "");
- while (fgets(s, LINESIZ, dbxfp)) {
- /* if no echo mode, do not write output to dialog window */
- if (Echo == FALSE) continue;
- EnterCommand = FALSE;
- if (strcmp(s, "(dbx) ")) {
- if (strlen(string) + strlen(s) > stringsize) {
- string = XtRealloc(string, stringsize + BUFSIZ);
- stringsize += BUFSIZ;
- }
- strcat(string, s);
- if (strlen(output) + strlen(s) > outputsize) {
- output = XtRealloc(output, outputsize + BUFSIZ);
- outputsize += BUFSIZ;
- }
- strcat(output, s);
- }
- else {
- parse(output);
- strcpy(output, "");
- strcpy(s, "");
- strcat(string, PROMPT);
- EnterCommand = TRUE;
- continueFlag = FALSE;
- if (initialFlag) {
- initialFlag = FALSE;
- displayFlag = TRUE;
- }
- }
- }
- filter(string);
- AppendDialogText(string);
- if (displayFlag) {
- displayFlag = FALSE;
- DisplayInit();
- }
- }
-