File: utils.c

package info (click to toggle)
xxgdb 1.12-9.2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 620 kB
  • ctags: 783
  • sloc: ansic: 8,582; makefile: 46; perl: 36
file content (138 lines) | stat: -rw-r--r-- 4,077 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*****************************************************************************
 *
 *  xdbx - X Window System interface to the dbx debugger
 *
 *  Copyright 1989 The University of Texas at Austin
 *  Copyright 1990 Microelectronics and Computer Technology Corporation
 *
 *  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, and that the name of The University of Texas
 *  and Microelectronics and Computer Technology Corporation (MCC) not be 
 *  used in advertising or publicity pertaining to distribution of
 *  the software without specific, written prior permission.  The
 *  University of Texas and MCC makes no representations about the 
 *  suitability of this software for any purpose.  It is provided "as is" 
 *  without express or implied warranty.
 *
 *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
 *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
 *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *  Author:  	Po Cheung
 *  Created:   	March 10, 1989
 *
 *****************************************************************************/

/*  utils.c
 *
 *    Contain common routines used by other functions.
 *
 *    TextGetLastPos():		Get the last insertion position of text.
 *    TextPositionToLine(): 	Return text position give a line number.
 *    LineToStopNo():		Return the stop number given a line number.
 *    DisableWindowResize():	Fix the size of a window inside vpane.
 *    bell():			Ring the bell.
 *    concat():			Concatenate two strings together
 */

#include "global.h"

XawTextPosition TextGetLastPos(w)
    Widget w;
{
    TextWidget ctx = (TextWidget) w;
    return (ctx->text.lastPos);
}

/*
 * Get the line number where the caret is.
 */
int TextPositionToLine(pos)
XawTextPosition pos;
{
    int line;

    if (displayedFile) {
	if (pos >= displayedFile->linepos[displayedFile->topline]) {
	    for (line = displayedFile->topline;
		 pos > displayedFile->linepos[line]; line++);
	    return (pos == displayedFile->linepos[line] ? line : line-1);
	}
	else {
	    for (line = 1; pos > displayedFile->linepos[line]; line++);
	    return (pos == displayedFile->linepos[line] ? line : line-1);
	}
    }
    else
        return 0;
}

/*
 *  Return the stop number associated with a given line number.
 *  Return 0 if stop number not found.
 */
int LineToStop_no(line)
int line;
{
    int i;

    for (i=1; i <= nstops; i++)
        if (stops[i].line == line && stops[i].file && displayedFile &&
            strcmp(stops[i].file, displayedFile->pathname) == 0) {
            return i;
        }
    return 0;
}


void DisableWindowResize(w)
Widget w;
{
    Arg args[MAXARGS];
    Cardinal n;
    Dimension height;

    n = 0;
    XtSetArg(args[n], XtNheight, &height);                       n++;
    XtGetValues(w, args, n);
    XawPanedSetMinMax(w, height, height);
    XawPanedAllowResize(w, False);
}


void bell(volume)
int volume;
{
	if (debug)
		fprintf (stderr, "ring the bell\n");
    XBell(XtDisplay(toplevel), volume);
}

/* append string s2 to end of string s1 and return the result */

char *concat(s1, s2)
char *s1, *s2;
{
    if (s2) {
        if (s1 == NULL) {
            s1 = XtMalloc((strlen(s2)+1)*sizeof(char));
            strcpy(s1, s2);
        }
        else {
            s1 = XtRealloc(s1, strlen(s1)+strlen(s2)+2);
            strcat(s1, s2);
        }
    }
#if 0	/*(PW)4DEC90 : bug ! if s2 is null, there is no reason to set s1 to 0 */
    else
        s1 = NULL;
#endif
    return (s1);
}