#include "debug.h"
#include "callback.h"
#include "command.h"
+#include "event.h"
+#include "navit_nls.h"
/*
-gui.fullscreen()
+gui.fullscreen=!gui.fullscreen
gui.menu()
gui.get_data()
zoom_in()
return ret;
}
-static int
+/*static int
is_int(struct result *res)
{
return 1;
-}
+}*/
static int
is_double(struct result *res)
static void
dump(struct result *res)
{
+#if 0
char object[res->varlen+1];
char attribute[res->attrnlen+1];
if (res->var)
attribute[res->attrnlen]='\0';
dbg(0,"type:%s\n", attr_to_name(res->attr.type));
dbg(0,"attribute '%s' from '%s'\n", attribute, object);
+#endif
}
static enum attr_type
resolve(struct context *ctx, struct result *res, struct attr *parent) //FIXME What is that parent for?
{
resolve_object(ctx, res);
- if (res->attr.type >= attr_type_object_begin && res->attr.type <= attr_type_object_end) {
- if (res->attrn)
- command_get_attr(ctx, res);
- return;
- }
+ if (res->attrn)
+ command_get_attr(ctx, res);
}
static double
op++;
}
- if (op[0] >= 'a' && op[0] <= 'z') {
+ if ((op[0] >= 'a' && op[0] <= 'z') || op[0] == '_') {
res->attr.type=attr_none;
res->var=op;
- while ((op[0] >= 'a' && op[0] <= 'z') || op[0] == '_') {
- res->varlen++;
- op++;
+ for (;;) {
+ while ((op[0] >= 'a' && op[0] <= 'z') || op[0] == '_') {
+ res->varlen++;
+ op++;
+ }
+ if (res->varlen == 3 && !strncmp(res->var,"new",3) && op[0] == ' ') {
+ res->varlen++;
+ op++;
+ } else
+ break;
}
ctx->expr=op;
return;
if (res->attrn)
strncpy(function, res->attrn, res->attrnlen);
function[res->attrnlen]='\0';
- dbg(0,"function=%s\n", function);
+ dbg(1,"function=%s\n", function);
if (ctx->expr[0] != ')') {
list=eval_list(ctx);
if (ctx->error) return;
ctx->error=missing_closing_brace;
return;
}
- if (command_object_get_attr(ctx, &res->attr, attr_callback_list, &cbl)) {
- int valid;
- dbg(0,"function call %s from %s\n",function, attr_to_name(res->attr.type));
- callback_list_call_attr_4(cbl.u.callback_list, attr_command, function, list, NULL, &valid);
+ if (!strcmp(function,"_") && list && list[0] && list[0]->type >= attr_type_string_begin && list[0]->type <= attr_type_string_end) {
+ res->attr.type=list[0]->type;
+ res->attr.u.str=g_strdup(gettext(list[0]->u.str));
+
+ } if (!strncmp(function,"new ",4)) {
+ enum attr_type attr_type=attr_from_name(function+4);
+ if (attr_type != attr_none) {
+ struct object_func *func=object_func_lookup(attr_type);
+ if (func && func->new) {
+ res->attr.type=attr_type;
+ res->attr.u.data=func->new(NULL, list);
+ }
+ }
+ } else {
+ if (command_object_get_attr(ctx, &res->attr, attr_callback_list, &cbl)) {
+ int valid;
+ dbg(1,"function call %s from %s\n",function, attr_to_name(res->attr.type));
+ callback_list_call_attr_4(cbl.u.callback_list, attr_command, function, list, NULL, &valid);
+ }
+ res->attr.type=attr_none;
}
res->var=NULL;
res->varlen=0;
res->attrn=NULL;
res->attrnlen=0;
- res->attr.type=attr_none;
}
static void
return;
}
} else if (op[0] == '(') {
- dbg(0,"function call\n");
+ dbg(1,"function call\n");
resolve_object(ctx, res);
command_call_function(ctx, res);
}
if (!get_op(ctx,0,"=",NULL)) return;
eval_conditional(ctx, &tmp);
if (ctx->error) return;
+ resolve(ctx, &tmp, NULL);
+ if (ctx->error) return;
resolve_object(ctx, res);
command_set_attr(ctx, res, &tmp);
}
attr_list_free(ret);
return NULL;
}
+ resolve(ctx, &tmp, NULL);
ret=attr_generic_add_attr(ret, &tmp.attr);
if (!get_op(ctx,0,",",NULL)) return ret;
}
}
#endif
-void
+static void
command_evaluate_to(struct attr *attr, char *expr, struct context *ctx, struct result *res)
{
memset(res, 0, sizeof(*res));
if (!ctx.error)
resolve(&ctx, &res, NULL);
if (error)
- *error=ctx.error;
+ *error=&ctx.error;
}
{
struct result res;
struct context ctx;
- char *ret;
+ char *ret=NULL;
command_evaluate_to(attr, expr, &ctx, &res);
if (!ctx.error)
+ resolve(&ctx, &res, NULL);
+ if (!ctx.error)
ret=get_string(&ctx, &res);
if (error)
- *error=ctx.error;
+ *error=&ctx.error;
if (ctx.error)
return NULL;
else
{
struct result res;
struct context ctx;
- char *ret;
+ int ret=0;
command_evaluate_to(attr, expr, &ctx, &res);
if (!ctx.error)
+ resolve(&ctx, &res, NULL);
+ if (!ctx.error)
ret=get_int(&ctx, &res);
if (error)
- *error=ctx.error;
+ *error=&ctx.error;
if (ctx.error)
return 0;
else
return ret;
}
+int
+command_evaluate_to_boolean(struct attr *attr, char *expr, int **error)
+{
+ struct result res;
+ struct context ctx;
+ int ret=0;
+
+ command_evaluate_to(attr, expr, &ctx, &res);
+ if (!ctx.error)
+ resolve(&ctx, &res, NULL);
+ if (!ctx.error) {
+ if (res.attr.type == attr_none)
+ ret=0;
+ else if ((res.attr.type >= attr_type_int_begin && res.attr.type <= attr_type_int_end) ||
+ (res.attr.type >= attr_type_double_begin && res.attr.type <= attr_type_double_end))
+ ret=get_int(&ctx, &res);
+ else
+ ret=res.attr.u.data != NULL;
+ }
+ if (error)
+ *error=&ctx.error;
+ if (ctx.error)
+ return 0;
+ else
+ return ret;
+}
+
void
command_evaluate(struct attr *attr, char *expr)
{
}
void
+command_add_table_attr(struct command_table *table, int count, void *data, struct attr *attr)
+{
+ attr->type=attr_callback;
+ attr->u.callback=callback_new_attr_3(callback_cast(command_table_call),attr_command, table, count, data);
+}
+
+void
command_add_table(struct callback_list *cbl, struct command_table *table, int count, void *data)
{
- struct callback *cb=callback_new_attr_3(callback_cast(command_table_call),attr_command, table, count, data);
- callback_list_add(cbl, cb);
+ struct attr attr;
+ command_add_table_attr(table, count, data, &attr);
+ callback_list_add(cbl, attr.u.callback);
}
void