libxlu: nested list support

1. Extend grammar of parser.
2. Adjust internal functions to accept XLU_ConfigValue instead of
   char *.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
This commit is contained in:
Wei Liu authored and Ian Campbell committed 2015-03-18 12:04:56 +00:00
1 parent 1a09c5113a
commit 3ba52a60ff
4 files changed
+25 -40

No files matched your search

+7 -23
View File
@@ -332,19 +332,14 @@ XLU_ConfigValue *xlu__cfg_string_mk(CfgParseContext *ctx, char *atom)
return NULL;
}
XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, char *atom)
XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx,
XLU_ConfigValue *val)
{
XLU_ConfigValue *value = NULL;
XLU_ConfigValue **values = NULL;
XLU_ConfigValue *val = NULL;
if (ctx->err) goto x;
val = malloc(sizeof(*val));
if (!val) goto xe;
val->type = XLU_STRING;
val->u.string = atom;
values = malloc(sizeof(*values));
if (!values) goto xe;
values[0] = val;
@@ -363,19 +358,17 @@ XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, char *atom)
x:
free(value);
free(values);
free(val);
free(atom);
xlu__cfg_value_free(val);
return NULL;
}
void xlu__cfg_list_append(CfgParseContext *ctx,
XLU_ConfigValue *list,
char *atom)
XLU_ConfigValue *val)
{
XLU_ConfigValue *val = NULL;
if (ctx->err) return;
assert(atom);
assert(val);
assert(list->type == XLU_LIST);
if (list->u.list.nvalues >= list->u.list.avalues) {
@@ -384,7 +377,7 @@ void xlu__cfg_list_append(CfgParseContext *ctx,
if (list->u.list.avalues > INT_MAX / 100) {
ctx->err = ERANGE;
free(atom);
xlu__cfg_value_free(val);
return;
}
@@ -393,7 +386,7 @@ void xlu__cfg_list_append(CfgParseContext *ctx,
sizeof(*new_values) * new_avalues);
if (!new_values) {
ctx->err = errno;
free(atom);
xlu__cfg_value_free(val);
return;
}
@@ -401,15 +394,6 @@ void xlu__cfg_list_append(CfgParseContext *ctx,
list->u.list.values = new_values;
}
val = malloc(sizeof(*val));
if (!val) {
ctx->err = errno;
free(atom);
return;
}
val->type = XLU_STRING;
val->u.string = atom;
list->u.list.values[list->u.list.nvalues] = val;
list->u.list.nvalues++;
}
+3 -2
View File
@@ -27,10 +27,11 @@ void xlu__cfg_set_store(CfgParseContext*, char *name,
XLU_ConfigValue *val, int lineno);
XLU_ConfigValue *xlu__cfg_string_mk(CfgParseContext *ctx,
char *atom);
XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, char *atom);
XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx,
XLU_ConfigValue *val);
void xlu__cfg_list_append(CfgParseContext *ctx,
XLU_ConfigValue *list,
char *atom);
XLU_ConfigValue *val);
void xlu__cfg_value_free(XLU_ConfigValue *value);
char *xlu__cfgl_strdup(CfgParseContext*, const char *src);
char *xlu__cfgl_dequote(CfgParseContext*, const char *src);
+13 -13
View File
@@ -377,7 +377,7 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 3
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 24
#define YYLAST 25
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 12
@@ -444,8 +444,8 @@ static const yytype_int8 yyrhs[] =
15, -1, 16, 17, -1, 17, -1, 1, 6, -1,
3, 7, 18, -1, 6, -1, 8, -1, 19, -1,
9, 22, 20, 10, -1, 4, -1, 5, -1, -1,
21, -1, 21, 11, 22, -1, 19, 22, -1, 21,
11, 22, 19, 22, -1, -1, 22, 6, -1
21, -1, 21, 11, 22, -1, 18, 22, -1, 21,
11, 22, 18, 22, -1, -1, 22, 6, -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
@@ -517,14 +517,14 @@ static const yytype_int8 yydefgoto[] =
static const yytype_int8 yypact[] =
{
-18, 4, 0, -18, -1, 6, -18, -18, -18, 3,
-18, -18, 11, -18, -18, -18, -18, -18, -18, 13,
-18, -18, 12, 10, 17, -18, -18, 13, -18, 17
-18, -18, 14, -18, -18, -18, -18, -18, -18, 11,
-18, -18, 12, 10, 18, -18, -18, 11, -18, 18
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-18, -18, -18, -18, -18, 15, -18, -17, -18, -18,
-18, -18, -18, -18, -18, 16, -17, -18, -18, -18,
-14
};
@@ -535,8 +535,8 @@ static const yytype_int8 yypgoto[] =
static const yytype_int8 yytable[] =
{
-2, 4, 21, 5, 3, 11, 6, 24, 7, 6,
28, 7, 27, 12, 29, 14, 15, 14, 15, 20,
16, 26, 25, 20, 13
28, 7, 27, 12, 29, 14, 15, 20, 14, 15,
16, 26, 25, 16, 20, 13
};
#define yypact_value_is_default(yystate) \
@@ -548,8 +548,8 @@ static const yytype_int8 yytable[] =
static const yytype_uint8 yycheck[] =
{
0, 1, 19, 3, 0, 6, 6, 21, 8, 6,
27, 8, 26, 7, 28, 4, 5, 4, 5, 6,
9, 11, 10, 6, 9
27, 8, 26, 7, 28, 4, 5, 6, 4, 5,
9, 11, 10, 9, 6, 9
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
@@ -558,7 +558,7 @@ static const yytype_uint8 yystos[] =
{
0, 13, 14, 0, 1, 3, 6, 8, 15, 16,
17, 6, 7, 17, 4, 5, 9, 18, 19, 22,
6, 19, 20, 21, 22, 10, 11, 22, 19, 22
6, 18, 20, 21, 22, 10, 11, 22, 18, 22
};
#define yyerrok (yyerrstatus = 0)
@@ -1564,14 +1564,14 @@ yyreduce:
/* Line 1806 of yacc.c */
#line 72 "libxlu_cfg_y.y"
{ (yyval.value)= xlu__cfg_list_mk(ctx,(yyvsp[(1) - (2)].string)); }
{ (yyval.value)= xlu__cfg_list_mk(ctx,(yyvsp[(1) - (2)].value)); }
break;
case 20:
/* Line 1806 of yacc.c */
#line 73 "libxlu_cfg_y.y"
{ xlu__cfg_list_append(ctx,(yyvsp[(1) - (5)].value),(yyvsp[(4) - (5)].string)); (yyval.value)= (yyvsp[(1) - (5)].value); }
{ xlu__cfg_list_append(ctx,(yyvsp[(1) - (5)].value),(yyvsp[(4) - (5)].value)); (yyval.value)= (yyvsp[(1) - (5)].value); }
break;
+2 -2
View File
@@ -69,8 +69,8 @@ valuelist: /* empty */ { $$= xlu__cfg_list_mk(ctx,NULL); }
| values { $$= $1; }
| values ',' nlok { $$= $1; }
values: atom nlok { $$= xlu__cfg_list_mk(ctx,$1); }
| values ',' nlok atom nlok { xlu__cfg_list_append(ctx,$1,$4); $$= $1; }
values: value nlok { $$= xlu__cfg_list_mk(ctx,$1); }
| values ',' nlok value nlok { xlu__cfg_list_append(ctx,$1,$4); $$= $1; }
nlok:
/* nothing */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.