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.13 by pcg, Thu Apr 8 20:31:45 2004 UTC vs.
Revision 1.15 by root, Sun Aug 15 04:54:21 2004 UTC

25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28#include "misc.intpro" /* PROTOS for internal routines */ 28#include "misc.intpro" /* PROTOS for internal routines */
29 29
30/* EXTPROTO */ 30/* INTPROTO */
31char * 31char *
32rxvt_wcstombs (const wchar_t *str, int len) 32rxvt_wcstombs (const wchar_t *str, int len)
33{ 33{
34 mbstate mbs; 34 mbstate mbs;
35 char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1); 35 char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1);
47 *dst++ = 0; 47 *dst++ = 0;
48 48
49 return r; 49 return r;
50} 50}
51 51
52/* EXTPROTO */ 52/* INTPROTO */
53char * 53char *
54rxvt_strdup (const char *str) 54rxvt_strdup (const char *str)
55{ 55{
56 return str ? strdup (str) : 0; 56 return str ? strdup (str) : 0;
57} 57}
58 58
59/* EXTPROTO */ 59/* INTPROTO */
60char * 60char *
61rxvt_r_basename (const char *str) 61rxvt_r_basename (const char *str)
62{ 62{
63 char *base = STRRCHR (str, '/'); 63 char *base = strrchr (str, '/');
64 64
65 return (char *) (base ? base + 1 : str); 65 return (char *) (base ? base + 1 : str);
66} 66}
67 67
68/* 68/*
69 * Print an error message 69 * Print an error message
70 */ 70 */
71/* EXTPROTO */ 71/* INTPROTO */
72void 72void
73rxvt_vlog (const char *fmt, va_list arg_ptr) 73rxvt_vlog (const char *fmt, va_list arg_ptr)
74{ 74{
75 char msg[1024]; 75 char msg[1024];
76 76
80 (*GET_R->log_hook) (msg); 80 (*GET_R->log_hook) (msg);
81 else 81 else
82 write (STDOUT_FILENO, msg, strlen (msg)); 82 write (STDOUT_FILENO, msg, strlen (msg));
83} 83}
84 84
85/* EXTPROTO */ 85/* INTPROTO */
86void 86void
87rxvt_log (const char *fmt,...) 87rxvt_log (const char *fmt,...)
88{ 88{
89 va_list arg_ptr; 89 va_list arg_ptr;
90 90
94} 94}
95 95
96/* 96/*
97 * Print an error message 97 * Print an error message
98 */ 98 */
99/* EXTPROTO */ 99/* INTPROTO */
100void 100void
101rxvt_warn (const char *fmt,...) 101rxvt_warn (const char *fmt,...)
102{ 102{
103 va_list arg_ptr; 103 va_list arg_ptr;
104 104
107 va_start (arg_ptr, fmt); 107 va_start (arg_ptr, fmt);
108 rxvt_vlog (fmt, arg_ptr); 108 rxvt_vlog (fmt, arg_ptr);
109 va_end (arg_ptr); 109 va_end (arg_ptr);
110} 110}
111 111
112/* EXTPROTO */ 112/* INTPROTO */
113void 113void
114rxvt_fatal (const char *fmt,...) 114rxvt_fatal (const char *fmt,...)
115{ 115{
116 va_list arg_ptr; 116 va_list arg_ptr;
117 117
124 rxvt_exit_failure (); 124 rxvt_exit_failure ();
125} 125}
126 126
127class rxvt_failure_exception rxvt_failure_exception; 127class rxvt_failure_exception rxvt_failure_exception;
128 128
129/* EXTPROTO */ 129/* INTPROTO */
130void 130void
131rxvt_exit_failure () 131rxvt_exit_failure ()
132{ 132{
133 throw (rxvt_failure_exception); 133 throw (rxvt_failure_exception);
134} 134}
137 * check that the first characters of S1 match S2 137 * check that the first characters of S1 match S2
138 * 138 *
139 * No Match 139 * No Match
140 * return: 0 140 * return: 0
141 * Match 141 * Match
142 * return: STRLEN (S2) 142 * return: strlen (S2)
143 */ 143 */
144/* EXTPROTO */ 144/* INTPROTO */
145int 145int
146rxvt_Str_match (const char *s1, const char *s2) 146rxvt_Str_match (const char *s1, const char *s2)
147{ 147{
148 int n = STRLEN (s2); 148 int n = strlen (s2);
149 149
150 return ((STRNCMP (s1, s2, n) == 0) ? n : 0); 150 return ((strncmp (s1, s2, n) == 0) ? n : 0);
151} 151}
152 152
153/* EXTPROTO */ 153/* INTPROTO */
154const char * 154const char *
155rxvt_Str_skip_space (const char *str) 155rxvt_Str_skip_space (const char *str)
156{ 156{
157 if (str) 157 if (str)
158 while (*str && isspace (*str)) 158 while (*str && isspace (*str))
163 163
164/* 164/*
165 * remove leading/trailing space and strip-off leading/trailing quotes. 165 * remove leading/trailing space and strip-off leading/trailing quotes.
166 * in place. 166 * in place.
167 */ 167 */
168/* EXTPROTO */ 168/* INTPROTO */
169char * 169char *
170rxvt_Str_trim (char *str) 170rxvt_Str_trim (char *str)
171{ 171{
172 char *r, *s; 172 char *r, *s;
173 int n; 173 int n;
212 * "M-x" prefixed strings, append "\r" if needed 212 * "M-x" prefixed strings, append "\r" if needed
213 * "\E]" prefixed strings (XTerm escape sequence) append ST if needed 213 * "\E]" prefixed strings (XTerm escape sequence) append ST if needed
214 * 214 *
215 * returns the converted string length 215 * returns the converted string length
216 */ 216 */
217/* EXTPROTO */ 217/* INTPROTO */
218int 218int
219rxvt_Str_escaped (char *str) 219rxvt_Str_escaped (char *str)
220{ 220{
221 char ch, *s, *d; 221 char ch, *s, *d;
222 int i, num, append = 0; 222 int i, num, append = 0;
290 * Split a comma-separated string into an array, stripping leading and 290 * Split a comma-separated string into an array, stripping leading and
291 * trailing spaces (and paired quotes) from each entry. Empty strings 291 * trailing spaces (and paired quotes) from each entry. Empty strings
292 * are properly returned 292 * are properly returned
293 * Caller should free each entry and array when done 293 * Caller should free each entry and array when done
294 */ 294 */
295/* EXTPROTO */ 295/* INTPROTO */
296char ** 296char **
297rxvt_splitcommastring (const char *cs) 297rxvt_splitcommastring (const char *cs)
298{ 298{
299 int l, n, p; 299 int l, n, p;
300 const char *s, *t; 300 const char *s, *t;
342 int maxpath, len; 342 int maxpath, len;
343 const char *p, *path; 343 const char *p, *path;
344 char name[256]; 344 char name[256];
345 345
346 if (!access (file, R_OK)) /* found (plain name) in current directory */ 346 if (!access (file, R_OK)) /* found (plain name) in current directory */
347 return STRDUP (file); 347 return strdup (file);
348 348
349 /* semi-colon delimited */ 349 /* semi-colon delimited */
350 if ((p = STRCHR (file, ';'))) 350 if ((p = strchr (file, ';')))
351 len = (p - file); 351 len = (p - file);
352 else 352 else
353 len = STRLEN (file); 353 len = strlen (file);
354 354
355#ifdef DEBUG_SEARCH_PATH 355#ifdef DEBUG_SEARCH_PATH
356 getcwd (name, sizeof (name)); 356 getcwd (name, sizeof (name));
357 fprintf (stderr, "pwd: \"%s\"\n", name); 357 fprintf (stderr, "pwd: \"%s\"\n", name);
358 fprintf (stderr, "find: \"%.*s\"\n", len, file); 358 fprintf (stderr, "find: \"%.*s\"\n", len, file);
359#endif 359#endif
360 360
361 /* leave room for an extra '/' and trailing '\0' */ 361 /* leave room for an extra '/' and trailing '\0' */
362 maxpath = sizeof (name) - (len + (ext ? STRLEN (ext) : 0) + 2); 362 maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2);
363 if (maxpath <= 0) 363 if (maxpath <= 0)
364 return NULL; 364 return NULL;
365 365
366 /* check if we can find it now */ 366 /* check if we can find it now */
367 STRNCPY (name, file, len); 367 strncpy (name, file, len);
368 name[len] = '\0'; 368 name[len] = '\0';
369 369
370 if (!access (name, R_OK)) 370 if (!access (name, R_OK))
371 return STRDUP (name); 371 return strdup (name);
372 if (ext) 372 if (ext)
373 { 373 {
374 STRCAT (name, ext); 374 strcat (name, ext);
375 if (!access (name, R_OK)) 375 if (!access (name, R_OK))
376 return STRDUP (name); 376 return strdup (name);
377 } 377 }
378 for (path = pathlist; path != NULL && *path != '\0'; path = p) 378 for (path = pathlist; path != NULL && *path != '\0'; path = p)
379 { 379 {
380 int n; 380 int n;
381 381
382 /* colon delimited */ 382 /* colon delimited */
383 if ((p = STRCHR (path, ':')) == NULL) 383 if ((p = strchr (path, ':')) == NULL)
384 p = STRCHR (path, '\0'); 384 p = strchr (path, '\0');
385 385
386 n = (p - path); 386 n = (p - path);
387 if (*p != '\0') 387 if (*p != '\0')
388 p++; 388 p++;
389 389
390 if (n > 0 && n <= maxpath) 390 if (n > 0 && n <= maxpath)
391 { 391 {
392 STRNCPY (name, path, n); 392 strncpy (name, path, n);
393 if (name[n - 1] != '/') 393 if (name[n - 1] != '/')
394 name[n++] = '/'; 394 name[n++] = '/';
395 name[n] = '\0'; 395 name[n] = '\0';
396 STRNCAT (name, file, len); 396 strncat (name, file, len);
397 397
398 if (!access (name, R_OK)) 398 if (!access (name, R_OK))
399 return STRDUP (name); 399 return strdup (name);
400 if (ext) 400 if (ext)
401 { 401 {
402 STRCAT (name, ext); 402 strcat (name, ext);
403 if (!access (name, R_OK)) 403 if (!access (name, R_OK))
404 return STRDUP (name); 404 return strdup (name);
405 } 405 }
406 } 406 }
407 } 407 }
408 return NULL; 408 return NULL;
409} 409}
410 410
411/* EXTPROTO */ 411/* INTPROTO */
412char * 412char *
413rxvt_File_find (const char *file, const char *ext, const char *path) 413rxvt_File_find (const char *file, const char *ext, const char *path)
414{ 414{
415 char *f; 415 char *f;
416 416
439 439
440/* 440/*
441 * Draw top/left and bottom/right border shadows around windows 441 * Draw top/left and bottom/right border shadows around windows
442 */ 442 */
443#if defined(RXVT_SCROLLBAR) || defined(MENUBAR) 443#if defined(RXVT_SCROLLBAR) || defined(MENUBAR)
444/* EXTPROTO */ 444/* INTPROTO */
445void 445void
446rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) 446rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h)
447{ 447{
448 int shadow; 448 int shadow;
449 449
460} 460}
461#endif 461#endif
462 462
463/* button shapes */ 463/* button shapes */
464#ifdef MENUBAR 464#ifdef MENUBAR
465/* EXTPROTO */ 465/* INTPROTO */
466void 466void
467rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) 467rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type)
468{ 468{
469 switch (type) 469 switch (type)
470 { 470 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines