ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/misc.C
(Generate patch)

Comparing rxvt-unicode/src/misc.C (file contents):
Revision 1.4 by pcg, Sat Jan 31 03:27:45 2004 UTC vs.
Revision 1.26 by root, Wed Feb 16 20:32:05 2005 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: misc.c 2 * File: misc.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston 6 * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
8 * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> 8 * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com>
9 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 14 * (at your option) any later version.
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *----------------------------------------------------------------------*/ 24 *----------------------------------------------------------------------*/
24 25
25#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
26#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
27#include "misc.intpro" /* PROTOS for internal routines */
28 28
29/* EXTPROTO */ 29char *
30rxvt_wcstombs (const wchar_t *str, int len)
31{
32 if (len < 0) len = wcslen (str);
33
34 mbstate mbs;
35 char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1);
36
37 char *dst = r;
38 while (len--)
39 {
40 ssize_t l = wcrtomb (dst, *str++, mbs);
41 if (l < 0)
42 *dst++ = '?';
43 else
44 dst += l;
45 }
46
47 *dst++ = 0;
48
49 return (char *)rxvt_realloc (r, dst - r);
50}
51
52wchar_t *
53rxvt_mbstowcs (const char *str, int len)
54{
55 if (len < 0) len = strlen (str);
56
57 wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t));
58
59 if ((ssize_t)mbstowcs (r, str, len + 1) < 0)
60 *r = 0;
61
62 return r;
63}
64
65char *
66rxvt_wcstoutf8 (const wchar_t *str, int len)
67{
68 if (len < 0) len = wcslen (str);
69
70 char *r = (char *)rxvt_malloc (len * 4 + 1);
71 char *p = r;
72
73 while (len--)
74 {
75 unicode_t w = *str++ & UNICODE_MASK;
76
77 if (w < 0x000080)
78 *p++ = w;
79 else if (w < 0x000800)
80 *p++ = 0xc0 | ( w >> 6),
81 *p++ = 0x80 | ( w & 0x3f);
82 else if (w < 0x010000)
83 *p++ = 0xe0 | ( w >> 12 ),
84 *p++ = 0x80 | ((w >> 6) & 0x3f),
85 *p++ = 0x80 | ( w & 0x3f);
86 else if (w < 0x110000)
87 *p++ = 0xf0 | ( w >> 18),
88 *p++ = 0x80 | ((w >> 12) & 0x3f),
89 *p++ = 0x80 | ((w >> 6) & 0x3f),
90 *p++ = 0x80 | ( w & 0x3f);
91 else
92 *p++ = '?';
93 }
94
95 *p++ = 0;
96
97 return (char *)rxvt_realloc (r, p - r);
98}
99
100wchar_t *
101rxvt_utf8towcs (const char *str, int len)
102{
103 if (len < 0) len = strlen (str);
104
105 wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)),
106 *p = r;
107
108 unsigned char *s = (unsigned char *)str,
109 *e = s + len;
110
111 for (;;)
112 {
113 len = e - s;
114
115 if (len == 0)
116 break;
117 else if (s[0] < 0x80)
118 *p++ = *s++;
119 else if (len >= 2
120 && s[0] >= 0xc2 && s[0] <= 0xdf
121 && (s[1] & 0xc0) == 0x80)
122 {
123 *p++ = ((s[0] & 0x1f) << 6)
124 | (s[1] & 0x3f);
125 s += 2;
126 }
127 else if (len >= 3
128 && ( (s[0] == 0xe0 && s[1] >= 0xa0 && s[1] <= 0xbf)
129 || (s[0] >= 0xe1 && s[0] <= 0xec && s[1] >= 0x80 && s[1] <= 0xbf)
130 || (s[0] == 0xed && s[1] >= 0x80 && s[1] <= 0x9f)
131 || (s[0] >= 0xee && s[0] <= 0xef && s[1] >= 0x80 && s[1] <= 0xbf)
132 )
133 && (s[2] & 0xc0) == 0x80)
134 {
135 *p++ = ((s[0] & 0x0f) << 12)
136 | ((s[1] & 0x3f) << 6)
137 | (s[2] & 0x3f);
138 s += 3;
139 }
140 else if (len >= 4
141 && ( (s[0] == 0xf0 && s[1] >= 0x90 && s[1] <= 0xbf)
142 || (s[0] >= 0xf1 && s[0] <= 0xf3 && s[1] >= 0x80 && s[1] <= 0xbf)
143 || (s[0] == 0xf4 && s[1] >= 0x80 && s[1] <= 0x8f)
144 )
145 && (s[2] & 0xc0) == 0x80
146 && (s[3] & 0xc0) == 0x80)
147 {
148 *p++ = ((s[0] & 0x07) << 18)
149 | ((s[1] & 0x3f) << 12)
150 | ((s[2] & 0x3f) << 6)
151 | (s[3] & 0x3f);
152 s += 4;
153 }
154 else
155 {
156 *p++ = 0xfffd;
157 s++;
158 }
159 }
160
161 *p = 0;
162
163 return r;
164}
165
30char * 166char *
31rxvt_strdup (const char *str) 167rxvt_strdup (const char *str)
32{ 168{
33 return str ? strdup (str) : 0; 169 return str ? strdup (str) : 0;
34} 170}
35 171
36/* EXTPROTO */ 172/* INTPROTO */
37char * 173char *
38rxvt_r_basename(const char *str) 174rxvt_r_basename (const char *str)
39{ 175{
40 char *base = STRRCHR(str, '/'); 176 char *base = strrchr (str, '/');
41 177
42 return (char *)(base ? base + 1 : str); 178 return (char *) (base ? base + 1 : str);
43} 179}
44 180
45/* 181/*
46 * Print an error message 182 * Print an error message
47 */ 183 */
48/* EXTPROTO */ 184/* INTPROTO */
49void 185void
186rxvt_vlog (const char *fmt, va_list arg_ptr)
187{
188 char msg[1024];
189
190 vsnprintf (msg, sizeof msg, fmt, arg_ptr);
191
192 if (GET_R && GET_R->log_hook)
193 (*GET_R->log_hook) (msg);
194 else
195 write (STDOUT_FILENO, msg, strlen (msg));
196}
197
198/* INTPROTO */
199void
50rxvt_print_error(const char *fmt,...) 200rxvt_log (const char *fmt,...)
51{ 201{
52 va_list arg_ptr; 202 va_list arg_ptr;
53 203
54 va_start(arg_ptr, fmt); 204 va_start (arg_ptr, fmt);
55 fprintf(stderr, APL_NAME ": "); 205 rxvt_vlog (fmt, arg_ptr);
56 vfprintf(stderr, fmt, arg_ptr);
57 fprintf(stderr, "\n");
58 va_end(arg_ptr); 206 va_end (arg_ptr);
207}
208
209/*
210 * Print an error message
211 */
212/* INTPROTO */
213void
214rxvt_warn (const char *fmt,...)
215{
216 va_list arg_ptr;
217
218 rxvt_log ("%s: ", RESNAME);
219
220 va_start (arg_ptr, fmt);
221 rxvt_vlog (fmt, arg_ptr);
222 va_end (arg_ptr);
223}
224
225/* INTPROTO */
226void
227rxvt_fatal (const char *fmt,...)
228{
229 va_list arg_ptr;
230
231 rxvt_log ("%s: ", RESNAME);
232
233 va_start (arg_ptr, fmt);
234 rxvt_vlog (fmt, arg_ptr);
235 va_end (arg_ptr);
236
237 rxvt_exit_failure ();
238}
239
240class rxvt_failure_exception rxvt_failure_exception;
241
242/* INTPROTO */
243void
244rxvt_exit_failure ()
245{
246 throw (rxvt_failure_exception);
59} 247}
60 248
61/* 249/*
62 * check that the first characters of S1 match S2 250 * check that the first characters of S1 match S2
63 * 251 *
64 * No Match 252 * No Match
65 * return: 0 253 * return: 0
66 * Match 254 * Match
67 * return: STRLEN (S2) 255 * return: strlen (S2)
68 */ 256 */
69/* EXTPROTO */ 257/* INTPROTO */
70int 258int
71rxvt_Str_match(const char *s1, const char *s2) 259rxvt_Str_match (const char *s1, const char *s2)
72{ 260{
73 int n = STRLEN(s2); 261 int n = strlen (s2);
74 262
75 return ((STRNCMP(s1, s2, n) == 0) ? n : 0); 263 return ((strncmp (s1, s2, n) == 0) ? n : 0);
76} 264}
77 265
78/* EXTPROTO */ 266/* INTPROTO */
79const char * 267const char *
80rxvt_Str_skip_space(const char *str) 268rxvt_Str_skip_space (const char *str)
81{ 269{
82 if (str) 270 if (str)
83 while (*str && isspace(*str)) 271 while (*str && isspace (*str))
84 str++; 272 str++;
273
85 return str; 274 return str;
86} 275}
87 276
88/* 277/*
89 * remove leading/trailing space and strip-off leading/trailing quotes. 278 * remove leading/trailing space and strip-off leading/trailing quotes.
90 * in place. 279 * in place.
91 */ 280 */
92/* EXTPROTO */ 281/* INTPROTO */
93char * 282char *
94rxvt_Str_trim(char *str) 283rxvt_Str_trim (char *str)
95{ 284{
96 char *r, *s; 285 char *r, *s;
97 int n;
98 286
99 if (!str || !*str) /* shortcut */ 287 if (!str || !*str) /* shortcut */
100 return str;
101
102/* skip leading spaces */
103 for (s = str; *s && isspace(*s); s++) ;
104/* goto end of string */
105 for (n = 0, r = s; *r++; n++) ;
106 r -= 2;
107/* dump return */
108 if (n > 0 && *r == '\n')
109 n--, r--;
110/* backtrack along trailing spaces */
111 for (; n > 0 && isspace(*r); r--, n--) ;
112/* skip matching leading/trailing quotes */
113 if (*s == '"' && *r == '"' && n > 1) {
114 s++;
115 n -= 2;
116 }
117/* copy back over: forwards copy */
118 for (r = str; n; n--)
119 *r++ = *s++;
120 *r = '\0';
121
122 return str; 288 return str;
289
290 /* skip leading spaces */
291 for (s = str; *s && isspace (*s); s++) ;
292
293 /* goto end of string */
294 r = s + strlen (s) - 1;
295
296 /* dump return and other trailing whitespace */
297 while (r > s && isspace (*r))
298 r--;
299
300#if 0
301 /* skip matching leading/trailing quotes */
302 if (*s == '"' && *r == '"' && n > 1)
303 {
304 s++;
305 n -= 2;
306 }
307#endif
308
309 memmove (str, s, r + 1 - s);
310 str[r + 1 - s] = 0;
311
312 return str;
123} 313}
124 314
125/* 315/*
126 * in-place interpretation of string: 316 * in-place interpretation of string:
127 * 317 *
134 * "M-x" prefixed strings, append "\r" if needed 324 * "M-x" prefixed strings, append "\r" if needed
135 * "\E]" prefixed strings (XTerm escape sequence) append ST if needed 325 * "\E]" prefixed strings (XTerm escape sequence) append ST if needed
136 * 326 *
137 * returns the converted string length 327 * returns the converted string length
138 */ 328 */
139/* EXTPROTO */ 329/* INTPROTO */
140int 330int
141rxvt_Str_escaped(char *str) 331rxvt_Str_escaped (char *str)
142{ 332{
143 char ch, *s, *d; 333 char ch, *s, *d;
144 int i, num, append = 0; 334 int i, num, append = 0;
145 335
146 if (!str || !*str) 336 if (!str || !*str)
147 return 0; 337 return 0;
148 338
149 d = s = str; 339 d = s = str;
150 340
151 if (*s == 'M' && s[1] == '-') { 341 if (*s == 'M' && s[1] == '-')
342 {
152 /* Emacs convenience, replace leading `M-..' with `\E..' */ 343 /* Emacs convenience, replace leading `M-..' with `\E..' */
153 *d++ = C0_ESC; 344 *d++ = C0_ESC;
154 s += 2; 345 s += 2;
155 if (toupper(*s) == 'X') 346 if (toupper (*s) == 'X')
156 /* append carriage-return for `M-xcommand' */ 347 /* append carriage-return for `M-xcommand' */
157 for (*d++ = 'x', append = '\r', s++; isspace(*s); s++) ; 348 for (*d++ = 'x', append = '\r', s++; isspace (*s); s++) ;
158 } 349 }
159 for (; (ch = *s++);) { 350 for (; (ch = *s++);)
351 {
160 if (ch == '\\') { 352 if (ch == '\\')
353 {
161 ch = *s++; 354 ch = *s++;
162 if (ch >= '0' && ch <= '7') { /* octal */ 355 if (ch >= '0' && ch <= '7')
163 num = ch - '0'; 356 { /* octal */
357 num = ch - '0';
164 for (i = 0; i < 2; i++, s++) { 358 for (i = 0; i < 2; i++, s++)
165 ch = *s; 359 {
360 ch = *s;
166 if (ch < '0' || ch > '7') 361 if (ch < '0' || ch > '7')
167 break; 362 break;
168 num = num * 8 + ch - '0'; 363 num = num * 8 + ch - '0';
169 } 364 }
170 ch = (char)num; 365 ch = (char)num;
171 } else if (ch == 'a') 366 }
367 else if (ch == 'a')
172 ch = C0_BEL; /* bell */ 368 ch = C0_BEL; /* bell */
173 else if (ch == 'b') 369 else if (ch == 'b')
174 ch = C0_BS; /* backspace */ 370 ch = C0_BS; /* backspace */
175 else if (ch == 'E' || ch == 'e') 371 else if (ch == 'E' || ch == 'e')
176 ch = C0_ESC; /* escape */ 372 ch = C0_ESC; /* escape */
373 else if (ch == 'n')
374 ch = '\n'; /* newline */
375 else if (ch == 'r')
376 ch = '\r'; /* carriage-return */
377 else if (ch == 't')
378 ch = C0_HT; /* tab */
379 }
177 else if (ch == 'n') 380 else if (ch == '^')
178 ch = '\n'; /* newline */ 381 {
179 else if (ch == 'r')
180 ch = '\r'; /* carriage-return */
181 else if (ch == 't')
182 ch = C0_HT; /* tab */
183 } else if (ch == '^') {
184 ch = *s++; 382 ch = *s++;
185 ch = toupper(ch); 383 ch = toupper (ch);
186 ch = (ch == '?' ? 127 : (ch - '@')); 384 ch = (ch == '?' ? 127 : (ch - '@'));
187 } 385 }
188 *d++ = ch; 386 *d++ = ch;
189 } 387 }
190 388
191/* ESC] is an XTerm escape sequence, must be terminated */ 389 /* ESC] is an XTerm escape sequence, must be terminated */
192 if (*str == '\0' && str[1] == C0_ESC && str[2] == ']') 390 if (*str == '\0' && str[1] == C0_ESC && str[2] == ']')
193 append = CHAR_ST; 391 append = CHAR_ST;
194 392
195/* add trailing character as required */ 393 /* add trailing character as required */
196 if (append && d[-1] != append) 394 if (append && d[-1] != append)
197 *d++ = append; 395 *d++ = append;
198 *d = '\0'; 396 *d = '\0';
199 397
200 return (d - str); 398 return (d - str);
201} 399}
202 400
203/* 401/*
204 * Split a comma-separated string into an array, stripping leading and 402 * Split a comma-separated string into an array, stripping leading and
205 * trailing spaces (and paired quotes) from each entry. Empty strings 403 * trailing spaces from each entry. Empty strings are properly returned
206 * are properly returned
207 * Caller should free each entry and array when done 404 * Caller should free each entry and array when done
208 */ 405 */
209/* EXTPROTO */ 406/* INTPROTO */
210char ** 407char **
211rxvt_splitcommastring(const char *cs) 408rxvt_splitcommastring (const char *cs)
212{ 409{
213 int l, n, p; 410 int l, n, p;
214 const char *s, *t; 411 const char *s, *t;
215 char **ret; 412 char **ret;
216 413
217 if ((s = cs) == NULL) 414 if ((s = cs) == NULL)
218 s = ""; 415 s = "";
219 416
220 for (n = 1, t = s; *t; t++) 417 for (n = 1, t = s; *t; t++)
221 if (*t == ',') 418 if (*t == ',')
222 n++; 419 n++;
420
223 ret = (char **)malloc((n + 1) * sizeof(char *)); 421 ret = (char **)malloc ((n + 1) * sizeof (char *));
224 ret[n] = NULL; 422 ret[n] = NULL;
225 423
226 for (l = 0, t = s; l < n; l++) { 424 for (l = 0, t = s; l < n; l++)
425 {
227 for ( ; *t && *t != ','; t++) ; 426 for ( ; *t && *t != ','; t++) ;
228 p = t - s; 427 p = t - s;
229 ret[l] = (char *)malloc(p + 1); 428 ret[l] = (char *)malloc (p + 1);
230 strncpy(ret[l], s, p); 429 strncpy (ret[l], s, p);
231 ret[l][p] = '\0'; 430 ret[l][p] = '\0';
232 rxvt_Str_trim(ret[l]); 431 rxvt_Str_trim (ret[l]);
233 s = ++t; 432 s = ++t;
234 } 433 }
434
235 return ret; 435 return ret;
436}
437
438void
439rxvt_freecommastring (char **cs)
440{
441 for (int i = 0; cs[i]; ++i)
442 free (cs[i]);
443
444 free (cs);
236} 445}
237 446
238/*----------------------------------------------------------------------* 447/*----------------------------------------------------------------------*
239 * file searching 448 * file searching
240 */ 449 */
248 * 457 *
249 * FILE is either semi-colon or zero terminated 458 * FILE is either semi-colon or zero terminated
250 */ 459 */
251/* INTPROTO */ 460/* INTPROTO */
252char * 461char *
253rxvt_File_search_path(const char *pathlist, const char *file, const char *ext) 462rxvt_File_search_path (const char *pathlist, const char *file, const char *ext)
254{ 463{
255 int maxpath, len; 464 int maxpath, len;
256 const char *p, *path; 465 const char *p, *path;
257 char name[256]; 466 char name[256];
258 467
259 if (!access(file, R_OK)) /* found (plain name) in current directory */ 468 if (!access (file, R_OK)) /* found (plain name) in current directory */
260 return STRDUP(file); 469 return strdup (file);
261 470
262/* semi-colon delimited */ 471 /* semi-colon delimited */
263 if ((p = STRCHR(file, ';'))) 472 if ((p = strchr (file, ';')))
264 len = (p - file); 473 len = (p - file);
265 else 474 else
266 len = STRLEN(file); 475 len = strlen (file);
267 476
268#ifdef DEBUG_SEARCH_PATH 477#ifdef DEBUG_SEARCH_PATH
269 getcwd(name, sizeof(name)); 478 getcwd (name, sizeof (name));
270 fprintf(stderr, "pwd: \"%s\"\n", name); 479 fprintf (stderr, "pwd: \"%s\"\n", name);
271 fprintf(stderr, "find: \"%.*s\"\n", len, file); 480 fprintf (stderr, "find: \"%.*s\"\n", len, file);
272#endif 481#endif
273 482
274/* leave room for an extra '/' and trailing '\0' */ 483 /* leave room for an extra '/' and trailing '\0' */
275 maxpath = sizeof(name) - (len + (ext ? STRLEN(ext) : 0) + 2); 484 maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2);
276 if (maxpath <= 0) 485 if (maxpath <= 0)
277 return NULL;
278
279/* check if we can find it now */
280 STRNCPY(name, file, len);
281 name[len] = '\0';
282
283 if (!access(name, R_OK))
284 return STRDUP(name);
285 if (ext) {
286 STRCAT(name, ext);
287 if (!access(name, R_OK))
288 return STRDUP(name);
289 }
290 for (path = pathlist; path != NULL && *path != '\0'; path = p) {
291 int n;
292
293 /* colon delimited */
294 if ((p = STRCHR(path, ':')) == NULL)
295 p = STRCHR(path, '\0');
296
297 n = (p - path);
298 if (*p != '\0')
299 p++;
300
301 if (n > 0 && n <= maxpath) {
302 STRNCPY(name, path, n);
303 if (name[n - 1] != '/')
304 name[n++] = '/';
305 name[n] = '\0';
306 STRNCAT(name, file, len);
307
308 if (!access(name, R_OK))
309 return STRDUP(name);
310 if (ext) {
311 STRCAT(name, ext);
312 if (!access(name, R_OK))
313 return STRDUP(name);
314 }
315 }
316 }
317 return NULL; 486 return NULL;
318}
319 487
488 /* check if we can find it now */
489 strncpy (name, file, len);
490 name[len] = '\0';
491
492 if (!access (name, R_OK))
493 return strdup (name);
494 if (ext)
495 {
496 strcat (name, ext);
497 if (!access (name, R_OK))
498 return strdup (name);
499 }
500 for (path = pathlist; path != NULL && *path != '\0'; path = p)
501 {
502 int n;
503
504 /* colon delimited */
505 if ((p = strchr (path, ':')) == NULL)
506 p = strchr (path, '\0');
507
508 n = (p - path);
509 if (*p != '\0')
510 p++;
511
512 if (n > 0 && n <= maxpath)
513 {
514 strncpy (name, path, n);
515 if (name[n - 1] != '/')
516 name[n++] = '/';
517 name[n] = '\0';
518 strncat (name, file, len);
519
520 if (!access (name, R_OK))
521 return strdup (name);
522 if (ext)
523 {
524 strcat (name, ext);
525 if (!access (name, R_OK))
526 return strdup (name);
527 }
528 }
529 }
530 return NULL;
531}
532
320/* EXTPROTO */ 533/* INTPROTO */
321char * 534char *
322rxvt_File_find(const char *file, const char *ext, const char *path) 535rxvt_File_find (const char *file, const char *ext, const char *path)
323{ 536{
324 char *f; 537 char *f;
325 538
326 if (file == NULL || *file == '\0') 539 if (file == NULL || *file == '\0')
327 return NULL; 540 return NULL;
328 541
329/* search environment variables here too */ 542 /* search environment variables here too */
330 if ((f = rxvt_File_search_path(path, file, ext)) == NULL) 543 if ((f = rxvt_File_search_path (path, file, ext)) == NULL)
331#ifdef PATH_ENV 544#ifdef PATH_ENV
332 if ((f = rxvt_File_search_path(getenv(PATH_ENV), file, ext)) == NULL) 545 if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL)
333#endif 546#endif
334 f = rxvt_File_search_path(getenv("PATH"), file, ext); 547 f = rxvt_File_search_path (getenv ("PATH"), file, ext);
335 548
336#ifdef DEBUG_SEARCH_PATH 549#ifdef DEBUG_SEARCH_PATH
337 if (f) 550 if (f)
338 fprintf(stderr, "found: \"%s\"\n", f); 551 fprintf (stderr, "found: \"%s\"\n", f);
339#endif 552#endif
340 553
341 return f; 554 return f;
342} 555}
343#endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ 556#endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */
344 557
345/*----------------------------------------------------------------------* 558/*----------------------------------------------------------------------*
346 * miscellaneous drawing routines 559 * miscellaneous drawing routines
348 561
349/* 562/*
350 * Draw top/left and bottom/right border shadows around windows 563 * Draw top/left and bottom/right border shadows around windows
351 */ 564 */
352#if defined(RXVT_SCROLLBAR) || defined(MENUBAR) 565#if defined(RXVT_SCROLLBAR) || defined(MENUBAR)
353/* EXTPROTO */ 566/* INTPROTO */
354void 567void
355rxvt_Draw_Shadow(Display *Xdisplay, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) 568rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h)
356{ 569{
357 int shadow; 570 int shadow;
358 571
359 shadow = (w == 0 || h == 0) ? 1 : SHADOW; 572 shadow = (w == 0 || h == 0) ? 1 : SHADOW;
360 w += x - 1; 573 w += x - 1;
361 h += y - 1; 574 h += y - 1;
362 for (; shadow-- > 0; x++, y++, w--, h--) { 575 for (; shadow-- > 0; x++, y++, w--, h--)
576 {
363 XDrawLine(Xdisplay, win, topShadow, x, y, w, y); 577 XDrawLine (display, win, topShadow, x, y, w, y);
364 XDrawLine(Xdisplay, win, topShadow, x, y, x, h); 578 XDrawLine (display, win, topShadow, x, y, x, h);
365 XDrawLine(Xdisplay, win, botShadow, w, h, w, y + 1); 579 XDrawLine (display, win, botShadow, w, h, w, y + 1);
366 XDrawLine(Xdisplay, win, botShadow, w, h, x + 1, h); 580 XDrawLine (display, win, botShadow, w, h, x + 1, h);
367 } 581 }
368} 582}
369#endif 583#endif
370 584
371/* button shapes */ 585/* button shapes */
372#ifdef MENUBAR 586#ifdef MENUBAR
373/* EXTPROTO */ 587/* INTPROTO */
374void 588void
375rxvt_Draw_Triangle(Display *Xdisplay, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) 589rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type)
376{ 590{
377 switch (type) { 591 switch (type)
592 {
378 case 'r': /* right triangle */ 593 case 'r': /* right triangle */
379 XDrawLine(Xdisplay, win, topShadow, x, y, x, y + w); 594 XDrawLine (display, win, topShadow, x, y, x, y + w);
380 XDrawLine(Xdisplay, win, topShadow, x, y, x + w, y + w / 2); 595 XDrawLine (display, win, topShadow, x, y, x + w, y + w / 2);
381 XDrawLine(Xdisplay, win, botShadow, x, y + w, x + w, y + w / 2); 596 XDrawLine (display, win, botShadow, x, y + w, x + w, y + w / 2);
382 break; 597 break;
383 598
384 case 'l': /* left triangle */ 599 case 'l': /* left triangle */
385 XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w, y); 600 XDrawLine (display, win, botShadow, x + w, y + w, x + w, y);
386 XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x, y + w / 2); 601 XDrawLine (display, win, botShadow, x + w, y + w, x, y + w / 2);
387 XDrawLine(Xdisplay, win, topShadow, x, y + w / 2, x + w, y); 602 XDrawLine (display, win, topShadow, x, y + w / 2, x + w, y);
388 break; 603 break;
389 604
390 case 'd': /* down triangle */ 605 case 'd': /* down triangle */
391 XDrawLine(Xdisplay, win, topShadow, x, y, x + w / 2, y + w); 606 XDrawLine (display, win, topShadow, x, y, x + w / 2, y + w);
392 XDrawLine(Xdisplay, win, topShadow, x, y, x + w, y); 607 XDrawLine (display, win, topShadow, x, y, x + w, y);
393 XDrawLine(Xdisplay, win, botShadow, x + w, y, x + w / 2, y + w); 608 XDrawLine (display, win, botShadow, x + w, y, x + w / 2, y + w);
394 break; 609 break;
395 610
396 case 'u': /* up triangle */ 611 case 'u': /* up triangle */
397 XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w / 2, y); 612 XDrawLine (display, win, botShadow, x + w, y + w, x + w / 2, y);
398 XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x, y + w); 613 XDrawLine (display, win, botShadow, x + w, y + w, x, y + w);
399 XDrawLine(Xdisplay, win, topShadow, x, y + w, x + w / 2, y); 614 XDrawLine (display, win, topShadow, x, y + w, x + w / 2, y);
400 break; 615 break;
401#if 0 616#if 0
402 case 's': /* square */ 617 case 's': /* square */
403 XDrawLine(Xdisplay, win, topShadow, x + w, y, x, y); 618 XDrawLine (display, win, topShadow, x + w, y, x, y);
404 XDrawLine(Xdisplay, win, topShadow, x, y, x, y + w); 619 XDrawLine (display, win, topShadow, x, y, x, y + w);
405 XDrawLine(Xdisplay, win, botShadow, x, y + w, x + w, y + w); 620 XDrawLine (display, win, botShadow, x, y + w, x + w, y + w);
406 XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w, y); 621 XDrawLine (display, win, botShadow, x + w, y + w, x + w, y);
407 break; 622 break;
408#endif 623#endif
624
409 } 625 }
410} 626}
411#endif 627#endif
412/*----------------------- end-of-file (C source) -----------------------*/ 628/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines