]> mj.ucw.cz Git - libucw.git/blob - lib/wordsplit.c
Syncing crashed repository with my work tree.
[libucw.git] / lib / wordsplit.c
1 /*
2  *      Sherlock Library -- Word Splitting
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <stdio.h>
8
9 #include "lib.h"
10 #include "string.h"
11
12 int
13 wordsplit(byte *src, byte **dst, uns max)
14 {
15   uns cnt = 0;
16
17   for(;;)
18     {
19       while (Cspace(*src))
20         *src++ = 0;
21       if (!*src)
22         break;
23       if (cnt >= max)
24         return -1;
25       if (*src == '"')
26         {
27           src++;
28           dst[cnt++] = src;
29           while (*src && *src != '"')
30             src++;
31           if (*src)
32             *src++ = 0;
33         }
34       else
35         {
36           dst[cnt++] = src;
37           while (*src && !Cspace(*src))
38             src++;
39         }
40     }
41   return cnt;
42 }