From 5da375c829d2bc5afdfd98c898339fb90175032f Mon Sep 17 00:00:00 2001 From: Oxore Date: Fri, 23 Jun 2017 01:57:44 +0700 Subject: codestyle.pl - code style checker added; *.[c|h]: trailing whitespaces are removed --- codestyle.pl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 codestyle.pl (limited to 'codestyle.pl') diff --git a/codestyle.pl b/codestyle.pl new file mode 100755 index 0000000..20b074d --- /dev/null +++ b/codestyle.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +sub ln80 { + my $file = $_[0]; + $/ = "\n"; + open(FILE, $_[0]) + or die("$file: no such file or direcory\n"); + while () { + chomp; + 1 while $_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; + if (length($_) > 80) { + print "WRN: in $file line $. has ".length($_)."/80 chars\n"; + } + } + close (FILE); +} + +sub eolSpace { + my $file = $_[0]; + $/ = "\n"; + open(FILE, $_[0]) + or die("$file: no such file or direcory\n"); + while () { + chomp; + if ($_ =~ /\s+$/) { + print "WRN: in $file line $. has trailing whitespaces\n"; + } + } + close (FILE); +} + +if (not $ARGV[0]) { + open(LS, 'find -name \*.\[c\|h\] |'); + while () { + chomp; + my $string = $_; + eolSpace($string); + ln80($string); + } +} else { + local $/ = " "; + foreach my $arg(@ARGV) { + ln80($arg); + eolSpace($arg); + } +} -- cgit v1.2.3