aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/cleanpatch
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 17:28:19 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 17:28:19 -0400
commitefffbeee5bc4168059683714b300d307f5193d69 (patch)
tree7fde51080f4534a86bfa27a430aaf7ef2bb8ef92 /scripts/cleanpatch
parent40b42f1ebf653cd72c32eb1a1a0b9fea2dfbfd7d (diff)
parentb824325443bb010689d22262c6a4e0feb63bad56 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild
* git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild: (33 commits) xtensa: use DATA_DATA in xtensa powerpc: add missing DATA_DATA to powerpc cris: use DATA_DATA in cris kallsyms: remove usage of memmem and _GNU_SOURCE from scripts/kallsyms.c kbuild: use -fno-optimize-sibling-calls unconditionally kconfig: reset generated values only if Kconfig and .config agree. kbuild: fix the warning when running make tags kconfig: strip 'CONFIG_' automatically in kernel configuration search kbuild: use POSIX BRE in headers install target Whitelist references from __dbe_table to .init modpost white list pattern adjustment kbuild: do section mismatch check on full vmlinux kbuild: whitelist references from variables named _timer to .init.text kbuild: remove hardcoded _logo names from modpost kbuild: remove hardcoded apic_es7000 from modpost kbuild: warn about references from .init.text to .exit.text kbuild: consolidate section checks kbuild: refactor code in modpost to improve maintainability kbuild: ignore section mismatch warnings originating from .note section kbuild: .paravirtprobe section is obsolete, so modpost doesn't need to handle it ...
Diffstat (limited to 'scripts/cleanpatch')
-rwxr-xr-xscripts/cleanpatch58
1 files changed, 55 insertions, 3 deletions
diff --git a/scripts/cleanpatch b/scripts/cleanpatch
index a53f987708f5..9680d03ad2b8 100755
--- a/scripts/cleanpatch
+++ b/scripts/cleanpatch
@@ -7,7 +7,9 @@
7use bytes; 7use bytes;
8use File::Basename; 8use File::Basename;
9 9
10# 10# Default options
11$max_width = 79;
12
11# Clean up space-tab sequences, either by removing spaces or 13# Clean up space-tab sequences, either by removing spaces or
12# replacing them with tabs. 14# replacing them with tabs.
13sub clean_space_tabs($) 15sub clean_space_tabs($)
@@ -48,9 +50,49 @@ sub clean_space_tabs($)
48 return $lo; 50 return $lo;
49} 51}
50 52
53# Compute the visual width of a string
54sub strwidth($) {
55 no bytes; # Tab alignment depends on characters
56
57 my($li) = @_;
58 my($c, $i);
59 my $pos = 0;
60 my $mlen = 0;
61
62 for ($i = 0; $i < length($li); $i++) {
63 $c = substr($li,$i,1);
64 if ($c eq "\t") {
65 $pos = ($pos+8) & ~7;
66 } elsif ($c eq "\n") {
67 $mlen = $pos if ($pos > $mlen);
68 $pos = 0;
69 } else {
70 $pos++;
71 }
72 }
73
74 $mlen = $pos if ($pos > $mlen);
75 return $mlen;
76}
77
51$name = basename($0); 78$name = basename($0);
52 79
53foreach $f ( @ARGV ) { 80@files = ();
81
82while (defined($a = shift(@ARGV))) {
83 if ($a =~ /^-/) {
84 if ($a eq '-width' || $a eq '-w') {
85 $max_width = shift(@ARGV)+0;
86 } else {
87 print STDERR "Usage: $name [-width #] files...\n";
88 exit 1;
89 }
90 } else {
91 push(@files, $a);
92 }
93}
94
95foreach $f ( @files ) {
54 print STDERR "$name: $f\n"; 96 print STDERR "$name: $f\n";
55 97
56 if (! -f $f) { 98 if (! -f $f) {
@@ -86,6 +128,7 @@ foreach $f ( @ARGV ) {
86 128
87 $in_bytes = 0; 129 $in_bytes = 0;
88 $out_bytes = 0; 130 $out_bytes = 0;
131 $lineno = 0;
89 132
90 @lines = (); 133 @lines = ();
91 134
@@ -93,10 +136,12 @@ foreach $f ( @ARGV ) {
93 $err = 0; 136 $err = 0;
94 137
95 while ( defined($line = <FILE>) ) { 138 while ( defined($line = <FILE>) ) {
139 $lineno++;
96 $in_bytes += length($line); 140 $in_bytes += length($line);
97 141
98 if (!$in_hunk) { 142 if (!$in_hunk) {
99 if ($line =~ /^\@\@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)\s\@\@/) { 143 if ($line =~
144 /^\@\@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)\s\@\@/) {
100 $minus_lines = $2; 145 $minus_lines = $2;
101 $plus_lines = $4; 146 $plus_lines = $4;
102 if ($minus_lines || $plus_lines) { 147 if ($minus_lines || $plus_lines) {
@@ -117,6 +162,13 @@ foreach $f ( @ARGV ) {
117 $text =~ s/[ \t\r]*$//; # Remove trailing spaces 162 $text =~ s/[ \t\r]*$//; # Remove trailing spaces
118 $text = clean_space_tabs($text); 163 $text = clean_space_tabs($text);
119 164
165 $l_width = strwidth($text);
166 if ($max_width && $l_width > $max_width) {
167 print STDERR
168 "$f:$lineno: adds line exceeds $max_width ",
169 "characters ($l_width)\n";
170 }
171
120 push(@hunk_lines, '+'.$text); 172 push(@hunk_lines, '+'.$text);
121 } elsif ($line =~ /^\-/) { 173 } elsif ($line =~ /^\-/) {
122 $minus_lines--; 174 $minus_lines--;