diff options
-rw-r--r-- | firmware/libc/sscanf.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/firmware/libc/sscanf.c b/firmware/libc/sscanf.c index 5bb08d8268..1bbb5abcbf 100644 --- a/firmware/libc/sscanf.c +++ b/firmware/libc/sscanf.c | |||
@@ -1,7 +1,22 @@ | |||
1 | #include <stdarg.h> | 1 | #include <stdarg.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <ctype.h> | 4 | |
5 | static inline bool my_isspace(char c) | ||
6 | { | ||
7 | return (c == ' ') || (c == '\t') || (c == '\n'); | ||
8 | } | ||
9 | |||
10 | static inline bool my_isdigit(char c) | ||
11 | { | ||
12 | return (c >= '0') && (c <= '9'); | ||
13 | } | ||
14 | |||
15 | static inline bool my_isxdigit(char c) | ||
16 | { | ||
17 | return ((c >= '0') && (c <= '9')) | ||
18 | || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')); | ||
19 | } | ||
5 | 20 | ||
6 | static int parse_dec(int (*peek)(void *userp), | 21 | static int parse_dec(int (*peek)(void *userp), |
7 | void (*pop)(void *userp), | 22 | void (*pop)(void *userp), |
@@ -21,7 +36,7 @@ static int parse_dec(int (*peek)(void *userp), | |||
21 | } | 36 | } |
22 | 37 | ||
23 | ch = (*peek)(userp); | 38 | ch = (*peek)(userp); |
24 | if (!isdigit(ch)) | 39 | if (!my_isdigit(ch)) |
25 | return -1; | 40 | return -1; |
26 | 41 | ||
27 | do | 42 | do |
@@ -30,7 +45,7 @@ static int parse_dec(int (*peek)(void *userp), | |||
30 | (*pop)(userp); | 45 | (*pop)(userp); |
31 | n++; | 46 | n++; |
32 | ch = (*peek)(userp); | 47 | ch = (*peek)(userp); |
33 | } while (isdigit(ch)); | 48 | } while (my_isdigit(ch)); |
34 | 49 | ||
35 | *vp = minus ? -v : v; | 50 | *vp = minus ? -v : v; |
36 | return n; | 51 | return n; |
@@ -46,7 +61,7 @@ static int parse_chars(int (*peek)(void *userp), | |||
46 | 61 | ||
47 | char *pt=vp; | 62 | char *pt=vp; |
48 | 63 | ||
49 | while (!isspace((*peek)(userp))) | 64 | while (!my_isspace((*peek)(userp))) |
50 | { | 65 | { |
51 | if(fake==false) | 66 | if(fake==false) |
52 | *(pt++) = (*peek)(userp); | 67 | *(pt++) = (*peek)(userp); |
@@ -71,7 +86,7 @@ static int parse_hex(int (*peek)(void *userp), | |||
71 | char ch; | 86 | char ch; |
72 | 87 | ||
73 | ch = (*peek)(userp); | 88 | ch = (*peek)(userp); |
74 | if (!isxdigit(ch)) | 89 | if (!my_isxdigit(ch)) |
75 | return -1; | 90 | return -1; |
76 | 91 | ||
77 | do | 92 | do |
@@ -86,7 +101,7 @@ static int parse_hex(int (*peek)(void *userp), | |||
86 | (*pop)(userp); | 101 | (*pop)(userp); |
87 | n++; | 102 | n++; |
88 | ch = (*peek)(userp); | 103 | ch = (*peek)(userp); |
89 | } while (isxdigit(ch)); | 104 | } while (my_isxdigit(ch)); |
90 | 105 | ||
91 | *vp = v; | 106 | *vp = v; |
92 | return n; | 107 | return n; |
@@ -97,7 +112,7 @@ static int skip_spaces(int (*peek)(void *userp), | |||
97 | void *userp) | 112 | void *userp) |
98 | { | 113 | { |
99 | int n = 0; | 114 | int n = 0; |
100 | while (isspace((*peek)(userp))) { | 115 | while (my_isspace((*peek)(userp))) { |
101 | n++; | 116 | n++; |
102 | (*pop)(userp); | 117 | (*pop)(userp); |
103 | } | 118 | } |