示例#1
0
char	*ft_strquote(char *cmd)
{
	size_t	i;
	char	quote;

	quote = 0;
	i = -1;
	while (cmd[++i])
	{
		if (cmd[i] == '\\'
			&& (cmd[i + 1] == '\"' || cmd[i + 1] == '\\' || cmd[i + 1] == '\''))
		{
			ft_memmove(cmd + i, cmd + i + 1, ft_strlen(cmd + i));
			cmd[i] = -cmd[i];
		}
		else if (((cmd[i] == '\"' || (cmd[i] == '\''))
					&& (!quote || quote == cmd[i])))
		{
			quote = (quote ? 0 : cmd[i]);
			ft_memmove(cmd + i, cmd + i + 1, ft_strlen(cmd + i));
			--i;
		}
		else if (quote)
			cmd[i] = -cmd[i];
	}
	return (cmd);
}
static void unittest1(t_test *test)
{
	char	testA1[] = "abcdef";
	char	testA2[] = "abcdef";

	ft_memmove(testA1 + 1, testA1, 5);
	ft_memmove(testA1 + 1, testA1, 0);
	memmove(testA2 + 1, testA2, 5);
	memmove(testA2 + 1, testA2, 0);
	mt_assert(strcmp(testA1, "aabcde") == 0);
	mt_assert(strcmp(testA1, testA2) == 0);
}
static void unittest2(t_test *test)
{
	char	testB1[] = "abcdef";
	char	testB2[] = "abcdef";

	ft_memmove(testB1, testB1 + 1, 5);
	ft_memmove(testB1, testB1 + 1, 0);
	memmove(testB2, testB2 + 1, 5);
	memmove(testB2, testB2 + 1, 0);
	mt_assert(strcmp(testB1, "bcdeff") == 0);
	mt_assert(strcmp(testB1, testB2) == 0);
}
示例#4
0
static char	*except(int n, char *nb)
{
	if (n < -2147483647)
	{
		ft_memset(nb, '\0', ft_strlen("-2147483648") + 1);
		ft_memmove(nb, "-2147483648", 11);
	}
	else
	{
		ft_memset(nb, '\0', ft_strlen("0") + 1);
		ft_memmove(nb, "0", 2);
	}
	return (nb);
}
示例#5
0
char		*apply_diez_shorter_low(char *tmp, char *buffer, int **tab)
{
	char		str[tab[2][0] + 2];
	int			i;

	i = 0;
	ft_bzero(str, tab[2][0] + 2);
	if (ft_strchr(buffer, 'e'))
	{
		while (buffer[i] != 'e')
		{
			str[i] = buffer[i];
			i++;
		}
		ft_memmove(buffer, buffer + i, ft_strlen(buffer) - i);
		ft_bzero(buffer + 4, ft_strlen(buffer) - 4);
		while (i <= tab[2][0])
			str[i++] = '0';
		ft_strcat(str, buffer);
		free(buffer);
		buffer = (char *)malloc((ft_strlen(str) + 1) * sizeof(char));
		ft_bzero(buffer, ft_strlen(str) + 1);
		ft_strcpy(buffer, str);
		return (buffer);
	}
	else
		return (apply_diez_shorter_low2(tmp, buffer, tab));
}
示例#6
0
int				get_next_line(int const fd, char **line)
{
	static char		*buf = NULL;
	int				ret;
	char			*str;

	if (!line || fd < 0)
		return (-1);
	ret = 1;
	if (buf == NULL)
		buf = ft_strnew(0);
	while (ret > 0)
	{
		if ((str = ft_strchr(buf, '\n')) != NULL)
		{
			*str = '\0';
			*line = ft_strdup(buf);
			ft_memmove(buf, str + 1, ft_strlen(str + 1) + 1);
			return (1);
		}
		buf = biggerbuf(fd, buf, &ret);
	}
	*line = ft_strdup(buf);
	free(buf);
	return (ret);
}
示例#7
0
文件: ft_stringaddl.c 项目: Julow/fdf
void			ft_stringaddl(t_string *str, const char *add, int len)
{
	if (!ft_stringext(str, len))
		return ;
	ft_memmove(str->content + str->length, add, len);
	str->length += len;
}
示例#8
0
static void	checkinputs_splitted(char input, char *buff,
								char **ptr, t_history *history)
{
	if (input == 127)
		mvbackspace(buff, ptr);
	else if (input == 126)
	{
		ft_putchar('~');
		**ptr = '~';
		(*ptr)++;
	}
	else if (input == 9)
		completion(buff, ptr);
	else if (input < 0)
		copycutpaste(input, buff, ptr);
	else if (input == 1)
		mvcstart(buff, ptr);
	else if (input == 5)
		mvcend(ptr);
	else if (input == 27)
		mvcursor(buff, ptr, history);
	else if (ft_isprint(input))
	{
		ft_memmove((*ptr) + 1, (*ptr), ft_strlen((*ptr)));
		(*ptr)[0] = input;
		ft_putstr(*ptr);
		mvcleft(ft_strlen((*ptr)++) - 1);
	}
}
示例#9
0
文件: loadinfo.c 项目: lpoujade/ft_ls
int					pfile_infos(t_files *node, char *fname, t_params opts)
{
	struct stat		stated;
	char			*slh;
	char			*tmp;

	slh = ft_strdup(epure_name(fname, opts));
	node->details = (char **)malloc(sizeof(char *) * 8);
	node->details[1] = NULL;
	node->details[7] = NULL;
	if ((lstat(fname, &stated) == -1))
	{
		node->details[0] = ft_strjoin(fname, ft_strjoin(": ", strerror(errno)));
		return (0);
	}
	node->fcount = S_ISDIR(stated.st_mode) && !node->fcount ? -1 : 0;
	node->stmp = stated.st_mtimespec;
	if (opts & ADD_FTYPE)
	{
		tmp = slh;
		ft_memmove((slh = ft_strnew(ft_strlen(slh) + 1)), tmp, ft_strlen(tmp));
		slh[ft_strlen(tmp)] = file_mode(stated.st_mode, 1);
		free(tmp);
	}
	if (!(opts & 0x01))
		node->details[0] = slh;
	return (opts & 0x01 ? s_pfileinfo(stated, node, slh) : stated.st_blocks);
}
示例#10
0
int		ft_print_d(t_printf info, int len, int nbr, char *add)
{
    info.value = ft_tild(&info, &len);
    if (info.rpad)
        return (ft_print_rd(info, len, nbr, add));
    if (info.value[0] == '-')
    {
        ft_memmove(info.value, info.value + 1, len);
        --len;
        add = "-";
    }
    if (!nbr && info.is_preci)
        len = 0;
    info.lpad -= ft_strlen(add);
    if (info.pad == '0')
    {
        info.preci += info.lpad;
        info.lpad = 0;
    }
    info.preci = (info.preci < len ? len : info.preci);
    while (info.lpad-- - info.preci > 0)
        ft_fwrite(&(info.pad), 1);
    ft_fwrite(add, ft_strlen(add));
    while (info.preci-- - len > 0)
        ft_fwrite("0", 1);
    ft_fwrite(info.value, len);
    return (0);
}
示例#11
0
t_dlist	*ft_dlstnew(void const *content, const unsigned int content_size)
{
	t_dlist	*res;

	if (!(res = (t_dlist *)malloc(sizeof(t_dlist))))
		return (NULL);
	if (!content)
	{
		res->content = NULL;
		res->content_size = 0;
	}
	else
	{
		if (!(res->content = (void *)malloc(content_size)))
		{
			free(res);
			return (NULL);
		}
		ft_memmove(res->content, content, content_size);
		res->content_size = content_size;
	}
	res->next = NULL;
	res->next = NULL;
	return (res);
}
示例#12
0
int				get_next_line(const int fd, char **line)
{
	static char		*stock = "";
	int				ret;
	char			*str;

	ret = 1;
	if (!line || fd < 0 || (stock[0] == '\0' && (!(stock = ft_strnew(0)))))
		return (-1);
	while (ret > 0)
	{
		if ((str = ft_strchr(stock, '\n')) != NULL)
		{
			*str = '\0';
			if (!(*line = ft_strdup(stock)))
				return (-1);
			ft_memmove(stock, str + 1, ft_strlen(str + 1) + 1);
			return (1);
		}
		if (!(stock = ft_read(fd, stock, &ret)))
			return (-1);
	}
	ft_strdel(&str);
	if (ret == 0 && ft_strlen(stock))
		ret = ft_end_line(&(*line), &stock);
	return (ret);
}
示例#13
0
t_list				*ft_lstnew(void const *content, size_t content_size)
{
	t_list			*ret;
	void			*cpy_content;

	ret = (t_list *)ft_memalloc(sizeof(t_list));
	if (ret)
	{
		if (!content || !content_size)
			init_to_null(&ret);
		else
		{
			cpy_content = ft_memalloc(content_size);
			if (cpy_content)
			{
				ret->content = ft_memmove(cpy_content, content, content_size);
				ret->content_size = content_size;
			}
			else
				return (NULL);
		}
		ret->next = NULL;
		return (ret);
	}
	return (NULL);
}
示例#14
0
char	*ft_strreplace(char *str, char *match, char *to)
{
	size_t	pos;
	int		len;
	char	*last;
	char	*tmp;

	last = NULL;
	if (!str || !match || !to)
		return (str);
	if ((tmp = ft_strstr(str, match)))
		str = ft_strdup(str);
	while (str != last && (last = str))
	{
		if ((tmp = ft_strstr(str, match)))
		{
			pos = (size_t)(tmp - str);
			if (pos < ft_strlen(str))
			{
				len = ft_strlen(match);
				ft_memmove(str + pos, str + pos + len,
						ft_strlen(str + pos + len) + 1);
				str = ft_strfinsert(str, to, pos, 1);
			}
		}
	}
	return (str);
}
示例#15
0
void		remove_client(t_server *serv, int rm, int *actual)
{
	t_client	*clt;

	clt = serv->clients;
	ft_memmove(clt + rm, clt + rm + 1, (*actual - rm - 1) * sizeof(t_client));
	(*actual)--;
}
示例#16
0
void	*ft_memdup(void *ptr, size_t size)
{
	void	*ret;

	if (!ptr || !(ret = malloc(size)))
		return (NULL);
	ft_memmove(ret, ptr, size);
	return (ret);
}
示例#17
0
void	remove_client(t_server *server, int i, int *actual_client)
{
	t_client	*client;

	client = server->clients;
	ft_memmove(client + i, client + i + 1,
		(*actual_client - i - 1) * sizeof(t_client));
	(*actual_client)--;
}
示例#18
0
void	*ft_memcpy(void *dest, const void *src, size_t n)
{
	if ((&(((char*)src)[0]) >= &(((char*)dest)[0]) && (&(((char*)dest)[0]) <=
					(&(((char*)src)[n])))))
		return (ft_memmove((char*)dest, (char*)src, (int)n));
	else
		while (n--)
			*((char*)(dest++)) = *((char*)(src++));
	return (dest);
}
示例#19
0
int		ft_join_move(char **line, char *buff, char *next_line, int nbread)
{
	*next_line = '\0';
	if (!(*line = ft_join_free(line, buff)))
		return (-1);
	buff = ft_memmove(buff, &next_line[1], ft_strlen(&next_line[1]) + 1);
	if (buff == NULL)
		return (-1);
	return (nbread);
}
示例#20
0
文件: main_memmove.c 项目: rim31/42-C
int main(int ac, char ** av)
{
	if (ac == 4)
	{

		printf("%s", ft_memmove(av[1], av[2], atoi(av[3])));
		printf("\n%s %s %d \n", av[1], av[2], atoi(av[3]));
		printf("%s", memmove(av[1], av[2], atoi(av[3])));
	}
	return (0);
}
示例#21
0
文件: print_sign.c 项目: LeGuit/libft
static void		get_buf(t_mod *m, t_ll arg, char *buf)
{
	if (arg < 0)
	{
		ft_slltstr(arg, buf);
		ft_memmove(buf, buf + 1, ft_strlen(buf));
		SET(m->flag, F_NEG);
	}
	else
		ft_slltstr(arg, buf);
}
示例#22
0
static void	part2(char *tmp)
{
	while (tmp[0] != '\0' && tmp[1] != '\0' && tmp[2] != '\0')
	{
		if (ft_strnequ(tmp, "/./", 3))
			ft_memmove((void*)tmp, (void*)tmp + 2, ft_strlen(tmp) - 1);
		else
			tmp++;
	}
	return ;
}
示例#23
0
static void	part1(char *tmp)
{
	while (tmp[0] != '\0' && tmp[1] != '\0')
	{
		if (ft_strnequ(tmp, "/""/", 2))
			ft_memmove((void*)tmp, (void*)(tmp + 1), ft_strlen(tmp));
		else
			tmp++;
	}
	return ;
}
示例#24
0
void	*ft_memmove(void *dst, const void *src, size_t len)
{
	char c;

	if (len != 0)
	{
		c = *(char *)src;
		ft_memmove(dst + 1, src + 1, len - 1);
		*(char *)dst = c;
	}
	return (dst);
}
示例#25
0
static int	test_memmove_1()
{
	char	norm[20] = "bonjour";
	char	ft[20] = "bonjour";
	char	src[20] = "aurevoir";
	char	*result1;
	char	*result2;

	result1 = memmove(norm, src, 5);
	result2 = ft_memmove(ft, src, 5);
	return (memcmp(result1, result2, 7));
}
示例#26
0
void	*ft_memmove(void *s1, const void *s2, size_t n)
{
	size_t i;

	i = n - 1;
	if (n == 0)
		return (s1);

	if (*((char *)s2 + i) != '\0')
		*((char *)s1 + i) = *((char *)s2 + i);
	return (ft_memmove(s1, s2, i));
}
示例#27
0
void
	tmp_dyna_swap(t_array *d, size_t before, size_t after)
{
	char			*tmp;
	const size_t	len = after - before;
	const size_t	m = d->type_size;

	tmp = ft_safe_calloc(len, m);
	ft_memcpy(tmp, d->data + before * m, m * len);
	ft_memmove(d->data + before * m, d->data + after * m,
		(d->size - after) * m);
	ft_memcpy(d->data + (d->size - len) * m, tmp, len * m);
}
示例#28
0
文件: ft_realloc.c 项目: lgarczyn/fdf
void			*ft_realloc(void *ptr, size_t size)
{
	void		*mem;

	if (!ptr && size)
		return (ft_memalloc(size));
	if (!ptr)
		return (ft_memalloc(1));
	mem = ft_memalloc(size);
	ft_memmove(mem, ptr, size);
	free(ptr);
	return (mem);
}
示例#29
0
static int	ft_rest(t_fd *actual, char **line)
{
	char *tmp;

	tmp = ft_strchr(actual->rest, '\n');
	if (tmp)
	{
		*line = ft_strsub(actual->rest, 0, tmp - actual->rest);
		ft_memmove(actual->rest, tmp + 1, ft_strlen(tmp));
		tmp = NULL;
		return (1);
	}
	return (0);
}
示例#30
0
static	char	*fill_tab(char *line, char *s)
{
	int i;

	i = 0;
	while (s[i] != '\n' && s[i] != '\0')
	{
		line[i] = s[i];
		i++;
	}
	line[i] = '\0';
	s = (char *)ft_memmove(s, s + count_len_line(line) + 1, ft_strlen(s));
	return (line);
}