aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-30 03:57:47 +0100
committerCharles <sircharlesaze@gmail.com>2019-10-30 03:57:47 +0100
commitd963161275bcb3af4097872ba033da3ff9255606 (patch)
tree41476dcab3fa209ae6f49c6f1abe37d454674a12 /parse.c
parent07c9232121c8d6cb1e473bd7b623792253375d93 (diff)
downloadft_printf-d963161275bcb3af4097872ba033da3ff9255606.tar.gz
ft_printf-d963161275bcb3af4097872ba033da3ff9255606.tar.bz2
ft_printf-d963161275bcb3af4097872ba033da3ff9255606.zip
Individual convert functions, more flags
- Each conversion type is handle by individual functions in convert_* files - handle the ' ', '#', '+' and length modifier flags.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/parse.c b/parse.c
index 6738566..871ff74 100644
--- a/parse.c
+++ b/parse.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */
-/* Updated: 2019/10/29 05:19:00 by cacharle ### ########.fr */
+/* Updated: 2019/10/30 03:41:02 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,26 +19,26 @@
** %(?:\d+\$)?[-]?(?:[0]|'.{1})?-?\d*(?:\.\d+)?[cdusxX]
*/
-t_flist *parse(char *format)
+int parse(char *format, t_flist **flist)
{
- t_flist *format_list;
t_flist *tmp;
t_pformat *parsed;
- format_list = NULL;
+ *flist = NULL;
while (*format)
{
format++;
if (format[-1] != '%')
continue;
if ((parsed = parse_reduced(format)) == NULL)
- return (list_destroy(&format_list));
+ return (list_destroy(flist));
if ((tmp = list_new(parsed)) == NULL)
- return (list_destroy(&format_list));
- list_push_front(&format_list, tmp);
- format += format_list->content->len;
+ return (list_destroy(flist));
+ list_push_front(flist, tmp);
+ format += (*flist)->content->len;
}
- return (list_reverse(format_list));
+ *flist = list_reverse(*flist);
+ return (1);
}
t_pformat *parse_reduced(char *fmt)
@@ -59,11 +59,12 @@ t_pformat *parse_reduced(char *fmt)
pformat->min_width = -1;
pformat->flags = 0;
pformat->len = ft_strlen(fmt);
- pformat->conversion = fmt[pformat->len - 1];
+ pformat->type = fmt[pformat->len - 1];
fmt[pformat->len - 1] = '\0';
fmt = extract_standalone_flags(pformat, fmt);
fmt = extract_min_width(pformat, fmt);
- extract_precision(pformat, fmt);
+ fmt = extract_precision(pformat, fmt);
+ extract_length_modifier(pformat, fmt);
free(start);
return (pformat);
}