]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add support for an "else" after an "if"
authorCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 30 Jun 2009 19:29:16 +0000 (20:29 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 30 Jun 2009 19:29:16 +0000 (20:29 +0100)
src/plugins/splash/script/script-execute.c
src/plugins/splash/script/script-parse.c
src/plugins/splash/script/script.h

index f2edcccf76c3ed88fd31a3a160d97af853428826..3320208eb6ba830e08d8481c1bee83329448d344 100644 (file)
@@ -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:
index e6133a5863a4411988fd731df693e1d4c37bbd4f..7ee20f6008f1012425f8ccbf3751a38fa2c38204 100644 (file)
@@ -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;
         }
         {
index c26d645309a6f64f0f8408494d1bf2c29993ab50..30d6144d4aaa641588fefeaec868a005f2eacd53 100644 (file)
@@ -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;