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.40 by root, Mon Feb 20 22:42:00 2006 UTC vs.
Revision 1.42 by ayin, Mon Aug 27 20:00:26 2007 UTC

246rxvt_Str_match (const char *s1, const char *s2) NOTHROW 246rxvt_Str_match (const char *s1, const char *s2) NOTHROW
247{ 247{
248 int n = strlen (s2); 248 int n = strlen (s2);
249 249
250 return ((strncmp (s1, s2, n) == 0) ? n : 0); 250 return ((strncmp (s1, s2, n) == 0) ? n : 0);
251}
252
253const char *
254rxvt_Str_skip_space (const char *str) NOTHROW
255{
256 if (str)
257 while (*str && isspace (*str))
258 str++;
259
260 return str;
261} 251}
262 252
263/* 253/*
264 * remove leading/trailing space and strip-off leading/trailing quotes. 254 * remove leading/trailing space and strip-off leading/trailing quotes.
265 * in place. 255 * in place.
425 free (cs[i]); 415 free (cs[i]);
426 416
427 free (cs); 417 free (cs);
428} 418}
429 419
430/*----------------------------------------------------------------------*
431 * file searching
432 */
433 420
434#ifdef XPM_BACKGROUND
435/*
436 * search for FILE in the current working directory, and within the
437 * colon-delimited PATHLIST, adding the file extension EXT if required.
438 *
439 * FILE is either semi-colon or zero terminated
440 */
441char *
442rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) NOTHROW
443{
444 int maxpath, len;
445 const char *p, *path;
446 char name[256];
447 421
448 if (!access (file, R_OK)) /* found (plain name) in current directory */
449 return strdup (file);
450
451 /* semi-colon delimited */
452 if ((p = strchr (file, ';')))
453 len = (p - file);
454 else
455 len = strlen (file);
456
457 /* leave room for an extra '/' and trailing '\0' */
458 maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2);
459 if (maxpath <= 0)
460 return NULL;
461
462 /* check if we can find it now */
463 strncpy (name, file, len);
464 name[len] = '\0';
465
466 if (!access (name, R_OK))
467 return strdup (name);
468 if (ext)
469 {
470 strcat (name, ext);
471 if (!access (name, R_OK))
472 return strdup (name);
473 }
474 for (path = pathlist; path != NULL && *path != '\0'; path = p)
475 {
476 int n;
477
478 /* colon delimited */
479 if ((p = strchr (path, ':')) == NULL)
480 p = strchr (path, '\0');
481
482 n = (p - path);
483 if (*p != '\0')
484 p++;
485
486 if (n > 0 && n <= maxpath)
487 {
488 strncpy (name, path, n);
489 if (name[n - 1] != '/')
490 name[n++] = '/';
491 name[n] = '\0';
492 strncat (name, file, len);
493
494 if (!access (name, R_OK))
495 return strdup (name);
496 if (ext)
497 {
498 strcat (name, ext);
499 if (!access (name, R_OK))
500 return strdup (name);
501 }
502 }
503 }
504 return NULL;
505}
506
507char *
508rxvt_File_find (const char *file, const char *ext, const char *path) NOTHROW
509{
510 char *f;
511
512 if (file == NULL || *file == '\0')
513 return NULL;
514
515 f = rxvt_File_search_path (path, file, ext);
516
517 return f;
518}
519#endif
520
521

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines