-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformat-handlers.c
68 lines (59 loc) · 1.12 KB
/
format-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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*functions handling format parsing*/
#include <stdlib.h>
#include "holberton.h"
#include <stdio.h>
#include <unistd.h>
/**
* grab_format - grabs format of given string
* @format: format string
* Return: format string
*/
char *grab_format(const char *format)
{
int j;
char *conv;
j = 0;
while (no_conversion(format[j]) && format[j])
++j;
if (no_conversion(format[j]))
{
return (NULL);
}
conv = malloc((j + 2) * sizeof(char));
conv = _strncpy(conv, format, j + 1);
conv[j + 1] = '\0';
return (conv);
}
/**
* fill_format - fills in the format_array with all conversion formatters
* including their flags
* @format: formatting string containing possible formatters
* Return: format_array
*/
void fill_format(const char *format)
{
int i, l_conv, flag;
char *conv;
flag = 0;
for (i = 0; format[i] != '\0'; ++i)
{
if (format[i] == '%')
{
flag = 1;
if (format[i + 1] == '%')
{
flag = 0;
i += 1;
}
}
if (flag == 1)
{
flag = 0;
conv = grab_format(format + i);
l_conv = _strlen(conv);
get_validity_func(conv[l_conv - 1])(conv);
free(conv);
i += l_conv - 1;
}
}
}