From c3f6a65da29adfa4e2b6e8cb59d9a479207488f7 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 27 Jul 2011 17:33:51 -0400 Subject: [PATCH] slc: correct 'min_args' and 'max_args' processing The 'min_args' and 'max_args' values were ignored whenever an 'argument' value was not present as a child of the 'command'. 'argument' values are often specified as children of the 'option' value when more than one 'option' is an argument. This patchset counts the number of 'argument' values specified under a 'command' regardless of the level at which it appears. If there are any 'argument' values, the 'min_args' and 'max_args' are used to generate validation code for the 'command'. Change-Id: Idc6129b4ff29914ac990f693b4dba51a30bdc971 --- lib/sl/slc-gram.y | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sl/slc-gram.y b/lib/sl/slc-gram.y index 39fae4313..530b1a344 100644 --- a/lib/sl/slc-gram.y +++ b/lib/sl/slc-gram.y @@ -492,11 +492,14 @@ gen_wrapper(struct assignment *as) struct assignment *tmp; char *n, *f; int nargs = 0; + int narguments = 0; name = find(as, "name"); n = strdup(name->u.value); gen_name(n); arg = find(as, "argument"); + if (arg) + narguments++; opt1 = find(as, "option"); function = find(as, "function"); if(function) @@ -547,9 +550,10 @@ gen_wrapper(struct assignment *as) fprintf(cfile, "\"%s\", ", help->u.value); else fprintf(cfile, "NULL, "); - if(aarg) + if(aarg) { fprintf(cfile, "\"%s\"", aarg->u.value); - else + narguments++; + } else fprintf(cfile, "NULL"); fprintf(cfile, " },\n"); } @@ -589,7 +593,7 @@ gen_wrapper(struct assignment *as) int min_args = -1; int max_args = -1; char *end; - if(arg == NULL) { + if(narguments == 0) { max_args = 0; } else { if((tmp = find(as, "min_args")) != NULL) {