Edje: support for parsing flag-style values (and combinantions of them) in edje_cc.

For example:

    field: FLAG_A FLAG_B FLAG_C;   // at least one flag is needed

And we can assign a bit for each FLAG_*, the result would be the OR between all of them.
Refactored a bit of parse_enum to re-use code there.


SVN revision: 34168
devs/devilhorns/wayland_egl
Caio Marcelo de Oliveira Filho 15 years ago
parent 368f148fef
commit 20df0987d1
  1. 2
      legacy/edje/src/bin/edje_cc.h
  2. 81
      legacy/edje/src/bin/edje_cc_parse.c

@ -87,12 +87,14 @@ int is_param(int n);
int is_num(int n);
char *parse_str(int n);
int parse_enum(int n, ...);
int parse_flags(int n, ...);
int parse_int(int n);
int parse_int_range(int n, int f, int t);
int parse_bool(int n);
double parse_float(int n);
double parse_float_range(int n, double f, double t);
void check_arg_count(int n);
void check_min_arg_count(int n);
int object_handler_num(void);
int statement_handler_num(void);

@ -786,54 +786,87 @@ parse_str(int n)
return s;
}
int
parse_enum(int n, ...)
static int
_parse_enum(char *str, va_list va)
{
char *str;
va_list va;
va_list va2;
va_copy(va2, va); /* iterator for the error message */
str = evas_list_nth(params, n);
if (!str)
{
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
progname, file_in, line - 1, n + 1);
exit(-1);
}
va_start(va, n);
for (;;)
{
char *s;
int v;
s = va_arg(va, char *);
/* End of the list, nothing matched. */
if (!s)
{
fprintf(stderr, "%s: Error. %s:%i token %s not one of:",
progname, file_in, line - 1, str);
va_start(va, n);
s = va_arg(va, char *);
s = va_arg(va2, char *);
while (s)
{
v = va_arg(va, int);
v = va_arg(va2, int);
fprintf(stderr, " %s", s);
s = va_arg(va, char *);
s = va_arg(va2, char *);
if (!s) break;
}
fprintf(stderr, "\n");
va_end(va2);
va_end(va);
exit(-1);
}
v = va_arg(va, int);
if (!strcmp(s, str))
{
va_end(va2);
va_end(va);
return v;
}
}
va_end(va);
return 0;
}
int
parse_enum(int n, ...)
{
char *str;
int result;
va_list va;
str = evas_list_nth(params, n);
if (!str)
{
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
progname, file_in, line - 1, n + 1);
exit(-1);
}
va_start(va, n);
result = _parse_enum(str, va);
va_end(va);
return result;
}
int
parse_flags(int n, ...)
{
char *str;
Evas_List *lst;
int result = 0;
va_list va;
va_start(va, n);
for (lst = evas_list_nth_list(params, n); lst != NULL; lst = lst->next)
result |= _parse_enum(lst->data, va);
va_end(va);
return result;
}
int
parse_int(int n)
{
@ -963,6 +996,20 @@ check_arg_count(int required_args)
}
}
void
check_min_arg_count(int min_required_args)
{
int num_args = evas_list_count (params);
if (num_args < min_required_args)
{
fprintf(stderr, "%s: Error. %s:%i got %i arguments, "
"but expected at least %i\n",
progname, file_in, line - 1, num_args, min_required_args);
exit(-1);
}
}
/* simple expression parsing stuff */
/*

Loading…
Cancel
Save