Example #1
0
static struct grecs_value *
parse_label(const char *str)
{
	struct grecs_value *val = NULL;
	size_t i;
	struct wordsplit ws;
	size_t len = strlen (str);
  
	if (len > 1 && str[0] == '(' && str[len-1] == ')') {
		struct grecs_list *lst;
      
		ws.ws_delim = ",";
		if (wordsplit_len (str + 1, len - 2, &ws,
				      WRDSF_DEFFLAGS|WRDSF_DELIM|
				      WRDSF_WS)) {
			return NULL;
		}

		lst = grecs_value_list_create();
		for (i = 0; i < ws.ws_wordc; i++) {
			struct grecs_value *p = grecs_zalloc(sizeof(*p));
			p->type = GRECS_TYPE_STRING;
			p->v.string = ws.ws_wordv[i];
			grecs_list_append(lst, p);
		}
		val = grecs_malloc(sizeof(*val));
		val->type = GRECS_TYPE_LIST;
		val->v.list = lst;
	} else {      
		if (wordsplit(str, &ws, WRDSF_DEFFLAGS))
			return NULL;
		val = grecs_zalloc(sizeof(*val));
		if (ws.ws_wordc == 1) {
			val->type = GRECS_TYPE_STRING;
			val->v.string = ws.ws_wordv[0];
		} else {
			val->type = GRECS_TYPE_ARRAY;
			val->v.arg.c = ws.ws_wordc;
			val->v.arg.v = grecs_calloc(ws.ws_wordc,
						    sizeof(val->v.arg.v[0]));
			for (i = 0; i < ws.ws_wordc; i++) {
				val->v.arg.v[i] =
					grecs_zalloc(sizeof(*val->v.arg.v[0]));
				val->v.arg.v[i]->type = GRECS_TYPE_STRING;
				val->v.arg.v[i]->v.string = ws.ws_wordv[i];
			}
		}
	}
	ws.ws_wordc = 0;
	wordsplit_free(&ws);
	return val;
}
Example #2
0
int
wordsplit (const char *command, struct wordsplit *ws, int flags)
{
  return wordsplit_len (command, command ? strlen (command) : 0, ws,
			   flags);
}