示例#1
0
int ftw(char *path, Myfunc *func)
{
    int len = sizeof(path);
    //strncpy(fullpath, path, len);
    strcpy(fullpath, path);
    printf("fullpath = %s\n", fullpath);
    return do_path(func); 
}
示例#2
0
LOCAL void PROC process (const char target[]) {
/*      if (strlen(target) > sizeof(path)-5) {
 *              sayerror (E_TARGET, "too long", target);
 *              return;
 *      }
 */     found = 0;
        do_path (nsplit (adds (path, target)));
        if (found == 0) sayerror (E_TARGET, "no targets", target);
}
示例#3
0
文件: main.c 项目: IC15BHR/myfind
/**
 * @brief checks the entry using subfunctions based on params, if passed, prints it
 *
 * @param path the path to be processed
 * @param params the parsed parameters
 * @param attr the entry attributes from lstat
 *
 * @returns EXIT_SUCCESS, EXIT_FAILURE
 */
int do_file(char *path, params_t *params, struct stat attr) {
  int printed = 0;

  do {
    /* ### FB: Mit ENUM Feld könnte hier ein switch genutzt werden und für mehr Übersicht sorgen. */
    /* filtering */
    if (params->type) {
      if (do_type(params->type, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS; /* the entry didn't pass the check, do not print it */
      }
    }
    if (params->nouser) {
      if (do_nouser(attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->user) {
      if (do_user(params->userid, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->name) {
      if (do_name(path, params->name) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->path) {
      if (do_path(path, params->path) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    /* printing */
    if (params->print) {
      if (do_print(path) != EXIT_SUCCESS) {
        return EXIT_FAILURE; /* a fatal error occurred */
      }
      printed = 1;
    }
    if (params->ls) {
      if (do_ls(path, attr) != EXIT_SUCCESS) {
        return EXIT_FAILURE;
      }
      printed = 1;
    }

    params = params->next;
  } while (params);

  if (printed == 0) {
    if (do_print(path) != EXIT_SUCCESS) {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}
示例#4
0
文件: main.c 项目: amq/myfind
/**
 * @brief checks the entry using subfunctions based on params, if passed, prints it
 *
 * @param path the path to be processed
 * @param params the parsed parameters
 * @param attr the entry attributes from lstat
 *
 * @returns EXIT_SUCCESS, EXIT_FAILURE
 */
int do_file(char *path, params_t *params, struct stat attr) {
  int printed = 0;

  do {
    /* filtering */
    if (params->type) {
      if (do_type(params->type, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS; /* the entry didn't pass the check, do not print it */
      }
    }
    if (params->nouser) {
      if (do_nouser(attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->user) {
      if (do_user(params->userid, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->name) {
      if (do_name(path, params->name) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->path) {
      if (do_path(path, params->path) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    /* printing */
    if (params->print) {
      if (do_print(path) != EXIT_SUCCESS) {
        return EXIT_FAILURE; /* a fatal error occurred */
      }
      printed = 1;
    }
    if (params->ls) {
      if (do_ls(path, attr) != EXIT_SUCCESS) {
        return EXIT_FAILURE;
      }
      printed = 1;
    }

    params = params->next;
  } while (params);

  if (printed == 0) {
    if (do_print(path) != EXIT_SUCCESS) {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}
示例#5
0
文件: 4-7.c 项目: njuguoyi/APUE3
static int my_ftw(const char *pathname, myfunc *func)
{
	/* 拷贝pathname是递归的需要 */
	fullpath = path_alloc(&pathlen);
	if (pathlen <= strlen(pathname)) {
		pathlen = strlen(pathname) * 2;
		if ((fullpath = realloc(fullpath, pathlen)) == NULL)
			err_sys("realloc failed");
	}
	strcpy(fullpath, pathname);
	return (do_path(func));
}
示例#6
0
LOCAL void PROC do_path (char *pathend) {
        struct find_t fi;

        do_mask (pathend); if (recurse == 0) return;

        adds (pathend, "*.*");
        if (_dos_findfirst (path, DIR_ATTR, &fi))
                return;

        do {    const char *p;
                if ((fi.attrib & _A_SUBDIR) == 0) continue;
                p = fi.name-1; do p++; while (*p == '.');
                if (*p == '\0') continue;               /* name == dots */

                do_path (adds (adds (pathend, fi.name), "\\"));
        } while (_dos_findnext (&fi) == 0);
}
示例#7
0
文件: 4-7.c 项目: njuguoyi/APUE3
static int do_path(myfunc* func)
{
	struct stat statbuf;
	struct dirent *dirp;
	DIR *dp;
	int ret, n;

	if (lstat(fullpath, &statbuf) < 0)
		return(func(fullpath, &statbuf, FTW_NS));
	if (S_ISDIR(statbuf.st_mode) == 0)
		return(func(fullpath, &statbuf, FTW_F));
	if ((ret = func(fullpath, &statbuf, FTW_D)) != 0)
		return ret;

	n = strlen(fullpath);
	if (n + NAME_MAX + 2 > pathlen)
	{
		pathlen *= 2;
		if ((fullpath = realloc(fullpath, pathlen)) == NULL)
			err_sys("realloc failed");
	}
	fullpath[n++] = '/';
	fullpath[n] = 0;
	if ((dp = opendir(fullpath)) == NULL)
		return(func(fullpath, &statbuf, FTW_DNR));

	while ((dirp = readdir(dp)) != NULL)
	{
		if (strcmp(dirp->d_name, ".") == 0 ||
			strcmp(dirp->d_name, "..") == 0)
			continue;
		strcpy(&fullpath[n], dirp->d_name);
		if ((ret = do_path(func)) != 0)
			break;
	}
	fullpath[n-1] = 0;

	if (closedir(dp) < 0)
		err_ret("cannot close directory %s", fullpath)	;
	return ret;
}
示例#8
0
int do_path(Myfunc *func)
{
    DIR * dp;
    struct dirent *dirp;
    struct stat statbuf;
    int ret;
    char *ptr;
    if(lstat(fullpath, &statbuf) < 0)
        return func(fullpath, &statbuf, FTW_NS);
    if(S_ISDIR(statbuf.st_mode) == 0)
        return func(fullpath, &statbuf, FTW_F);
    if((ret = func(fullpath, &statbuf, FTW_D)) != 0)
        return ret;
    if((dp = opendir(fullpath)) == NULL)
        return func(fullpath, &statbuf, FTW_DNR);
    /*
    ptr = fullpath + strlen(fullpath);
    *ptr++ = '/';
    *ptr = 0;
    */
    if(chdir(fullpath) == -1)
    {
        err_sys("change dir error"); 
    }
    while((dirp = readdir(dp)) != NULL)
    {
        if(strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
            continue;
        //strcpy(ptr, dirp->d_name);
        strcpy(fullpath, dirp->d_name);
        if((ret = do_path(func)) != 0)
            break;
    }
    //ptr[-1] = 0;
    if(closedir(dp) < 0)
        err_sys("close dir error");
    chdir("..");
    return ret;
}