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.41 by ayin, Sat Jun 30 23:58:29 2007 UTC

425 free (cs[i]); 425 free (cs[i]);
426 426
427 free (cs); 427 free (cs);
428} 428}
429 429
430/*----------------------------------------------------------------------*
431 * file searching
432 */
433 430
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 431
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