-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_print.c
More file actions
executable file
·52 lines (49 loc) · 1.24 KB
/
handle_print.c
File metadata and controls
executable file
·52 lines (49 loc) · 1.24 KB
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
44
45
46
47
48
49
50
51
52
#include "main.h"
/**
* handle_write_char - Function
* @format: Parameter
* @buff: Parameter
* @ks: Parameter
* @ma: Parameter
* @sap: Parameter
* @bt: Parameter
* @va: Parameter
* @a: Parameter
*
* Return: Value
*/
int handle_print(const char *format, int *a, va_list va, char buff[],
int ks, int ma, int sap, int bt)
{
int i, var = 0, pta = -1;
format_tp format_types[] = {
{'c', print_char}, {'s', print_string}, {'%', print_percent},
{'i', print_int}, {'d', print_int}, {'b', print_binary},
{'u', print_unsigned}, {'o', print_octal}, {'x', print_hexadecimal},
{'X', print_hexa_upper}, {'p', print_pointer}, {'S', print_non_printable},
{'r', print_reverse}, {'R', print_rot13string}, {'\0', NULL}
};
for (i = 0; format_types[i].format != '\0'; i++)
if (format[*a] == format_types[i].format)
return (format_types[i].f(va, buff, ks, ma, sap, bt));
if (format_types[i].format == '\0')
{
if (format[*a] == '\0')
return (-1);
var += write(1, "%%", 1);
if (format[*a - 1] == ' ')
var += write(1, " ", 1);
else if (ma)
{
--(*a);
while (format[*a] != ' ' && format[*a] != '%')
--(*a);
if (format[*a] == ' ')
--(*a);
return (1);
}
var += write(1, &format[*a], 1);
return (var);
}
return (pta);
}