home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xdbx / part01 / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  3.9 KB  |  135 lines

  1. /*****************************************************************************
  2.  *
  3.  *  xdbx - X Window System interface to the dbx debugger
  4.  *
  5.  *  Copyright 1989 The University of Texas at Austin
  6.  *  Copyright 1990 Microelectronics and Computer Technology Corporation
  7.  *
  8.  *  Permission to use, copy, modify, and distribute this software and its
  9.  *  documentation for any purpose and without fee is hereby granted,
  10.  *  provided that the above copyright notice appear in all copies and that
  11.  *  both that copyright notice and this permission notice appear in
  12.  *  supporting documentation, and that the name of The University of Texas
  13.  *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  14.  *  used in advertising or publicity pertaining to distribution of
  15.  *  the software without specific, written prior permission.  The
  16.  *  University of Texas and MCC makes no representations about the 
  17.  *  suitability of this software for any purpose.  It is provided "as is" 
  18.  *  without express or implied warranty.
  19.  *
  20.  *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  21.  *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22.  *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  23.  *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  24.  *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  25.  *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  26.  *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  *
  28.  *  Author:      Po Cheung
  29.  *  Created:       March 10, 1989
  30.  *
  31.  *****************************************************************************/
  32.  
  33. /*  utils.c
  34.  *
  35.  *    Contain common routines used by other functions.
  36.  *
  37.  *    TextGetLastPos():        Get the last insertion position of text.
  38.  *    TextPositionToLine():     Return text position give a line number.
  39.  *    LineToStopNo():        Return the stop number given a line number.
  40.  *    DisableWindowResize():    Fix the size of a window inside vpane.
  41.  *    bell():            Ring the bell.
  42.  *    concat():            Concatenate two strings together
  43.  */
  44.  
  45. #include "global.h"
  46.  
  47. XawTextPosition TextGetLastPos(w)
  48.     Widget w;
  49. {
  50.     TextWidget ctx = (TextWidget) w;
  51.     return (ctx->text.lastPos);
  52. }
  53.  
  54. /*
  55.  * Get the line number where the caret is.
  56.  */
  57. int TextPositionToLine(pos)
  58. XawTextPosition pos;
  59. {
  60.     int line;
  61.  
  62.     if (displayedFile) {
  63.     if (pos >= displayedFile->linepos[displayedFile->topline]) {
  64.         for (line = displayedFile->topline;
  65.          pos > displayedFile->linepos[line]; line++);
  66.         return (pos == displayedFile->linepos[line] ? line : line-1);
  67.     }
  68.     else {
  69.         for (line = 1; pos > displayedFile->linepos[line]; line++);
  70.         return (pos == displayedFile->linepos[line] ? line : line-1);
  71.     }
  72.     }
  73.     else
  74.         return 0;
  75. }
  76.  
  77. /*
  78.  *  Return the stop number associated with a given line number.
  79.  *  Return 0 if stop number not found.
  80.  */
  81. int LineToStop_no(line)
  82. int line;
  83. {
  84.     int i;
  85.  
  86.     for (i=1; i <= nstops; i++)
  87.         if (stops[i].line == line && stops[i].file && displayedFile &&
  88.             strcmp(stops[i].file, displayedFile->pathname) == NULL) {
  89.             return i;
  90.         }
  91.     return 0;
  92. }
  93.  
  94.  
  95. void DisableWindowResize(w)
  96. Widget w;
  97. {
  98.     Arg args[MAXARGS];
  99.     Cardinal n;
  100.     Dimension height;
  101.  
  102.     n = 0;
  103.     XtSetArg(args[n], XtNheight, &height);                       n++;
  104.     XtGetValues(w, args, n);
  105.     XawPanedSetMinMax(w, height, height);
  106.     XawPanedAllowResize(w, False);
  107. }
  108.  
  109.  
  110. void bell(volume)
  111. int volume;
  112. {
  113.     XBell(XtDisplay(toplevel), volume);
  114. }
  115.  
  116. /* append string s2 to end of string s1 and return the result */
  117.  
  118. char *concat(s1, s2)
  119. char *s1, *s2;
  120. {
  121.     if (s2) {
  122.         if (s1 == NULL) {
  123.             s1 = XtMalloc((strlen(s2)+1)*sizeof(char));
  124.             strcpy(s1, s2);
  125.         }
  126.         else {
  127.             s1 = XtRealloc(s1, strlen(s1)+strlen(s2)+2);
  128.             strcat(s1, s2);
  129.         }
  130.     }
  131.     else
  132.         s1 = NULL;
  133.     return (s1);
  134. }
  135.