[kbuild-devel] [patch] scripts: clean-whitespace.sh
After running this script with filename as parameter, look (with diff) for, what can be corrected. Only *.diff and *.patch files are handled as patches. Signed-off-by: Oleg Verych [EMAIL PROTECTED] -- Two clean rules added, that can change look of damaged lines. Yet script still fits one ordinary screen, so read the code! test cases: include/linux/ipv6.h, arch/x86_64/lib/{copy_user, memcpy}.S It's like lguest -- just for fun. clean-whitespace.sh | 28 1 file changed, 28 insertions(+) --- /dev/null 2007-04-04 10:55:19.204075250 +0200 +++ linux-just-for-fun/scripts/clean-whitespace.sh 2007-06-08 07:53:21.0 +0200 @@ -0,0 +1,28 @@ +#!/bin/sh -e +# clean whitespace damage; i/o = $1/$1.clean + +IFS='' ; t=`printf '\t'` ; s=' ' ; s4=$s$s$s$s ; w79=79 ; +i=$1 ; o=$1.clean +strip_file_end='/^$/{N;s_^\n$__;T e;:n;N;s_^.*\n\n$__;t n;:e;};' +not_patch_line='/^+[^+]/' + +case $1 in *[.]diff | *[.]patch) + file=patch ; sp='+[!+]' ; p='+' ; addr=$not_patch_line;; +esac + +sed -n ${addr:-$strip_file_end} { +s|[$t$s]*$||; # trailing whitespace +:next; # x*8 spaces on the line start - x*tabs +s|^\([\n]*\)$p\($t*\)$s4$s4|\1$p\2$t|;t next; # \n is needed after N command +s|^\([\n]*\)$p\($t*\)$s*$t|\1$p\2$t|g; # strip spaces between tabs +s|$s4$s4$s$s*|$t$t|g # more than 8 spaces - 2 tabs +s|$s*$t|$t|g # strip spaces before tab; tradeoff: may break some alignment ! +};p -- $i $o echo +please, see clean ${file:=source} file: $o + +exec expand $i | while read -r line # check for long line +do [ ${#line} -gt $w79 ] case $line in $sp*) echo \ +at least one line wider than $w79 chars, found +check your $file, please + 12 ; exit ;; esac +done - 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] scripts: clean-whitespace.sh
On Fri, Jun 08, 2007 at 04:28:49PM +0200, Sam Ravnborg wrote: On Thu, Jun 07, 2007 at 11:44:59PM -0700, Andrew Morton wrote: Then again, it's a better strategy than trying to read the code ;) Please, tell us what it does, so that we can decide whether we want it in Linux. It does the same as cleanfile.pl. I have seen no reason to replace cleanfile.pl with this version. It does better whitespace cleanup, than scripts/{cleanfile *and* cleanpatch} togather with more user, operating system kernel-friendly approach. Please, test it on proposed testcase - ipv6.h, and you will see, what i'm talking about. Patch description + script name is all one must to know to start use it *safely*. Linecount is down but so is maintainability / extendability. Really? If you think so... For those, who have (X)emacs on board, i recommend develock.el as good damage-showing tool. Sorry, Andrew, for garbage in you patch subject filters :) - 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] scripts: clean-whitespace.sh
On Thu, Jun 07, 2007 at 11:44:59PM -0700, Andrew Morton wrote: Then again, it's a better strategy than trying to read the code ;) Please, tell us what it does, so that we can decide whether we want it in Linux. It does the same as cleanfile.pl. I have seen no reason to replace cleanfile.pl with this version. Linecount is down but so is maintainability / extendability. 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] scripts: clean-whitespace.sh
On Fri, Jun 08, 2007 at 05:02:15PM +0200, Oleg Verych wrote: On Fri, Jun 08, 2007 at 04:28:49PM +0200, Sam Ravnborg wrote: On Thu, Jun 07, 2007 at 11:44:59PM -0700, Andrew Morton wrote: Then again, it's a better strategy than trying to read the code ;) Please, tell us what it does, so that we can decide whether we want it in Linux. It does the same as cleanfile.pl. I have seen no reason to replace cleanfile.pl with this version. It does better whitespace cleanup, than scripts/{cleanfile *and* cleanpatch} Made a short test here. Added the following to a file: static sam = ; clean-whitespace replaced spaces within with tabs. cleanfile did not. Seems that clean-whitespace has the wrong assumption that any sequence of tab-stop8 spacestab-stop must be replaced with a tab. It should obviously default to beginning of file. Running latest cleanfile (it is -mm) on your testfile gave following output: cleanfile: ipv6.h ipv6.h:105: line exceeds 79 characters (89) ipv6.h:111: line exceeds 79 characters (89) ipv6.h:350: line exceeds 79 characters (85) ipv6.h:356: line exceeds 79 characters (85) ipv6.h:362: line exceeds 79 characters (85) ipv6.h:386: line exceeds 79 characters (82) ipv6.h:413: line exceeds 79 characters (85) And spaces were replaced with tabs only where it is safe. 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] scripts: clean-whitespace.sh
On Fri, Jun 08, 2007 at 09:05:54PM +0200, Sam Ravnborg wrote: [] It does better whitespace cleanup, than scripts/{cleanfile *and* cleanpatch} Made a short test here. Added the following to a file: static sam = ; clean-whitespace replaced spaces within with tabs. cleanfile did not. So, user with `diff` will see that and fix or a way of usage spaces in strings, or will update BRE, used for that kind of match ;) Still, better job: |-*- [EMAIL PROTECTED]:/tmp$ ls -l ipv62.h.clean -rw-r- 1 olecom root 10591 Jun 8 22:47 ipv62.h.clean +2 bytes [EMAIL PROTECTED]:/tmp$ ls -l ipv66.h -rw-r- 1 olecom root 10704 Jun 8 22:47 ipv66.h [EMAIL PROTECTED]:/tmp$ |-*- But there will be two shifted words, because it doesn't calculate tabstops. I've choose to remove spaces before tab, so it will be visible and easy to fix by hand. Only spaces up-to next tabstop - 1 after possible tab is OK. - 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