pic_get_args can parse '*'

This commit is contained in:
Yuichi Nishiwaki 2013-11-15 22:53:41 +09:00
parent c57f1bfbe1
commit a68b470e06
1 changed files with 18 additions and 1 deletions

View File

@ -40,12 +40,17 @@ pic_get_args(pic_state *pic, const char *format, ...)
break; break;
case '|': case '|':
break; break;
case '*':
break;
} }
/* in order to run out of all arguments passed to this function /* in order to run out of all arguments passed to this function
(i.e. do va_arg for each argument), optional argument existence (i.e. do va_arg for each argument), optional argument existence
check is done in every case closure */ check is done in every case closure */
if (c == '*')
break;
switch (c) { switch (c) {
case '|': case '|':
opt = true; opt = true;
@ -240,7 +245,19 @@ pic_get_args(pic_state *pic, const char *format, ...)
} }
} }
} }
if (argc > i) { if ('*' == c) {
int *n;
pic_value **argv;
n = va_arg(ap, int *);
argv = va_arg(ap, pic_value **);
if (i <= argc) {
*n = argc - i;
*argv = &GET_OPERAND(pic, i);
i = argc;
}
}
else if (argc > i) {
pic_error(pic, "wrong number of arguments"); pic_error(pic, "wrong number of arguments");
} }
va_end(ap); va_end(ap);