2009-02-08 22:33:26 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
# include <alloca.h>
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
#elif defined _AIX
|
|
|
|
# define alloca __alloca
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# include <malloc.h>
|
|
|
|
# define alloca _alloca
|
|
|
|
#else
|
|
|
|
# include <stddef.h>
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
# endif
|
|
|
|
void *alloca (size_t);
|
|
|
|
#endif
|
|
|
|
|
2009-10-25 04:19:12 -07:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2009-12-08 20:30:45 -08:00
|
|
|
#include <math.h>
|
2009-10-25 04:19:12 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
#include "edje_cc.h"
|
2009-12-17 03:58:15 -08:00
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_File.h>
|
2003-06-11 06:20:48 -07:00
|
|
|
|
2011-03-22 00:30:57 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
# define EPP_EXT ".exe"
|
|
|
|
#else
|
|
|
|
# define EPP_EXT
|
|
|
|
#endif
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
static void new_object(void);
|
|
|
|
static void new_statement(void);
|
2004-12-15 09:58:10 -08:00
|
|
|
static char *perform_math (char *input);
|
2003-06-11 06:20:48 -07:00
|
|
|
static int isdelim(char c);
|
|
|
|
static char *next_token(char *p, char *end, char **new_p, int *delim);
|
|
|
|
static char *stack_id(void);
|
|
|
|
static void stack_chop_top(void);
|
|
|
|
static void parse(char *data, off_t size);
|
|
|
|
|
2004-03-10 19:21:06 -08:00
|
|
|
/* simple expression parsing protos */
|
|
|
|
static int my_atoi(const char * s);
|
|
|
|
static char * _alphai(char *s, int * val);
|
|
|
|
static char * _betai(char *s, int * val);
|
|
|
|
static char * _gammai(char *s, int * val);
|
|
|
|
static char * _deltai(char *s, int * val);
|
|
|
|
static char * _get_numi(char *s, int * val);
|
|
|
|
static int _is_numi(char c);
|
|
|
|
static int _is_op1i(char c);
|
|
|
|
static int _is_op2i(char c);
|
|
|
|
static int _calci(char op, int a, int b);
|
|
|
|
|
|
|
|
static double my_atof(const char * s);
|
|
|
|
static char * _alphaf(char *s, double * val);
|
|
|
|
static char * _betaf(char *s, double * val);
|
|
|
|
static char * _gammaf(char *s, double * val);
|
|
|
|
static char * _deltaf(char *s, double * val);
|
|
|
|
static char * _get_numf(char *s, double * val);
|
|
|
|
static int _is_numf(char c);
|
|
|
|
static int _is_op1f(char c);
|
|
|
|
static int _is_op2f(char c);
|
|
|
|
static double _calcf(char op, double a, double b);
|
2004-10-13 11:07:56 -07:00
|
|
|
static int strstrip(const char *in, char *out, size_t size);
|
2004-03-10 19:21:06 -08:00
|
|
|
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
int line = 0;
|
2008-10-22 04:34:42 -07:00
|
|
|
Eina_List *stack = NULL;
|
|
|
|
Eina_List *params = NULL;
|
2003-06-11 06:20:48 -07:00
|
|
|
|
2004-03-27 21:26:17 -08:00
|
|
|
static char file_buf[4096];
|
|
|
|
static int verbatim = 0;
|
2004-04-24 21:20:58 -07:00
|
|
|
static int verbatim_line1 = 0;
|
|
|
|
static int verbatim_line2 = 0;
|
2004-03-27 21:26:17 -08:00
|
|
|
static char *verbatim_str = NULL;
|
2003-08-29 01:34:53 -07:00
|
|
|
|
2011-04-08 19:35:01 -07:00
|
|
|
static void
|
|
|
|
err_show_stack(void)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = stack_id();
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
printf("PARSE STACK:\n%s\n", s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("NO PARSE STACK\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
err_show_params(void)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
printf("PARAMS:");
|
|
|
|
EINA_LIST_FOREACH(params, l, p)
|
|
|
|
{
|
|
|
|
printf(" %s", p);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
err_show(void)
|
|
|
|
{
|
|
|
|
err_show_stack();
|
|
|
|
err_show_params();
|
|
|
|
}
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
static void
|
|
|
|
new_object(void)
|
|
|
|
{
|
|
|
|
char *id;
|
|
|
|
int i;
|
2003-06-11 07:14:23 -07:00
|
|
|
int handled = 0;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
id = stack_id();
|
|
|
|
for (i = 0; i < object_handler_num(); i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(object_handlers[i].type, id))
|
|
|
|
{
|
2003-06-11 07:14:23 -07:00
|
|
|
handled = 1;
|
|
|
|
if (object_handlers[i].func)
|
|
|
|
{
|
|
|
|
object_handlers[i].func();
|
|
|
|
}
|
|
|
|
break;
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
2004-10-05 22:25:03 -07:00
|
|
|
if (!handled)
|
|
|
|
{
|
|
|
|
for (i = 0; i < statement_handler_num(); i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(statement_handlers[i].type, id))
|
|
|
|
{
|
2004-10-19 10:39:35 -07:00
|
|
|
free(id);
|
2004-10-05 22:25:03 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-06-11 07:14:23 -07:00
|
|
|
if (!handled)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unhandled keyword %s",
|
|
|
|
progname, file_in, line - 1,
|
|
|
|
(char *)eina_list_data_get(eina_list_last(stack)));
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2003-06-11 07:14:23 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
free(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
new_statement(void)
|
|
|
|
{
|
|
|
|
char *id;
|
|
|
|
int i;
|
2003-06-11 07:14:23 -07:00
|
|
|
int handled = 0;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
id = stack_id();
|
|
|
|
for (i = 0; i < statement_handler_num(); i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(statement_handlers[i].type, id))
|
|
|
|
{
|
2003-06-11 07:14:23 -07:00
|
|
|
handled = 1;
|
|
|
|
if (statement_handlers[i].func)
|
|
|
|
{
|
|
|
|
statement_handlers[i].func();
|
|
|
|
}
|
|
|
|
break;
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
2003-06-11 07:14:23 -07:00
|
|
|
}
|
|
|
|
if (!handled)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unhandled keyword %s",
|
|
|
|
progname, file_in, line - 1,
|
|
|
|
(char *)eina_list_data_get(eina_list_last(stack)));
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2003-06-11 07:14:23 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
free(id);
|
|
|
|
}
|
|
|
|
|
2004-12-15 09:58:10 -08:00
|
|
|
static char *
|
|
|
|
perform_math (char *input)
|
|
|
|
{
|
|
|
|
char buf[256];
|
2004-12-22 06:41:12 -08:00
|
|
|
double res;
|
2004-12-15 09:58:10 -08:00
|
|
|
|
|
|
|
/* FIXME
|
2004-12-22 06:41:12 -08:00
|
|
|
* Always apply floating-point arithmetic.
|
2008-11-02 14:51:24 -08:00
|
|
|
* Does this cause problems for integer parameters? (yes it will)
|
2004-12-15 09:58:10 -08:00
|
|
|
*
|
|
|
|
* What we should do is, loop over the string and figure out whether
|
|
|
|
* there are floating point operands, too and then switch to
|
|
|
|
* floating point math.
|
|
|
|
*/
|
2008-11-02 14:51:24 -08:00
|
|
|
res = my_atof(input);
|
|
|
|
snprintf(buf, sizeof (buf), "%lf", res);
|
|
|
|
return strdup(buf);
|
2004-12-15 09:58:10 -08:00
|
|
|
}
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
static int
|
|
|
|
isdelim(char c)
|
|
|
|
{
|
2004-01-15 16:51:43 -08:00
|
|
|
const char *delims = "{},;:";
|
2003-06-11 06:20:48 -07:00
|
|
|
char *d;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
d = (char *)delims;
|
|
|
|
while (*d)
|
|
|
|
{
|
|
|
|
if (c == *d) return 1;
|
|
|
|
d++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
next_token(char *p, char *end, char **new_p, int *delim)
|
|
|
|
{
|
|
|
|
char *tok_start = NULL, *tok_end = NULL, *tok = NULL, *sa_start = NULL;
|
|
|
|
int in_tok = 0;
|
|
|
|
int in_quote = 0;
|
2004-12-15 09:58:10 -08:00
|
|
|
int in_parens = 0;
|
2003-08-29 01:34:53 -07:00
|
|
|
int in_comment_ss = 0;
|
|
|
|
int in_comment_cpp = 0;
|
|
|
|
int in_comment_sa = 0;
|
2003-06-11 06:20:48 -07:00
|
|
|
int had_quote = 0;
|
2007-07-11 13:47:28 -07:00
|
|
|
int is_escaped = 0;
|
2003-06-11 06:20:48 -07:00
|
|
|
|
|
|
|
*delim = 0;
|
|
|
|
if (p >= end) return NULL;
|
|
|
|
while (p < end)
|
|
|
|
{
|
|
|
|
if (*p == '\n')
|
|
|
|
{
|
|
|
|
in_comment_ss = 0;
|
2003-08-29 01:34:53 -07:00
|
|
|
in_comment_cpp = 0;
|
2003-06-11 06:20:48 -07:00
|
|
|
line++;
|
|
|
|
}
|
|
|
|
if ((!in_comment_ss) && (!in_comment_sa))
|
|
|
|
{
|
|
|
|
if ((!in_quote) && (*p == '/') && (p < (end - 1)) && (*(p + 1) == '/'))
|
|
|
|
in_comment_ss = 1;
|
2003-07-29 19:58:22 -07:00
|
|
|
if ((!in_quote) && (*p == '#'))
|
2003-08-29 01:34:53 -07:00
|
|
|
in_comment_cpp = 1;
|
2003-06-11 06:20:48 -07:00
|
|
|
if ((!in_quote) && (*p == '/') && (p < (end - 1)) && (*(p + 1) == '*'))
|
|
|
|
{
|
|
|
|
in_comment_sa = 1;
|
|
|
|
sa_start = p;
|
|
|
|
}
|
|
|
|
}
|
2003-08-29 01:34:53 -07:00
|
|
|
if ((in_comment_cpp) && (*p == '#'))
|
|
|
|
{
|
|
|
|
char *pp, fl[4096];
|
|
|
|
char *tmpstr = NULL;
|
|
|
|
int l, nm;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-08-29 01:34:53 -07:00
|
|
|
/* handle cpp comments */
|
|
|
|
/* their line format is
|
2011-08-12 05:39:17 -07:00
|
|
|
* #line <line no. of next line> <filename from next line on> [??]
|
2003-08-29 01:34:53 -07:00
|
|
|
*/
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-08-29 01:34:53 -07:00
|
|
|
pp = p;
|
|
|
|
while ((pp < end) && (*pp != '\n'))
|
|
|
|
{
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
l = pp - p;
|
2007-07-20 22:06:39 -07:00
|
|
|
tmpstr = alloca(l + 1);
|
2003-08-29 01:34:53 -07:00
|
|
|
if (!tmpstr)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i malloc %i bytes failed",
|
|
|
|
progname, file_in, line - 1, l + 1);
|
2003-08-29 01:34:53 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
strncpy(tmpstr, p, l);
|
|
|
|
tmpstr[l] = 0;
|
|
|
|
l = sscanf(tmpstr, "%*s %i \"%[^\"]\"", &nm, fl);
|
|
|
|
if (l == 2)
|
|
|
|
{
|
|
|
|
strcpy(file_buf, fl);
|
|
|
|
line = nm;
|
|
|
|
file_in = file_buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((!in_comment_ss) && (!in_comment_sa) && (!in_comment_cpp))
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
|
|
|
if (!in_tok)
|
|
|
|
{
|
|
|
|
if (!in_quote)
|
|
|
|
{
|
|
|
|
if (!isspace(*p))
|
|
|
|
{
|
|
|
|
if (*p == '"')
|
2003-06-19 16:56:27 -07:00
|
|
|
{
|
|
|
|
in_quote = 1;
|
|
|
|
had_quote = 1;
|
|
|
|
}
|
2004-12-15 09:58:10 -08:00
|
|
|
else if (*p == '(')
|
|
|
|
in_parens++;
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
in_tok = 1;
|
|
|
|
tok_start = p;
|
|
|
|
if (isdelim(*p)) *delim = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (in_quote)
|
|
|
|
{
|
2007-07-11 13:47:28 -07:00
|
|
|
if ((*p) == '\\')
|
|
|
|
is_escaped = !is_escaped;
|
|
|
|
else if (((*p) == '"') && (!is_escaped))
|
2003-06-19 16:56:27 -07:00
|
|
|
{
|
|
|
|
in_quote = 0;
|
|
|
|
had_quote = 1;
|
|
|
|
}
|
2007-07-11 13:47:28 -07:00
|
|
|
else if (is_escaped)
|
|
|
|
is_escaped = 0;
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
2004-12-15 09:58:10 -08:00
|
|
|
else if (in_parens)
|
|
|
|
{
|
2007-07-11 13:47:28 -07:00
|
|
|
if (((*p) == ')') && (!is_escaped))
|
2004-12-15 09:58:10 -08:00
|
|
|
in_parens--;
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*p == '"')
|
|
|
|
{
|
|
|
|
in_quote = 1;
|
|
|
|
had_quote = 1;
|
|
|
|
}
|
2004-12-15 09:58:10 -08:00
|
|
|
else if (*p == '(')
|
|
|
|
in_parens++;
|
|
|
|
|
|
|
|
/* check for end-of-token */
|
2003-06-11 06:20:48 -07:00
|
|
|
if (
|
|
|
|
(isspace(*p)) ||
|
|
|
|
((*delim) && (!isdelim(*p))) ||
|
|
|
|
(isdelim(*p))
|
|
|
|
)
|
2010-07-30 22:01:34 -07:00
|
|
|
{/*the line below this is never used because it skips to
|
|
|
|
* the 'done' label which is after the return call for
|
|
|
|
* in_tok being 0. is this intentional?
|
|
|
|
*/
|
2003-06-11 06:20:48 -07:00
|
|
|
in_tok = 0;
|
2010-07-30 22:01:34 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
tok_end = p - 1;
|
2003-06-11 07:14:23 -07:00
|
|
|
if (*p == '\n') line--;
|
2003-06-11 06:20:48 -07:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (in_comment_sa)
|
|
|
|
{
|
|
|
|
if ((*p == '/') && (*(p - 1) == '*') && ((p - sa_start) > 2))
|
|
|
|
in_comment_sa = 0;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (!in_tok) return NULL;
|
|
|
|
tok_end = p - 1;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
done:
|
|
|
|
*new_p = p;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-12 15:34:51 -07:00
|
|
|
tok = mem_alloc(tok_end - tok_start + 2);
|
2003-06-11 06:20:48 -07:00
|
|
|
strncpy(tok, tok_start, tok_end - tok_start + 1);
|
|
|
|
tok[tok_end - tok_start + 1] = 0;
|
2007-07-11 13:47:28 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
if (had_quote)
|
|
|
|
{
|
2007-07-11 13:47:28 -07:00
|
|
|
is_escaped = 0;
|
2003-06-11 06:20:48 -07:00
|
|
|
p = tok;
|
2007-07-11 13:47:28 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
while (*p)
|
|
|
|
{
|
2007-07-11 13:47:28 -07:00
|
|
|
if ((*p == '\"') && (!is_escaped))
|
2006-08-13 03:37:04 -07:00
|
|
|
{
|
|
|
|
memmove(p, p + 1, strlen(p));
|
|
|
|
}
|
2005-09-12 02:43:49 -07:00
|
|
|
else if ((*p == '\\') && (*(p + 1) == 'n'))
|
|
|
|
{
|
|
|
|
memmove(p, p + 1, strlen(p));
|
|
|
|
*p = '\n';
|
|
|
|
}
|
|
|
|
else if ((*p == '\\') && (*(p + 1) == 't'))
|
|
|
|
{
|
|
|
|
memmove(p, p + 1, strlen(p));
|
|
|
|
*p = '\t';
|
|
|
|
}
|
2006-08-13 03:37:04 -07:00
|
|
|
else if (*p == '\\')
|
|
|
|
{
|
|
|
|
memmove(p, p + 1, strlen(p));
|
|
|
|
if (*p == '\\') p++;
|
2007-07-11 13:47:28 -07:00
|
|
|
else is_escaped = 1;
|
2006-08-13 03:37:04 -07:00
|
|
|
}
|
2003-06-19 16:56:27 -07:00
|
|
|
else
|
2007-07-11 13:47:28 -07:00
|
|
|
{
|
|
|
|
if (is_escaped) is_escaped = 0;
|
|
|
|
p++;
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
2008-11-02 14:51:24 -08:00
|
|
|
else if ((tok) && (*tok == '('))
|
2007-07-11 08:33:03 -07:00
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
tmp = tok;
|
|
|
|
tok = perform_math(tok);
|
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
stack_id(void)
|
|
|
|
{
|
|
|
|
char *id;
|
|
|
|
int len;
|
2008-10-22 04:34:42 -07:00
|
|
|
Eina_List *l;
|
|
|
|
char *data;
|
2003-06-11 06:20:48 -07:00
|
|
|
|
|
|
|
len = 0;
|
2008-10-22 04:34:42 -07:00
|
|
|
EINA_LIST_FOREACH(stack, l, data)
|
|
|
|
len += strlen(data) + 1;
|
2003-06-12 15:34:51 -07:00
|
|
|
id = mem_alloc(len);
|
2003-06-11 06:20:48 -07:00
|
|
|
id[0] = 0;
|
2008-10-22 04:34:42 -07:00
|
|
|
EINA_LIST_FOREACH(stack, l, data)
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
2008-10-22 04:34:42 -07:00
|
|
|
strcat(id, data);
|
|
|
|
if (eina_list_next(l)) strcat(id, ".");
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stack_chop_top(void)
|
|
|
|
{
|
|
|
|
char *top;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
/* remove top from stack */
|
2008-10-22 04:34:42 -07:00
|
|
|
top = eina_list_data_get(eina_list_last(stack));
|
2003-06-11 06:20:48 -07:00
|
|
|
if (top)
|
|
|
|
{
|
|
|
|
free(top);
|
2008-10-22 04:34:42 -07:00
|
|
|
stack = eina_list_remove(stack, top);
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. parse error %s:%i. } marker without matching { marker",
|
|
|
|
progname, file_in, line - 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2003-06-11 06:20:48 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse(char *data, off_t size)
|
|
|
|
{
|
|
|
|
char *p, *end, *token;
|
|
|
|
int delim = 0;
|
|
|
|
int do_params = 0;
|
2003-06-16 06:55:13 -07:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
INF("%s: Parsing input file",
|
|
|
|
progname);
|
2003-06-16 06:55:13 -07:00
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
p = data;
|
|
|
|
end = data + size;
|
|
|
|
line = 1;
|
2010-08-21 06:52:25 -07:00
|
|
|
while ((token = next_token(p, end, &p, &delim)))
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
2004-10-23 18:10:04 -07:00
|
|
|
/* if we are in param mode, the only delimiter
|
|
|
|
* we'll accept is the semicolon
|
|
|
|
*/
|
|
|
|
if (do_params && delim && *token != ';')
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. parse error %s:%i. %c marker before ; marker",
|
|
|
|
progname, file_in, line - 1, *token);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2004-10-23 18:10:04 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
else if (delim)
|
|
|
|
{
|
|
|
|
if (*token == ',' || *token == ':') do_params = 1;
|
|
|
|
else if (*token == '}')
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
|
|
|
if (do_params)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. parse error %s:%i. } marker before ; marker",
|
2004-10-23 23:43:45 -07:00
|
|
|
progname, file_in, line - 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2003-06-11 06:20:48 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stack_chop_top();
|
|
|
|
}
|
2004-10-23 18:10:04 -07:00
|
|
|
else if (*token == ';')
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
|
|
|
if (do_params)
|
|
|
|
{
|
|
|
|
do_params = 0;
|
|
|
|
new_statement();
|
|
|
|
/* clear out params */
|
|
|
|
while (params)
|
|
|
|
{
|
2008-10-22 04:34:42 -07:00
|
|
|
free(eina_list_data_get(params));
|
|
|
|
params = eina_list_remove(params, eina_list_data_get(params));
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
/* remove top from stack */
|
|
|
|
stack_chop_top();
|
|
|
|
}
|
|
|
|
}
|
2004-10-23 18:10:04 -07:00
|
|
|
else if (*token == '{')
|
2003-06-11 06:20:48 -07:00
|
|
|
{
|
|
|
|
if (do_params)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. parse error %s:%i. { marker before ; marker",
|
|
|
|
progname, file_in, line - 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(token);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (do_params)
|
2008-10-22 04:34:42 -07:00
|
|
|
params = eina_list_append(params, token);
|
2003-06-11 06:20:48 -07:00
|
|
|
else
|
|
|
|
{
|
2008-10-22 04:34:42 -07:00
|
|
|
stack = eina_list_append(stack, token);
|
2003-06-11 06:20:48 -07:00
|
|
|
new_object();
|
2004-03-27 21:26:17 -08:00
|
|
|
if ((verbatim == 1) && (p < (end - 2)))
|
|
|
|
{
|
|
|
|
int escaped = 0;
|
|
|
|
int inquotes = 0;
|
|
|
|
int insquotes = 0;
|
|
|
|
int squigglie = 1;
|
2004-04-24 21:20:58 -07:00
|
|
|
int l1 = 0, l2 = 0;
|
2004-03-27 21:26:17 -08:00
|
|
|
char *verbatim_1;
|
|
|
|
char *verbatim_2;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
l1 = line;
|
|
|
|
while ((p[0] != '{') && (p < end))
|
|
|
|
{
|
|
|
|
if (*p == '\n') line++;
|
|
|
|
p++;
|
|
|
|
}
|
2004-03-27 21:26:17 -08:00
|
|
|
p++;
|
|
|
|
verbatim_1 = p;
|
|
|
|
verbatim_2 = NULL;
|
|
|
|
for (; p < end; p++)
|
|
|
|
{
|
2004-04-24 21:20:58 -07:00
|
|
|
if (*p == '\n') line++;
|
2004-03-27 21:26:17 -08:00
|
|
|
if (escaped) escaped = 0;
|
|
|
|
if (!escaped)
|
|
|
|
{
|
|
|
|
if (p[0] == '\\') escaped = 1;
|
|
|
|
else if (p[0] == '\"')
|
|
|
|
{
|
|
|
|
if (!insquotes)
|
|
|
|
{
|
|
|
|
if (inquotes) inquotes = 0;
|
|
|
|
else inquotes = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (p[0] == '\'')
|
|
|
|
{
|
|
|
|
if (!inquotes)
|
|
|
|
{
|
|
|
|
if (insquotes) insquotes = 0;
|
|
|
|
else insquotes = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((!inquotes) && (!insquotes))
|
|
|
|
{
|
|
|
|
if (p[0] == '{') squigglie++;
|
|
|
|
else if (p[0] == '}') squigglie--;
|
|
|
|
if (squigglie == 0)
|
|
|
|
{
|
|
|
|
verbatim_2 = p - 1;
|
2004-04-24 21:20:58 -07:00
|
|
|
l2 = line;
|
2004-03-27 21:26:17 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (verbatim_2 > verbatim_1)
|
|
|
|
{
|
|
|
|
int l;
|
|
|
|
char *v;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2004-03-27 21:26:17 -08:00
|
|
|
l = verbatim_2 - verbatim_1 + 1;
|
|
|
|
v = malloc(l + 1);
|
|
|
|
strncpy(v, verbatim_1, l);
|
|
|
|
v[l] = 0;
|
2004-04-24 21:20:58 -07:00
|
|
|
set_verbatim(v, l1, l2);
|
2004-03-27 21:26:17 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. parse error %s:%i. { marker does not have matching } marker",
|
|
|
|
progname, file_in, line - 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2004-03-27 21:26:17 -08:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
new_object();
|
|
|
|
verbatim = 0;
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-06-16 06:55:13 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
INF("%s: Parsing done",
|
2003-06-16 06:55:13 -07:00
|
|
|
progname);
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
|
|
|
|
2003-08-29 01:34:53 -07:00
|
|
|
static char *clean_file = NULL;
|
|
|
|
static void
|
|
|
|
clean_tmp_file(void)
|
|
|
|
{
|
|
|
|
if (clean_file) unlink(clean_file);
|
|
|
|
}
|
|
|
|
|
2004-03-27 21:26:17 -08:00
|
|
|
int
|
|
|
|
is_verbatim(void)
|
|
|
|
{
|
|
|
|
return verbatim;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
track_verbatim(int on)
|
|
|
|
{
|
|
|
|
verbatim = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-24 21:20:58 -07:00
|
|
|
set_verbatim(char *s, int l1, int l2)
|
2004-03-27 21:26:17 -08:00
|
|
|
{
|
2004-04-24 21:20:58 -07:00
|
|
|
verbatim_line1 = l1;
|
|
|
|
verbatim_line2 = l2;
|
2004-03-27 21:26:17 -08:00
|
|
|
verbatim_str = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
get_verbatim(void)
|
|
|
|
{
|
|
|
|
return verbatim_str;
|
|
|
|
}
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
int
|
|
|
|
get_verbatim_line1(void)
|
|
|
|
{
|
|
|
|
return verbatim_line1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
get_verbatim_line2(void)
|
|
|
|
{
|
|
|
|
return verbatim_line2;
|
|
|
|
}
|
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
void
|
|
|
|
compile(void)
|
|
|
|
{
|
2011-03-20 19:47:23 -07:00
|
|
|
char buf[4096], buf2[4096];
|
2005-01-09 21:51:14 -08:00
|
|
|
char inc[4096];
|
2003-08-29 01:34:53 -07:00
|
|
|
static char tmpn[4096];
|
2008-06-06 11:31:49 -07:00
|
|
|
int fd;
|
|
|
|
off_t size;
|
|
|
|
char *data, *p;
|
2010-07-02 08:37:37 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Edje_Style *stl;
|
2008-06-06 11:31:49 -07:00
|
|
|
|
2009-08-25 10:25:23 -07:00
|
|
|
if (!tmp_dir)
|
2008-06-06 11:31:49 -07:00
|
|
|
#ifdef HAVE_EVIL
|
2009-10-25 04:40:06 -07:00
|
|
|
tmp_dir = (char *)evil_tmpdir_get();
|
2008-06-06 11:31:49 -07:00
|
|
|
#else
|
2009-08-25 10:25:23 -07:00
|
|
|
tmp_dir = "/tmp";
|
2008-06-06 11:31:49 -07:00
|
|
|
#endif
|
2007-06-16 23:51:42 -07:00
|
|
|
|
2005-01-09 22:15:00 -08:00
|
|
|
strncpy(inc, file_in, 4000);
|
|
|
|
inc[4001] = 0;
|
2005-01-09 21:51:14 -08:00
|
|
|
p = strrchr(inc, '/');
|
|
|
|
if (!p) strcpy(inc, "./");
|
|
|
|
else *p = 0;
|
2011-04-08 19:35:01 -07:00
|
|
|
snprintf(tmpn, PATH_MAX, "%s/edje_cc.edc-tmp-XXXXXX", tmp_dir);
|
2003-08-29 01:34:53 -07:00
|
|
|
fd = mkstemp(tmpn);
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
int ret;
|
2004-10-24 06:47:55 -07:00
|
|
|
char *def;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-08-29 01:34:53 -07:00
|
|
|
clean_file = tmpn;
|
|
|
|
close(fd);
|
|
|
|
atexit(clean_tmp_file);
|
2004-10-24 06:47:55 -07:00
|
|
|
if (!defines)
|
|
|
|
def = mem_strdup("");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len;
|
2011-08-18 04:41:04 -07:00
|
|
|
char *define;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2004-10-24 06:47:55 -07:00
|
|
|
len = 0;
|
2011-08-18 04:41:04 -07:00
|
|
|
EINA_LIST_FOREACH(defines, l, define)
|
|
|
|
len += strlen(define) + 1;
|
2004-10-24 06:47:55 -07:00
|
|
|
def = mem_alloc(len + 1);
|
|
|
|
def[0] = 0;
|
2011-08-18 04:41:04 -07:00
|
|
|
EINA_LIST_FOREACH(defines, l, define)
|
2004-10-24 06:47:55 -07:00
|
|
|
{
|
2011-08-18 04:41:04 -07:00
|
|
|
strcat(def, define);
|
2004-10-24 06:47:55 -07:00
|
|
|
strcat(def, " ");
|
|
|
|
}
|
|
|
|
}
|
2005-12-20 20:29:16 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the input through the C pre-processor.
|
2009-12-16 16:50:43 -08:00
|
|
|
*/
|
2011-02-21 00:04:44 -08:00
|
|
|
ret = -1;
|
2011-04-24 00:36:15 -07:00
|
|
|
snprintf(buf2, sizeof(buf2), "%s/edje/utils/epp" EPP_EXT,
|
|
|
|
eina_prefix_lib_get(pfx));
|
2011-03-20 19:47:23 -07:00
|
|
|
if (ecore_file_exists(buf2))
|
2011-02-23 12:30:14 -08:00
|
|
|
{
|
2011-03-20 19:47:23 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s %s -I%s %s -o %s",
|
|
|
|
buf2, file_in, inc, def, tmpn);
|
2011-02-23 12:30:14 -08:00
|
|
|
ret = system(buf);
|
|
|
|
}
|
2011-04-04 01:30:02 -07:00
|
|
|
else
|
2009-12-17 03:58:15 -08:00
|
|
|
{
|
2011-04-04 01:30:02 -07:00
|
|
|
ERR("Error. Cannot run epp: %s", buf2);
|
|
|
|
exit(-1);
|
2009-12-17 03:58:15 -08:00
|
|
|
}
|
2005-12-20 20:29:16 -08:00
|
|
|
if (ret == EXIT_SUCCESS)
|
|
|
|
file_in = tmpn;
|
2011-04-04 01:30:02 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Error. Exit code of epp not clean: %i", ret);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2005-12-20 20:29:16 -08:00
|
|
|
free(def);
|
2003-08-29 01:34:53 -07:00
|
|
|
}
|
2009-02-19 02:13:28 -08:00
|
|
|
fd = open(file_in, O_RDONLY | O_BINARY, S_IRUSR | S_IWUSR);
|
2003-06-11 06:20:48 -07:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. cannot open file \"%s\" for input. %s",
|
|
|
|
progname, file_in, strerror(errno));
|
2003-06-11 06:20:48 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
2003-06-16 06:55:13 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
2011-04-08 19:35:01 -07:00
|
|
|
INF("%s: Opening \"%s\" for input", progname, file_in);
|
2003-06-16 06:55:13 -07:00
|
|
|
}
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-11 06:20:48 -07:00
|
|
|
size = lseek(fd, 0, SEEK_END);
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2004-10-20 09:48:58 -07:00
|
|
|
data = malloc(size);
|
2007-08-27 02:32:17 -07:00
|
|
|
if (data && (read(fd, data, size) == size))
|
2011-04-08 19:35:01 -07:00
|
|
|
parse(data, size);
|
2003-06-11 06:20:48 -07:00
|
|
|
else
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. cannot read file \"%s\". %s",
|
|
|
|
progname, file_in, strerror(errno));
|
2003-06-11 06:20:48 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
2004-10-20 09:48:58 -07:00
|
|
|
free(data);
|
2003-06-11 06:20:48 -07:00
|
|
|
close(fd);
|
2010-07-02 08:37:37 -07:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(edje_file->styles, l, stl)
|
2011-04-08 19:35:01 -07:00
|
|
|
{
|
|
|
|
if (!stl->name)
|
|
|
|
{
|
|
|
|
ERR("%s: Error. style must have a name.", progname);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2003-06-11 06:20:48 -07:00
|
|
|
}
|
2003-06-12 06:02:28 -07:00
|
|
|
|
2003-07-22 22:19:50 -07:00
|
|
|
int
|
|
|
|
is_param(int n)
|
|
|
|
{
|
|
|
|
char *str;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-07-22 22:19:50 -07:00
|
|
|
if (str) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-01-15 11:47:02 -08:00
|
|
|
is_num(int n)
|
2003-07-22 22:19:50 -07:00
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
char *end;
|
2010-09-18 17:33:45 -07:00
|
|
|
long int ret;
|
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-07-22 22:19:50 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
2004-10-23 23:43:45 -07:00
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-07-22 22:19:50 -07:00
|
|
|
}
|
|
|
|
if (str[0] == 0) return 0;
|
|
|
|
end = str;
|
2010-09-18 17:33:45 -07:00
|
|
|
ret = strtol(str, &end, 0);
|
2011-01-15 11:47:02 -08:00
|
|
|
if ((ret == LONG_MIN) || (ret == LONG_MAX))
|
|
|
|
{
|
|
|
|
n = 0; // do nothing. shut gcc warnings up
|
|
|
|
}
|
2003-07-22 22:19:50 -07:00
|
|
|
if ((end != str) && (end[0] == 0)) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-12 06:02:28 -07:00
|
|
|
char *
|
|
|
|
parse_str(int n)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
char *s;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-12 06:02:28 -07:00
|
|
|
}
|
2003-06-12 15:34:51 -07:00
|
|
|
s = mem_strdup(str);
|
2003-06-12 06:02:28 -07:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2008-04-01 14:28:28 -07:00
|
|
|
static int
|
|
|
|
_parse_enum(char *str, va_list va)
|
2003-06-12 06:02:28 -07:00
|
|
|
{
|
2008-04-01 14:28:28 -07:00
|
|
|
va_list va2;
|
|
|
|
va_copy(va2, va); /* iterator for the error message */
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-12 06:02:28 -07:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int v;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2003-06-12 06:02:28 -07:00
|
|
|
s = va_arg(va, char *);
|
2008-04-01 14:28:28 -07:00
|
|
|
|
|
|
|
/* End of the list, nothing matched. */
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!s)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
fprintf(stderr, "%s: Error. %s:%i token %s not one of:",
|
|
|
|
progname, file_in, line - 1, str);
|
2008-04-01 14:28:28 -07:00
|
|
|
s = va_arg(va2, char *);
|
2003-06-12 06:02:28 -07:00
|
|
|
while (s)
|
|
|
|
{
|
2010-01-15 12:01:42 -08:00
|
|
|
va_arg(va2, int);
|
2003-06-12 06:02:28 -07:00
|
|
|
fprintf(stderr, " %s", s);
|
2008-04-01 14:28:28 -07:00
|
|
|
s = va_arg(va2, char *);
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!s) break;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
2008-04-01 14:28:28 -07:00
|
|
|
va_end(va2);
|
2003-06-12 06:02:28 -07:00
|
|
|
va_end(va);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-12 06:02:28 -07:00
|
|
|
}
|
2008-04-01 14:28:28 -07:00
|
|
|
|
2003-06-12 06:02:28 -07:00
|
|
|
v = va_arg(va, int);
|
|
|
|
if (!strcmp(s, str))
|
|
|
|
{
|
2008-04-01 14:28:28 -07:00
|
|
|
va_end(va2);
|
2003-06-12 06:02:28 -07:00
|
|
|
va_end(va);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
2008-04-01 14:30:54 -07:00
|
|
|
va_end(va2);
|
|
|
|
va_end(va);
|
2003-06-12 06:02:28 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-01 14:28:28 -07:00
|
|
|
int
|
|
|
|
parse_enum(int n, ...)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int result;
|
|
|
|
va_list va;
|
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2008-04-01 14:28:28 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
2008-04-01 14:28:28 -07:00
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2008-04-01 14:28:28 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(va, n);
|
|
|
|
result = _parse_enum(str, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
parse_flags(int n, ...)
|
|
|
|
{
|
2008-10-22 04:34:42 -07:00
|
|
|
Eina_List *lst;
|
2008-04-01 14:28:28 -07:00
|
|
|
int result = 0;
|
|
|
|
va_list va;
|
2008-10-22 04:34:42 -07:00
|
|
|
char *data;
|
2008-04-01 14:28:28 -07:00
|
|
|
|
|
|
|
va_start(va, n);
|
2008-10-22 04:34:42 -07:00
|
|
|
EINA_LIST_FOREACH(eina_list_nth_list(params, n), lst, data)
|
|
|
|
result |= _parse_enum(data, va);
|
2008-04-01 14:28:28 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-06-12 06:02:28 -07:00
|
|
|
int
|
|
|
|
parse_int(int n)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int i;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-12 06:02:28 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
i = my_atoi(str);
|
2003-06-12 06:02:28 -07:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
parse_int_range(int n, int f, int t)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int i;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-12 06:02:28 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
i = my_atoi(str);
|
2003-06-12 06:02:28 -07:00
|
|
|
if ((i < f) || (i > t))
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i integer %i out of range of %i to %i inclusive",
|
|
|
|
progname, file_in, line - 1, i, f, t);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2003-06-12 06:02:28 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2004-10-13 11:07:56 -07:00
|
|
|
int
|
|
|
|
parse_bool(int n)
|
|
|
|
{
|
|
|
|
char *str, buf[4096];
|
|
|
|
int i;
|
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2004-10-13 11:07:56 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2004-10-13 11:07:56 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strstrip(str, buf, sizeof (buf)))
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i expression is too long",
|
|
|
|
progname, file_in, line - 1);
|
2004-10-13 11:07:56 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(buf, "false") || !strcasecmp(buf, "off"))
|
|
|
|
return 0;
|
|
|
|
if (!strcasecmp(buf, "true") || !strcasecmp(buf, "on"))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
i = my_atoi(str);
|
|
|
|
if ((i < 0) || (i > 1))
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i integer %i out of range of 0 to 1 inclusive",
|
|
|
|
progname, file_in, line - 1, i);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2004-10-13 11:07:56 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2003-06-12 06:02:28 -07:00
|
|
|
double
|
|
|
|
parse_float(int n)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
double i;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-12 06:02:28 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
i = my_atof(str);
|
2003-06-12 06:02:28 -07:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2003-07-07 00:55:18 -07:00
|
|
|
parse_float_range(int n, double f, double t)
|
2003-06-12 06:02:28 -07:00
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
double i;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2008-10-22 04:34:42 -07:00
|
|
|
str = eina_list_nth(params, n);
|
2003-06-12 06:02:28 -07:00
|
|
|
if (!str)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
|
|
|
|
progname, file_in, line - 1, n + 1);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2007-08-26 05:54:51 -07:00
|
|
|
exit(-1);
|
2003-06-12 06:02:28 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
i = my_atof(str);
|
2003-06-12 06:02:28 -07:00
|
|
|
if ((i < f) || (i > t))
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i float %3.3f out of range of %3.3f to %3.3f inclusive",
|
|
|
|
progname, file_in, line - 1, i, f, t);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2003-06-12 06:02:28 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
|
2011-04-11 05:08:03 -07:00
|
|
|
int
|
|
|
|
get_arg_count(void)
|
|
|
|
{
|
|
|
|
return eina_list_count (params);
|
|
|
|
}
|
|
|
|
|
2004-10-23 13:12:21 -07:00
|
|
|
void
|
|
|
|
check_arg_count(int required_args)
|
|
|
|
{
|
2008-10-22 04:34:42 -07:00
|
|
|
int num_args = eina_list_count (params);
|
2004-10-23 13:12:21 -07:00
|
|
|
|
|
|
|
if (num_args != required_args)
|
|
|
|
{
|
2011-04-08 19:35:01 -07:00
|
|
|
ERR("%s: Error. %s:%i got %i arguments, but expected %i",
|
|
|
|
progname, file_in, line - 1, num_args, required_args);
|
|
|
|
err_show();
|
2004-10-23 13:12:21 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 14:28:28 -07:00
|
|
|
void
|
|
|
|
check_min_arg_count(int min_required_args)
|
|
|
|
{
|
2008-10-22 04:34:42 -07:00
|
|
|
int num_args = eina_list_count (params);
|
2008-04-01 14:28:28 -07:00
|
|
|
|
|
|
|
if (num_args < min_required_args)
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i got %i arguments, "
|
|
|
|
"but expected at least %i",
|
|
|
|
progname, file_in, line - 1, num_args, min_required_args);
|
2011-04-08 19:35:01 -07:00
|
|
|
err_show();
|
2008-04-01 14:28:28 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-10 19:21:06 -08:00
|
|
|
/* simple expression parsing stuff */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* alpha ::= beta + beta || beta
|
|
|
|
* beta ::= gamma + gamma || gamma
|
|
|
|
* gamma ::= num || delta
|
|
|
|
* delta ::= '(' alpha ')'
|
2007-08-26 05:54:51 -07:00
|
|
|
*
|
2004-04-24 21:20:58 -07:00
|
|
|
*/
|
2004-03-10 19:21:06 -08:00
|
|
|
|
|
|
|
/* int set of function */
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static int
|
2009-12-08 20:30:45 -08:00
|
|
|
my_atoi(const char *s)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
char buf[4096];
|
2009-12-08 20:30:45 -08:00
|
|
|
|
|
|
|
if (!s) return 0;
|
|
|
|
if (!strstrip(s, buf, sizeof(buf)))
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i expression is too long\n",
|
|
|
|
progname, file_in, line - 1);
|
2004-04-24 21:20:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2004-10-13 11:07:56 -07:00
|
|
|
_alphai(buf, &res);
|
2004-03-10 19:21:06 -08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_deltai(char *s, int *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2004-08-24 03:06:33 -07:00
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
if ('(' != s[0])
|
2007-08-26 05:54:51 -07:00
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unexpected character at %s\n",
|
|
|
|
progname, file_in, line - 1, s);
|
2004-04-24 21:20:58 -07:00
|
|
|
return s;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
else
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
|
|
|
s++;
|
|
|
|
s = _alphai(s, val);
|
|
|
|
s++;
|
|
|
|
return s;
|
|
|
|
}
|
2009-12-08 20:30:45 -08:00
|
|
|
return s;
|
|
|
|
}
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2009-12-08 20:30:45 -08:00
|
|
|
static char *
|
|
|
|
_funci(char *s, int *val)
|
|
|
|
{
|
|
|
|
if (!strncmp(s, "floor(", 6))
|
|
|
|
{
|
|
|
|
s += 5;
|
|
|
|
s = _deltai(s, val);
|
|
|
|
*val = *val;
|
|
|
|
}
|
|
|
|
else if (!strncmp(s, "ceil(", 5))
|
|
|
|
{
|
|
|
|
s += 4;
|
|
|
|
s = _deltai(s, val);
|
|
|
|
*val = *val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unexpected character at %s\n",
|
|
|
|
progname, file_in, line - 1, s);
|
2009-12-08 20:30:45 -08:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_gammai(char *s, int *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2004-08-24 03:06:33 -07:00
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
if (_is_numi(s[0]))
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
|
|
|
s = _get_numi(s, val);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
else if ('(' == s[0])
|
|
|
|
{
|
|
|
|
s = _deltai(s, val);
|
|
|
|
return s;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
else
|
2009-12-08 20:30:45 -08:00
|
|
|
{
|
|
|
|
s = _funci(s, val);
|
2009-12-22 05:46:00 -08:00
|
|
|
// ERR("%s: Error. %s:%i unexpected character at %s\n",
|
2009-12-08 20:30:45 -08:00
|
|
|
// progname, file_in, line - 1, s);
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_betai(char *s, int *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
int a1, a2;
|
|
|
|
char op;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2009-12-08 20:30:45 -08:00
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
s = _gammai(s, &a1);
|
2004-04-24 21:20:58 -07:00
|
|
|
while (_is_op1i(s[0]))
|
|
|
|
{
|
|
|
|
op = s[0];
|
|
|
|
s++;
|
|
|
|
s = _gammai(s, &a2);
|
|
|
|
a1 = _calci(op, a1, a2);
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
(*val) = a1;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_alphai(char *s, int *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
int a1, a2;
|
|
|
|
char op;
|
2009-12-08 20:30:45 -08:00
|
|
|
|
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
s = _betai(s, &a1);
|
2004-04-24 21:20:58 -07:00
|
|
|
while (_is_op2i(s[0]))
|
|
|
|
{
|
|
|
|
op = s[0];
|
|
|
|
s++;
|
|
|
|
s = _betai(s, &a2);
|
|
|
|
a1 = _calci(op, a1, a2);
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
(*val) = a1;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_get_numi(char *s, int *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
int pos = 0;
|
2009-12-08 20:30:45 -08:00
|
|
|
|
|
|
|
if (!val) return s;
|
|
|
|
while ((('0' <= s[pos]) && ('9' >= s[pos])) ||
|
|
|
|
((0 == pos) && ('-' == s[pos])))
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
|
|
|
buf[pos] = s[pos];
|
|
|
|
pos++;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
buf[pos] = '\0';
|
|
|
|
(*val) = atoi(buf);
|
2009-12-08 20:30:45 -08:00
|
|
|
return (s + pos);
|
2004-03-10 19:21:06 -08:00
|
|
|
}
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
int
|
|
|
|
_is_numi(char c)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
if (((c >= '0') && (c <= '9')) || ('-' == c) || ('+' == c))
|
2004-04-24 21:20:58 -07:00
|
|
|
return 1;
|
2004-03-10 19:21:06 -08:00
|
|
|
else
|
2004-04-24 21:20:58 -07:00
|
|
|
return 0;
|
2004-03-10 19:21:06 -08:00
|
|
|
}
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
int
|
|
|
|
_is_op1i(char c)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2011-01-15 20:08:09 -08:00
|
|
|
switch (c)
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-08 20:30:45 -08:00
|
|
|
case '*':;
|
|
|
|
case '%':;
|
|
|
|
case '/': return 1;
|
2011-01-15 20:08:09 -08:00
|
|
|
default: break;
|
2004-04-24 21:20:58 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
int
|
|
|
|
_is_op2i(char c)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2011-01-15 20:08:09 -08:00
|
|
|
switch (c)
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-08 20:30:45 -08:00
|
|
|
case '+':;
|
|
|
|
case '-': return 1;
|
2011-01-15 20:08:09 -08:00
|
|
|
default: break;
|
2004-04-24 21:20:58 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
int
|
|
|
|
_calci(char op, int a, int b)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
switch(op)
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-08 20:30:45 -08:00
|
|
|
case '+':
|
2004-04-24 21:20:58 -07:00
|
|
|
a += b;
|
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '-':
|
2004-04-24 21:20:58 -07:00
|
|
|
a -= b;
|
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '/':
|
|
|
|
if (0 != b) a /= b;
|
2004-04-24 21:20:58 -07:00
|
|
|
else
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i divide by zero\n",
|
|
|
|
progname, file_in, line - 1);
|
2004-04-24 21:20:58 -07:00
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '*':
|
2004-04-24 21:20:58 -07:00
|
|
|
a *= b;
|
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '%':
|
|
|
|
if (0 != b) a = a % b;
|
|
|
|
else
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i modula by zero\n",
|
|
|
|
progname, file_in, line - 1);
|
2009-12-08 20:30:45 -08:00
|
|
|
return a;
|
|
|
|
default:
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unexpected character '%c'\n",
|
|
|
|
progname, file_in, line - 1, op);
|
2004-04-24 21:20:58 -07:00
|
|
|
}
|
2011-01-15 20:08:09 -08:00
|
|
|
return a;
|
2004-03-10 19:21:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* float set of functoins */
|
|
|
|
|
2004-04-24 21:20:58 -07:00
|
|
|
double
|
2009-12-08 20:30:45 -08:00
|
|
|
my_atof(const char *s)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
double res = 0;
|
|
|
|
char buf[4096];
|
2009-12-08 20:30:45 -08:00
|
|
|
|
|
|
|
if (!s) return 0;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2004-10-13 11:07:56 -07:00
|
|
|
if (!strstrip(s, buf, sizeof (buf)))
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i expression is too long",
|
|
|
|
progname, file_in, line - 1);
|
2004-04-24 21:20:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2004-10-13 11:07:56 -07:00
|
|
|
_alphaf(buf, &res);
|
2004-03-10 19:21:06 -08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_deltaf(char *s, double *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2004-08-24 03:06:33 -07:00
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
if ('(' != s[0])
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unexpected character at %s",
|
|
|
|
progname, file_in, line - 1, s);
|
2004-04-24 21:20:58 -07:00
|
|
|
return s;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
else
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
|
|
|
s++;
|
|
|
|
s = _alphaf(s, val);
|
|
|
|
s++;
|
|
|
|
}
|
2009-12-08 20:30:45 -08:00
|
|
|
return s;
|
|
|
|
}
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2009-12-08 20:30:45 -08:00
|
|
|
static char *
|
|
|
|
_funcf(char *s, double *val)
|
|
|
|
{
|
|
|
|
if (!strncmp(s, "floor(", 6))
|
|
|
|
{
|
|
|
|
s += 5;
|
|
|
|
s = _deltaf(s, val);
|
|
|
|
*val = floor(*val);
|
|
|
|
}
|
|
|
|
else if (!strncmp(s, "ceil(", 5))
|
|
|
|
{
|
|
|
|
s += 4;
|
|
|
|
s = _deltaf(s, val);
|
|
|
|
*val = ceil(*val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unexpected character at %s\n",
|
|
|
|
progname, file_in, line - 1, s);
|
2009-12-08 20:30:45 -08:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_gammaf(char *s, double *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2004-08-24 03:06:33 -07:00
|
|
|
if (!val) return NULL;
|
2009-12-08 20:30:45 -08:00
|
|
|
|
2004-03-10 19:21:06 -08:00
|
|
|
if (_is_numf(s[0]))
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
|
|
|
s = _get_numf(s, val);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
else if ('(' == s[0])
|
|
|
|
{
|
|
|
|
s = _deltaf(s, val);
|
|
|
|
return s;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
else
|
2009-12-08 20:30:45 -08:00
|
|
|
{
|
|
|
|
s = _funcf(s, val);
|
2009-12-22 05:46:00 -08:00
|
|
|
// ERR("%s: Error. %s:%i unexpected character at %s\n",
|
2009-12-08 20:30:45 -08:00
|
|
|
// progname, file_in, line - 1, s);
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_betaf(char *s, double *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
double a1=0, a2=0;
|
|
|
|
char op;
|
2009-12-08 20:30:45 -08:00
|
|
|
|
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
s = _gammaf(s, &a1);
|
2004-04-24 21:20:58 -07:00
|
|
|
while (_is_op1f(s[0]))
|
|
|
|
{
|
|
|
|
op = s[0];
|
|
|
|
s++;
|
|
|
|
s = _gammaf(s, &a2);
|
|
|
|
a1 = _calcf(op, a1, a2);
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
(*val) = a1;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_alphaf(char *s, double *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
double a1=0, a2=0;
|
|
|
|
char op;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2009-12-08 20:30:45 -08:00
|
|
|
if (!val) return NULL;
|
2004-03-10 19:21:06 -08:00
|
|
|
s = _betaf(s, &a1);
|
2004-04-24 21:20:58 -07:00
|
|
|
while (_is_op2f(s[0]))
|
|
|
|
{
|
|
|
|
op = s[0];
|
|
|
|
s++;
|
|
|
|
s = _betaf(s, &a2);
|
|
|
|
a1 = _calcf(op, a1, a2);
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
(*val) = a1;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static char *
|
2009-12-08 20:30:45 -08:00
|
|
|
_get_numf(char *s, double *val)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
int pos = 0;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2009-12-08 20:30:45 -08:00
|
|
|
if (!val) return s;
|
2007-08-26 05:54:51 -07:00
|
|
|
|
2009-12-08 20:30:45 -08:00
|
|
|
while ((('0' <= s[pos]) && ('9' >= s[pos])) ||
|
2004-04-24 21:20:58 -07:00
|
|
|
('.' == s[pos]) ||
|
2009-12-08 20:30:45 -08:00
|
|
|
((0 == pos) && ('-' == s[pos])))
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
|
|
|
buf[pos] = s[pos];
|
|
|
|
pos++;
|
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
buf[pos] = '\0';
|
|
|
|
(*val) = atof(buf);
|
|
|
|
return (s+pos);
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static int
|
2004-04-24 21:20:58 -07:00
|
|
|
_is_numf(char c)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
2007-08-26 05:54:51 -07:00
|
|
|
if (((c >= '0') && (c <= '9'))
|
|
|
|
|| ('-' == c)
|
2004-04-24 21:20:58 -07:00
|
|
|
|| ('.' == c)
|
|
|
|
|| ('+' == c))
|
|
|
|
return 1;
|
2011-01-15 20:13:37 -08:00
|
|
|
return 0;
|
2004-03-10 19:21:06 -08:00
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static int
|
2004-04-24 21:20:58 -07:00
|
|
|
_is_op1f(char c)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
switch(c)
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-08 20:30:45 -08:00
|
|
|
case '*':;
|
|
|
|
case '%':;
|
|
|
|
case '/': return 1;
|
2011-01-15 20:08:49 -08:00
|
|
|
default: break;
|
2004-04-24 21:20:58 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static int
|
2004-04-24 21:20:58 -07:00
|
|
|
_is_op2f(char c)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
switch(c)
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-08 20:30:45 -08:00
|
|
|
case '+':;
|
|
|
|
case '-': return 1;
|
2011-01-15 20:08:49 -08:00
|
|
|
default: break;
|
2004-04-24 21:20:58 -07:00
|
|
|
}
|
2004-03-10 19:21:06 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-24 03:06:33 -07:00
|
|
|
static double
|
2004-04-24 21:20:58 -07:00
|
|
|
_calcf(char op, double a, double b)
|
2004-03-10 19:21:06 -08:00
|
|
|
{
|
|
|
|
switch(op)
|
2004-04-24 21:20:58 -07:00
|
|
|
{
|
2009-12-08 20:30:45 -08:00
|
|
|
case '+':
|
2004-04-24 21:20:58 -07:00
|
|
|
a += b;
|
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '-':
|
2004-04-24 21:20:58 -07:00
|
|
|
a -= b;
|
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '/':
|
2004-04-24 21:20:58 -07:00
|
|
|
if (b != 0) a /= b;
|
|
|
|
else
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i divide by zero\n",
|
|
|
|
progname, file_in, line - 1);
|
2004-04-24 21:20:58 -07:00
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '*':
|
2004-04-24 21:20:58 -07:00
|
|
|
a *= b;
|
|
|
|
return a;
|
2009-12-08 20:30:45 -08:00
|
|
|
case '%':
|
|
|
|
if (0 != b) a = (double)((int)a % (int)b);
|
|
|
|
else
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i modula by zero\n",
|
|
|
|
progname, file_in, line - 1);
|
2009-12-08 20:30:45 -08:00
|
|
|
return a;
|
|
|
|
default:
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i unexpected character '%c'\n",
|
|
|
|
progname, file_in, line - 1, op);
|
2004-04-24 21:20:58 -07:00
|
|
|
}
|
2011-01-15 20:08:49 -08:00
|
|
|
return a;
|
2004-03-10 19:21:06 -08:00
|
|
|
}
|
2004-10-13 11:07:56 -07:00
|
|
|
|
|
|
|
static int
|
|
|
|
strstrip(const char *in, char *out, size_t size)
|
|
|
|
{
|
|
|
|
if ((size -1 ) < strlen(in))
|
|
|
|
{
|
2009-12-22 05:46:00 -08:00
|
|
|
ERR("%s: Error. %s:%i expression is too long",
|
2004-10-23 23:43:45 -07:00
|
|
|
progname, file_in, line - 1);
|
2004-10-13 11:07:56 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* remove spaces and tabs */
|
|
|
|
while (*in)
|
|
|
|
{
|
|
|
|
if ((0x20 != *in) && (0x09 != *in))
|
|
|
|
{
|
|
|
|
*out = *in;
|
|
|
|
out++;
|
|
|
|
}
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|