/tools/maint/whitespace-detect.in
Autoconf | 150 lines | 94 code | 25 blank | 31 comment | 22 complexity | 496d0fbfa35de28e846303ca32a39740 MD5 | raw file
Possible License(s): GPL-2.0
- #! @PERL@
- # -*- perl -*-
- #
- # whitespace-detect.in
- #
- # Copyright (C) 2008, 2009 Francesco Salvestrini
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License along
- # with this program; if not, write to the Free Software Foundation, Inc.,
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- #
- use strict;
- use warnings;
- my $program = "whitespace-detect";
- my $version = "0.1";
- sub hint ($)
- {
- my $string = shift;
- if (defined($string)) {
- print "$program: " . $string . "\n";
- }
- print "Try `$program --help' for more information.\n";
- }
- sub help ()
- {
- print "Usage: $program [OPTION]... FILE...\n";
- print "\n";
- print " Check input file trailing whitespaces.\n";
- print "\n";
- print "OPTIONS:\n";
- print "\n";
- print " --help, -h display this help and exit\n";
- print " --version, -v output version information and exit\n";
- print "\n";
- print "Report bugs to <" . '@PACKAGE_BUGREPORT@' . ">\n";
- }
- sub version ()
- {
- print "$program $version\n";
- print "Written by Francesco Salvestrini.\n";
- print "\n";
- print "This is free software; see the source for copying conditions. There is NO\n";
- print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
- }
- if ($#ARGV < 0) {
- hint("Missing parameters");
- exit 1;
- }
- if (($ARGV[0] eq "--help") ||
- ($ARGV[0] eq "-h")) {
- help();
- exit 0
- }
- if (($ARGV[0] eq "--version") ||
- ($ARGV[0] eq "-v")) {
- version();
- exit 0;
- }
- my $found = 0;
- for my $i (0 .. $#ARGV) {
- my $filename;
- my $filehandle;
- $filename = $ARGV[$i];
- if (!open($filehandle, "<", $filename)) {
- print STDERR "$program: Cannot open \`" . $filename . "' for input\n";
- exit 1;
- }
- my $lineno = 0;
- my $skip = 0;
- while (<$filehandle>) {
- my $line = $_;
- $lineno++;
- # Check for continuation ending character '\'
- if ($line =~ /\\$/) {
- # Skip appended lines if previously found
- if ($skip == 1) {
- next;
- }
- my $tmp = $line;
- # Clean up the string from non-quoting characters
- $tmp =~ s/\\[\'\"]//g;
- $tmp =~ s/[^\'\"]//g;
- # Clean up balanced quoting characters
- $tmp =~ s/\'\'//g;
- $tmp =~ s/\"\"//g;
- # If the string is empty the ending '\' appends
- # the next line
- if ($tmp eq "") {
- $skip = 1;
- next;
- }
- } else {
- # This is the last appended line, skip to the next one
- $skip = 0;
- next;
- }
- if (($line =~ /^[ ]*[\t]+[ ]*/) && ($skip == 0)) {
- $found = 1;
- print STDERR
- "$program: File \`" . $filename . "' " .
- "contains initial tabs at line " . $lineno . "\n";
- #last;
- }
- if (($line =~ /[ \t]+$/) && ($skip == 0)) {
- $found = 1;
- print STDERR
- "$program: File \`" . $filename . "' " .
- "contains trailing whites at line " . $lineno . "\n";
- #last;
- }
- }
- close($filehandle);
- }
- #exit $found;
- exit 0;