home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / xdbx / part03 / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-14  |  3.2 KB  |  143 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. XtTextPosition  StartPos;    /* starting position of input text */
  24.  
  25. /*  Write s to dbx, and flush the output.  */
  26.  
  27. void writeDbx(s) 
  28. char *s;
  29. {
  30.     fputs(s, dbxfp);
  31.     fflush(dbxfp);
  32. }
  33.  
  34. /*  Returns the working directory of dbx (for Sun dbx only).
  35.  */
  36. char *dbxpwd()
  37. {
  38.     char s[LINESIZ], *dir;
  39.  
  40. #ifdef BSD
  41.     return NULL;
  42. #else
  43.     if (dbxfp == NULL) return (".");
  44.     Echo = FALSE;
  45.     writeDbx("pwd\n");
  46.     while (fgets(s, LINESIZ, dbxfp) == NULL);
  47.     s[strlen(s)-1] = '\0';
  48.     dir = XtNewString(s);
  49.     while (fgets(s, LINESIZ, dbxfp));
  50.     Echo = TRUE;
  51.     return dir;
  52. #endif
  53. }
  54.  
  55.  
  56. XtTextPosition TextGetLastPos(w)
  57.     Widget w;
  58. {
  59.     TextWidget ctx = (TextWidget) w;
  60.     return (ctx->text.lastPos);
  61. }
  62.  
  63.  
  64. void AppendDialogText(s)
  65.     char   *s;
  66. {
  67.     XtTextPosition     i, lastPos;
  68.     XtTextBlock     textblock;
  69.  
  70.     if (!s || !strcmp(s, "")) return;
  71.  
  72.     textblock.firstPos = 0;
  73.     textblock.length   = strlen(s);
  74.     textblock.ptr      = s;
  75.  
  76.     lastPos = TextGetLastPos(dialogWindow);
  77.     if (lastPos + textblock.length > DIALOGSIZE) {
  78.     for (i=lastPos/2; DialogText[i] != '\n'; i++);
  79.     strcpy(DialogText, &DialogText[i+1]);
  80.         lastPos = strlen(DialogText);
  81.     XtTextSetLastPos(dialogWindow, lastPos);
  82.     }
  83.     XtTextReplace(dialogWindow, lastPos, lastPos, &textblock);
  84.     StartPos = TextGetLastPos(dialogWindow);
  85.     XtTextSetInsertionPoint(dialogWindow, StartPos);
  86. }
  87.  
  88. /*
  89.  * Get the line number where the caret is.
  90.  */
  91. Line TextPositionToLine(pos)
  92. XtTextPosition pos;
  93. {
  94.     Line line;
  95.  
  96.     if (displayedFile) {
  97.         for (line = displayedFile->topline;
  98.              pos >= displayedFile->linepos[line]; line++);
  99.         return (line-1);
  100.     }
  101.     else
  102.         return 0;
  103. }
  104.  
  105. /*
  106.  *  Return the stop number associated with a given line number.
  107.  *  Return 0 if stop number not found.
  108.  */
  109. int LineToStop_no(line)
  110. Line line;
  111. {
  112.     int i;
  113.  
  114.     for (i=1; i <= nstops; i++)
  115.         if (stops[i].line == line && stops[i].filename && displayedFile &&
  116.             strcmp(stops[i].filename, displayedFile->filename) == NULL) {
  117.             return i;
  118.         }
  119.     return 0;
  120. }
  121.  
  122.  
  123. void DisableWindowResize(w)
  124. Widget w;
  125. {
  126.     Arg args[MAXARGS];
  127.     Cardinal n;
  128.     Dimension height;
  129.  
  130.     n = 0;
  131.     XtSetArg(args[n], XtNheight, &height);                       n++;
  132.     XtGetValues(w, args, n);
  133.     XtPanedSetMinMax(w, height, height);
  134.     XtPanedAllowResize(w, False);
  135. }
  136.  
  137.  
  138. void Bell(volume)
  139. int volume;
  140. {
  141.     XBell(XtDisplay(toplevel), volume);
  142. }
  143.