Example #1
0
static int	ft_read_line(int fd, char **buf, char **line, char *pos)
{
	int	result;

	*line = ft_strdup(*buf);
	while (!pos)
	{
		if ((result = read(fd, *buf, BUFF_SIZE)) < 0)
			return (-1);
		if ((pos = ft_strchr(*buf, '\n')) == NULL && !result)
			return ((*buf)[0] = 0);
		else if (pos)
		{
			(*buf)[result] = result ? 0 : (*buf)[result];
			pos[0] = 0;
			*line = ft_strjoinf(*line, *buf);
			ft_strcpy(*buf, pos + 1);
		}
		else
		{
			(*buf)[result] = result ? 0 : (*buf)[result];
			*line = ft_strjoinf(*line, *buf);
			(*buf)[0] = 0;
		}
	}
	return (*line ? 1 : -1);
}
Example #2
0
void				treat_ptr(t_prf *env, char **result)
{
	unsigned long int	to_format;

	to_format = va_arg(env->args, unsigned long int);
	*result = ft_itoa_base(to_format, env->cur_specs->base);
	*result = ft_strjoinf("0x", *result, 2);
}
Example #3
0
void	sh1_env_replace_tield(char **env, char **arg)
{
	char	*home;
	char	*tmp;

	tmp = *arg;
	if ((home = sh1_getenv(env, "HOME")) == NULL)
		*arg = ft_strdup("~");
	else
		*arg = ft_strdup(home);
	*arg = ft_strjoinf(*arg, tmp + 1);
	free(tmp);
}
Example #4
0
static void			prec_on_nb(t_specs *specs, char **result)
{
	char			*tmp;
	int				orig_len;
	int				len;

	orig_len = ft_strlen(*result);
	len = specs->precision;
	if (!specs->precision && !ft_strcmp(*result, "0"))
		**result = '\0';
	else if (specs->precision > orig_len)
	{
		tmp = (char *)ft_memalloc(sizeof(char) * (len + 1));
		ft_memset(tmp, '0', specs->precision);
		ft_strncpy(tmp + (specs->precision - orig_len), *result, orig_len);
		ft_strdel(result);
		*result = tmp;
		if ((tmp = ft_strchr(*result, '-')) != 0)
		{
			*tmp = '0';
			*result = ft_strjoinf("-", *result, 2);
		}
	}
}