aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/parse.c b/parse.c
index d486ae7..83a7d55 100644
--- a/parse.c
+++ b/parse.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* parse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */
+/* Updated: 2019/10/29 00:11:50 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include <stdlib.h>
#include "header.h"
@@ -7,30 +19,25 @@
** %(?:\d+\$)?[-]?(?:[0]|'.{1})?-?\d*(?:\.\d+)?[cdusxX]
*/
-#include <stdio.h>
-t_flist *parse(const char *format)
+t_flist *parse(char *format)
{
- t_flist *format_list;
- t_flist *tmp;
- t_pformat *parsed;
+ t_flist *format_list;
+ t_flist *tmp;
+ t_pformat *parsed;
format_list = NULL;
while (*format)
{
- if (*format != '%')
- {
- format++;
- continue;
- }
format++;
- if ((parsed = parse_reduced(isolate_conversion(format))) == NULL)
+ if (format[-1] != '%')
+ continue;
+ if ((parsed = parse_reduced(format)) == NULL)
return (list_destroy(&format_list));
if ((tmp = list_new(parsed)) == NULL)
return (list_destroy(&format_list));
list_push_front(&format_list, tmp);
}
- list_reverse(&format_list);
- return (format_list);
+ return (list_reverse(format_list));
}
t_pformat *parse_reduced(char *fmt)
@@ -45,17 +52,14 @@ t_pformat *parse_reduced(char *fmt)
return (NULL);
if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL)
return (NULL);
- pformat->left_adjusted = FALSE;
- pformat->zero_padding = FALSE;
- pformat->precision.value = -1;
- pformat->precision.wildcard = FALSE;
- pformat->min_width.value = -1;
- pformat->min_width.wildcard = FALSE;
+ pformat->precision = -1;
+ pformat->min_width = -1;
+ pformat->flags = 0;
pformat->len = ft_strlen(fmt);
- pformat->conversion = strrchr_index(CONVERSIONS_STR, fmt[pformat->len - 1]);
+ pformat->conversion = fmt[pformat->len - 1];
fmt[pformat->len - 1] = '\0';
- fmt = extract_standalone_flags(pformat, fmt + i);
- fmt = extract_min_width(pformat, fmt + i);
- fmt = extract_precision(pformat, fmt + i);
+ fmt = extract_standalone_flags(pformat, fmt);
+ fmt = extract_min_width(pformat, fmt);
+ fmt = extract_precision(pformat, fmt);
return (pformat);
}