示例#1
0
/*
 * Validate files in the backup with size or CRC.
 */
static bool
pgBackupValidateFiles(parray *files, const char *root, bool size_only)
{
    int		i;

    for (i = 0; i < parray_num(files); i++)
    {
        struct stat st;

        pgFile *file = (pgFile *) parray_get(files, i);

        if (interrupted)
            elog(ERROR_INTERRUPTED, _("interrupted during validate"));

        /* skipped backup while incremental backup */
        if (file->write_size == BYTES_INVALID || !S_ISREG(file->mode))
            continue;

        /* print progress */
        elog(LOG, _("(%d/%lu) %s"), i + 1, (unsigned long) parray_num(files),
             get_relative_path(file->path, root));

        /* always validate file size */
        if (stat(file->path, &st) == -1)
        {
            if (errno == ENOENT)
                elog(WARNING, _("backup file \"%s\" vanished"), file->path);
            else
                elog(ERROR_SYSTEM, _("can't stat backup file \"%s\": %s"),
                     get_relative_path(file->path, root), strerror(errno));
            return false;
        }
        if (file->write_size != st.st_size)
        {
            elog(WARNING, _("size of backup file \"%s\" must be %lu but %lu"),
                 get_relative_path(file->path, root),
                 (unsigned long) file->write_size,
                 (unsigned long) st.st_size);
            return false;
        }

        /* validate CRC too */
        if (!size_only)
        {
            pg_crc32	crc;

            crc = pgFileGetCRC(file);
            if (crc != file->crc)
            {
                elog(WARNING, _("CRC of backup file \"%s\" must be %X but %X"),
                     get_relative_path(file->path, root), file->crc, crc);
                return false;
            }
        }
    }

    return true;
}
示例#2
0
gboolean
mkp_project_move (MkpProject *project, const gchar *path)
{
	GFile	*old_root_file;
	GFile *new_file;
	gchar *relative;
	GHashTableIter iter;
	gpointer key;
	gpointer value;
	AnjutaTokenFile *tfile;
	GHashTable* old_hash;

	/* Change project root directory */
	old_root_file = project->root_file;
	project->root_file = g_file_new_for_path (path);

	/* Change project root directory in groups */
	old_hash = project->groups;
	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	g_hash_table_iter_init (&iter, old_hash);
	while (g_hash_table_iter_next (&iter, &key, &value))
	{
		MkpGroup *group = (MkpGroup *)value;

		relative = get_relative_path (old_root_file, group->base.file);
		new_file = g_file_resolve_relative_path (project->root_file, relative);
		g_free (relative);
		g_object_unref (group->base.file);
		group->base.file = new_file;

		g_hash_table_insert (project->groups, g_file_get_uri (new_file), group);
	}
	g_hash_table_destroy (old_hash);

	/* Change all files */
	old_hash = project->files;
	project->files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, g_object_unref);
	g_hash_table_iter_init (&iter, old_hash);
	while (g_hash_table_iter_next (&iter, &key, (gpointer *)&tfile))
	{
		relative = get_relative_path (old_root_file, anjuta_token_file_get_file (tfile));
		new_file = g_file_resolve_relative_path (project->root_file, relative);
		g_free (relative);
		anjuta_token_file_move (tfile, new_file);

		g_hash_table_insert (project->files, new_file, tfile);
		g_object_unref (key);
	}
	g_hash_table_steal_all (old_hash);
	g_hash_table_destroy (old_hash);

	g_object_unref (old_root_file);

	return TRUE;
}
示例#3
0
static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboolean full_path, GPatternSpec *pattern)
{
	GtkTreeModel *model = GTK_TREE_MODEL(s_file_store);
	GtkTreeIter child;
	gboolean iterate;

	iterate = gtk_tree_model_iter_children(model, &child, iter);
	if (iterate)
	{
		while (iterate)
		{
			find_file_recursive(&child, case_sensitive, full_path, pattern);
			iterate = gtk_tree_model_iter_next(model, &child);
		}
	}
	else
	{
		gchar *utf8_name;

		if (iter == NULL)
			return;

		if (full_path)
		{
			gchar *utf8_path, *utf8_base_path;

			utf8_path = build_path(iter);
			utf8_base_path = get_project_base_path();
			utf8_name = get_relative_path(utf8_base_path, utf8_path);
			g_free(utf8_path);
			g_free(utf8_base_path);
		}
		else
			gtk_tree_model_get(GTK_TREE_MODEL(model), iter, FILEVIEW_COLUMN_NAME, &utf8_name, -1);

		if (!case_sensitive)
			SETPTR(utf8_name, g_utf8_strdown(utf8_name, -1));

		if (g_pattern_match_string(pattern, utf8_name))
		{
			gchar *utf8_base_path = get_project_base_path();
			gchar *utf8_path, *rel_path;

			utf8_path = build_path(iter);
			rel_path = get_relative_path(utf8_base_path, utf8_path);
			msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", rel_path ? rel_path : utf8_path);
			g_free(utf8_path);
			g_free(rel_path);
			g_free(utf8_base_path);
		}

		g_free(utf8_name);
	}
}
示例#4
0
/* Returns actual_to by calculating the relative path from -> to and
   applying that to actual_from. An assumption that actual_from is a
   dir is made, and it may or may not end with a '/' */
char const *
get_relocated_path (char const * from, char const * to, char const * actual_from)
{
  char const * relative_from_to = get_relative_path (from, to);
  char * actual_to = (char *) malloc (strlen(actual_from) + 2 + strlen(relative_from_to));
  return actual_to;
}
示例#5
0
static void add_item(gpointer name, G_GNUC_UNUSED gpointer value, gpointer user_data)
{
	gchar *item;
	GSList **lst = (GSList **) user_data;

	item = get_relative_path(g_current_project->path, name);
	*lst = g_slist_prepend(*lst, item);
}
示例#6
0
int path_getrelative(lua_State *L)
{
	const char *src = luaL_checkstring(L, -2);
	const char *dst = luaL_checkstring(L, -1);
	char buffer[PATH_BUFSIZE];
	get_relative_path(src, dst, buffer, PATH_BUFSIZE);
	lua_pushstring(L, buffer);
	return 1;
}
示例#7
0
//filemanager
std::string filemanager::to_relative(const std::string& abspath)
{
	if(abspath.empty())
		return "";

	if(!relative_)
		return equalize_path(abspath);

	return get_relative_path(equalize_path(base_), equalize_path(abspath));
}
示例#8
0
static gboolean match(TMTag *tag, const gchar *name, gboolean declaration, gboolean case_sensitive,
	MatchType match_type, GPatternSpec *pspec, gchar *utf8_path)
{
	const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t;
	gboolean matches = FALSE;
	gint type;

	type = declaration ? forward_types : tm_tag_max_t - forward_types;
	matches = tag->type & type;

	if (matches)
	{
		gchar *name_case;

		if (case_sensitive)
			name_case = g_strdup(tag->name);
		else
			name_case = g_utf8_strdown(tag->name, -1);

		switch (match_type)
		{
			case MATCH_FULL:
				matches = g_strcmp0(name_case, name) == 0;
				break;
			case MATCH_PATTERN:
				matches = g_pattern_match_string(pspec, name_case);
				break;
			case MATCH_PREFIX:
				matches = g_str_has_prefix(name_case, name);
				break;
		}
		g_free(name_case);
	}

	if (matches && utf8_path)
	{
		gchar *utf8_file_name = utils_get_utf8_from_locale(tag->file->file_name);
		gchar *relpath;

		relpath = get_relative_path(utf8_path, utf8_file_name);
		matches = relpath != NULL;
		g_free(relpath);
		g_free(utf8_file_name);
	}

	return matches;
}
示例#9
0
char *
single_path_relocation(const char *from, const char *to)
{
#if defined(__MINGW32__)
  char exe_path[PATH_MAX];
  get_executable_path (NULL, &exe_path[0], sizeof(exe_path)/sizeof(exe_path[0]));
  if (strrchr (exe_path, '/') != NULL)
  {
     strrchr (exe_path, '/')[1] = '\0';
  }
  char * rel_to_datadir = get_relative_path (from, to);
  strcat (exe_path, rel_to_datadir);
  simplify_path (&exe_path[0]);
  return malloc_copy_string(exe_path);
#else
  return malloc_copy_string(to);
#endif
}
示例#10
0
static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type, gchar *utf8_path)
{
	gchar *utf8_base_path = get_project_base_path();
	gchar *locale_base_path = utils_get_locale_from_utf8(utf8_base_path);
	GPtrArray *tags_array = geany_data->app->tm_workspace->tags_array;
	guint i;
	gchar *name_case;
	GPatternSpec *pspec;

	if (case_sensitive)
		name_case = g_strdup(name);
	else
		name_case = g_utf8_strdown(name, -1);

	pspec = g_pattern_spec_new(name_case);

	msgwin_set_messages_dir(locale_base_path);
	msgwin_clear_tab(MSG_MESSAGE);
	for (i = 0; i < tags_array->len; i++) /* TODO: binary search */
	{
		TMTag *tag = tags_array->pdata[i];

		if (match(tag, name_case, declaration, case_sensitive, match_type, pspec, utf8_path))
		{
			gchar *scopestr = tag->scope ? g_strconcat(tag->scope, "::", NULL) : g_strdup("");
			gchar *utf8_fname = utils_get_utf8_from_locale(tag->file->file_name);
			gchar *relpath;

			relpath = get_relative_path(utf8_base_path, utf8_fname);
			msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s:%lu:\n\t[%s]\t %s%s%s", relpath ? relpath : utf8_fname,
				tag->line, tm_tag_type_name(tag), scopestr, tag->name, tag->arglist ? tag->arglist : "");
			g_free(scopestr);
			g_free(relpath);
			g_free(utf8_fname);
		}
	}
	msgwin_switch_tab(MSG_MESSAGE, TRUE);

	g_free(name_case);
	g_pattern_spec_free(pspec);
	g_free(utf8_base_path);
	g_free(locale_base_path);
}
ProteinsAnchorsSamplingSpace read_protein_anchors_mapping(
    multifit::ProteomicsData *prots, const std::string &anchors_prot_map_fn,
    int max_paths) {
  ProteinsAnchorsSamplingSpace ret(prots);
  std::fstream in;
  IMP_LOG_TERSE("FN:" << anchors_prot_map_fn << std::endl);
  in.open(anchors_prot_map_fn.c_str(), std::fstream::in);
  if (!in.good()) {
    IMP_WARN(
        "Problem opening file " << anchors_prot_map_fn
                                << " for reading; returning empty mapping data"
                                << std::endl);
    in.close();
    return ret;
  }
  std::string line;
  // first line should be the anchors line
  getline(in, line);
  std::string anchors_fn =
      get_relative_path(anchors_prot_map_fn, parse_anchors_line(line));
  IMP_LOG_TERSE("FN:" << anchors_fn << std::endl);
  multifit::AnchorsData anchors_data =
      multifit::read_anchors_data(anchors_fn.c_str());
  ret.set_anchors(anchors_data);
  ret.set_anchors_filename(anchors_fn);
  while (!in.eof()) {
    if (!getline(in, line)) break;
    IMP_LOG_VERBOSE("working on line:" << line);
    IMP_USAGE_CHECK(is_protein_line(line), "the line should be a protein line");
    boost::tuple<std::string, std::string, IntsList> prot_data =
        parse_protein_line(anchors_prot_map_fn, line, max_paths);
    ret.set_paths_for_protein(boost::get<0>(prot_data),
                              boost::get<2>(prot_data));
    ret.set_paths_filename_for_protein(boost::get<0>(prot_data),
                                       boost::get<1>(prot_data));
  }
  return ret;
}
示例#12
0
文件: main.c 项目: 573/MINGW-packages
void
get_relative_path_debug (char const * from, char const * to, char const * expected)
{
  char const * result = get_relative_path (from, to);
  if ( result == NULL )
  {
    _exit(1);
  }
  else
  {
    int ok = (strcmp(result, expected) == 0) ? 1 : 0;
    if (ok)
    {
      printf ("PASS: %s to %s is %s\n", from, to, result);
    }
    else
    {
      printf ("FAIL: %s to %s is %s, should be %s\n", from, to, result, expected);
      _exit(1);
    }
    free ((void *)result);
  }
}
示例#13
0
const osd_directory_entry *zippath_readdir(zippath_directory *directory)
{
	const osd_directory_entry *result = NULL;
	const zip_file_header *header;
	const char *relpath;
	const char *separator;
	const char *s;
	zippath_returned_directory *rdent;

	if (!directory->returned_parent)
	{
		/* first thing's first - return parent directory */
		directory->returned_parent = true;
		memset(&directory->returned_entry, 0, sizeof(directory->returned_entry));
		directory->returned_entry.name = "..";
		directory->returned_entry.type = ENTTYPE_DIR;
		result = &directory->returned_entry;
	}
	else if (directory->directory != NULL)
	{
		/* a normal directory read */
		do
		{
			result = osd_readdir(directory->directory);
		}
		while((result != NULL) && (!strcmp(result->name, ".") || !strcmp(result->name, "..")));

		/* special case - is this entry a ZIP file?  if so we need to return it as a "directory" */
		if ((result != NULL) && is_zip_file(result->name))
		{
			/* copy; but change the entry type */
			directory->returned_entry = *result;
			directory->returned_entry.type = ENTTYPE_DIR;
			result = &directory->returned_entry;
		}
	}
	else if (directory->zipfile != NULL)
	{
		do
		{
			/* a zip file read */
			do
			{
				if (!directory->called_zip_first)
					header = zip_file_first_file(directory->zipfile);
				else
					header = zip_file_next_file(directory->zipfile);
				directory->called_zip_first = true;
				relpath = NULL;
			}
			while((header != NULL) && ((relpath = get_relative_path(directory, header)) == NULL));

			if (relpath != NULL)
			{
				/* we've found a ZIP entry; but this may be an entry deep within the target directory */
				for (s = relpath; *s && !is_zip_file_separator(*s); s++)
					;
				separator = *s ? s : NULL;

				if (separator != NULL)
				{
					/* a nested entry; loop through returned_dirlist to see if we've returned the parent directory */
					for (rdent = directory->returned_dirlist; rdent != NULL; rdent = rdent->next)
					{
						if (!core_strnicmp(rdent->name.c_str(), relpath, separator - relpath))
							break;
					}

					if (rdent == NULL)
					{
						/* we've found a new directory; add this to returned_dirlist */
						rdent = new zippath_returned_directory;
						rdent->next = directory->returned_dirlist;
						rdent->name.assign(relpath, separator - relpath);
						directory->returned_dirlist = rdent;

						/* ...and return it */
						memset(&directory->returned_entry, 0, sizeof(directory->returned_entry));
						directory->returned_entry.name = rdent->name.c_str();
						directory->returned_entry.type = ENTTYPE_DIR;
						result = &directory->returned_entry;
					}
				}
				else
				{
					/* a real file */
					memset(&directory->returned_entry, 0, sizeof(directory->returned_entry));
					directory->returned_entry.name = relpath;
					directory->returned_entry.type = ENTTYPE_FILE;
					directory->returned_entry.size = header->uncompressed_length;
					result = &directory->returned_entry;
				}
			}
		}
		while((relpath != NULL) && (result == NULL));
	}
	return result;
}
示例#14
0
文件: amp-group.c 项目: GNOME/anjuta
static void
amp_group_node_update_preset_variable (AmpGroupNode *group)
{
	gchar *path;
	AnjutaToken *value;
	AmpVariable *var;
	GFile *root;
	GFile *file;
	AnjutaProjectNode *node;

	if (group->preset_token != NULL) anjuta_token_free (group->preset_token);
	group->preset_token = anjuta_token_new_static (ANJUTA_TOKEN_FILE,  NULL);

	/* Get project root */
	for (node = ANJUTA_PROJECT_NODE (group); anjuta_project_node_parent (node) != NULL; node = anjuta_project_node_parent (node));
	root = anjuta_project_node_get_file (node);

	/* Set source directory variables */
	file = anjuta_project_node_get_file (group);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, ".",
	                                  NULL);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);

	path = g_file_get_path (file);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, path,
	                                  NULL);
	g_free (path);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("abs_srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("abs_builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);

	path = get_relative_path (file, root);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, path,
	                                  NULL);
	g_free (path);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("top_srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("top_builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);

	path = g_file_get_path (root);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, path,
	                                  NULL);
	g_free (path);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("abs_top_srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("abs_top_builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
}
示例#15
0
文件: main.c 项目: 573/MINGW-packages
int main(int argc, char *argv[])
{
#define BINDIR  "/mingw64/bin"
#define DATADIR "/mingw64/share"

  char exe_path[PATH_MAX];
  get_executable_path (argv[0], &exe_path[0], sizeof (exe_path) / sizeof (exe_path[0]));
  printf ("executable path is %s\n", exe_path);

  char * rel_to_datadir = get_relative_path (BINDIR, DATADIR);
  if (strrchr (exe_path, '/') != NULL)
  {
     strrchr (exe_path, '/')[1] = '\0';
  }
  strcat (exe_path, rel_to_datadir);
  simplify_path (&exe_path[0]);
  printf("real path of DATADIR is %s\n", exe_path);

  if (argc >= 2)
  {
    get_relative_path_debug (argv[argc-2], argv[argc-1], 0);
  }
  get_relative_path_debug (NULL,                      NULL,                              "./");
  get_relative_path_debug ("/mingw64/bin",            "/mingw64/etc/pkcs11/pkcs11.conf", "../etc/pkcs11/pkcs11.conf");
  get_relative_path_debug ("/a/b/c/d",                "/a/b/c",                          "..");
  get_relative_path_debug ("/a/b/c/d/",               "/a/b/c/",                         "../");
  get_relative_path_debug ("/",                       "/",                               "/");
  get_relative_path_debug ("/a/testone/c/d",          "/a/testtwo/c",                    "../../../testtwo/c");
  get_relative_path_debug ("/a/testone/c/d/",         "/a/testtwo/c/",                   "../../../testtwo/c/");
  get_relative_path_debug ("/home/part2/part3/part4", "/work/proj1/proj2",               "../../../../work/proj1/proj2");

  simplify_path_debug ("a/b/..", "a");
  simplify_path_debug ("a/b/c/../../", "a/");
  simplify_path_debug ("a/../a/..",    "");
  simplify_path_debug ("../a/../a/",   "../a/");

  simplify_path_debug ("./././",     "./");
  simplify_path_debug ("/test/",     "/test/");
  simplify_path_debug (".",          ".");
  simplify_path_debug ("..",         "..");
  simplify_path_debug ("../",        "../");
  simplify_path_debug ("././.",      ".");
  simplify_path_debug ("../..",      "../..");
  simplify_path_debug ("/",          "/");
  simplify_path_debug ("./test/",    "./test/");
  simplify_path_debug ("./test",     "./test");
  simplify_path_debug ("/test",      "/test");
  simplify_path_debug ("../test",    "../test");
  simplify_path_debug ("../../test", "../../test");
  simplify_path_debug ("../test/..", "..");
  simplify_path_debug (".././../",   "../../");

  sanitise_path_debug ("C:\\windows\\path", "C:/windows/path");
  sanitise_path_debug ("", "");
  sanitise_path_debug ("\\\\", "/");

  char const * win_path = X509_get_default_private_dir ();
  printf ("%s -> %s\n", X509_PRIVATE_DIR, win_path);

  char * trusts = msys2_get_relocated_path_list (TRUST_PATHS);
  printf ("%s -> %s\n", TRUST_PATHS, trusts);
  free ((void*)trusts);

  char * single = msys2_get_relocated_path_list (SINGLE_PATH_LIST);
  printf ("%s -> %s\n", SINGLE_PATH_LIST, single);
  free ((void*)single);
  
  char *multi = get_relocated_path_list(BINDIR, TRUST_PATHS);
  printf ("Source pathlist: %s \n", TRUST_PATHS);
  printf ("Real pathlist: %s\n", multi);
  free ((void*)multi);
  return 0;
}
示例#16
0
/* Send file through socket
 * @param socket: file descriptor of client
 * @param filename: name of the file
 * @param position: index of the filename in absolute path
 * @param fdout: file descriptor to write
 *
 * @return: return bytes sended
 */
int send_file(int socket, char filename[], int position, int fdout) {
    file_t file;
    struct stat stat_filename;
    int numb_bytes;
    int sended = 0;
    char type;

    bzero(&file, sizeof(file_t));
    get_relative_path(file.name_of_file, filename, position);
    stat(filename, &stat_filename);

    /* if is a directory, send only the name of the directory */
    if (stat_filename.st_mode & S_IFDIR) {
        type = (char) DIRECTORY;
        dprintf(fdout, "\tSending %s... ", filename);

        file.size_string = (unsigned int) strlen(file.name_of_file) + 1;
        /* tells server we are sending a directory */
        write_to(socket, &type, sizeof(char));
        write(socket, &file.size_string, sizeof(file.size_string));
        write(socket, &file.name_of_file, (int) strlen(file.name_of_file) + 1);
        DIR_S++;
        dprintf(fdout, "OK\n");
        return 0;
    /* if is a file */
    } else if (stat_filename.st_mode & S_IFDIR || \
               stat_filename.st_mode & S_IFLNK) {
        type = (char) FILE;

        /* open file to read */
        file.fd_file = open(filename, O_RDONLY);
        file.size_file = (unsigned int) stat_filename.st_size;
        file.size_string = (unsigned int) strlen(file.name_of_file) + 1;

        dprintf(fdout, "\tSending %s... ", filename);

        /* tells server we are sending a file */
        write_to(socket, &type, sizeof(char));
        write_to(socket, &file.size_file, sizeof(file.size_file));
        write_to(socket, &file.size_string, sizeof(file.size_string));
        write_to(socket, &file.name_of_file, (int)strlen(file.name_of_file) + 1);

        while (TRUE) {
            numb_bytes = sendfile(socket, file.fd_file, NULL, SIZE_BUF);
            if (numb_bytes < 0) {
                error("ERROR");
                return errno;
            }

            sended += numb_bytes;
            if (sended == file.size_file)
                break;
        }
        dprintf(fdout, "OK\n");
        /*
        printf("\t\tSended %.3f of %.3f kB [%.3f%%]\n",
                    sended/1000., file.size_file/1000.,
                    (sended*100.)/file.size_file);
        */
        FILES_S++;
        close(file.fd_file);
        return sended;
    }
    return -1;
}
示例#17
0
char *
get_relocated_path_list(char const * from, char const * to_path_list)
{
  char exe_path[MAX_PATH];
  char * temp;
  get_executable_path (NULL, &exe_path[0], sizeof (exe_path) / sizeof (exe_path[0]));
  if ((temp = strrchr (exe_path, '/')) != NULL)
  {
    temp[1] = '\0';
  }

  char **arr = NULL;
  /* Ask Alexey why he added this. Are we not 100% sure
     that we're dealing with unix paths here? */
  char split_char = ':';
  if (strchr (to_path_list, ';'))
  {
    split_char = ';';
  }
  size_t count = split_path_list (to_path_list, split_char, &arr);
  int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */
  size_t exe_path_size = strlen (exe_path);
  size_t i;
  /* Space required is:
     count * (exe_path_size + strlen (rel_to_datadir))
     rel_to_datadir upper bound is:
     (count * strlen (from)) + (3 * num_slashes (from))
     + strlen(arr[i]) + 1.
     .. pathalogically num_slashes (from) is strlen (from)
     (from = ////////) */
  size_t space_required = (count * (exe_path_size + 4 * strlen (from))) + count - 1;
  for (i = 0; i < count; ++i)
  {
    space_required += strlen (arr[i]);
  }
  char * scratch = (char *) alloca (space_required);
  if (scratch == NULL)
    return NULL;
  for (i = 0; i < count; ++i)
  {
    char * rel_to_datadir = get_relative_path (from, arr[i]);
    scratch[0] = '\0';
    arr[i] = scratch;
    strcat (scratch, exe_path);
    strcat (scratch, rel_to_datadir);
    simplify_path (arr[i]);
    size_t arr_i_size = strlen (arr[i]);
    result_size += arr_i_size;
    scratch = arr[i] + arr_i_size + 1;
  }
  char * result = (char *) malloc (result_size);
  if (result == NULL)
  {
    return NULL;
  }
  result[0] = '\0';
  for (i = 0; i < count; ++i)
  {
    strcat (result, arr[i]);
    if (i != count-1)
    {
#if defined(_WIN32)
      strcat (result, ";");
#else
      strcat (result, ":");
#endif
    }
  }
  free ((void*)arr);
  return result;
}
示例#18
0
文件: am-writer.c 项目: GNOME/anjuta
gboolean
amp_source_node_create_token (AmpProject  *project, AmpSourceNode *source, GError **error)
{
	AmpGroupNode *group;
	AmpTargetNode *target;
	AnjutaProjectNode *sibling;
	gboolean after;
	AnjutaToken *token;
	AnjutaToken *prev;
	AnjutaToken *args;
	gchar *relative_name;

	/* Get parent target */
	target = AMP_TARGET_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (source), ANJUTA_PROJECT_TARGET));
	if (target == NULL) return FALSE;

	group = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));
	relative_name = get_relative_path (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (group)), anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (source)));

	/* Add in Makefile.am */
	/* Find a sibling if possible */
	after = TRUE;
	for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (source)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling))
	{
		if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_SOURCE)
		{
			break;
		}
		else if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_OBJECT)
		{
			sibling = anjuta_project_node_first_child (sibling);
			break;
		}
	}
	if (sibling == NULL)
	{
		after = FALSE;
		for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (source)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling))
		{
			if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_SOURCE)
			{
				break;
			}
			else if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_OBJECT)
			{
				sibling = anjuta_project_node_first_child (sibling);
				break;
 			}
		}
	}
	if (sibling == NULL)
	{
		after = TRUE;
		prev = NULL;
		args = NULL;
	}
	else
	{
		prev = amp_source_node_get_token (AMP_SOURCE_NODE (sibling));
		args = anjuta_token_list (prev);
	}

	/* Check if a valid source variable is already defined */
	if (args == NULL)
	{
		GList *last;
		for (last = amp_target_node_get_token (target, AM_TOKEN__SOURCES); last != NULL; last = g_list_next (last))
		{
			args = anjuta_token_last_item ((AnjutaToken *)last->data);
			break;
		}
		if (last == NULL)
		{
			for (last = amp_target_node_get_token (target, AM_TOKEN__DATA); last != NULL; last = g_list_next (last))
			{
				args = anjuta_token_last_item ((AnjutaToken *)last->data);
				break;
			}
		}

	}

	if (args == NULL)
	{
		gchar *target_var;
		gchar *canon_name;
		AnjutaToken *var;

		canon_name = canonicalize_automake_variable (anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (target)));
		target_var = g_strconcat (canon_name,  "_SOURCES", NULL);

		var = anjuta_token_find_target_property_position (target, AM_TOKEN__SOURCES);
		if (var == NULL)
			var = anjuta_token_find_target_property_position (target, AM_TOKEN__DATA);

		args = anjuta_token_insert_token_list (FALSE, var,
					ANJUTA_TOKEN_LIST, NULL,
    				ANJUTA_TOKEN_NAME, target_var,
	    			ANJUTA_TOKEN_SPACE, " ",
					ANJUTA_TOKEN_OPERATOR, "=",
    				ANJUTA_TOKEN_LIST, NULL,
	            	ANJUTA_TOKEN_SPACE, " ",
					NULL);

		args = anjuta_token_last_item (args);
		g_free (target_var);
	}

	if (args != NULL)
	{
		AnjutaTokenStyle *style;

		style = anjuta_token_style_new_from_base (project->am_space_list);
		anjuta_token_style_update (style, args);

		token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, relative_name);
		if (after)
		{
			anjuta_token_insert_word_after (args, prev, token);
		}
		else
		{
			anjuta_token_insert_word_before (args, prev, token);
		}

		/* Try to use the same style than the current target list */
		anjuta_token_style_format (style, args);
		anjuta_token_style_free (style);

		amp_group_node_update_makefile (group, token);

		amp_source_node_add_token (source, token);
	}

	return TRUE;
}