History

checkpatch: add an index variable for fixed lines

Make the fix code a bit easier to read. This should also start to allow an easier mechanism to insert/delete lines eventually too.

Joe Perches committed 12 years ago

Commit 194f66f1 parent c00df191 file · +60 −54Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+60−54
@@ -583,6 +583,8 @@ $chk_signoff = 0 if ($file); · 582 unmodified lines
583my @rawlines = ();583my @rawlines = ();
584my @lines = ();584my @lines = ();
585my @fixed = ();585my @fixed = ();
586my $fixlinenr = -1;
587
586my $vname;588my $vname;
587for my $filename (@ARGV) {589for my $filename (@ARGV) {
588 my $FILE;590 my $FILE;
@@ -611,6 +613,7 @@ for my $filename (@ARGV) { · 22 unmodified lines
611 @rawlines = ();613 @rawlines = ();
612 @lines = ();614 @lines = ();
613 @fixed = ();615 @fixed = ();
616 $fixlinenr = -1;
614}617}
615 618
616exit($exit);619exit($exit);
@@ -1801,8 +1804,10 @@ sub process { · 1184 unmodified lines
1801 1804
1802 $realcnt = 0;1805 $realcnt = 0;
1803 $linenr = 0;1806 $linenr = 0;
1807 $fixlinenr = -1;
1804 foreach my $line (@lines) {1808 foreach my $line (@lines) {
1805 $linenr++;1809 $linenr++;
1810 $fixlinenr++;
1806 my $sline = $line; #copy of $line1811 my $sline = $line; #copy of $line
1807 $sline =~ s/$;/ /g; #with comments as spaces1812 $sline =~ s/$;/ /g; #with comments as spaces
1808 1813
@@ -1933,7 +1938,7 @@ sub process { · 124 unmodified lines
1933 if (WARN("BAD_SIGN_OFF",1938 if (WARN("BAD_SIGN_OFF",
1934 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&1939 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
1935 $fix) {1940 $fix) {
1936 $fixed[$linenr - 1] =1941 $fixed[$fixlinenr] =
1937 "$ucfirst_sign_off $email";1942 "$ucfirst_sign_off $email";
1938 }1943 }
1939 }1944 }
@@ -1941,7 +1946,7 @@ sub process { · 1 unmodified line
1941 if (WARN("BAD_SIGN_OFF",1946 if (WARN("BAD_SIGN_OFF",
1942 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&1947 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
1943 $fix) {1948 $fix) {
1944 $fixed[$linenr - 1] =1949 $fixed[$fixlinenr] =
1945 "$ucfirst_sign_off $email";1950 "$ucfirst_sign_off $email";
1946 }1951 }
1947 1952
@@ -1950,7 +1955,7 @@ sub process { · 2 unmodified lines
1950 if (WARN("BAD_SIGN_OFF",1955 if (WARN("BAD_SIGN_OFF",
1951 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&1956 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
1952 $fix) {1957 $fix) {
1953 $fixed[$linenr - 1] =1958 $fixed[$fixlinenr] =
1954 "$ucfirst_sign_off $email";1959 "$ucfirst_sign_off $email";
1955 }1960 }
1956 }1961 }
@@ -2089,14 +2094,14 @@ sub process { · 132 unmodified lines
2089 if (ERROR("DOS_LINE_ENDINGS",2094 if (ERROR("DOS_LINE_ENDINGS",
2090 "DOS line endings\n" . $herevet) &&2095 "DOS line endings\n" . $herevet) &&
2091 $fix) {2096 $fix) {
2092 $fixed[$linenr - 1] =~ s/[\s\015]+$//;2097 $fixed[$fixlinenr] =~ s/[\s\015]+$//;
2093 }2098 }
2094 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {2099 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
2095 my $herevet = "$here\n" . cat_vet($rawline) . "\n";2100 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
2096 if (ERROR("TRAILING_WHITESPACE",2101 if (ERROR("TRAILING_WHITESPACE",
2097 "trailing whitespace\n" . $herevet) &&2102 "trailing whitespace\n" . $herevet) &&
2098 $fix) {2103 $fix) {
2099 $fixed[$linenr - 1] =~ s/\s+$//;2104 $fixed[$fixlinenr] =~ s/\s+$//;
2100 }2105 }
2101 2106
2102 $rpt_cleaners = 1;2107 $rpt_cleaners = 1;
@@ -2235,7 +2240,7 @@ sub process { · 132 unmodified lines
2235 if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",2240 if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
2236 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&2241 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
2237 $fix) {2242 $fix) {
2238 $fixed[$linenr - 1] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;2243 $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
2239 }2244 }
2240 2245
2241 }2246 }
@@ -2272,7 +2277,7 @@ sub process { · 30 unmodified lines
2272 if (ERROR("CODE_INDENT",2277 if (ERROR("CODE_INDENT",
2273 "code indent should use tabs where possible\n" . $herevet) &&2278 "code indent should use tabs where possible\n" . $herevet) &&
2274 $fix) {2279 $fix) {
2275 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;2280 $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
2276 }2281 }
2277 }2282 }
2278 2283
@@ -2282,9 +2287,9 @@ sub process { · 3 unmodified lines
2282 if (WARN("SPACE_BEFORE_TAB",2287 if (WARN("SPACE_BEFORE_TAB",
2283 "please, no space before tabs\n" . $herevet) &&2288 "please, no space before tabs\n" . $herevet) &&
2284 $fix) {2289 $fix) {
2285 while ($fixed[$linenr - 1] =~2290 while ($fixed[$fixlinenr] =~
2286 s/(^\+.*) {8,8}+\t/$1\t\t/) {}2291 s/(^\+.*) {8,8}+\t/$1\t\t/) {}
2287 while ($fixed[$linenr - 1] =~2292 while ($fixed[$fixlinenr] =~
2288 s/(^\+.*) +\t/$1\t/) {}2293 s/(^\+.*) +\t/$1\t/) {}
2289 }2294 }
2290 }2295 }
@@ -2318,7 +2323,7 @@ sub process { · 27 unmodified lines
2318 if (CHK("PARENTHESIS_ALIGNMENT",2323 if (CHK("PARENTHESIS_ALIGNMENT",
2319 "Alignment should match open parenthesis\n" . $hereprev) &&2324 "Alignment should match open parenthesis\n" . $hereprev) &&
2320 $fix && $line =~ /^\+/) {2325 $fix && $line =~ /^\+/) {
2321 $fixed[$linenr - 1] =~2326 $fixed[$fixlinenr] =~
2322 s/^\+[ \t]*/\+$goodtabindent/;2327 s/^\+[ \t]*/\+$goodtabindent/;
2323 }2328 }
2324 }2329 }
@@ -2329,7 +2334,7 @@ sub process { · 4 unmodified lines
2329 if (CHK("SPACING",2334 if (CHK("SPACING",
2330 "No space is necessary after a cast\n" . $herecurr) &&2335 "No space is necessary after a cast\n" . $herecurr) &&
2331 $fix) {2336 $fix) {
2332 $fixed[$linenr - 1] =~2337 $fixed[$fixlinenr] =~
2333 s/(\(\s*$Type\s*\))[ \t]+/$1/;2338 s/(\(\s*$Type\s*\))[ \t]+/$1/;
2334 }2339 }
2335 }2340 }
@@ -2433,7 +2438,7 @@ sub process { · 97 unmodified lines
2433 if (WARN("LEADING_SPACE",2438 if (WARN("LEADING_SPACE",
2434 "please, no spaces at the start of a line\n" . $herevet) &&2439 "please, no spaces at the start of a line\n" . $herevet) &&
2435 $fix) {2440 $fix) {
2436 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;2441 $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
2437 }2442 }
2438 }2443 }
2439 2444
@@ -2798,10 +2803,10 @@ sub process { · 358 unmodified lines
2798 if (ERROR("C99_COMMENTS",2803 if (ERROR("C99_COMMENTS",
2799 "do not use C99 // comments\n" . $herecurr) &&2804 "do not use C99 // comments\n" . $herecurr) &&
2800 $fix) {2805 $fix) {
2801 my $line = $fixed[$linenr - 1];2806 my $line = $fixed[$fixlinenr];
2802 if ($line =~ /\/\/(.*)$/) {2807 if ($line =~ /\/\/(.*)$/) {
2803 my $comment = trim($1);2808 my $comment = trim($1);
2804 $fixed[$linenr - 1] =~ s@\/\/(.*)$@/\* $comment \*/@;2809 $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
2805 }2810 }
2806 }2811 }
2807 }2812 }
@@ -2860,7 +2865,7 @@ sub process { · 52 unmodified lines
2860 "do not initialise globals to 0 or NULL\n" .2865 "do not initialise globals to 0 or NULL\n" .
2861 $herecurr) &&2866 $herecurr) &&
2862 $fix) {2867 $fix) {
2863 $fixed[$linenr - 1] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/;2868 $fixed[$fixlinenr] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/;
2864 }2869 }
2865 }2870 }
2866# check for static initialisers.2871# check for static initialisers.
@@ -2869,7 +2874,7 @@ sub process { · 2 unmodified lines
2869 "do not initialise statics to 0 or NULL\n" .2874 "do not initialise statics to 0 or NULL\n" .
2870 $herecurr) &&2875 $herecurr) &&
2871 $fix) {2876 $fix) {
2872 $fixed[$linenr - 1] =~ s/(\bstatic\s.*?)\s*=\s*(0|NULL|false)\s*;/$1;/;2877 $fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*(0|NULL|false)\s*;/$1;/;
2873 }2878 }
2874 }2879 }
2875 2880
@@ -2899,7 +2904,7 @@ sub process { · 23 unmodified lines
2899 if (ERROR("FUNCTION_WITHOUT_ARGS",2904 if (ERROR("FUNCTION_WITHOUT_ARGS",
2900 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&2905 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
2901 $fix) {2906 $fix) {
2902 $fixed[$linenr - 1] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;2907 $fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
2903 }2908 }
2904 }2909 }
2905 2910
@@ -2908,7 +2913,7 @@ sub process { · 2 unmodified lines
2908 if (WARN("DEFINE_PCI_DEVICE_TABLE",2913 if (WARN("DEFINE_PCI_DEVICE_TABLE",
2909 "Prefer struct pci_device_id over deprecated DEFINE_PCI_DEVICE_TABLE\n" . $herecurr) &&2914 "Prefer struct pci_device_id over deprecated DEFINE_PCI_DEVICE_TABLE\n" . $herecurr) &&
2910 $fix) {2915 $fix) {
2911 $fixed[$linenr - 1] =~ s/\b(?:static\s+|)DEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=\s*/static const struct pci_device_id $1\[\] = /;2916 $fixed[$fixlinenr] =~ s/\b(?:static\s+|)DEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=\s*/static const struct pci_device_id $1\[\] = /;
2912 }2917 }
2913 }2918 }
2914 2919
@@ -2945,7 +2950,7 @@ sub process { · 30 unmodified lines
2945 my $sub_from = $ident;2950 my $sub_from = $ident;
2946 my $sub_to = $ident;2951 my $sub_to = $ident;
2947 $sub_to =~ s/\Q$from\E/$to/;2952 $sub_to =~ s/\Q$from\E/$to/;
2948 $fixed[$linenr - 1] =~2953 $fixed[$fixlinenr] =~
2949 s@\Q$sub_from\E@$sub_to@;2954 s@\Q$sub_from\E@$sub_to@;
2950 }2955 }
2951 }2956 }
@@ -2973,7 +2978,7 @@ sub process { · 21 unmodified lines
2973 my $sub_from = $match;2978 my $sub_from = $match;
2974 my $sub_to = $match;2979 my $sub_to = $match;
2975 $sub_to =~ s/\Q$from\E/$to/;2980 $sub_to =~ s/\Q$from\E/$to/;
2976 $fixed[$linenr - 1] =~2981 $fixed[$fixlinenr] =~
2977 s@\Q$sub_from\E@$sub_to@;2982 s@\Q$sub_from\E@$sub_to@;
2978 }2983 }
2979 }2984 }
@@ -3035,7 +3040,7 @@ sub process { · 55 unmodified lines
3035 if (WARN("PREFER_PR_LEVEL",3040 if (WARN("PREFER_PR_LEVEL",
3036 "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) &&3041 "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) &&
3037 $fix) {3042 $fix) {
3038 $fixed[$linenr - 1] =~3043 $fixed[$fixlinenr] =~
3039 s/\bpr_warning\b/pr_warn/;3044 s/\bpr_warning\b/pr_warn/;
3040 }3045 }
3041 }3046 }
@@ -3069,7 +3074,7 @@ sub process { · 27 unmodified lines
3069 if (WARN("SPACING",3074 if (WARN("SPACING",
3070 "missing space after $1 definition\n" . $herecurr) &&3075 "missing space after $1 definition\n" . $herecurr) &&
3071 $fix) {3076 $fix) {
3072 $fixed[$linenr - 1] =~3077 $fixed[$fixlinenr] =~
3073 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;3078 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
3074 }3079 }
3075 }3080 }
@@ -3139,7 +3144,7 @@ sub process { · 63 unmodified lines
3139 }3144 }
3140 3145
3141 if (show_type("SPACING") && $fix) {3146 if (show_type("SPACING") && $fix) {
3142 $fixed[$linenr - 1] =~3147 $fixed[$fixlinenr] =~
3143 s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;3148 s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
3144 }3149 }
3145 }3150 }
@@ -3156,7 +3161,7 @@ sub process { · 10 unmodified lines
3156 if (ERROR("BRACKET_SPACE",3161 if (ERROR("BRACKET_SPACE",
3157 "space prohibited before open square bracket '['\n" . $herecurr) &&3162 "space prohibited before open square bracket '['\n" . $herecurr) &&
3158 $fix) {3163 $fix) {
3159 $fixed[$linenr - 1] =~3164 $fixed[$fixlinenr] =~
3160 s/^(\+.*?)\s+\[/$1\[/;3165 s/^(\+.*?)\s+\[/$1\[/;
3161 }3166 }
3162 }3167 }
@@ -3191,7 +3196,7 @@ sub process { · 28 unmodified lines
3191 if (WARN("SPACING",3196 if (WARN("SPACING",
3192 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&3197 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
3193 $fix) {3198 $fix) {
3194 $fixed[$linenr - 1] =~3199 $fixed[$fixlinenr] =~
3195 s/\b$name\s+\(/$name\(/;3200 s/\b$name\s+\(/$name\(/;
3196 }3201 }
3197 }3202 }
@@ -3459,8 +3464,8 @@ sub process { · 261 unmodified lines
3459 $fixed_line = $fixed_line . $fix_elements[$#elements];3464 $fixed_line = $fixed_line . $fix_elements[$#elements];
3460 }3465 }
3461 3466
3462 if ($fix && $line_fixed && $fixed_line ne $fixed[$linenr - 1]) {3467 if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) {
3463 $fixed[$linenr - 1] = $fixed_line;3468 $fixed[$fixlinenr] = $fixed_line;
3464 }3469 }
3465 3470
3466 3471
@@ -3471,7 +3476,7 @@ sub process { · 4 unmodified lines
3471 if (WARN("SPACING",3476 if (WARN("SPACING",
3472 "space prohibited before semicolon\n" . $herecurr) &&3477 "space prohibited before semicolon\n" . $herecurr) &&
3473 $fix) {3478 $fix) {
3474 1 while $fixed[$linenr - 1] =~3479 1 while $fixed[$fixlinenr] =~
3475 s/^(\+.*\S)\s+;/$1;/;3480 s/^(\+.*\S)\s+;/$1;/;
3476 }3481 }
3477 }3482 }
@@ -3504,7 +3509,7 @@ sub process { · 26 unmodified lines
3504 if (ERROR("SPACING",3509 if (ERROR("SPACING",
3505 "space required before the open brace '{'\n" . $herecurr) &&3510 "space required before the open brace '{'\n" . $herecurr) &&
3506 $fix) {3511 $fix) {
3507 $fixed[$linenr - 1] =~ s/^(\+.*(?:do|\))){/$1 {/;3512 $fixed[$fixlinenr] =~ s/^(\+.*(?:do|\))){/$1 {/;
3508 }3513 }
3509 }3514 }
3510 3515
@@ -3522,7 +3527,7 @@ sub process { · 11 unmodified lines
3522 if (ERROR("SPACING",3527 if (ERROR("SPACING",
3523 "space required after that close brace '}'\n" . $herecurr) &&3528 "space required after that close brace '}'\n" . $herecurr) &&
3524 $fix) {3529 $fix) {
3525 $fixed[$linenr - 1] =~3530 $fixed[$fixlinenr] =~
3526 s/}((?!(?:,|;|\)))\S)/} $1/;3531 s/}((?!(?:,|;|\)))\S)/} $1/;
3527 }3532 }
3528 }3533 }
@@ -3532,7 +3537,7 @@ sub process { · 3 unmodified lines
3532 if (ERROR("SPACING",3537 if (ERROR("SPACING",
3533 "space prohibited after that open square bracket '['\n" . $herecurr) &&3538 "space prohibited after that open square bracket '['\n" . $herecurr) &&
3534 $fix) {3539 $fix) {
3535 $fixed[$linenr - 1] =~3540 $fixed[$fixlinenr] =~
3536 s/\[\s+/\[/;3541 s/\[\s+/\[/;
3537 }3542 }
3538 }3543 }
@@ -3540,7 +3545,7 @@ sub process { · 1 unmodified line
3540 if (ERROR("SPACING",3545 if (ERROR("SPACING",
3541 "space prohibited before that close square bracket ']'\n" . $herecurr) &&3546 "space prohibited before that close square bracket ']'\n" . $herecurr) &&
3542 $fix) {3547 $fix) {
3543 $fixed[$linenr - 1] =~3548 $fixed[$fixlinenr] =~
3544 s/\s+\]/\]/;3549 s/\s+\]/\]/;
3545 }3550 }
3546 }3551 }
@@ -3551,7 +3556,7 @@ sub process { · 4 unmodified lines
3551 if (ERROR("SPACING",3556 if (ERROR("SPACING",
3552 "space prohibited after that open parenthesis '('\n" . $herecurr) &&3557 "space prohibited after that open parenthesis '('\n" . $herecurr) &&
3553 $fix) {3558 $fix) {
3554 $fixed[$linenr - 1] =~3559 $fixed[$fixlinenr] =~
3555 s/\(\s+/\(/;3560 s/\(\s+/\(/;
3556 }3561 }
3557 }3562 }
@@ -3561,7 +3566,8 @@ sub process { · 3 unmodified lines
3561 if (ERROR("SPACING",3566 if (ERROR("SPACING",
3562 "space prohibited before that close parenthesis ')'\n" . $herecurr) &&3567 "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
3563 $fix) {3568 $fix) {
3564 $fixed[$linenr - 1] =~3569 print("fixlinenr: <$fixlinenr> fixed[fixlinenr]: <$fixed[$fixlinenr]>\n");
3570 $fixed[$fixlinenr] =~
3565 s/\s+\)/\)/;3571 s/\s+\)/\)/;
3566 }3572 }
3567 }3573 }
@@ -3580,7 +3586,7 @@ sub process { · 12 unmodified lines
3580 if (WARN("INDENTED_LABEL",3586 if (WARN("INDENTED_LABEL",
3581 "labels should not be indented\n" . $herecurr) &&3587 "labels should not be indented\n" . $herecurr) &&
3582 $fix) {3588 $fix) {
3583 $fixed[$linenr - 1] =~3589 $fixed[$fixlinenr] =~
3584 s/^(.)\s+/$1/;3590 s/^(.)\s+/$1/;
3585 }3591 }
3586 }3592 }
@@ -3642,7 +3648,7 @@ sub process { · 55 unmodified lines
3642 if (ERROR("SPACING",3648 if (ERROR("SPACING",
3643 "space required before the open parenthesis '('\n" . $herecurr) &&3649 "space required before the open parenthesis '('\n" . $herecurr) &&
3644 $fix) {3650 $fix) {
3645 $fixed[$linenr - 1] =~3651 $fixed[$fixlinenr] =~
3646 s/\b(if|while|for|switch)\(/$1 \(/;3652 s/\b(if|while|for|switch)\(/$1 \(/;
3647 }3653 }
3648 }3654 }
@@ -3779,7 +3785,7 @@ sub process { · 130 unmodified lines
3779 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) &&3785 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) &&
3780 $fix) {3786 $fix) {
3781 my $hexval = sprintf("0x%x", oct($var));3787 my $hexval = sprintf("0x%x", oct($var));
3782 $fixed[$linenr - 1] =~3788 $fixed[$fixlinenr] =~
3783 s/\b$var\b/$hexval/;3789 s/\b$var\b/$hexval/;
3784 }3790 }
3785 }3791 }
@@ -3815,7 +3821,7 @@ sub process { · 29 unmodified lines
3815 if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",3821 if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
3816 "Whitespace after \\ makes next lines useless\n" . $herecurr) &&3822 "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
3817 $fix) {3823 $fix) {
3818 $fixed[$linenr - 1] =~ s/\s+$//;3824 $fixed[$fixlinenr] =~ s/\s+$//;
3819 }3825 }
3820 }3826 }
3821 3827
@@ -4170,7 +4176,7 @@ sub process { · 348 unmodified lines
4170 WARN("MISPLACED_INIT",4176 WARN("MISPLACED_INIT",
4171 "$attr should be placed after $var\n" . $herecurr))) &&4177 "$attr should be placed after $var\n" . $herecurr))) &&
4172 $fix) {4178 $fix) {
4173 $fixed[$linenr - 1] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;4179 $fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;
4174 }4180 }
4175 }4181 }
4176 }4182 }
@@ -4184,7 +4190,7 @@ sub process { · 7 unmodified lines
4184 if (ERROR("INIT_ATTRIBUTE",4190 if (ERROR("INIT_ATTRIBUTE",
4185 "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&4191 "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
4186 $fix) {4192 $fix) {
4187 $fixed[$linenr - 1] =~4193 $fixed[$fixlinenr] =~
4188 s/$InitAttributeData/${attr_prefix}initconst/;4194 s/$InitAttributeData/${attr_prefix}initconst/;
4189 }4195 }
4190 }4196 }
@@ -4195,12 +4201,12 @@ sub process { · 4 unmodified lines
4195 if (ERROR("INIT_ATTRIBUTE",4201 if (ERROR("INIT_ATTRIBUTE",
4196 "Use of $attr requires a separate use of const\n" . $herecurr) &&4202 "Use of $attr requires a separate use of const\n" . $herecurr) &&
4197 $fix) {4203 $fix) {
4198 my $lead = $fixed[$linenr - 1] =~4204 my $lead = $fixed[$fixlinenr] =~
4199 /(^\+\s*(?:static\s+))/;4205 /(^\+\s*(?:static\s+))/;
4200 $lead = rtrim($1);4206 $lead = rtrim($1);
4201 $lead = "$lead " if ($lead !~ /^\+$/);4207 $lead = "$lead " if ($lead !~ /^\+$/);
4202 $lead = "${lead}const ";4208 $lead = "${lead}const ";
4203 $fixed[$linenr - 1] =~ s/(^\+\s*(?:static\s+))/$lead/;4209 $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
4204 }4210 }
4205 }4211 }
4206 4212
@@ -4213,7 +4219,7 @@ sub process { · 6 unmodified lines
4213 if (WARN("CONSTANT_CONVERSION",4219 if (WARN("CONSTANT_CONVERSION",
4214 "$constant_func should be $func\n" . $herecurr) &&4220 "$constant_func should be $func\n" . $herecurr) &&
4215 $fix) {4221 $fix) {
4216 $fixed[$linenr - 1] =~ s/\b$constant_func\b/$func/g;4222 $fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
4217 }4223 }
4218 }4224 }
4219 4225
@@ -4263,7 +4269,7 @@ sub process { · 43 unmodified lines
4263 if (ERROR("SPACING",4269 if (ERROR("SPACING",
4264 "exactly one space required after that #$1\n" . $herecurr) &&4270 "exactly one space required after that #$1\n" . $herecurr) &&
4265 $fix) {4271 $fix) {
4266 $fixed[$linenr - 1] =~4272 $fixed[$fixlinenr] =~
4267 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;4273 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
4268 }4274 }
4269 4275
@@ -4311,7 +4317,7 @@ sub process { · 41 unmodified lines
4311 if (WARN("INLINE",4317 if (WARN("INLINE",
4312 "plain inline is preferred over $1\n" . $herecurr) &&4318 "plain inline is preferred over $1\n" . $herecurr) &&
4313 $fix) {4319 $fix) {
4314 $fixed[$linenr - 1] =~ s/\b(__inline__|__inline)\b/inline/;4320 $fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
4315 4321
4316 }4322 }
4317 }4323 }
@@ -4336,7 +4342,7 @@ sub process { · 18 unmodified lines
4336 if (WARN("PREFER_PRINTF",4342 if (WARN("PREFER_PRINTF",
4337 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&4343 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
4338 $fix) {4344 $fix) {
4339 $fixed[$linenr - 1] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;4345 $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;
4340 4346
4341 }4347 }
4342 }4348 }
@@ -4347,7 +4353,7 @@ sub process { · 4 unmodified lines
4347 if (WARN("PREFER_SCANF",4353 if (WARN("PREFER_SCANF",
4348 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&4354 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
4349 $fix) {4355 $fix) {
4350 $fixed[$linenr - 1] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;4356 $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;
4351 }4357 }
4352 }4358 }
4353 4359
@@ -4362,7 +4368,7 @@ sub process { · 8 unmodified lines
4362 if (WARN("SIZEOF_PARENTHESIS",4368 if (WARN("SIZEOF_PARENTHESIS",
4363 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&4369 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
4364 $fix) {4370 $fix) {
4365 $fixed[$linenr - 1] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;4371 $fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
4366 }4372 }
4367 }4373 }
4368 4374
@@ -4385,7 +4391,7 @@ sub process { · 16 unmodified lines
4385 if (WARN("PREFER_SEQ_PUTS",4391 if (WARN("PREFER_SEQ_PUTS",
4386 "Prefer seq_puts to seq_printf\n" . $herecurr) &&4392 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
4387 $fix) {4393 $fix) {
4388 $fixed[$linenr - 1] =~ s/\bseq_printf\b/seq_puts/;4394 $fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
4389 }4395 }
4390 }4396 }
4391 }4397 }
@@ -4414,7 +4420,7 @@ sub process { · 22 unmodified lines
4414 if (WARN("PREFER_ETHER_ADDR_COPY",4420 if (WARN("PREFER_ETHER_ADDR_COPY",
4415 "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . $herecurr) &&4421 "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . $herecurr) &&
4416 $fix) {4422 $fix) {
4417 $fixed[$linenr - 1] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;4423 $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
4418 }4424 }
4419 }4425 }
4420 4426
@@ -4502,7 +4508,7 @@ sub process { · 81 unmodified lines
4502 if (CHK("AVOID_EXTERNS",4508 if (CHK("AVOID_EXTERNS",
4503 "extern prototypes should be avoided in .h files\n" . $herecurr) &&4509 "extern prototypes should be avoided in .h files\n" . $herecurr) &&
4504 $fix) {4510 $fix) {
4505 $fixed[$linenr - 1] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;4511 $fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
4506 }4512 }
4507 }4513 }
4508 4514
@@ -4579,7 +4585,7 @@ sub process { · 70 unmodified lines
4579 if (WARN("ALLOC_WITH_MULTIPLY",4585 if (WARN("ALLOC_WITH_MULTIPLY",
4580 "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) &&4586 "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) &&
4581 $fix) {4587 $fix) {
4582 $fixed[$linenr - 1] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;4588 $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
4583 4589
4584 }4590 }
4585 }4591 }
@@ -4603,7 +4609,7 @@ sub process { · 17 unmodified lines
4603 if (WARN("ONE_SEMICOLON",4609 if (WARN("ONE_SEMICOLON",
4604 "Statements terminations use 1 semicolon\n" . $herecurr) &&4610 "Statements terminations use 1 semicolon\n" . $herecurr) &&
4605 $fix) {4611 $fix) {
4606 $fixed[$linenr - 1] =~ s/(\s*;\s*){2,}$/;/g;4612 $fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
4607 }4613 }
4608 }4614 }
4609 4615
@@ -4651,7 +4657,7 @@ sub process { · 41 unmodified lines
4651 if (WARN("USE_FUNC",4657 if (WARN("USE_FUNC",
4652 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&4658 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&
4653 $fix) {4659 $fix) {
4654 $fixed[$linenr - 1] =~ s/\b__FUNCTION__\b/__func__/g;4660 $fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
4655 }4661 }
4656 }4662 }
4657 4663