Re: [kbuild-devel] [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines
On Tue, Jun 05, 2007 at 09:33:35AM +0200, Oleg Verych wrote: Hallo. On Sun, Jun 03, 2007 at 10:47:00PM +0200, Sam Ravnborg wrote: Subject: [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines From: H. Peter Anvin [EMAIL PROTECTED] Date: Fri, 25 May 2007 17:58:26 -0700 Make the cleanfile and cleanpatch script warn about long lines, by default lines whose visual width exceeds 79 characters. Per suggestion from Auke Kok. Signed-off-by: H. Peter Anvin [EMAIL PROTECTED] Signed-off-by: Sam Ravnborg [EMAIL PROTECTED] Thank you, Sam, for sending messages back in Kbuild list again. I have ~30k backlog in LKML, so that thing is good. Delete them all - it only hurst a few minutes ;-) So, there are some new scripts. What if my proposition will be better, so to speak? Any problems i'm willing to fix/enhance. Note: only one copy of the file required. Sym-linked name *diff* or *patch* will process patches. I know, that symlinks in sources isn't good, thus change $0 - $1 will process first parameter. Sorry - but I really do not get your point here. Are you trying to say that current cleanpatch is not good enough or do you propose a new script to do something similar? We do not want everyones favorite patch preprocessing script in the kernel. So the only option is to incorporate changes in cleanpatch. If on the other hand you are proposing a script to clean whitespace damage in the code then git already does this nicely. I do not recall the actual receipt but searching the git mailing list should reveal it. So for whitespace cleanup we should use git but maybe via a small helper script. Sam - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ kbuild-devel mailing list kbuild-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kbuild-devel
Re: [kbuild-devel] [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines
On Tue, Jun 05, 2007 at 10:19:59AM +0200, Sam Ravnborg wrote: [] So, there are some new scripts. What if my proposition will be better, so to speak? Any problems i'm willing to fix/enhance. Note: only one copy of the file required. Sym-linked name *diff* or *patch* will process patches. I know, that symlinks in sources isn't good, thus change $0 - $1 will process first parameter. Sorry - but I really do not get your point here. Are you trying to say that current cleanpatch is not good enough or do you propose a new script to do something similar? Better means, less bloated scripts in the source tree to make userspace suck less... We do not want everyones favorite patch preprocessing script in the kernel. So the only option is to incorporate changes in cleanpatch. I don't see scripts/clean* in .21, so decided, to make a hopefully better, nicer unix-way and posix re-write, this morning. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ kbuild-devel mailing list kbuild-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kbuild-devel
Re: [kbuild-devel] [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines
On Tue, Jun 05, 2007 at 04:12:54PM +0200, Sam Ravnborg wrote: On Tue, Jun 05, 2007 at 03:38:34PM +0200, Oleg Verych wrote: On Tue, Jun 05, 2007 at 10:19:59AM +0200, Sam Ravnborg wrote: [] If on the other hand you are proposing a script to clean whitespace damage in the code then git already does this nicely. I've read that too quickly, sorry. What then all that clean scripts are for? cleanfile compress spaces to tabs where appropriate. It does more than just warn about too long lines and remove leading whitespace. Ah! It's not an occasion, that this script does job of two, you are referring to. I should add documentation to this script, that will far longer, that script itself. -*- slightly i/o optimized clean-whitespace.sh -*- #!/bin/sh -e # clean whitespace damage; i/o=stdin/stdout # IFS='' ; t=`printf '\t'` ; s=' ' ; s7=$s$s$s$s$s$s$s ; w79=79 ; case $0 in *diff* | *patch*) p='+' ; s='';; esac expand | while read line do case $line in ++*) echo $line;; $p*) [ ${#line} -gt $w79 ] : ${long:=line} echo $line | sed /^$p/{s_ *\$__;s_^$p$s7${s}_$p${t}_;s_$s7 _${t}_g} ;; *) echo $line;; esac done [ -n $long ] echo at least one line, wider than $w79 chars, found 12 -*- First line stops word splitting, puts tab symbol in t, space in s, seven spaces to s7 and line width limit to w79. Second -- adjust set variables for need of unified diff processing, if name of the script $0 (can be changed to match command-line parameters) have diff or patch. Last -- bark, if there is at least one line longer that w79. Rest is processing of files/patches to expand(posix tool) tabs to spaces then: - patches are processed only by lines, starting from `+', but not `++' - remove trailing whitespace; - substitute eight spaces to one tab symbol - patches have linestart`+tab' expanded to seven spaces, due to `+' and tabstop, thus seven spaces are substituted in this case. Anything else, if have not noticed in whitespace damage matching can be added on request ;) Please look at latest -git tree if you are trying to improve the clean* scripts or add counterparts. Thanks, Sam - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ kbuild-devel mailing list kbuild-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kbuild-devel
Re: [kbuild-devel] [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines
On Tue, Jun 05, 2007 at 04:57:59PM +0200, Oleg Verych wrote: [] expand | while read line do case $line in ++*) echo $line;; $p*) [ ${#line} -gt $w79 ] : ${long:=line} echo $line | sed /^$p/{s_ *\$__;s_^$p$s7${s}_$p${t}_;s_$s7 _${t}_g} ;; *) echo $line;; esac done [ -n $long ] echo at least one line, wider than $w79 chars, found 12 -*- [] Last -- bark, if there is at least one line longer that w79. Well, if test will be in the pipe end, i.e. ... | { while; test lingth; } - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ kbuild-devel mailing list kbuild-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kbuild-devel
[kbuild-devel] [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines
Subject: [PATCH 08/19] scripts: Make cleanfile/cleanpatch warn about long lines From: H. Peter Anvin [EMAIL PROTECTED] Date: Fri, 25 May 2007 17:58:26 -0700 Make the cleanfile and cleanpatch script warn about long lines, by default lines whose visual width exceeds 79 characters. Per suggestion from Auke Kok. Signed-off-by: H. Peter Anvin [EMAIL PROTECTED] Signed-off-by: Sam Ravnborg [EMAIL PROTECTED] --- scripts/cleanfile | 54 ++- scripts/cleanpatch | 58 +-- 2 files changed, 107 insertions(+), 5 deletions(-) diff --git a/scripts/cleanfile b/scripts/cleanfile index f1ba8aa..cefd29e 100755 --- a/scripts/cleanfile +++ b/scripts/cleanfile @@ -7,7 +7,9 @@ use bytes; use File::Basename; -# +# Default options +$max_width = 79; + # Clean up space-tab sequences, either by removing spaces or # replacing them with tabs. sub clean_space_tabs($) @@ -48,9 +50,49 @@ sub clean_space_tabs($) return $lo; } +# Compute the visual width of a string +sub strwidth($) { +no bytes; # Tab alignment depends on characters + +my($li) = @_; +my($c, $i); +my $pos = 0; +my $mlen = 0; + +for ($i = 0; $i length($li); $i++) { + $c = substr($li,$i,1); + if ($c eq \t) { + $pos = ($pos+8) ~7; + } elsif ($c eq \n) { + $mlen = $pos if ($pos $mlen); + $pos = 0; + } else { + $pos++; + } +} + +$mlen = $pos if ($pos $mlen); +return $mlen; +} + $name = basename($0); -foreach $f ( @ARGV ) { [EMAIL PROTECTED] = (); + +while (defined($a = shift(@ARGV))) { +if ($a =~ /^-/) { + if ($a eq '-width' || $a eq '-w') { + $max_width = shift(@ARGV)+0; + } else { + print STDERR Usage: $name [-width #] files...\n; + exit 1; + } +} else { + push(@files, $a); +} +} + +foreach $f ( @files ) { print STDERR $name: $f\n; if (! -f $f) { @@ -90,8 +132,10 @@ foreach $f ( @ARGV ) { @blanks = (); @lines = (); +$lineno = 0; while ( defined($line = FILE) ) { + $lineno++; $in_bytes += length($line); $line =~ s/[ \t\r]*$//; # Remove trailing spaces $line = clean_space_tabs($line); @@ -107,6 +151,12 @@ foreach $f ( @ARGV ) { @blanks = (); $blank_bytes = 0; } + + $l_width = strwidth($line); + if ($max_width $l_width $max_width) { + print STDERR + $f:$lineno: line exceeds $max_width characters ($l_width)\n; + } } # Any blanks at the end of the file are discarded diff --git a/scripts/cleanpatch b/scripts/cleanpatch index a53f987..9680d03 100755 --- a/scripts/cleanpatch +++ b/scripts/cleanpatch @@ -7,7 +7,9 @@ use bytes; use File::Basename; -# +# Default options +$max_width = 79; + # Clean up space-tab sequences, either by removing spaces or # replacing them with tabs. sub clean_space_tabs($) @@ -48,9 +50,49 @@ sub clean_space_tabs($) return $lo; } +# Compute the visual width of a string +sub strwidth($) { +no bytes; # Tab alignment depends on characters + +my($li) = @_; +my($c, $i); +my $pos = 0; +my $mlen = 0; + +for ($i = 0; $i length($li); $i++) { + $c = substr($li,$i,1); + if ($c eq \t) { + $pos = ($pos+8) ~7; + } elsif ($c eq \n) { + $mlen = $pos if ($pos $mlen); + $pos = 0; + } else { + $pos++; + } +} + +$mlen = $pos if ($pos $mlen); +return $mlen; +} + $name = basename($0); -foreach $f ( @ARGV ) { [EMAIL PROTECTED] = (); + +while (defined($a = shift(@ARGV))) { +if ($a =~ /^-/) { + if ($a eq '-width' || $a eq '-w') { + $max_width = shift(@ARGV)+0; + } else { + print STDERR Usage: $name [-width #] files...\n; + exit 1; + } +} else { + push(@files, $a); +} +} + +foreach $f ( @files ) { print STDERR $name: $f\n; if (! -f $f) { @@ -86,6 +128,7 @@ foreach $f ( @ARGV ) { $in_bytes = 0; $out_bytes = 0; +$lineno = 0; @lines = (); @@ -93,10 +136,12 @@ foreach $f ( @ARGV ) { $err = 0; while ( defined($line = FILE) ) { + $lineno++; $in_bytes += length($line); if (!$in_hunk) { - if ($line =~ /[EMAIL PROTECTED]@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)[EMAIL PROTECTED]@/) { + if ($line =~ + /[EMAIL PROTECTED]@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)[EMAIL PROTECTED]@/) { $minus_lines = $2; $plus_lines = $4; if ($minus_lines || $plus_lines) { @@ -117,6 +162,13 @@ foreach $f ( @ARGV ) { $text =~ s/[ \t\r]*$//; # Remove trailing spaces $text = clean_space_tabs($text); + $l_width = strwidth($text); +