-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.c
43 lines (40 loc) · 1.09 KB
/
handlers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "main.h"
/**
* specifier_handler - defines list of specifiers-to-handler map
* and executes the handler mamtching the `specifier` argument.
*
* @my_buffer: struct holding the final string and count
* @specifier: the given specifier char
* @args: list of variable arguments
* @parsed_chars: pointer to variable tracking the chars parsed
* Return: (0) on success (-1) on failure / no matching specifier
*/
int specifier_handler(buf *my_buffer,
char *specifier, va_list args, int *parsed_chars)
{
int i = 0;
int converter_ret = 0;
specifier_map specifier_list[] = {
{'c', convert_char},
{'s', convert_str},
{'%', convert_percent},
{'d', convert_int},
{'i', convert_int},
{'u', convert_uint},
{'b', convert_bin},
{'o', convert_oct},
{'x', convert_hex},
{'X', convert_hexa},
{'p', convert_addr},
{'\0', NULL}};
while (specifier_list[i].specifier)
{
if (specifier_list[i].specifier == *specifier)
{
converter_ret = specifier_list[i].op(my_buffer, args, parsed_chars);
return (converter_ret);
}
i++;
}
return (-1);
}