~ubuntu-branches/ubuntu/karmic/rxvt-unicode/karmic

« back to all changes in this revision

Viewing changes to src/misc.C

  • Committer: Bazaar Package Importer
  • Author(s): Decklin Foster
  • Date: 2007-08-03 12:44:44 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070803124444-uwmus5csvd7rm4fp
Tags: 8.3-1
* New upstream release (Closes: #433004)
  - Rolled with autoconf 2.61 (Closes: #422540)
* Match https URLs in selection-popup (Closes: #428659)
* Fix typos in urxvtperl(3) (Closes: #411074, #415848)
* Use sensible-browser instead of x-www-browser directly (Closes: #415846)
* Added urxvtcd as alternative (Closes: #381967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
427
427
  free (cs);
428
428
}
429
429
 
430
 
/*----------------------------------------------------------------------*
431
 
 * file searching
432
 
 */
433
 
 
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
 
 */
441
 
char *
442
 
rxvt_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
 
 
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
 
 
507
 
char *
508
 
rxvt_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
430
 
521
431