#/usr/bin/perl

# Usage: nostrict lint [lint_args]

# Build bit vectors with 1's for protected lines.  We use vecs
# rather than normal arrays in order to save (lots of) memory.

for $arg (@ARGV) {
    next unless $arg =~ /\.[ch]$/;
    open(IN,$arg);
    while (<IN>) {
	if (m#/\*\s*NOSTRICT\s*\*/# .. m#;\s*($|/\*)#) {
	    vec($ok{$arg}, $., 1) = 1;
	}
    }
    close IN;
}

# Now run the command as an input pipe.

open(LINT, "-|") || exec @ARGV;

# Note that in this loop, a "next" defaults to printing the
# line.  We null out $_ if we *don't* want to print it.

while (<LINT>) {
    $curfile = $1 if /^(\S+\.[ch])\b/;
    next unless (($file,$line) = /(\S+)\((\d+)\)/)
	|| ($line) = /^\s*\((\d+)\)/;
    $file =~ s/\?$//;
    $file = $curfile unless $file;
    next unless defined $ok{$file};
    $_ = '' if vec($ok{$file}, $line, 1);

    # Some lines contain two references.

    next unless ($file,$line) = /::\s*(\S+)\((\d+)\)/;
    $file =~ s/\?$//;
    next unless defined $ok{$file};
    $_ = '' if vec($ok{$file}, $line, 1);
}
continue {
    print;
}