git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9255 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
a80dd369c0
commit
76ab007404
|
@ -51,6 +51,16 @@ sub error {
|
||||||
print("error: $desc at line $lineno in \"$filename\"\n");
|
print("error: $desc at line $lineno in \"$filename\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Indentation check.
|
||||||
|
sub check_indentation {
|
||||||
|
|
||||||
|
shift =~ /^(\s*)/;
|
||||||
|
if (length($1) != $i_level) {
|
||||||
|
style "indentation violation";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $emptycnt = 0;
|
||||||
foreach my $line (@c_source) {
|
foreach my $line (@c_source) {
|
||||||
|
|
||||||
$lineno += 1;
|
$lineno += 1;
|
||||||
|
@ -75,7 +85,22 @@ foreach my $line (@c_source) {
|
||||||
style "detected TAB";
|
style "detected TAB";
|
||||||
$line =~ s/$tab/ /;
|
$line =~ s/$tab/ /;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#****************************************************************************
|
||||||
|
# Check on empty lines.
|
||||||
|
my $tmp = $line;
|
||||||
|
$tmp =~ s/\s//;
|
||||||
|
if (length($tmp) == 0) {
|
||||||
|
$emptycnt = $emptycnt + 1;
|
||||||
|
if ($emptycnt == 2) {
|
||||||
|
style "detected multiple empty lines"
|
||||||
|
}
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$emptycnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#****************************************************************************
|
#****************************************************************************
|
||||||
# Stripping strings content for ease of parsing, all strings become _string_.
|
# Stripping strings content for ease of parsing, all strings become _string_.
|
||||||
$line =~ s/\\\"//;
|
$line =~ s/\\\"//;
|
||||||
|
@ -88,12 +113,8 @@ foreach my $line (@c_source) {
|
||||||
if ($state eq "start") {
|
if ($state eq "start") {
|
||||||
# Searching for a global code element or a comment start.
|
# Searching for a global code element or a comment start.
|
||||||
|
|
||||||
#****************************************************************************
|
|
||||||
# Indentation check.
|
# Indentation check.
|
||||||
$line =~ /^(\s*)/;
|
check_indentation $line;
|
||||||
if (length($1) != $i_level) {
|
|
||||||
style "indentation violation";
|
|
||||||
}
|
|
||||||
|
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
# Functions matching, triggered by the "(".
|
# Functions matching, triggered by the "(".
|
||||||
|
@ -102,6 +123,9 @@ foreach my $line (@c_source) {
|
||||||
$line =~ s/^(static|)\s*(struct|union|)\s*([a-zA-Z_][a-zA-Z0-9_]*\s*[*]*)\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\(//;
|
$line =~ s/^(static|)\s*(struct|union|)\s*([a-zA-Z_][a-zA-Z0-9_]*\s*[*]*)\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\(//;
|
||||||
# print "function: " . $1 . " " . $2 . " " . $3 . " " . $4 . "(";
|
# print "function: " . $1 . " " . $2 . " " . $3 . " " . $4 . "(";
|
||||||
|
|
||||||
|
# Size of the match up to parameters.
|
||||||
|
my $size = $+[0] - $-[0];
|
||||||
|
|
||||||
# Function line number.
|
# Function line number.
|
||||||
$f_lineno = $lineno;
|
$f_lineno = $lineno;
|
||||||
|
|
||||||
|
@ -110,12 +134,14 @@ foreach my $line (@c_source) {
|
||||||
$line =~ s/\)\s*{\s*$//;
|
$line =~ s/\)\s*{\s*$//;
|
||||||
# print $line . "\n";
|
# print $line . "\n";
|
||||||
$f_params = $line;
|
$f_params = $line;
|
||||||
|
$i_level = $indentation;
|
||||||
$state = "infunc";
|
$state = "infunc";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# print $line;
|
# print $line;
|
||||||
$state = "inparams";
|
|
||||||
$f_params = $line;
|
$f_params = $line;
|
||||||
|
$i_level = $size;
|
||||||
|
$state = "inparams";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
|
@ -214,12 +240,17 @@ foreach my $line (@c_source) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
# Scanning for params end and function body begin.
|
# Scanning for function parameters end and function body begin.
|
||||||
elsif ($state eq "inparams") {
|
elsif ($state eq "inparams") {
|
||||||
|
|
||||||
|
# Indentation check.
|
||||||
|
check_indentation $line;
|
||||||
|
|
||||||
if ($line =~ /.*\)\s*{\s*$/) {
|
if ($line =~ /.*\)\s*{\s*$/) {
|
||||||
# print $line . "\n";
|
# print $line . "\n";
|
||||||
$line =~ s/\)\s*{\s*$//;
|
$line =~ s/\)\s*{\s*$//;
|
||||||
$f_params = $f_params . $line;
|
$f_params = $f_params . $line;
|
||||||
|
$i_level = $indentation;
|
||||||
$state = "infunc";
|
$state = "infunc";
|
||||||
print "$f_params\n";
|
print "$f_params\n";
|
||||||
}
|
}
|
||||||
|
@ -231,11 +262,18 @@ foreach my $line (@c_source) {
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
# Scanning for function end.
|
# Scanning for function end.
|
||||||
elsif ($state eq "infunc") {
|
elsif ($state eq "infunc") {
|
||||||
if (($line =~ /^\}/) || ($line =~ /^\);/)) {
|
|
||||||
# Function end because the final '}' or ');' in case of a prototype.
|
# Checking for function end, the final "}".
|
||||||
|
if ($line =~ /^\}/) {
|
||||||
|
$i_level = 0;
|
||||||
$state = "start";
|
$state = "start";
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
elsif ($line =~ /(\/\*.*\*\/)/) {
|
|
||||||
|
# Indentation check.
|
||||||
|
check_indentation $line;
|
||||||
|
|
||||||
|
if ($line =~ /(\/\*.*\*\/)/) {
|
||||||
# Single line comments inside functions.
|
# Single line comments inside functions.
|
||||||
}
|
}
|
||||||
elsif ("$line" =~ /(\/\*.*)/) {
|
elsif ("$line" =~ /(\/\*.*)/) {
|
||||||
|
|
Loading…
Reference in New Issue