minishell
parse_format.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* parse_format.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/23 00:19:18 by kfujita #+# #+# */
9 /* Updated: 2023/05/03 20:20:49 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <stdlib.h>
14 #include <limits.h>
15 #include <stdint.h>
16 #include "ft_printf_local.h"
17 
18 t_list *parse_format(const char *fmt, va_list *args)
19 {
20  t_list *p_ret;
21  size_t ret_len;
22 
23  p_ret = NULL;
24  ret_len = 0;
25  while (*fmt != '\0' && ret_len < INT_MAX)
26  {
27  if (*fmt == '%')
28  ft_lstadd_back(&p_ret,
29  ft_lstnew(parse_opt(&ret_len, (char **)&fmt, args)));
30  else
31  ft_lstadd_back(&p_ret,
32  ft_lstnew(check_no_opt_str(&ret_len, (char **)&fmt, NULL)));
33  if (p_ret == NULL || ft_lstlast(p_ret)->content == NULL)
34  ret_len = UINTPTR_MAX;
35  }
36  if (ret_len >= INT_MAX)
37  ft_lstclear(&p_ret, free);
38  return (p_ret);
39 }
t_fmt * check_no_opt_str(size_t *len, char **fmt, t_fmt *p_ret)
void ft_lstadd_back(t_list **lst, t_list *new)
void ft_lstclear(t_list **lst, void(*del)(void *))
Definition: ft_lstclear.c:16
t_list * ft_lstnew(void *content)
Definition: ft_lstnew.c:16
t_list * ft_lstlast(t_list *lst)
Definition: ft_lstlast.c:16
t_fmt * parse_opt(size_t *len, char **fmt, va_list *args)
Definition: parse_opt.c:17
t_list * parse_format(const char *fmt, va_list *args)
Definition: parse_format.c:18
Definition: ft_lst.h:18