-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.c
More file actions
40 lines (38 loc) · 937 Bytes
/
parser.c
File metadata and controls
40 lines (38 loc) · 937 Bytes
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
#include "main.h"
/**
* parse_format - parse format string
* @fmt: Format string to parse
* Description: Determines if the format string
* contains valid format specifiers.
* Return: 1 (valid) or 0 (invalid).
*/
int parse_format(const char *fmt)
{ int i = 0, ret_val = 1, len = strlen(fmt) - 1;
while (i <= len)
{
if (fmt[i] == '%')
{
if (i + 1 > len) /* fmt[i] is the last char of *fmt */
{
ret_val = 0;
break;
}
/* char fmt[i] does not denote allowed specifier */
if (fmt[i + 1] != 'c' && fmt[i + 1] != 's' && fmt[i +
1] != '%' && fmt[i + 1] != 'd' && fmt[i
+ 1] != 'i' && fmt[i + 1] != 'r' && fmt
[i + 1] != 'R' && fmt[i + 1] != 'b' &&
fmt[i + 1] != 'u' && fmt[i + 1] != 'o'
&& fmt[i + 1] != 'x' && fmt[i + 1] !=
'X' && fmt[i + 1] != 'p')
{
ret_val = 0;
break;
}
i += 2; /* skip determined fmt specifier */
}
else
i++;
}
return (ret_val);
}