1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2018 Arnon Warshavsky <arnon@qwilt.com>
4 # This awk script receives a list of expressions to monitor
5 # and a list of folders to search these expressions in
6 # - No search is done inside comments
7 # - Both additions and removals of the expressions are checked
8 # A positive balance of additions fails the check
11 split(FOLDERS,deny_folders," ");
12 split(EXPRESSIONS,deny_expr," ");
19 # search for add/remove instances in current file
20 # state machine assumes the comments structure is enforced by
27 if (index($0,comment_start) > 0) {
31 if (in_comment == 0) {
32 for (i in deny_expr) {
33 forbidden_added = "^\\+.*" deny_expr[i];
34 forbidden_removed="^-.*" deny_expr[i];
35 current = expressions[deny_expr[i]]
36 if ($0 ~ forbidden_added) {
38 expressions[deny_expr[i]] = current + 1
40 if ($0 ~ forbidden_removed) {
42 expressions[deny_expr[i]] = current - 1
47 if (index($0,comment_end) > 0) {
51 # switch to next file , check if the balance of add/remove
52 # of previous filehad new additions
53 ($0 ~ "^\\+\\+\\+ b/") {
58 for (i in deny_folders) {
59 re = "^\\+\\+\\+ b/" deny_folders[i];
68 print "Warning in " substr(last_file,7) ":"