From fa4bf89263e897695dbf48061369a23d695fef8b Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 15 Oct 2019 13:02:53 +0200 Subject: Parsing rewrite - 4 extraction functions which parse some format attributes and remove them. - Not handling wildcard yet --- extract.c | 62 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'extract.c') diff --git a/extract.c b/extract.c index a6a3bba..27f1078 100644 --- a/extract.c +++ b/extract.c @@ -1,3 +1,4 @@ +#include #include "header.h" char *extract_ap_index(t_pformat *pformat, char *fmt) @@ -27,44 +28,46 @@ char *extract_standalone_flags(t_pformat *pformat, char *fmt) int i; char *fmt_dup; - i = -1; - while (IS_STANDALONE_FLAG(fmt[++i])) + i = 0; + while (IS_STANDALONE_FLAG(fmt[i])) { if (!pformat->zero_padding) pformat->zero_padding = fmt[i] == '0'; if (!pformat->left_adjusted) pformat->left_adjusted = fmt[i] == '-'; + i++; } fmt_dup = ft_strdup(&fmt[i]); free(fmt); - return (fmt_dup); + return (fmt_dup); } char *extract_min_width(t_pformat *pformat, char *fmt) { int i; int tmp; - char fmt_dup; + char *fmt_dup; i = 0; - if (*fmt == '*') - { - pformat->min_width->wildcard->exist = TRUE; - i++; - } + /* if (*fmt == '*') */ + /* { */ + /* pformat->min_width.wildcard.exist = TRUE; */ + /* i++; */ + /* } */ if (ft_isdigit(fmt[i])) { - tmp = ft_atoi(fmt[i]); + tmp = ft_atoi(&fmt[i]); while (ft_isdigit(fmt[i])) i++; - if (fmt[i] == '$') - pformat->min_width->wildcard->ap_index = tmp; - else - { - pformat->min_width->hardcoded = tmp; - pformat->min_width->wildcard->exist = FALSE; - } + /* printf("%d\n", tmp); */ + /* if (fmt[i] == '$') */ + /* pformat->min_width.wildcard.ap_index = tmp; */ + /* else */ + /* { */ + pformat->min_width.hardcoded = tmp; + pformat->min_width.wildcard.exist = FALSE; + /* } */ } fmt_dup = ft_strdup(&fmt[i]); free(fmt); @@ -74,25 +77,26 @@ char *extract_min_width(t_pformat *pformat, char *fmt) char *extract_precision(t_pformat *pformat, char *fmt) { int i; + int tmp; char *fmt_dup; if (*fmt != '.') return (fmt); i = 1; - if (fmt[i] == '*') - { - pformat->precision->wildcard->exist = TRUE; - i++; - } - else if (!ft_isdigit(fmt[i])) - pformat->precision->hardcoded = 0; - tmp = ft_atoi(fmt[i]); + /* if (fmt[i] == '*') */ + /* { */ + /* pformat->precision.wildcard.exist = TRUE; */ + /* i++; */ + /* } */ + /* else if (!ft_isdigit(fmt[i])) */ + /* pformat->precision.hardcoded = 0; */ + tmp = ft_atoi(&fmt[i]); while (ft_isdigit(fmt[i])) i++; - if (pformat->precision->wildcard->exist && fmt[i] == '$') - pformat->precision->wilcard->ap_index = tmp; - else - pformat->precision->hardcoded = tmp; + /* if (pformat->precision.wildcard.exist && fmt[i] == '$') */ + /* pformat->precision.wildcard.ap_index = tmp; */ + /* else */ + pformat->precision.hardcoded = tmp; fmt_dup = ft_strdup(&fmt[i]); free(fmt); return (fmt); -- cgit