minishell
parse_opt_num.c File Reference
Include dependency graph for parse_opt_num.c:

Go to the source code of this file.

Functions

static int calc_num_len (long num, int base, t_fmt *p_ret)
 
static bool parse_num_type (char fmt, t_fmt *p_ret)
 
bool parse_opt_num (char fmt, va_list *args, t_fmt *p_ret)
 

Function Documentation

◆ calc_num_len()

static int calc_num_len ( long  num,
int  base,
t_fmt p_ret 
)
static

Definition at line 16 of file parse_opt_num.c.

17 {
18  char *buf;
19 
20  buf = p_ret->data.str_buf;
21  if (p_ret->type == UINT_16BASE)
22  {
23  if (p_ret->f_hash && num != 0)
24  p_ret->header[0] = '0';
25  }
26  else if (num < 0)
27  {
28  p_ret->header[0] = '-';
29  num *= -1;
30  }
31  else if (p_ret->f_plus && p_ret->type != UINT_10BASE)
32  p_ret->header[0] = '+';
33  else if (p_ret->f_space && p_ret->type != UINT_10BASE)
34  p_ret->header[0] = ' ';
35  p_ret->head_len = ft_strlen(p_ret->header);
36  if (num == 0)
37  {
38  p_ret->data.c = '0';
39  return (1);
40  }
41  return (get_numstr_base(buf, num, base, p_ret->f_upper));
42 }
@ UINT_10BASE
@ UINT_16BASE
size_t ft_strlen(const char *s)
Definition: ft_strlen.c:15
int get_numstr_base(char *buf, size_t num, int base, bool is_upper)
t_dtype type
t_data data
bool f_plus
bool f_upper
t_uint8 head_len
char header[3]
bool f_space
bool f_hash
char str_buf[STR_BUF_LEN]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_num_type()

static bool parse_num_type ( char  fmt,
t_fmt p_ret 
)
static

Definition at line 44 of file parse_opt_num.c.

45 {
46  if (fmt == 'd' || fmt == 'i')
47  p_ret->type = INT_10BASE;
48  else if (fmt == 'u')
49  p_ret->type = UINT_10BASE;
50  else if (fmt == 'x' || fmt == 'X')
51  {
52  p_ret->type = UINT_16BASE;
53  p_ret->header[1] = fmt;
54  }
55  else
56  return (false);
57  return (true);
58 }
@ INT_10BASE
Here is the caller graph for this function:

◆ parse_opt_num()

bool parse_opt_num ( char  fmt,
va_list *  args,
t_fmt p_ret 
)

Definition at line 60 of file parse_opt_num.c.

61 {
62  if (!parse_num_type(fmt, p_ret))
63  return (false);
64  if (fmt == 'X')
65  p_ret->f_upper = true;
66  if (p_ret->type == INT_10BASE)
67  p_ret->data.s_digit = va_arg(*args, int);
68  else
69  p_ret->data.s_digit = va_arg(*args, unsigned int);
70  if (p_ret->type == INT_10BASE)
71  p_ret->str_len = calc_num_len(p_ret->data.s_digit, 10, p_ret);
72  else if (p_ret->type == UINT_10BASE)
73  p_ret->str_len = calc_num_len(p_ret->data.u_digit, 10, p_ret);
74  else
75  p_ret->str_len = calc_num_len(p_ret->data.u_digit, 16, p_ret);
76  return (true);
77 }
static int calc_num_len(long num, int base, t_fmt *p_ret)
Definition: parse_opt_num.c:16
static bool parse_num_type(char fmt, t_fmt *p_ret)
Definition: parse_opt_num.c:44
int str_len
unsigned int u_digit
Here is the call graph for this function:
Here is the caller graph for this function: