Skip to content

Commit b595574

Browse files
committed
posix: c_lib_ext: formated code using clang-format
Formated fnmatch c and h files and test files using clang-format Signed-off-by: Harun Spago <harun.spago.code@gmail.com>
1 parent 4ca8e2a commit b595574

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

include/zephyr/posix/fnmatch.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
#define FNM_NOSYS 2 /* Function not implemented. */
4141
#define FNM_NORES 3 /* Out of resources */
4242

43-
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
44-
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
45-
#define FNM_PERIOD 0x04 /* Period must be matched by period. */
46-
#define FNM_CASEFOLD 0x08 /* Pattern is matched case-insensitive */
43+
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
44+
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
45+
#define FNM_PERIOD 0x04 /* Period must be matched by period. */
46+
#define FNM_CASEFOLD 0x08 /* Pattern is matched case-insensitive */
4747
#define FNM_LEADING_DIR 0x10 /* Ignore /<tail> after Imatch. */
4848

4949
#ifdef __cplusplus
@@ -52,7 +52,6 @@ extern "C" {
5252

5353
/**
5454
* Function used to check if the given pattern is in the string, using the given flags
55-
*
5655
* @param pattern pattern that is matched against the string
5756
* @param string string that is checked for the pattern
5857
* @param flags used to signal special matching conditions
@@ -61,8 +60,6 @@ extern "C" {
6160
* FNM_PERIOD 0x04 Period must be matched by period.
6261
* FNM_CASEFOLD 0x08 Pattern is matched case-insensitive
6362
* FNM_LEADING_DIR 0x10 Ignore /<tail> after Imatch.
64-
*
65-
*
6663
* @return int
6764
* @retval 0 pattern found in string
6865
* @retval FNM_NOMATCH pattern not found in string

lib/posix/c_lib_ext/fnmatch.c

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848

4949
#define EOS '\0'
5050

51-
#define MATCH_CLASS6(p,a,b,c,d,e,f,g) \
52-
((p)[0]==(a) && (p)[1]==(b) && (p)[2]==(c) && (p)[3]==(d) && (p)[4]==(e) && (p)[5]==(f) && (p)[6]==(g))
51+
#define MATCH_CLASS6(p, a, b, c, d, e, f, g) \
52+
((p)[0] == (a) && (p)[1] == (b) && (p)[2] == (c) && (p)[3] == (d) && (p)[4] == (e) && \
53+
(p)[5] == (f) && (p)[6] == (g))
5354

54-
#define MATCH_CLASS7(p,a,b,c,d,e,f,g,h) \
55-
((p)[0]==(a) && (p)[1]==(b) && (p)[2]==(c) && (p)[3]==(d) && (p)[4]==(e) && (p)[5]==(f) && (p)[6]==(g) && (p)[7]==(h))
55+
#define MATCH_CLASS7(p, a, b, c, d, e, f, g, h) \
56+
((p)[0] == (a) && (p)[1] == (b) && (p)[2] == (c) && (p)[3] == (d) && (p)[4] == (e) && \
57+
(p)[5] == (f) && (p)[6] == (g) && (p)[7] == (h))
5658

5759
enum fnm_char_class {
5860
FNM_CC_ALNUM,
@@ -75,77 +77,77 @@ static bool fnm_cc_is_valid(const char *pattern, size_t psize, enum fnm_char_cla
7577
return false;
7678
}
7779

78-
pattern++; /* skip ':' */
80+
pattern++; /* skip ':' */
7981
psize--;
8082

8183
/* Each class name ends with ":]" */
8284
switch (pattern[0]) {
8385
case 'a':
84-
if (MATCH_CLASS6(pattern,'a','l','n','u','m',':',']')) {
86+
if (MATCH_CLASS6(pattern, 'a', 'l', 'n', 'u', 'm', ':', ']')) {
8587
*cc = FNM_CC_ALNUM;
8688
return true;
8789
}
88-
if (MATCH_CLASS6(pattern,'a','l','p','h','a',':',']')) {
90+
if (MATCH_CLASS6(pattern, 'a', 'l', 'p', 'h', 'a', ':', ']')) {
8991
*cc = FNM_CC_ALPHA;
9092
return true;
9193
}
9294
break;
9395

9496
case 'c':
95-
if (MATCH_CLASS6(pattern,'c','n','t','r','l',':',']')) {
97+
if (MATCH_CLASS6(pattern, 'c', 'n', 't', 'r', 'l', ':', ']')) {
9698
*cc = FNM_CC_CNTRL;
9799
return true;
98100
}
99101
break;
100102

101103
case 'd':
102-
if (MATCH_CLASS6(pattern,'d','i','g','i','t',':',']')) {
104+
if (MATCH_CLASS6(pattern, 'd', 'i', 'g', 'i', 't', ':', ']')) {
103105
*cc = FNM_CC_DIGIT;
104106
return true;
105107
}
106108
break;
107109

108110
case 'g':
109-
if (MATCH_CLASS6(pattern,'g','r','a','p','h',':',']')) {
111+
if (MATCH_CLASS6(pattern, 'g', 'r', 'a', 'p', 'h', ':', ']')) {
110112
*cc = FNM_CC_GRAPH;
111113
return true;
112114
}
113115
break;
114116

115117
case 'l':
116-
if (MATCH_CLASS6(pattern,'l','o','w','e','r',':',']')) {
118+
if (MATCH_CLASS6(pattern, 'l', 'o', 'w', 'e', 'r', ':', ']')) {
117119
*cc = FNM_CC_LOWER;
118120
return true;
119121
}
120122
break;
121123

122124
case 'p':
123-
if (MATCH_CLASS6(pattern,'p','r','i','n','t',':',']')) {
125+
if (MATCH_CLASS6(pattern, 'p', 'r', 'i', 'n', 't', ':', ']')) {
124126
*cc = FNM_CC_PRINT;
125127
return true;
126128
}
127-
if (MATCH_CLASS6(pattern,'p','u','n','c','t',':',']')) {
129+
if (MATCH_CLASS6(pattern, 'p', 'u', 'n', 'c', 't', ':', ']')) {
128130
*cc = FNM_CC_PUNCT;
129131
return true;
130132
}
131133
break;
132134

133135
case 's':
134-
if (MATCH_CLASS6(pattern,'s','p','a','c','e',':',']')) {
136+
if (MATCH_CLASS6(pattern, 's', 'p', 'a', 'c', 'e', ':', ']')) {
135137
*cc = FNM_CC_SPACE;
136138
return true;
137139
}
138140
break;
139141

140142
case 'u':
141-
if (MATCH_CLASS6(pattern,'u','p','p','e','r',':',']')) {
143+
if (MATCH_CLASS6(pattern, 'u', 'p', 'p', 'e', 'r', ':', ']')) {
142144
*cc = FNM_CC_UPPER;
143145
return true;
144146
}
145147
break;
146148

147149
case 'x':
148-
if (MATCH_CLASS7(pattern,'x','d','i','g','i','t',':',']')) {
150+
if (MATCH_CLASS7(pattern, 'x', 'd', 'i', 'g', 'i', 't', ':', ']')) {
149151
*cc = FNM_CC_XDIGIT;
150152
return true;
151153
}
@@ -161,13 +163,20 @@ static bool fnm_cc_is_valid(const char *pattern, size_t psize, enum fnm_char_cla
161163
static inline int fnm_cc_match(int c, enum fnm_char_class cc)
162164
{
163165
switch (cc) {
164-
case FNM_CC_ALNUM: return isalnum(c);
165-
case FNM_CC_ALPHA: return isalpha(c);
166-
case FNM_CC_CNTRL: return iscntrl(c);
167-
case FNM_CC_DIGIT: return isdigit(c);
168-
case FNM_CC_GRAPH: return isgraph(c);
169-
case FNM_CC_LOWER: return (c >= 'a' && c <= 'z');
170-
case FNM_CC_PRINT: return isprint(c);
166+
case FNM_CC_ALNUM:
167+
return isalnum(c);
168+
case FNM_CC_ALPHA:
169+
return isalpha(c);
170+
case FNM_CC_CNTRL:
171+
return iscntrl(c);
172+
case FNM_CC_DIGIT:
173+
return isdigit(c);
174+
case FNM_CC_GRAPH:
175+
return isgraph(c);
176+
case FNM_CC_LOWER:
177+
return (c >= 'a' && c <= 'z');
178+
case FNM_CC_PRINT:
179+
return isprint(c);
171180
case FNM_CC_PUNCT: {
172181
/** Explicit list of punctuation characters in ASCII */
173182
const char *punct_chars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
@@ -179,9 +188,12 @@ static inline int fnm_cc_match(int c, enum fnm_char_class cc)
179188
}
180189
return 0;
181190
}
182-
case FNM_CC_SPACE: return isspace(c);
183-
case FNM_CC_UPPER: return isupper(c);
184-
case FNM_CC_XDIGIT: return isxdigit(c);
191+
case FNM_CC_SPACE:
192+
return isspace(c);
193+
case FNM_CC_UPPER:
194+
return isupper(c);
195+
case FNM_CC_XDIGIT:
196+
return isxdigit(c);
185197
default:
186198
break;
187199
}
@@ -214,6 +226,7 @@ static bool match_posix_class(const char **pattern, int test)
214226

215227
/* move pattern pointer past ":]" */
216228
const char *end = strstr(p, ":]");
229+
217230
if (end) {
218231
*pattern = end + 2;
219232
}

0 commit comments

Comments
 (0)