Blame


1 b2cfc4e2 2003-09-30 devnull #include <lib9.h>
2 b2cfc4e2 2003-09-30 devnull
3 b2cfc4e2 2003-09-30 devnull int
4 b2cfc4e2 2003-09-30 devnull getfields(char *str, char **args, int max, int mflag, char *set)
5 b2cfc4e2 2003-09-30 devnull {
6 b2cfc4e2 2003-09-30 devnull Rune r;
7 b2cfc4e2 2003-09-30 devnull int nr, intok, narg;
8 b2cfc4e2 2003-09-30 devnull
9 b2cfc4e2 2003-09-30 devnull if(max <= 0)
10 b2cfc4e2 2003-09-30 devnull return 0;
11 b2cfc4e2 2003-09-30 devnull
12 b2cfc4e2 2003-09-30 devnull narg = 0;
13 b2cfc4e2 2003-09-30 devnull args[narg] = str;
14 b2cfc4e2 2003-09-30 devnull if(!mflag)
15 b2cfc4e2 2003-09-30 devnull narg++;
16 b2cfc4e2 2003-09-30 devnull intok = 0;
17 b2cfc4e2 2003-09-30 devnull for(;; str += nr) {
18 b2cfc4e2 2003-09-30 devnull nr = chartorune(&r, str);
19 b2cfc4e2 2003-09-30 devnull if(r == 0)
20 b2cfc4e2 2003-09-30 devnull break;
21 b2cfc4e2 2003-09-30 devnull if(utfrune(set, r)) {
22 b2cfc4e2 2003-09-30 devnull if(narg >= max)
23 b2cfc4e2 2003-09-30 devnull break;
24 b2cfc4e2 2003-09-30 devnull *str = 0;
25 b2cfc4e2 2003-09-30 devnull intok = 0;
26 b2cfc4e2 2003-09-30 devnull args[narg] = str + nr;
27 b2cfc4e2 2003-09-30 devnull if(!mflag)
28 b2cfc4e2 2003-09-30 devnull narg++;
29 b2cfc4e2 2003-09-30 devnull } else {
30 b2cfc4e2 2003-09-30 devnull if(!intok && mflag)
31 b2cfc4e2 2003-09-30 devnull narg++;
32 b2cfc4e2 2003-09-30 devnull intok = 1;
33 b2cfc4e2 2003-09-30 devnull }
34 b2cfc4e2 2003-09-30 devnull }
35 b2cfc4e2 2003-09-30 devnull return narg;
36 b2cfc4e2 2003-09-30 devnull }