9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

tokenize.c (375B)


      1 #include <ctype.h>
      2 
      3 #include <libk.h>
      4 
      5 int
      6 tokenize(char *line, int siz, char *tokens[], int ntoks)
      7 {
      8 	int n;
      9 
     10 	for (n = 0; n < ntoks; n++) {
     11 		while (siz > 0 && isspace(*line))
     12 			siz--, *line++ = '\0';
     13 
     14 		if (siz == 0)
     15 			return n;
     16 		tokens[n] = line;
     17 
     18 		while (siz > 0 && !isspace(*line))
     19 			siz--, line++;
     20 		if (siz == 0)
     21 			return n;
     22 
     23 		*line++ = '\0';
     24 	}
     25 
     26 	return n;
     27 }