diff options
Diffstat (limited to 'compute_scripts.awk')
-rwxr-xr-x | compute_scripts.awk | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/compute_scripts.awk b/compute_scripts.awk index 2d7ea72..1db79e0 100755 --- a/compute_scripts.awk +++ b/compute_scripts.awk @@ -38,6 +38,8 @@ BEGIN { directive_args_patterns["ENDIF"] = "^$" directive_args_patterns["ELSE"] = "^$" directive_args_patterns["ELIF"] = "^(NOT[[:space:]]+)?" identifier_re "$" + directive_args_patterns["DEFINE"] = "^" identifier_re "$" + directive_args_patterns["UNDEF"] = "^" identifier_re "$" directive_args_patterns["ERROR"] = "^.*$" directive_args_patterns["COPY"] = "^[^[:space:]]+$" directive_args_patterns["INCLUDE"] = "^[^[:space:]]+$" @@ -57,6 +59,8 @@ BEGIN { directive_args_patterns["LOADJS"] = "^[^[:space:]]+$" directive_args_patterns["LOADCSS"] = "^[^[:space:]]+$" + + directive_args_patterns["LOADHTML"] = "^[^[:space:]]+$" } function validate_path(read_path, path, line) { @@ -200,7 +204,7 @@ function process_file(path, read_path, mode, sub(/[[:space:]].*$/, "", directive) if (directive !~ \ - /^(IF|ENDIF|ELSE|ELIF|ERROR|INCLUDE|INCLUDE_VERBATIM|COPY_FILE)$/ && + /^(IF|ENDIF|ELSE|ELIF|DEFINE|UNDEF|ERROR|INCLUDE|INCLUDE_VERBATIM|COPY_FILE)$/ && (mode != "js" || directive !~ /^(IMPORT|FROM|EXPORT)$/) && (mode != "html" || directive !~ /^(LOADJS|LOADCSS)$/) && (mode != "manifest" || directive !~ /^(LOADJS|LOADHTML)$/)) { @@ -222,7 +226,7 @@ function process_file(path, read_path, mode, if (directive == "IF") { if (if_nesting_true == if_nesting) { - if (if_condition_true(directive_args)) + if (if_condition_true(directive_args, path)) if_nesting_true++ else if_branch_processed = false @@ -261,7 +265,7 @@ function process_file(path, read_path, mode, } if (if_nesting == if_nesting_true + 1 && !if_branch_processed && - if_condition_true(directive_args)) { + if_condition_true(directive_args, path)) { if_nesting_true++ } else if (if_nesting == if_nesting_true) { if_branch_processed = true @@ -269,6 +273,10 @@ function process_file(path, read_path, mode, } } else if (if_nesting_true != if_nesting) { continue + } else if (directive == "DEFINE") { + defines[path,directive_args] + } else if (directive == "UNDEF") { + delete defines[path,directive_args] } else if (directive == "ERROR") { printf "ERROR: File %s says: %s\n", read_path, directive_args > "/dev/stderr" @@ -332,7 +340,7 @@ function process_file(path, read_path, mode, delete reading[read_path] } -function if_condition_true(directive_args, +function if_condition_true(directive_args, path, result, bool, first_iter, word, negated, alt) { first_iter = true @@ -344,7 +352,7 @@ function if_condition_true(directive_args, negated = word ~ /^!/ sub(/^!/, "", word) - bool = (word in defines) != negated + bool = (word in defines || (path,word) in defines) != negated if (first_iter) { result = bool |