minishell
parse_opt_c_str.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* parse_opt_c_str.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/04/23 02:44:07 by kfujita #+# #+# */
9
/* Updated: 2023/01/26 21:33:55 by kfujita ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
ft_printf_local.h
"
14
#include "../ft_string/ft_string.h"
15
16
const
char
*
const
g_nullstr
=
"(null)"
;
17
18
bool
parse_opt_c_str
(
char
fmt, va_list *args,
t_fmt
*p_ret)
19
{
20
if
(fmt ==
'c'
|| fmt ==
'%'
)
21
{
22
p_ret->
type
=
CHAR
;
23
if
(fmt ==
'c'
)
24
p_ret->
data
.
c
= (char)va_arg(*args,
int
);
25
else
26
p_ret->
data
.
c
=
'%'
;
27
p_ret->
str_len
= 1;
28
}
29
else
if
(fmt ==
's'
)
30
{
31
p_ret->
type
=
STR
;
32
p_ret->
data
.
str
= va_arg(*args,
char
*);
33
if
(p_ret->
data
.
str
== NULL)
34
p_ret->
data
.
str
= (
char
*)
g_nullstr
;
35
p_ret->
str_len
=
ft_strlen
(p_ret->
data
.
str
);
36
}
37
else
38
return
(
false
);
39
return
(
true
);
40
}
ft_printf_local.h
CHAR
@ CHAR
Definition:
ft_printf_local.h:29
STR
@ STR
Definition:
ft_printf_local.h:28
ft_strlen
size_t ft_strlen(const char *s)
Definition:
ft_strlen.c:15
parse_opt_c_str
bool parse_opt_c_str(char fmt, va_list *args, t_fmt *p_ret)
Definition:
parse_opt_c_str.c:18
g_nullstr
const char *const g_nullstr
Definition:
parse_opt_c_str.c:16
t_fmt
Definition:
ft_printf_local.h:48
t_fmt::type
t_dtype type
Definition:
ft_printf_local.h:49
t_fmt::data
t_data data
Definition:
ft_printf_local.h:50
t_fmt::str_len
int str_len
Definition:
ft_printf_local.h:53
t_data::c
char c
Definition:
ft_printf_local.h:42
t_data::str
char * str
Definition:
ft_printf_local.h:39
libft
ft_printf
parse_opt_c_str.c
Generated by
1.9.1