vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

getfields.c (515B)


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