… | |
… | |
429 | |
429 | |
430 | /*----------------------------------------------------------------------* |
430 | /*----------------------------------------------------------------------* |
431 | * file searching |
431 | * file searching |
432 | */ |
432 | */ |
433 | |
433 | |
434 | /* #define DEBUG_SEARCH_PATH */ |
|
|
435 | |
|
|
436 | #ifdef XPM_BACKGROUND |
434 | #ifdef XPM_BACKGROUND |
437 | /* |
435 | /* |
438 | * search for FILE in the current working directory, and within the |
436 | * search for FILE in the current working directory, and within the |
439 | * colon-delimited PATHLIST, adding the file extension EXT if required. |
437 | * colon-delimited PATHLIST, adding the file extension EXT if required. |
440 | * |
438 | * |
441 | * FILE is either semi-colon or zero terminated |
439 | * FILE is either semi-colon or zero terminated |
442 | */ |
440 | */ |
443 | char * |
441 | char * |
444 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) NOTHROW |
442 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) NOTHROW |
445 | { |
443 | { |
446 | int maxpath, len; |
444 | int maxpath, len; |
447 | const char *p, *path; |
445 | const char *p, *path; |
448 | char name[256]; |
446 | char name[256]; |
… | |
… | |
453 | /* semi-colon delimited */ |
451 | /* semi-colon delimited */ |
454 | if ((p = strchr (file, ';'))) |
452 | if ((p = strchr (file, ';'))) |
455 | len = (p - file); |
453 | len = (p - file); |
456 | else |
454 | else |
457 | len = strlen (file); |
455 | len = strlen (file); |
458 | |
|
|
459 | #ifdef DEBUG_SEARCH_PATH |
|
|
460 | getcwd (name, sizeof (name)); |
|
|
461 | fprintf (stderr, "pwd: \"%s\"\n", name); |
|
|
462 | fprintf (stderr, "find: \"%.*s\"\n", len, file); |
|
|
463 | #endif |
|
|
464 | |
456 | |
465 | /* leave room for an extra '/' and trailing '\0' */ |
457 | /* leave room for an extra '/' and trailing '\0' */ |
466 | maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2); |
458 | maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2); |
467 | if (maxpath <= 0) |
459 | if (maxpath <= 0) |
468 | return NULL; |
460 | return NULL; |
… | |
… | |
510 | } |
502 | } |
511 | } |
503 | } |
512 | return NULL; |
504 | return NULL; |
513 | } |
505 | } |
514 | |
506 | |
515 | char * |
507 | char * |
516 | rxvt_File_find (const char *file, const char *ext, const char *path) NOTHROW |
508 | rxvt_File_find (const char *file, const char *ext, const char *path) NOTHROW |
517 | { |
509 | { |
518 | char *f; |
510 | char *f; |
519 | |
511 | |
520 | if (file == NULL || *file == '\0') |
512 | if (file == NULL || *file == '\0') |
521 | return NULL; |
513 | return NULL; |
522 | |
514 | |
523 | f = rxvt_File_search_path (path, file, ext); |
515 | f = rxvt_File_search_path (path, file, ext); |
524 | |
516 | |
525 | #ifdef DEBUG_SEARCH_PATH |
517 | return f; |
526 | if (f) |
518 | } |
527 | fprintf (stderr, "found: \"%s\"\n", f); |
|
|
528 | #endif |
519 | #endif |
529 | |
520 | |
530 | return f; |
|
|
531 | } |
|
|
532 | #endif |
|
|
533 | |
521 | |
534 | // should not be used in interactive programs, for obvious reasons |
|
|
535 | void rxvt_usleep (int usecs) NOTHROW |
|
|
536 | { |
|
|
537 | #if HAVE_NANOSLEEP |
|
|
538 | struct timespec ts; |
|
|
539 | |
|
|
540 | ts.tv_sec = 0; |
|
|
541 | ts.tv_nsec = usecs * 1000; |
|
|
542 | nanosleep (&ts, NULL); |
|
|
543 | #else |
|
|
544 | /* use select for timing */ |
|
|
545 | struct timeval tv; |
|
|
546 | |
|
|
547 | tv.tv_sec = 0; |
|
|
548 | tv.tv_usec = usecs; |
|
|
549 | select (0, NULL, NULL, NULL, &tv); |
|
|
550 | #endif |
|
|
551 | } |
|
|
552 | |
|
|
553 | /*----------------------- end-of-file (C source) -----------------------*/ |
|
|
554 | |
|
|