ReactOS 0.4.15-dev-7931-gfd331f1
strtokc.c File Reference
#include <string.h>
#include "Strn.h"
Include dependency graph for strtokc.c:

Go to the source code of this file.

Functions

charstrtokc (char *parsestr, const char *delims, char **context)
 
int strntokc (char *dstTokenStart, size_t tokenSize, char *parsestr, const char *delims, char **context)
 

Function Documentation

◆ strntokc()

int strntokc ( char dstTokenStart,
size_t  tokenSize,
char parsestr,
const char delims,
char **  context 
)

Definition at line 92 of file strtokc.c.

93{
94 char *cp;
95 const char *cp2;
96 char c, c2;
97 char *start;
98 int len;
99 char *dst, *lim;
100
101 dst = dstTokenStart;
102 lim = dst + tokenSize - 1; /* Leave room for nul byte. */
103
104 if (parsestr == NULL)
105 start = *context;
106 else
107 start = parsestr;
108
109 if ((start == NULL) || (delims == NULL)) {
110 *context = NULL;
111 goto done;
112 }
113
114 /* Eat leading delimiters. */
115 for (cp = start; ; ) {
116next1:
117 c = *cp++;
118 if (c == '\0') {
119 /* No more tokens. */
120 *context = NULL;
121 goto done;
122 }
123 for (cp2 = delims; ; ) {
124 c2 = (char) *cp2++;
125 if (c2 == '\0') {
126 /* This character was not a delimiter.
127 * The token starts here.
128 */
129 start = cp - 1;
130 if (dst < lim)
131 *dst++ = c;
132 goto starttok;
133 }
134 if (c2 == c) {
135 /* This char was a delimiter. */
136 /* Skip it, look at next character. */
137 goto next1;
138 }
139 }
140 /*NOTREACHED*/
141 }
142
143starttok:
144 for ( ; ; cp++) {
145 c = *cp;
146 if (c == '\0') {
147 /* Token is finished. */
148 *context = cp;
149 break;
150 }
151 for (cp2 = delims; ; ) {
152 c2 = (char) *cp2++;
153 if (c2 == '\0') {
154 /* This character was not a delimiter.
155 * Keep it as part of current token.
156 */
157 break;
158 }
159 if (c2 == c) {
160 /* This char was a delimiter. */
161 /* End of token. */
162 *cp++ = '\0';
163 *context = cp;
164 goto done;
165 }
166 }
167 if (dst < lim) /* Don't overrun token size. */
168 *dst++ = c;
169 }
170
171done:
172 *dst = '\0';
173 len = (int) (dst - dstTokenStart); /* Return length of token. */
174
175#if (STRN_ZERO_PAD == 1)
176 /* Pad with zeros. */
177 for (++dst; dst <= lim; )
178 *dst++ = 0;
179#endif /* STRN_ZERO_PAD */
180
181 return (len);
182} /* strntokc */
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned char
Definition: typeof.h:29
GLuint start
Definition: gl.h:1545
const GLubyte * c
Definition: glext.h:8905
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
#define c
Definition: ke_i.h:80
POINT cp
Definition: magnifier.c:59
Definition: http.c:7252

◆ strtokc()

char * strtokc ( char parsestr,
const char delims,
char **  context 
)

Definition at line 7 of file strtokc.c.

8{
9 char *cp;
10 const char *cp2;
11 char c, c2;
12 char *start;
13
14 if (parsestr == NULL)
15 start = *context;
16 else
17 start = parsestr;
18
19 if ((start == NULL) || (delims == NULL)) {
20 *context = NULL;
21 return NULL;
22 }
23
24 /* Eat leading delimiters. */
25 for (cp = start; ; ) {
26next1:
27 c = *cp++;
28 if (c == '\0') {
29 /* No more tokens. */
30 *context = NULL;
31 return (NULL);
32 }
33 for (cp2 = delims; ; ) {
34 c2 = (char) *cp2++;
35 if (c2 == '\0') {
36 /* This character was not a delimiter.
37 * The token starts here.
38 */
39 start = cp - 1;
40 goto starttok;
41 }
42 if (c2 == c) {
43 /* This char was a delimiter. */
44 /* Skip it, look at next character. */
45 goto next1;
46 }
47 }
48 /*NOTREACHED*/
49 }
50
51starttok:
52 for ( ; ; cp++) {
53 c = *cp;
54 if (c == '\0') {
55 /* Token is finished. */
56 *context = cp;
57 break;
58 }
59 for (cp2 = delims; ; ) {
60 c2 = (char) *cp2++;
61 if (c2 == '\0') {
62 /* This character was not a delimiter.
63 * Keep it as part of current token.
64 */
65 break;
66 }
67 if (c2 == c) {
68 /* This char was a delimiter. */
69 /* End of token. */
70 *cp++ = '\0';
71 *context = cp;
72 return (start);
73 }
74 }
75 }
76 return (start);
77} /* strtokc */