예제 #1
0
static char *default_import_callback(void *ctx, const char *dir, const char *file,
                                     char **found_here_cptr, int *success)
{
    auto *vm = static_cast<JsonnetVm *>(ctx);

    std::string input, found_here, err_msg;

    ImportStatus status = try_path(dir, file, input, found_here, err_msg);

    std::vector<std::string> jpaths(vm->jpaths);

    // If not found, try library search path.
    while (status == IMPORT_STATUS_FILE_NOT_FOUND) {
        if (jpaths.size() == 0) {
            *success = 0;
            const char *err = "no match locally or in the Jsonnet library paths.";
            char *r = jsonnet_realloc(vm, nullptr, std::strlen(err) + 1);
            std::strcpy(r, err);
            return r;
        }
        status = try_path(jpaths.back(), file, input, found_here, err_msg);
        jpaths.pop_back();
    }

    if (status == IMPORT_STATUS_IO_ERROR) {
        *success = 0;
        return from_string(vm, err_msg);
    } else {
        assert(status == IMPORT_STATUS_OK);
        *success = 1;
        *found_here_cptr = from_string(vm, found_here);
        return from_string(vm, input);
    }
}
예제 #2
0
int
find_next_path(ep_t *src, ep_t *dest, int **arr, int size)
{
    fnp_cc++;

    try_path(NORTH, src, dest, arr, size);
    try_path(EAST, src, dest, arr, size);
    try_path(WEST, src, dest, arr, size);
    try_path(SOUTH, src, dest, arr, size);

    DPRINT("TRACE: Returning %C - (%d, %d)\n",
           dest->ep_id, src->ep_row, src->ep_col);
}
예제 #3
0
파일: main.cpp 프로젝트: arne-cl/frodo-wii
void Frodo::LoadFrodorc()
{
	const char *paths[] = {
			"/frodo", // Wii
			".",
			"/apps/frodo", // Wii
			"frodo",
			NULL, // Filled in below
			NULL, // also filled in below
			"/usr/share/frodo",
			NULL,
	};
	const char *prefs_path = NULL;
	const char *prefs_name = NULL;
	const char *total_name = NULL;
	char home_1[255];
	char home_2[255];
	int i;

	if (getenv("HOME"))
	{
		snprintf(home_1, sizeof(home_1), "%s/.frodo", getenv("HOME"));
		snprintf(home_2, sizeof(home_2), "%s/frodo", getenv("HOME"));
	}
	else
	{
		strcpy(home_1, "");
		strcpy(home_2, "");
	}
	paths[4] = home_1;
	paths[5] = home_2;

	for (i = 0; paths[i]; i++)
	{
		const char *p;
		const char *name = "frodorc";

		p = try_path(paths[i], name);

		if (p)
		{
			prefs_path = paths[i];
			prefs_name = name;
			total_name = p;
			break;
		}
		free((void*)p);
	}

	// Load preferences
	if (total_name)
	{
		ThePrefs.Load(total_name);
		strncpy(ThePrefs.PrefsPath, total_name, sizeof(ThePrefs.PrefsPath));
	} else
		printf("No frodorc, using default\n");

	free((void*)total_name);
}
예제 #4
0
char	*get_valid_path(char *cmd, t_shell *shell, char **env_tab)
{
	char	*new_cmd;
	char	**path_tab;

	path_tab = get_path(env_tab);
	if (access(cmd, X_OK) == 0)
		return (ft_strdup(cmd));
	if ((new_cmd = try_path(cmd, path_tab)) == NULL)
		return (NULL);
	if (ft_strcmp(new_cmd, cmd) == 0)
	{
		free(new_cmd);
		new_cmd = try_path(cmd, shell->path);
	}
	return (new_cmd);
}
예제 #5
0
extern "C" int wmain(int argc, wchar_t* argv[])
{
	setup_logger(logger::Level::TrObj);

	fsys::Folders_t foldersToProcess;
	fsys::Files_t filesToProcess;

	auto&& options = global::options();
	for (int i = 1; i < argc; ++i) {
		if (cstr::compare_cs(argv[i], L"/?") == 0) {
			options.showHelp = 1;
			break;
		} else if (cstr::compare_cs(argv[i], L"/d") == 0) {
			options.userLogLevel = logger::Level::Debug2;
		} else if (cstr::compare_cs(argv[i], L"/q") == 0) {
			options.userLogLevel = logger::Level::Warn;
		} else if (cstr::compare_cs(argv[i], L"/r") == 0) {
			options.doRecursive = 1;
		} else if (cstr::compare_cs(argv[i], L"/l") == 0) {
			options.doHardlink = 1;
		} else if (cstr::compare_cs(argv[i], L"/m") == 0) {
			options.minimumSize = 0;
		} else if (cstr::compare_cs(argv[i], L"/j") == 0) {
			options.skipLinks = 1;
		} else if (cstr::compare_cs(argv[i], L"/s") == 0) {
			options.skipSystemFiles = 1;
		} else if (cstr::compare_cs(argv[i], L"/h") == 0) {
			options.skipHiddenFiles = 1;
		} else if (cstr::compare_cs(argv[i], L"/t") == 0) {
			options.timeMustMatch = 1;
		} else if (cstr::compare_cs(argv[i], L"/a") == 0) {
			options.attrMustMatch = 1;
		} else {
			try_path(foldersToProcess, filesToProcess, argv[i]);
		}
	}

	setup_user_logger_level(options.userLogLevel);

	if (options.showHelp) {
		show_help();
	} else {
		LogDebug(L"argc: %d\n", argc);
		for (int i = 0; i < argc; ++i)
			LogDebug(L"'%s'\n", argv[i]);

		FileProcessor processor(std::move(foldersToProcess), std::move(filesToProcess));
		processor.execute();

		show_statistics();
	}

	return 0;
}
예제 #6
0
파일: package.c 프로젝트: dleonard0/ponyc
// Attempt to find the specified package directory in our search path
// @return The resulting directory path, which should not be deleted and is
// valid indefinitely. NULL is directory cannot be found.
static const char* find_path(ast_t* from, const char* path)
{
  // First check for an absolute path
  if(is_path_absolute(path))
    return try_path(NULL, path);

  const char* result;

  if((from == NULL) || (ast_id(from) == TK_PROGRAM))
  {
    // Try a path relative to the current working directory
    result = try_path(NULL, path);

    if(result != NULL)
      return result;
  }
  else
  {
    // Try a path relative to the importing package
    from = ast_nearest(from, TK_PACKAGE);
    package_t* pkg = (package_t*)ast_data(from);
    result = try_path(pkg->path, path);

    if(result != NULL)
      return result;
  }

  // Try the search paths
  for(strlist_t* p = search; p != NULL; p = strlist_next(p))
  {
    result = try_path(strlist_data(p), path);

    if(result != NULL)
      return result;
  }

  errorf(path, "couldn't locate this path");
  return NULL;
}
예제 #7
0
static char *import_callback (void *ctx_, const char *dir, const char *file, int *success)
{
    const auto &ctx = *static_cast<ImportCallbackContext*>(ctx_);

    std::string input;

    ImportStatus status = try_path(dir, file, input);

    std::vector<std::string> jpaths(*ctx.jpaths);

    // If not found, try library search path.
    while (status == IMPORT_STATUS_FILE_NOT_FOUND) {
        if (jpaths.size() == 0) {
            *success = 0;
            const char *err = "No match locally or in the Jsonnet library path.";
            char *r = jsonnet_realloc(ctx.vm, nullptr, std::strlen(err) + 1);
            std::strcpy(r, err);
            return r;
        }
        status = try_path(jpaths.back(), file, input);
        jpaths.pop_back();
    }

    if (status == IMPORT_STATUS_IO_ERROR) {
        *success = 0;
        const char *err = std::strerror(errno);
        char *r = jsonnet_realloc(ctx.vm, nullptr, std::strlen(err) + 1);
        std::strcpy(r, err);
        return r;
    } else {
        assert(status == IMPORT_STATUS_OK);
        *success = 1;
        char *r = jsonnet_realloc(ctx.vm, nullptr, input.length() + 1);
        std::strcpy(r, input.c_str());
        return r;
    }
}
예제 #8
0
파일: main.c 프로젝트: mgrimald/ft_sh1
void		command_in_path(char **tab_cmd, char **env)
{
	char		*cmd;
	char		**path;

	if ((path = (char**)get_str_env("PATH")) == NULL || *path == '\0')
	{
		ft_putendl("ERROR : THERE IS NO PATH");
		return ;
	}
	cmd = (char*)ft_strnew(ft_strlen((char*)path) + ft_strlen(tab_cmd[0]) + 3);
	path = ft_strsplit((char*)path, ':');
	try_path(path, cmd, tab_cmd, env);
	ft_strdel(&cmd);
	free_tab(path);
}
예제 #9
0
파일: package.c 프로젝트: lzpfmh/ponyc
// Try base/../pony_packages/path, and keep adding .. to look another level up
// until we are looking in /pony_packages/path
static const char* try_package_path(const char* base, const char* path)
{
  char path1[FILENAME_MAX];
  char path2[FILENAME_MAX];
  path_cat(NULL, base, path1);

  do
  {
    path_cat(path1, "..", path2);

    if(pony_realpath(path2, path1) != path1)
      break;

    path_cat(path1, "pony_packages", path2);

    const char* result = try_path(path2, path);

    if(result != NULL)
      return result;
  } while(!is_root(path1));

  return NULL;
}
예제 #10
0
파일: package.c 프로젝트: lzpfmh/ponyc
// Attempt to find the specified package directory in our search path
// @return The resulting directory path, which should not be deleted and is
// valid indefinitely. NULL is directory cannot be found.
static const char* find_path(ast_t* from, const char* path,
  bool* out_is_relative)
{
  if(out_is_relative != NULL)
    *out_is_relative = false;

  // First check for an absolute path
  if(is_path_absolute(path))
    return try_path(NULL, path);

  // Get the base directory
  const char* base;

  if((from == NULL) || (ast_id(from) == TK_PROGRAM))
  {
    base = NULL;
  } else {
    from = ast_nearest(from, TK_PACKAGE);
    package_t* pkg = (package_t*)ast_data(from);
    base = pkg->path;
  }

  // Try a path relative to the base
  const char* result = try_path(base, path);

  if(result != NULL)
  {
    if(out_is_relative != NULL)
      *out_is_relative = true;

    return result;
  }

  // If it's a relative path, don't try elsewhere
  if(!is_path_relative(path))
  {
    // Check ../pony_packages and further up the tree
    if(base != NULL)
    {
      result = try_package_path(base, path);

      if(result != NULL)
        return result;

      // Check ../pony_packages from the compiler target
      if((from != NULL) && (ast_id(from) == TK_PACKAGE))
      {
        ast_t* target = ast_child(ast_parent(from));
        package_t* pkg = (package_t*)ast_data(target);
        base = pkg->path;

        result = try_package_path(base, path);

        if(result != NULL)
          return result;
      }
    }

    // Try the search paths
    for(strlist_t* p = search; p != NULL; p = strlist_next(p))
    {
      result = try_path(strlist_data(p), path);

      if(result != NULL)
        return result;
    }
  }

  errorf(path, "couldn't locate this path");
  return NULL;
}
std::string filestorage::extract_filename(const std::string &string_path) {
	fs::path try_path(string_path);
	return try_path.filename().native();
}