コード例 #1
0
ファイル: queue.c プロジェクト: KnightKu/fileutils
void dequeue (CIRCLE_handle * handle)
{
	char buf[CIRCLE_MAX_STRING_LEN];
	char * p;
	int depth;

	handle->dequeue(buf);
	switch(buf[0])
	{
		case 'D':
			depth = atoi(&buf[2]);
			p = strchr(&buf[2], ':');
			handle_dir(p+1, depth);
		break;

		case 'F':
			handle_file(&buf[2]);
		break;

		default:
			fprintf(stderr, "bad buffer %s\n", buf);
			return;
		break;
	}

	return;
}
コード例 #2
0
ファイル: gzip.c プロジェクト: jaredmcneill/freebsd
/* do what is asked for, for the path name */
static void
handle_pathname(char *path)
{
	char *opath = path, *s = NULL;
	ssize_t len;
	int slen;
	struct stat sb;

	/* check for stdout/stdin */
	if (path[0] == '-' && path[1] == '\0') {
		if (dflag)
			handle_stdin();
		else
			handle_stdout();
		return;
	}

retry:
	if (stat(path, &sb) != 0 || (fflag == 0 && cflag == 0 &&
	    lstat(path, &sb) != 0)) {
		/* lets try <path>.gz if we're decompressing */
		if (dflag && s == NULL && errno == ENOENT) {
			len = strlen(path);
			slen = suffixes[0].ziplen;
			s = malloc(len + slen + 1);
			if (s == NULL)
				maybe_err("malloc");
			memcpy(s, path, len);
			memcpy(s + len, suffixes[0].zipped, slen + 1);
			path = s;
			goto retry;
		}
		maybe_warn("can't stat: %s", opath);
		goto out;
	}

	if (S_ISDIR(sb.st_mode)) {
#ifndef SMALL
		if (rflag)
			handle_dir(path);
		else
#endif
			maybe_warnx("%s is a directory", path);
		goto out;
	}

	if (S_ISREG(sb.st_mode))
		handle_file(path, &sb);
	else
		maybe_warnx("%s is not a regular file", path);

out:
	if (s)
		free(s);
}
コード例 #3
0
ファイル: dir_scan.hpp プロジェクト: he3210/mycode
			void dir_analysis(std::string& task)
			{
				struct stat my_stat;
				bzero(&my_stat,sizeof(my_stat));
				if(lstat(task.c_str(),&my_stat)==-1)//对取到的目录进行解析,解析失败任务unfinished也要减1
				{
					perror("lstat");
					mod_unfinished();
					return;
				}
				if(S_ISREG(my_stat.st_mode))//如果是普通文件查找是否包含查询词
				{
					handle_reg(task);
				}
				else if(S_ISDIR(my_stat.st_mode))//目录,解析后重新将目录流中的目录放入工作队列
				{
					handle_dir(task);
				}
				else
				{
					handle_other(task);//直接将unfinished减掉1
				}
			}
コード例 #4
0
ファイル: gsettings-data-convert.c プロジェクト: BARGAN/gconf
int
main (int argc, char *argv[])
{
  time_t stored_mtime;
  const gchar * const *data_dirs;
  gint i;
  GError *error;
  GHashTable *converted;
  GOptionContext *context;
  const gchar *extra_file = NULL;
  GOptionEntry entries[] = {
    { "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "show verbose messages", NULL },
    { "dry-run", 0, 0, G_OPTION_ARG_NONE, &dry_run, "do not perform any changes", NULL },
    { "file", 0, 0, G_OPTION_ARG_STRING, &extra_file, "perform conversions from an extra file", NULL },
    { NULL }
  };

  g_type_init();

  context = g_option_context_new ("");

  g_option_context_set_summary (context,
    "Migrate settings from the users GConf database to GSettings.");

  g_option_context_add_main_entries (context, entries, NULL);

  error = NULL;
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_printerr ("%s\n", error->message);
      return 1;
    }

  converted = load_state (&stored_mtime);

  if (extra_file)
    {
      gchar *base;

      base = g_path_get_basename (extra_file);

      if (g_hash_table_lookup (converted, base))
        {
          if (verbose)
            g_print ("'%s' is already converted.  Skipping.\n", base);
        }
      else
        {
          if (handle_file (extra_file))
            {
              gchar *myname = g_strdup (base);

              g_hash_table_insert (converted, myname, myname);
              changed = TRUE;
            }
        }

      g_free (base);
    }

  data_dirs = g_get_system_data_dirs ();
  for (i = 0; data_dirs[i]; i++)
    {
      gchar *convert_dir;

      convert_dir = g_build_filename (data_dirs[i], "GConf", "gsettings", NULL);

      if (!handle_dir (convert_dir, stored_mtime, converted))
        return 1;

      g_free (convert_dir);
    }

  if (changed && !dry_run)
    {
      if (!save_state (converted))
        return 1;
    }

  return 0;
}
コード例 #5
0
/* do what is asked for, for the path name */
static void
handle_pathname(char *path)
{
	char *opath = path, *s = NULL;
	ssize_t len;
	int slen;
	struct stat sb;

	/* check for stdout/stdin */
	if (path[0] == '-' && path[1] == '\0') {
		if (dflag)
			handle_stdin();
		else
			handle_stdout();
		return;
	}

#ifdef __APPLE__
	if (zcat && COMPAT_MODE("bin/zcat", "Unix2003")) {
		char *suffix = strrchr(path, '.');
		if (suffix == NULL || strcmp(suffix, Z_SUFFIX) != 0) {
			len = strlen(path);
			slen = sizeof(Z_SUFFIX) - 1;
			s = malloc(len + slen + 1);
			memcpy(s, path, len);
			memcpy(s + len, Z_SUFFIX, slen + 1);
			path = s;
		}
	}
#endif

retry:
	if (stat(path, &sb) != 0 || (fflag == 0 && cflag == 0 &&
	    lstat(path, &sb) != 0)) {
		/* lets try <path>.gz if we're decompressing */
		if (dflag && s == NULL && errno == ENOENT) {
			len = strlen(path);
			slen = suffixes[0].ziplen;
			s = malloc(len + slen + 1);
			if (s == NULL)
				maybe_err("malloc");
			memcpy(s, path, len);
			memcpy(s + len, suffixes[0].zipped, slen + 1);
			path = s;
			goto retry;
		}
#ifdef __APPLE__
		/* Include actual path for clarity. */
		maybe_warn("can't stat: %s (%s)", opath, path);
#else
		maybe_warn("can't stat: %s", opath);
#endif
		goto out;
	}

	if (S_ISDIR(sb.st_mode)) {
#ifndef SMALL
		if (rflag)
			handle_dir(path);
		else
#endif
			maybe_warnx("%s is a directory", path);
		goto out;
	}

	if (S_ISREG(sb.st_mode))
		handle_file(path, &sb);
	else
		maybe_warnx("%s is not a regular file", path);

out:
	if (s)
		free(s);
}