-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.c
More file actions
48 lines (44 loc) · 1.05 KB
/
Copy pathparser.c
File metadata and controls
48 lines (44 loc) · 1.05 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
#include "main.h"
/**
* parser - Goes through and prints format string
* @format: String to be parsed through
* @printFunctions: Struct of type FunctionList of print functions
* @argms: Variadic list of args
* Return: Number of printed chars or -1 if failure
*/
int parser(const char *format, FunctionList printFunctions[], va_list argms)
{
int i = 0, j, length = 0;
while (format[i])
{
if (format[i] == '%' && format[i + 1] != '%' && format[i + 1] != '\0')
{
int specifier_check = 0;
for (j = 0; j < 11; j++)
{
if (format[i + 1] == printFunctions[j].specifier)
{
specifier_check = 1;
length += printFunctions[j].pf(argms);
i++;
break;
}
}
if (!specifier_check)
length += _putchar('%');
}
else if (format[i] == '%' && format[i + 1] == '%')
{
length += _putchar('%');
i++;
}
else if (format[0] == '%' && format[1] == '\0')
return (-1);
else if (format[i] == '%' && format[i + 1] == '\0')
return (-1);
else if (format[i] != '%')
length += _putchar(format[i]);
i++;
}
return (length);
}