Function to break a line into a list of tokens. Delimiters are replaced by end-of-string characters ('\0'), and a list of pointers to thus created substrings is created. \param line (input) - a line to be tokenized, the line will be modified! \param token_list (output) - a resulting table containing pointers to tokens, or NULLs (the table will be initially nulled )
| 195 | or if line was empty. |
| 196 | */ |
| 197 | static int tokenize_line(char *line, char **token_list, size_t siz, char delim) |
| 198 | { |
| 199 | size_t i; |
| 200 | char *tok; |
| 201 | |
| 202 | /* Erase the table */ |
| 203 | for (i = 0; i < siz; i++) |
| 204 | { |
| 205 | token_list[i] = NULL; |
| 206 | } |
| 207 | |
| 208 | /* Empty line passed? */ |
| 209 | if (line == NULL) |
| 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /* Reinitialize, find the first token */ |
| 215 | i = 0; |
| 216 | tok = mystrtok(line, delim); |
| 217 | |
| 218 | /* Line contains no delim */ |
| 219 | if (tok == NULL) |
| 220 | { |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | token_list[ i++ ] = tok; |
| 225 | |
| 226 | /* Find the remaining tokens */ |
| 227 | while (i < siz) |
| 228 | { |
| 229 | tok = mystrtok(NULL, delim); |
| 230 | |
| 231 | /* If NULL, no more tokens left */ |
| 232 | if (tok == NULL) |
| 233 | { |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | /* Add token to the list */ |
| 238 | token_list[ i++ ] = tok; |
| 239 | } |
| 240 | |
| 241 | /* Any tokens left? */ |
| 242 | if (i == siz) |
| 243 | { |
| 244 | return 0; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | return i; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | |
| 253 | /** Tokenizer that handles two delimiters by returning an empty string. |