}
-static int filename_equal(const char *cp, const char *dp)
+static int filename_equal(const char *cp, const char *dp, int type)
{
int i = strlen(dp);
DBG(SEARCH, ul_debug("compare '%s' and '%s'", cp, dp));
- if (dp[0] == 's' && dp[1] == '.' && filename_equal(cp, dp + 2))
+ if (type & SRC_DIR &&
+ dp[0] == 's' && dp[1] == '.' && filename_equal(cp, dp + 2, type))
return 1;
- if (i > 1 && !strcmp(dp + i - 2, ".Z"))
- i -= 2;
- else if (i > 2 && !strcmp(dp + i - 3, ".gz"))
- i -= 3;
- else if (i > 2 && !strcmp(dp + i - 3, ".xz"))
- i -= 3;
- else if (i > 3 && !strcmp(dp + i - 4, ".bz2"))
- i -= 4;
- else if (i > 3 && !strcmp(dp + i - 4, ".zst"))
- i -= 4;
+ if (type & MAN_DIR) {
+ if (i > 1 && !strcmp(dp + i - 2, ".Z"))
+ i -= 2;
+ else if (i > 2 && !strcmp(dp + i - 3, ".gz"))
+ i -= 3;
+ else if (i > 2 && !strcmp(dp + i - 3, ".xz"))
+ i -= 3;
+ else if (i > 3 && !strcmp(dp + i - 4, ".bz2"))
+ i -= 4;
+ else if (i > 3 && !strcmp(dp + i - 4, ".zst"))
+ i -= 4;
+ }
while (*cp && *dp && *cp == *dp)
cp++, dp++, i--;
if (*cp == 0 && *dp == 0)
return 1;
- if (*cp == 0 && *dp++ == '.') {
+ if (!(type & BIN_DIR) && *cp == 0 && *dp++ == '.') {
--i;
while (i > 0 && *dp)
if (--i, *dp++ == '.')
return 0;
}
-static void findin(const char *dir, const char *pattern, int *count, char **wait)
+static void findin(const char *dir, const char *pattern, int *count,
+ char **wait, int type)
{
DIR *dirp;
struct dirent *dp;
DBG(SEARCH, ul_debug("find '%s' in '%s'", pattern, dir));
while ((dp = readdir(dirp)) != NULL) {
- if (!filename_equal(pattern, dp->d_name))
+ if (!filename_equal(pattern, dp->d_name, type))
continue;
if (uflag && *count == 0)
for (; ls; ls = ls->next) {
if ((ls->type & want) && ls->path)
- findin(ls->path, patbuf, &count, &wait);
+ findin(ls->path, patbuf, &count, &wait, ls->type);
}
free(wait);