summaryrefslogtreecommitdiff
path: root/navit/command.c
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2012-07-16 11:41:31 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2012-07-16 11:41:31 +0000
commit83fa0438510c35d9023aec2c980724af73258867 (patch)
tree9e398927e9eaf895b3660a48e48f89878161d943 /navit/command.c
parent87b4f3933dd3dee64702c0a15beed89b2723d85a (diff)
downloadnavit-svn-83fa0438510c35d9023aec2c980724af73258867.tar.gz
Add:Core:Integrated obj_filter.c into command.c
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5190 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/command.c')
-rw-r--r--navit/command.c77
1 files changed, 58 insertions, 19 deletions
diff --git a/navit/command.c b/navit/command.c
index 84fb1f27..1ed24947 100644
--- a/navit/command.c
+++ b/navit/command.c
@@ -15,7 +15,6 @@
#include "command.h"
#include "event.h"
#include "navit_nls.h"
-#include "obj_filter.h"
/*
gui.fullscreen=!gui.fullscreen
@@ -195,7 +194,6 @@ command_get_attr(struct context *ctx, struct result *res)
static void
command_set_attr(struct context *ctx, struct result *res, struct result *newres)
{
- int result=0;
enum attr_type attr_type=command_attr_type(res);
struct object_func *func=object_func_lookup(res->attr.type);
if (!func || !func->set_attr)
@@ -210,7 +208,7 @@ command_set_attr(struct context *ctx, struct result *res, struct result *newres)
g_free(tmp);
}
newres->attr.type=attr_type;
- result=func->set_attr(res->attr.u.data, &newres->attr);
+ func->set_attr(res->attr.u.data, &newres->attr);
*res=*newres;
}
@@ -287,8 +285,6 @@ static void
eval_value(struct context *ctx, struct result *res) {
const char *op;
int len,dots=0;
- struct obj_filter_t out;
- int parsed_chars;
op=ctx->expr;
res->varlen=0;
@@ -299,18 +295,6 @@ eval_value(struct context *ctx, struct result *res) {
while (g_ascii_isspace(*op)) {
op++;
}
-
- parsed_chars = parse_obj_filter(op, &out);
- if (parsed_chars) {
- struct attr* res_attr = filter_object(ctx->attr, out.iterator_type, out.filter_expr, out.idx);
- if (res_attr) {
- res->attr = *res_attr;
- g_free(res_attr);
- ctx->expr = op+parsed_chars;
- return;
- }
- }
-
if ((op[0] >= 'a' && op[0] <= 'z') || op[0] == '_') {
res->attr.type=attr_none;
res->var=op;
@@ -486,6 +470,34 @@ eval_postfix(struct context *ctx, struct result *res)
res->attrnlen=tmp.varlen;
dump(res);
} else if (op[0] == '[') {
+ resolve_object(ctx, res);
+ if (ctx->error) return;
+ if (get_op(ctx,0,"@",NULL)) {
+ struct object_func *obj_func=object_func_lookup(res->attr.type);
+ struct attr_iter *iter;
+ struct attr attr;
+ enum attr_type attr_type=command_attr_type(res);
+ void *obj=res->attr.u.data;
+ if (!obj_func) {
+ dbg(0,"no object func\n");
+ return;
+ }
+ if (!obj_func->iter_new || !obj_func->iter_destroy) {
+ dbg(0,"no iter func\n");
+ return;
+ }
+ iter = obj_func->iter_new(NULL);
+ res->attr.type=attr_none;
+ res->attr.u.data=NULL;
+ res->varlen=0;
+ while (obj_func->get_attr(obj, attr_type, &attr, iter)) {
+ if (command_evaluate_to_boolean(&attr, ctx->expr, &ctx->error))
+ res->attr=attr;
+ }
+ obj_func->iter_destroy(iter);
+ if (ctx->error) return;
+ ctx->expr+=command_evaluate_to_length(ctx->expr, &ctx->error);
+ }
if (!get_op(ctx,0,"]",NULL)) {
ctx->error=missing_closing_bracket;
return;
@@ -587,12 +599,24 @@ eval_equality(struct context *ctx, struct result *res)
eval_additive(ctx, &tmp);
if (ctx->error) return;
+ resolve(ctx, res, NULL);
+ resolve(ctx, &tmp, NULL);
switch (op[0]) {
case '=':
- set_int(ctx, res, (get_int(ctx, res) == get_int(ctx, &tmp)));
+ if (res->attr.type == attr_none || tmp.attr.type == attr_none) {
+ set_int(ctx, res, 0);
+ } else if (ATTR_IS_STRING(res->attr.type) && ATTR_IS_STRING(tmp.attr.type))
+ set_int(ctx, res, (!strcmp(get_string(ctx, res),get_string(ctx, &tmp))));
+ else
+ set_int(ctx, res, (get_int(ctx, res) == get_int(ctx, &tmp)));
break;
case '!':
- set_int(ctx, res, (get_int(ctx, res) != get_int(ctx, &tmp)));
+ if (res->attr.type == attr_none || tmp.attr.type == attr_none) {
+ set_int(ctx, res, 1);
+ } else if (ATTR_IS_STRING(res->attr.type) && ATTR_IS_STRING(tmp.attr.type))
+ set_int(ctx, res, (!!strcmp(get_string(ctx, res),get_string(ctx, &tmp))));
+ else
+ set_int(ctx, res, (get_int(ctx, res) != get_int(ctx, &tmp)));
break;
case '<':
if (op[1] == '=') {
@@ -900,6 +924,21 @@ command_evaluate_to_boolean(struct attr *attr, const char *expr, int *error)
return ret;
}
+int
+command_evaluate_to_length(const char *expr, int *error)
+{
+ struct attr attr;
+ struct result res;
+ struct context ctx;
+
+ attr.type=attr_none;
+ attr.u.data=NULL;
+ command_evaluate_to(&attr, expr, &ctx, &res);
+ if (!ctx.error)
+ return ctx.expr-expr;
+ return 0;
+}
+
void
command_evaluate(struct attr *attr, const char *expr)
{