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
24 if (index($0,comment_start) > 0) {
28 if (in_comment == 0) {
29 for (i in deny_expr) {
30 forbidden_added = "^\\+.*" deny_expr[i];
31 forbidden_removed="^-.*" deny_expr[i];
32 current = expressions[deny_expr[i]]
33 if ($0 ~ forbidden_added) {
35 expressions[deny_expr[i]] = current + 1
37 if ($0 ~ forbidden_removed) {
39 expressions[deny_expr[i]] = current - 1
44 if (index($0,comment_end) > 0) {
48 # switch to next file , check if the balance of add/remove
49 # of previous filehad new additions
50 ($0 ~ "^\\+\\+\\+ b/") {
55 for (i in deny_folders) {
56 re = "^\\+\\+\\+ b/" deny_folders[i];
57 if ($0 ~ deny_folders[i]) {
65 print "Warning in " substr(last_file,6) ":"