From 6e02ec2767aff848585d7eb035dfe777d7dd1569 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 24 Jul 2013 18:54:18 -0500 Subject: [PATCH] Update: finish writing the if operation Looks like I never fully finished it. This should just about do it. Testing is needed. --- sources/sh/kit-operation-if | 54 ++++++++++++++++++++++++++++----------------- sources/sh/kit-rule | 10 +++++++++ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/sources/sh/kit-operation-if b/sources/sh/kit-operation-if index 68d1cef..2027d42 100755 --- a/sources/sh/kit-operation-if +++ b/sources/sh/kit-operation-if @@ -4,6 +4,7 @@ # # type values: # - is: perform a comparison against the value of some variable. +# - not: perform an inverse comparison against the value of some variable. # - like: perform comparison against the value of some variable, using regex. TODO: pcre? grep? # - end: terminate an if block. # @@ -29,11 +30,11 @@ kit_operation_if_resume() { if [[ $(fss_basic_read -t -n if_condition $resume_path$resume_file) -gt 0 ]] ; then condition=$(fss_basic_read -n if_condition -c 0 $resume_path$resume_file) - if [[ $(kit_fss_has_error) != "" ]] ; then + if [[ $(kit_fss_has_error) == "" ]] ; then + if_condition=$condition + else kit_operation_error "Error while processing the if data '${c_notice}if_condition$c_error' from the resume file '$c_notice$resume_path$resume_file$c_error', cannot resume" fi - - if_condition=$condition fi } @@ -44,7 +45,10 @@ kit_operation_if() { local r_value= local safe_object= local safe_content= - local position= + local found= + local reserved= + local dynamic= + local permission= # operation controls local parent=$parent-$self @@ -52,7 +56,9 @@ kit_operation_if() { kit_operation_message - # TODO: if if_condition is already set, present error then return + if [[ $(kit_core_is_empty $if_condition) != "" ]] ; then + kit_operation_error "The '${c_notice}if_condition$c_error' cannot be called while in another if statememt. Nesting is unsupported." + fi type=$(echo object $line | fss_extended_read -c 0 -s 0) name=$(echo object $line | fss_extended_read -c 0 -s 1) @@ -62,40 +68,48 @@ kit_operation_if() { kit_operation_error "The '${c_notice}type$c_error' parameter for the '$c_notice$operation$c_error' operation is missing" fi - if [[ $type == "is" ]] ; then + if [[ $type == "is" || $type == "not" ]] ; then if [[ $(kit_core_is_empty $name) == "" ]] ; then kit_operation_error "The '${c_notice}name$c_error' parameter for the '$c_notice$operation$c_error' operation is missing" fi - position=$(kit_reserved_is $name) + found=$(kit_reserved_is $name) - if [[ $(kit_core_is_empty $position) == "" ]] ; then - position=$(kit_dynamic_is $name) + if [[ $(kit_core_is_empty $found) == "" ]] ; then + found=$(kit_dynamic_is $name) - if [[ $(kit_core_is_empty $position) == "" ]] ; then - position=$(kit_permission_is $name) + if [[ $(kit_core_is_empty $found) == "" ]] ; then + found=$(kit_permission_is $name) - if [[ $(kit_core_is_empty $position) == "" ]] ; then + if [[ $(kit_core_is_empty $found) == "" ]] ; then l_value= - # TODO: if variable does not exist, print error and return. + + kit_operation_error "There is no variable by the name of '$c_notice$name$c_error' for the '$c_notice$operation$c_error' operation" else kit_permission_get $name - l_value=$reserved + l_value=$permission fi else kit_dynamic_get $name - l_value=$reserved + l_value=$dynamic fi - # TODO: also check for non-reserved variables. else kit_reserved_get $name l_value=$reserved fi - if [[ $l_value == $r_value ]] ; then - if_condition=true - else - if_condition=false + if [[ $type == "is" ]] ; then + if [[ $l_value == $r_value ]] ; then + if_condition=true + else + if_condition=false + fi + elif [[ $type == "not" ]] ; then + if [[ $l_value != $r_value ]] ; then + if_condition=true + else + if_condition=false + fi fi sed -i -e '/^[[:space:]]*if_condition\>[[:space:]]*/d' $resume_path$resume_file diff --git a/sources/sh/kit-rule b/sources/sh/kit-rule index dac6133..0272f59 100755 --- a/sources/sh/kit-rule +++ b/sources/sh/kit-rule @@ -217,6 +217,8 @@ kit_rule() { kit_operation_path_resume kit_operation_version_resume + kit_operation_if_resume + kit_dynamic_inline_resume else resume_execution= @@ -263,6 +265,13 @@ kit_rule() { kit_dynamic_process inline "$parent-$rule" + if [[ $if_condition == "false" ]] ; then + kit_log_message message "skipping operation '${operation}' on line $line_number because the current if state is false." + + let c++ + continue + fi + case $operation in "shell") kit_operation_shell ;; "version") kit_operation_version ;; @@ -275,6 +284,7 @@ kit_rule() { "library") kit_operation_library ;; "strip") kit_operation_strip ;; "path") kit_operation_path ;; + "if") kit_operation_if ;; *) kit_message_warning "No such operation called '$c_notice$operation$c_reset'" esac -- 1.8.3.1