Exemplo n.º 1
0
Arquivo: ft_printf.c Projeto: Selk/Dev
int			ft_printf(const char *format, ...)
{
    va_list		args;
    int			i;
    int			(*funct_array[14])(va_list	args);
    int			size;

    va_start(args, format);
    ft_ini_func(funct_array);
    i = 0;
    size = 0;
    while (format[i])
    {
        if (format[i] == '%' && format[i + 1] != '\0'
                && ft_get_flag(format[i + 1]) != -1)
            size += funct_array[ft_get_flag(format[1 + i++])](args);
        else if (format[i] == '%' && format[i + 1] == '%')
            size += ft_putchar(format[i++]);
        else if (format[i] != '%' && format[i] != '#')
            size += ft_putchar(format[i]);
        i++;
    }
    va_end(args);
    return (size);
}
Exemplo n.º 2
0
Arquivo: process.c Projeto: Selk/Dev
void		process(va_list args, t_env *env, char spec)
{
	int			(*funct_array[15])(va_list	args, t_env	*env);

	env->specifier = spec;
	ft_ini_func(funct_array);
	if (check_flag_minus(env) == 1)
		env->minus = 1;
	if (check_flag_zero(env) == 1)
		env->zero = 1;
	if (check_flag_space(env) == 1)
		env->space = 1;
	if (check_flag_plus(env) == 1)
		env->plus = 1;
	if (check_flag_sharp(env) == 1)
		env->sharp = 1;
	env->size += funct_array[ft_get_flag(env->specifier)](args, env);
	clean_env(env);
}
Exemplo n.º 3
0
int			ft_get_var(char **str, int ret, va_list ap)
{
	t_print	*print;
	size_t	i;

	i = 0;
	if (!(print = (t_print*)ft_memalloc(sizeof(*print))))
		return (-1);
	if ((print->flag = ft_get_flag(*str, &i)) < 0)
		return (ft_free_print(print));
	if ((print->width = ft_get_width(*str, &i, print, ap)) < 0)
		return (ft_free_print(print));
	if ((print->prec = ft_get_prec(*str, &i, print, ap)) < 0)
		return (ft_free_print(print));
	if (!(print->len = ft_get_len(*str, &i)))
		return (ft_free_print(print));
	if (ft_get_type(*str, &i, print) < 0)
		return (ft_free_print(print));
	if (!(print->value = ft_get_value(print, ap, ret)))
		return (ft_free_print(print));
	str[0] += i + 1;
	return (ft_create_str(print, print->flag, print->dot));
}