Esempio n. 1
0
static int	remove_dotdot(t_path **path_list, t_path *current)
{
	t_path	*tmp;
	int		modif;

	modif = 0;
	while (current && ft_strcmp(current->str, "..")
			&& current->next && ft_strequ(current->next->str, ".."))
	{
		modif++;
		tmp = current->next->next;
		free(current->next->str);
		free(current->next);
		free(current->str);
		free(current);
		*path_list = tmp;
		current = tmp;
	}
	while (current && current->next)
	{
		modif += remove_dotdot(&current->next, current->next);
		current = current->next;
	}
	if (modif)
		remove_dotdot(path_list, *path_list);
	return (modif);
}
Esempio n. 2
0
char		*path_simplifier(char *path)
{
	int		i;
	int		len;
	t_path	*path_list;

	i = 0;
	path_list = NULL;
	while (path[i])
	{
		len = 0;
		while (path[i] && path[i] == '/')
			i++;
		while (path[i + len] && path[i + len] != '/')
			len++;
		add_path(&path_list, ft_strsub(path, i, len));
		i += len;
	}
	remove_dot(&path_list);
	remove_dotdot(&path_list, path_list);
	free(path);
	path = rebuild_path(path_list);
	free_pathlist(path_list);
	return (path);
}
Esempio n. 3
0
void
test_remove(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	test_remove_path(&ntests, &lost_points);

	ntests++;
	result = remove_dir();
	handle_result(result, &lost_points);

	ntests++;
	result = remove_dot();
	handle_result(result, &lost_points);

	ntests++;
	result = remove_dotdot();
	handle_result(result, &lost_points);

	ntests++;
	result = remove_empty();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 4
0
void
test_remove(void)
{
	test_remove_path();

	remove_dir();
	remove_dot();
	remove_dotdot();
	remove_empty();
}
Esempio n. 5
0
struct inclist *inc_path(char *file, char *include, boolean dot, struct IncludesCollection *incCollection)
{
    static char path[ BUFSIZ ];
    char   **pp, *p;
    struct inclist *ip;
    struct stat st;
    boolean found = FALSE;
    (void)dot;

    /*
     * Check all previously found include files for a path that
     * has already been expanded.
     */
    for (ip = inclist; ip->i_file; ip++)
        if ((strcmp(ip->i_incstring, include) == 0) && !ip->i_included_sym)
        {
          found = TRUE;
          break;
        }

    /*
     * If the path was surrounded by "" or is an absolute path,
     * then check the exact path provided.
     */
// FIXME: creates duplicates in the dependency files if absolute paths are
// given, which certainly is not the intended behavior. Also it slows down
// makedepend performance considerably.
//  if (!found && (dot || *include == '/')) {
//
//      if ((exists_path(incCollection, include)) && stat(include, &st) == 0 && !( st.st_mode & S_IFDIR)) {
//          ip = newinclude(include, include);
//          found = TRUE;
//      }
//      else if (show_where_not)
//          warning1("\tnot in %s\n", include);
//  }

    /*
     * See if this include file is in the directory of the
     * file being compiled.
     */
    if (!found) {
        for (p=file+strlen(file); p>file; p--)
            if (*p == '/')
                break;
        if (p == file)
            strcpy(path, include);
        else {
            strncpy(path, file, (p-file) + 1);
            path[ (p-file) + 1 ] = '\0';
            strcpy(path + (p-file) + 1, include);
        }
        remove_dotdot(path);
        if ((exists_path(incCollection, path)) && stat(path, &st) == 0 && !( st.st_mode & S_IFDIR)) {
            ip = newinclude(path, include);
            found = TRUE;
        }
        else if (show_where_not)
            warning1("\tnot in %s\n", path);
    }

    /*
     * Check the include directories specified. (standard include dir
     * should be at the end.)
     */
    if (!found)
        for (pp = includedirs; *pp; pp++) {
            sprintf(path, "%s/%s", *pp, include);
            remove_dotdot(path);
            if ((exists_path(incCollection, path)) && stat(path, &st) == 0 && !(st.st_mode & S_IFDIR)) {
                ip = newinclude(path, include);
                found = TRUE;
                break;
            }
            else if (show_where_not)
                warning1("\tnot in %s\n", path);
        }

    if (!found)
        ip = NULL;
    return(ip);
}
Esempio n. 6
0
struct inclist *
inc_path(char *file, char *include, int type)
{
	static char		path[ BUFSIZ ];
	register char		**pp, *p;
	register struct inclist	*ip;
	struct stat		st;

	/*
	 * Check all previously found include files for a path that
	 * has already been expanded.
	 */
	if ((type == INCLUDE) || (type == INCLUDEDOT))
		inclistnext = inclist;
	ip = inclistnext;

	for (; ip->i_file; ip++) {
		if ((strcmp(ip->i_incstring, include) == 0) &&
		    !(ip->i_flags & INCLUDED_SYM)) {
			inclistnext = ip + 1;
			return ip;
		}
	}

	if (inclistnext == inclist) {
		/*
		 * If the path was surrounded by "" or is an absolute path,
		 * then check the exact path provided.
		 */
		if ((type == INCLUDEDOT) ||
		    (type == INCLUDENEXTDOT) ||
		    (*include == '/')) {
			if (stat(include, &st) == 0)
				return newinclude(include, include);
			if (show_where_not)
				warning1("\tnot in %s\n", include);
		}

		/*
		 * If the path was surrounded by "" see if this include file is
		 * in the directory of the file being parsed.
		 */
		if ((type == INCLUDEDOT) || (type == INCLUDENEXTDOT)) {
			for (p=file+strlen(file); p>file; p--)
				if (*p == '/')
					break;
			if (p == file) {
				strcpy(path, include);
			} else {
				strncpy(path, file, (p-file) + 1);
				path[ (p-file) + 1 ] = '\0';
				strcpy(path + (p-file) + 1, include);
			}
			remove_dotdot(path);
			if (stat(path, &st) == 0)
				return newinclude(path, include);
			if (show_where_not)
				warning1("\tnot in %s\n", path);
		}
	}

	/*
	 * Check the include directories specified.  Standard include dirs
	 * should be at the end.
	 */
	if ((type == INCLUDE) || (type == INCLUDEDOT))
		includedirsnext = includedirs;
	pp = includedirsnext;

	for (; *pp; pp++) {
		sprintf(path, "%s/%s", *pp, include);
		remove_dotdot(path);
		if (stat(path, &st) == 0) {
			includedirsnext = pp + 1;
			return newinclude(path, include);
		}
		if (show_where_not)
			warning1("\tnot in %s\n", path);
	}

	return NULL;
}
Esempio n. 7
0
struct inclist *inc_path(char *file, char *include, boolean dot)
{
	static char path[BUFSIZ];
	register char **pp, *p;
	register struct inclist *ip;
	struct stat st;
	boolean found = FALSE;

	/*
	 * Check all previously found include files for a path that
	 * has already been expanded.
	 */
	for (ip = inclist; ip->i_file; ip++)
		if ((strcmp(ip->i_incstring, include) == 0) &&
			!(ip->i_flags & INCLUDED_SYM))
		{
			found = TRUE;
			break;
		}

	/*
	 * If the path was surrounded by "" or is an absolute path,
	 * then check the exact path provided.
	 */
	if (!found && (dot || *include == '/'))
	{
		if (stat(include, &st) == 0)
		{
			ip = newinclude(include, include);
			found = TRUE;
		}
		else if (show_where_not)
			warning1("\tnot in %s\n", include);
	}

	/*
	 * If the path was surrounded by "" see if this include file is in the
	 * directory of the file being parsed.
	 */
	if (!found && dot)
	{
		for (p = file + strlen(file); p > file; p--)
			if (*p == '/')
				break;
		if (p == file)
			strcpy(path, include);
		else
		{
			strncpy(path, file, (p - file) + 1);
			path[(p - file) + 1] = '\0';
			strcpy(path + (p - file) + 1, include);
		}
		remove_dotdot(path);
		if (stat(path, &st) == 0)
		{
			ip = newinclude(path, include);
			found = TRUE;
		}
		else if (show_where_not)
			warning1("\tnot in %s\n", path);
	}

	/*
	 * Check the include directories specified. (standard include dir
	 * should be at the end.)
	 */
	if (!found)
		for (pp = includedirs; *pp; pp++)
		{
			sprintf(path, "%s/%s", *pp, include);
			remove_dotdot(path);
			if (stat(path, &st) == 0)
			{
				ip = newinclude(path, include);
				found = TRUE;
				break;
			}
			else if (show_where_not)
				warning1("\tnot in %s\n", path);
		}

	if (!found)
		ip = NULL;
	return (ip);
}