diff options
Diffstat (limited to 'compute_scripts.awk')
-rwxr-xr-x | compute_scripts.awk | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/compute_scripts.awk b/compute_scripts.awk index b778934..e17d12c 100755 --- a/compute_scripts.awk +++ b/compute_scripts.awk @@ -28,7 +28,12 @@ BEGIN { path_ext_re = "(\\.[-_.a-zA-Z0-9]*)?" path_re = "^" path_dir_re identifier_re path_ext_re "$" - directive_args_patterns["IF"] = "^(NOT[[:space:]]+)?" identifier_re "$" + if_clause_re = "!?" identifier_re + if_AND_re = "([[:space:]]+&&[[:space:]]+" if_clause_re ")*" + if_OR_re = "([[:space:]]+[|][|][[:space:]]+" if_clause_re ")*" + + directive_args_patterns["IF"] = ("^" if_clause_re \ + "(" if_AND_re "|" if_OR_re ")$") directive_args_patterns["ENDIF"] = "^$" directive_args_patterns["ELSE"] = "^$" directive_args_patterns["ELIF"] = "^(NOT[[:space:]]+)?" identifier_re "$" @@ -215,8 +220,7 @@ function process_file(path, read_path, mode, if (directive == "IF") { if (if_nesting_true == if_nesting) { - if ((last_token(directive_args) in defines) == \ - (directive_args ~ /^[^[:space:]]+$/)) + if (if_condition_true(directive_args)) if_nesting_true++ else if_branch_processed = false @@ -255,8 +259,7 @@ function process_file(path, read_path, mode, } if (if_nesting == if_nesting_true + 1 && !if_branch_processed && - (last_token(directive_args) in defines) == \ - (directive_args ~ /^[^[:space:]]+$/)) { + if_condition_true(directive_args)) { if_nesting_true++ } else if (if_nesting == if_nesting_true) { if_branch_processed = true @@ -323,6 +326,35 @@ function process_file(path, read_path, mode, delete reading[read_path] } +function if_condition_true(directive_args, + result, bool, first_iter, word, negated, alt) { + first_iter = true + + while (directive_args) { + word = first_token(directive_args) + sub(/^[^[:space:]]+[[:space:]]*/, "", directive_args) + alt = alt || directive_args ~ /^[|][|]/ + sub(/^[^[:space:]]+[[:space:]]*/, "", directive_args) + + negated = word ~ /^!/ + sub(/^!/, "", word) + bool = (word in defines) != negated + + if (first_iter) { + result = bool + first_iter = false + continue + } + + if (alt) + result = result || bool + else # if (directive_args ~ /^AND/) + result = result && bool + } + + return result +} + function include_file(root_path, read_path, included_path, line, verbatim, read_line, result) { if (validate_path(read_path, included_path, line)) |