From: Charlie Brej Date: Tue, 30 Jun 2009 19:29:16 +0000 (+0100) Subject: [script] Add support for an "else" after an "if" X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fbcb8312c3ab5d7c571125ddb53a1d9459188eea;p=thirdparty%2Fplymouth.git [script] Add support for an "else" after an "if" --- diff --git a/src/plugins/splash/script/script-execute.c b/src/plugins/splash/script/script-execute.c index f2edcccf..3320208e 100644 --- a/src/plugins/splash/script/script-execute.c +++ b/src/plugins/splash/script/script-execute.c @@ -847,6 +847,7 @@ script_return script_execute_function (script_state* state, script_function* fun script_return script_execute (script_state* state, script_op* op) { script_return reply = {SCRIPT_RETURN_TYPE_NORMAL, NULL}; + if (!op) return reply; switch (op->type){ case SCRIPT_OP_TYPE_EXPRESSION: { @@ -864,7 +865,10 @@ script_return script_execute (script_state* state, script_op* op) { script_obj* obj = script_evaluate (state, op->data.cond_op.cond); if (script_obj_as_bool(obj)){ - reply = script_execute (state, op->data.cond_op.op); // FIXME propagate break + reply = script_execute (state, op->data.cond_op.op1); + } + else { + reply = script_execute (state, op->data.cond_op.op2); } script_obj_unref(obj); break; @@ -875,7 +879,7 @@ script_return script_execute (script_state* state, script_op* op) while (1){ obj = script_evaluate (state, op->data.cond_op.cond); if (script_obj_as_bool(obj)){ - reply = script_execute (state, op->data.cond_op.op); // FIXME handle break + reply = script_execute (state, op->data.cond_op.op1); script_obj_unref(obj); switch (reply.type) { case SCRIPT_RETURN_TYPE_NORMAL: diff --git a/src/plugins/splash/script/script-parse.c b/src/plugins/splash/script/script-parse.c index e6133a58..7ee20f60 100644 --- a/src/plugins/splash/script/script-parse.c +++ b/src/plugins/splash/script/script-parse.c @@ -536,11 +536,22 @@ static script_op* script_parse_if_while (ply_scan_t* scan) curtoken = ply_scan_get_next_token(scan); script_op* cond_op = script_parse_op(scan); + script_op* else_op = NULL; + + curtoken = ply_scan_get_current_token(scan); + if (type == SCRIPT_OP_TYPE_IF && + curtoken->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER && + !strcmp(curtoken->data.string, "else")){ + curtoken = ply_scan_get_next_token(scan); + else_op = script_parse_op(scan); + } + script_op* op = malloc(sizeof(script_op)); op->type = type; op->data.cond_op.cond = cond; - op->data.cond_op.op = cond_op; + op->data.cond_op.op1 = cond_op; + op->data.cond_op.op2 = else_op; return op; } @@ -773,6 +784,7 @@ static void script_parse_exp_free (script_exp* exp) void script_parse_op_free (script_op* op) { + if (!op) return; switch (op->type){ case SCRIPT_OP_TYPE_EXPRESSION: { @@ -788,7 +800,8 @@ void script_parse_op_free (script_op* op) case SCRIPT_OP_TYPE_WHILE: { script_parse_exp_free (op->data.cond_op.cond); - script_parse_op_free (op->data.cond_op.op); + script_parse_op_free (op->data.cond_op.op1); + script_parse_op_free (op->data.cond_op.op2); break; } { diff --git a/src/plugins/splash/script/script.h b/src/plugins/splash/script/script.h index c26d6453..30d6144d 100644 --- a/src/plugins/splash/script/script.h +++ b/src/plugins/splash/script/script.h @@ -177,7 +177,8 @@ typedef struct script_op ply_list_t* list; struct { script_exp* cond; - struct script_op* op; + struct script_op* op1; + struct script_op* op2; } cond_op; struct { script_exp* name;