diff options
| author | nass1pro <nass1pro@gmail.com> | 2020-06-09 19:48:34 +0200 |
|---|---|---|
| committer | nass1pro <nass1pro@gmail.com> | 2020-06-13 11:31:00 +0200 |
| commit | 579a26f5593039ffbbd1a81e45ecf0ef8797cb5d (patch) | |
| tree | c5b6761db98e27d15bab3fb45ba9e0a646cf06e0 /test_mini/libft/src/io/ft_printf/internals/parse.c | |
| parent | 9fabc25a980550afc6337fd729632462f2680daa (diff) | |
| download | minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.tar.gz minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.tar.bz2 minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.zip | |
add lexer
add single quote
Diffstat (limited to 'test_mini/libft/src/io/ft_printf/internals/parse.c')
| -rw-r--r-- | test_mini/libft/src/io/ft_printf/internals/parse.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test_mini/libft/src/io/ft_printf/internals/parse.c b/test_mini/libft/src/io/ft_printf/internals/parse.c new file mode 100644 index 0000000..4650481 --- /dev/null +++ b/test_mini/libft/src/io/ft_printf/internals/parse.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */ +/* Updated: 2019/11/13 08:13:02 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +int parse(const char *format, t_flist **flist) +{ + t_flist *tmp; + t_pformat *parsed; + + *flist = NULL; + while (*format) + { + format++; + if (format[-1] != '%') + continue; + if ((parsed = parse_reduced(format)) == NULL) + return ((int)list_destroy(flist)); + if ((tmp = list_new(parsed)) == NULL) + return ((int)list_destroy(flist)); + list_push_front(flist, tmp); + format += (*flist)->data->fmt_len; + } + *flist = list_reverse(*flist); + return (1); +} + +t_pformat *parse_reduced(const char *fmt) +{ + t_pformat *pformat; + const char *start; + + if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL) + return (NULL); + pformat->precision = -1; + pformat->width = -1; + pformat->flags = 0; + start = fmt; + fmt = extract_flags(pformat, fmt); + fmt = extract_width(pformat, fmt); + fmt = extract_precision(pformat, fmt); + fmt = extract_length_modifier(pformat, fmt); + pformat->fmt_len = fmt - start + 1; + if (*fmt == '\0' || ft_strchr(SPECIFIERS_STR, *fmt) == NULL) + { + pformat->fmt_len--; + pformat->specifier = '_'; + } + else + pformat->specifier = *ft_strchr(SPECIFIERS_STR, *fmt); + return (pformat); +} |
