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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2008
simple functions
*/
#include "xrdp.h"
/*****************************************************************************/
/* returns boolean */
int APP_CC
rect_contains_pt(struct xrdp_rect* in, int x, int y)
{
if (x < in->left)
{
return 0;
}
if (y < in->top)
{
return 0;
}
if (x >= in->right)
{
return 0;
}
if (y >= in->bottom)
{
return 0;
}
return 1;
}
/*****************************************************************************/
int APP_CC
rect_intersect(struct xrdp_rect* in1, struct xrdp_rect* in2,
struct xrdp_rect* out)
{
int rv;
struct xrdp_rect dumby;
if (out == 0)
{
out = &dumby;
}
*out = *in1;
if (in2->left > in1->left)
{
out->left = in2->left;
}
if (in2->top > in1->top)
{
out->top = in2->top;
}
if (in2->right < in1->right)
{
out->right = in2->right;
}
if (in2->bottom < in1->bottom)
{
out->bottom = in2->bottom;
}
rv = !ISRECTEMPTY(*out);
if (!rv)
{
g_memset(out, 0, sizeof(struct xrdp_rect));
}
return rv;
}
/*****************************************************************************/
/* returns boolean */
int APP_CC
rect_contained_by(struct xrdp_rect* in1, int left, int top,
int right, int bottom)
{
if (left < in1->left || top < in1->top ||
right > in1->right || bottom > in1->bottom)
{
return 0;
}
else
{
return 1;
}
}
/*****************************************************************************/
/* adjust the bounds to fit in the bitmap */
/* return false if there is nothing to draw else return true */
int APP_CC
check_bounds(struct xrdp_bitmap* b, int* x, int* y, int* cx, int* cy)
{
if (*x >= b->width)
{
return 0;
}
if (*y >= b->height)
{
return 0;
}
if (*x < 0)
{
*cx += *x;
*x = 0;
}
if (*y < 0)
{
*cy += *y;
*y = 0;
}
if (*cx <= 0)
{
return 0;
}
if (*cy <= 0)
{
return 0;
}
if (*x + *cx > b->width)
{
*cx = b->width - *x;
}
if (*y + *cy > b->height)
{
*cy = b->height - *y;
}
return 1;
}
/*****************************************************************************/
/* add a ch at index position in text, index starts at 0 */
/* if index = -1 add it to the end */
int APP_CC
add_char_at(char* text, int text_size, twchar ch, int index)
{
int len;
int i;
twchar* wstr;
len = g_mbstowcs(0, text, 0);
wstr = (twchar*)g_malloc((len + 16) * sizeof(twchar), 0);
g_mbstowcs(wstr, text, len + 1);
if ((index >= len) || (index < 0))
{
wstr[len] = ch;
wstr[len + 1] = 0;
g_wcstombs(text, wstr, text_size);
g_free(wstr);
return 0;
}
for (i = (len - 1); i >= index; i--)
{
wstr[i + 1] = wstr[i];
}
wstr[i + 1] = ch;
wstr[len + 1] = 0;
g_wcstombs(text, wstr, text_size);
g_free(wstr);
return 0;
}
/*****************************************************************************/
/* remove a ch at index position in text, index starts at 0 */
/* if index = -1 remove it from the end */
int APP_CC
remove_char_at(char* text, int text_size, int index)
{
int len;
int i;
twchar* wstr;
len = g_mbstowcs(0, text, 0);
if (len <= 0)
{
return 0;
}
wstr = (twchar*)g_malloc((len + 16) * sizeof(twchar), 0);
g_mbstowcs(wstr, text, len + 1);
if ((index >= (len - 1)) || (index < 0))
{
wstr[len - 1] = 0;
g_wcstombs(text, wstr, text_size);
g_free(wstr);
return 0;
}
for (i = index; i < (len - 1); i++)
{
wstr[i] = wstr[i + 1];
}
wstr[len - 1] = 0;
g_wcstombs(text, wstr, text_size);
g_free(wstr);
return 0;
}
/*****************************************************************************/
int APP_CC
set_string(char** in_str, const char* in)
{
if (in_str == 0)
{
return 0;
}
g_free(*in_str);
*in_str = g_strdup(in);
return 0;
}
/*****************************************************************************/
int APP_CC
wchar_repeat(twchar* dest, int dest_size_in_wchars, twchar ch, int repeat)
{
int index;
for (index = 0; index < repeat; index++)
{
if (index >= dest_size_in_wchars)
{
break;
}
dest[index] = ch;
}
return 0;
}
|