]> mj.ucw.cz Git - libucw.git/blob - lib/wordsplit.c
Added very simple functions for emulating a fastbuf stream over a static
[libucw.git] / lib / wordsplit.c
1 /*
2  *      Sherlock Library -- Word Splitting
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11 #include "lib/chartype.h"
12
13 int
14 wordsplit(byte *src, byte **dst, uns max)
15 {
16   uns cnt = 0;
17
18   for(;;)
19     {
20       while (Cspace(*src))
21         *src++ = 0;
22       if (!*src)
23         break;
24       if (cnt >= max)
25         return -1;
26       if (*src == '"')
27         {
28           src++;
29           dst[cnt++] = src;
30           while (*src && *src != '"')
31             src++;
32           if (*src)
33             *src++ = 0;
34         }
35       else
36         {
37           dst[cnt++] = src;
38           while (*src && !Cspace(*src))
39             src++;
40         }
41     }
42   return cnt;
43 }