"Fossies" - the Fresh Open Source Software Archive 
Member "xxgdb-1.12/utils.c" (18 Nov 1994, 4077 Bytes) of package /linux/misc/old/xxgdb-1.12.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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) == 0) {
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 if (debug)
114 fprintf (stderr, "ring the bell\n");
115 XBell(XtDisplay(toplevel), volume);
116 }
117
118 /* append string s2 to end of string s1 and return the result */
119
120 char *concat(s1, s2)
121 char *s1, *s2;
122 {
123 if (s2) {
124 if (s1 == NULL) {
125 s1 = XtMalloc((strlen(s2)+1)*sizeof(char));
126 strcpy(s1, s2);
127 }
128 else {
129 s1 = XtRealloc(s1, strlen(s1)+strlen(s2)+2);
130 strcat(s1, s2);
131 }
132 }
133 #if 0 /*(PW)4DEC90 : bug ! if s2 is null, there is no reason to set s1 to 0 */
134 else
135 s1 = NULL;
136 #endif
137 return (s1);
138 }