home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / xdbx / part03 / dbx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-14  |  3.4 KB  |  129 lines

  1. /****************************************************************************** 
  2.  *
  3.  *  xdbx - X Window System interface to dbx
  4.  *
  5.  *  Copyright 1989 The University of Texas at Austin
  6.  *
  7.  *  Author:    Po Cheung
  8.  *  Date:    March 10, 1989
  9.  *
  10.  *  Permission to use, copy, modify, and distribute this software and
  11.  *  its documentation for any purpose and without fee is hereby granted,
  12.  *  provided that the above copyright notice appear in all copies and that
  13.  *  both that copyright notice and this permission notice appear in
  14.  *  supporting documentation.  The University of Texas at Austin makes no 
  15.  *  representations about the suitability of this software for any purpose.  
  16.  *  It is provided "as is" without express or implied warranty.
  17.  *
  18.  ******************************************************************************/
  19.  
  20.  
  21. #include "global.h"
  22.  
  23. Boolean        EnterCommand;        /* To differntiate between xdbx command
  24.                         input and debugged program input */
  25. static char     *output = NULL;     /* buffer for dbx output */
  26. static int    outputsize = 0;        /* size of buffer */
  27. static Boolean     continueFlag;        /* read flag for dbxinit commands */
  28.  
  29. static void Dbxinit(fp)
  30. FILE *fp;
  31. {
  32.     char s[LINESIZ];
  33.  
  34.     while (fgets(s, LINESIZ, fp)) {
  35.     strcpy(Command, s);
  36.     AppendDialogText(Command);
  37.     writeDbx(Command);
  38.     continueFlag = TRUE;
  39.     while (continueFlag)
  40.         readDbx();
  41.     }
  42.     close(fp);
  43. }
  44.  
  45. /*
  46.  * Called only once to display the source file, if any, right after
  47.  * xdbx is started up.
  48.  */
  49. void DisplayInit()
  50. {
  51.     FILE *fp;
  52.     char *path;
  53.  
  54.     displayedFile = LoadFile(QueryFile());
  55.     UpdateMessageWindow("Ready for execution");
  56.     if (fp = fopen(xdbxinit, "r")) {
  57.     if (displayedFile)
  58.             Dbxinit(fp);
  59.     if (Homedir)
  60.             rename(xdbxinit, "~/.dbxinit");
  61.     else
  62.             rename(xdbxinit, ".dbxinit");
  63.     }
  64. }
  65.  
  66. /*
  67.  *  This is a callback procedure invoked everytime input is pending
  68.  *  on the file descriptor to dbx.
  69.  *  It reads all the data available on the descriptor line by line
  70.  *  into 'string', and write it to the dialog window.
  71.  *  Once the dbx prompt is read in, it calls parse() to take appropriate
  72.  *  action.
  73.  */
  74. XtInputCallbackProc readDbx(client_data, source, id)
  75. caddr_t   client_data;
  76. int       *source;
  77. XtInputId *id;
  78. {
  79.     char   s[LINESIZ], *string;
  80.     int    stringsize;
  81.     static Boolean initialFlag = TRUE, 
  82.            displayFlag = FALSE;
  83.  
  84.     /* allocate one block to 'output' to begin with */
  85.     if (outputsize == 0) {
  86.     outputsize = BUFSIZ;
  87.     output = XtMalloc(outputsize);
  88.         strcpy(output, "");
  89.     }
  90.     stringsize = BUFSIZ;
  91.     string = XtMalloc(stringsize);
  92.     strcpy(string, "");
  93.     while (fgets(s, LINESIZ, dbxfp)) {
  94.         /* if no echo mode, do not write output to dialog window */
  95.     if (Echo == FALSE) continue;
  96.     EnterCommand = FALSE;
  97.     if (strcmp(s, "(dbx) ")) {
  98.         if (strlen(string) + strlen(s) > stringsize) {
  99.         string = XtRealloc(string, stringsize + BUFSIZ);
  100.         stringsize += BUFSIZ;
  101.         }
  102.         strcat(string, s);
  103.         if (strlen(output) + strlen(s) > outputsize) {
  104.         output = XtRealloc(output, outputsize + BUFSIZ);
  105.         outputsize += BUFSIZ;
  106.         }
  107.         strcat(output, s);
  108.     }
  109.     else {
  110.         parse(output);
  111.         strcpy(output, "");
  112.         strcpy(s, "");
  113.         strcat(string, PROMPT);
  114.         EnterCommand = TRUE;
  115.         continueFlag = FALSE;
  116.         if (initialFlag) {
  117.         initialFlag = FALSE;
  118.         displayFlag = TRUE;
  119.         }
  120.     }
  121.     }
  122.     filter(string);
  123.     AppendDialogText(string);
  124.     if (displayFlag) {
  125.     displayFlag = FALSE;
  126.     DisplayInit();
  127.     }
  128. }
  129.