diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ab12e3040abb..63409dbd0de5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -57,7 +57,7 @@ my $codespell = 0; | |||
| 57 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; | 57 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; |
| 58 | my $conststructsfile = "$D/const_structs.checkpatch"; | 58 | my $conststructsfile = "$D/const_structs.checkpatch"; |
| 59 | my $typedefsfile = ""; | 59 | my $typedefsfile = ""; |
| 60 | my $color = 1; | 60 | my $color = "auto"; |
| 61 | my $allow_c99_comments = 1; | 61 | my $allow_c99_comments = 1; |
| 62 | 62 | ||
| 63 | sub help { | 63 | sub help { |
| @@ -116,7 +116,8 @@ Options: | |||
| 116 | (default:/usr/share/codespell/dictionary.txt) | 116 | (default:/usr/share/codespell/dictionary.txt) |
| 117 | --codespellfile Use this codespell dictionary | 117 | --codespellfile Use this codespell dictionary |
| 118 | --typedefsfile Read additional types from this file | 118 | --typedefsfile Read additional types from this file |
| 119 | --color Use colors when output is STDOUT (default: on) | 119 | --color[=WHEN] Use colors 'always', 'never', or only when output |
| 120 | is a terminal ('auto'). Default is 'auto'. | ||
| 120 | -h, --help, --version display this help and exit | 121 | -h, --help, --version display this help and exit |
| 121 | 122 | ||
| 122 | When FILE is - read standard input. | 123 | When FILE is - read standard input. |
| @@ -182,6 +183,14 @@ if (-f $conf) { | |||
| 182 | unshift(@ARGV, @conf_args) if @conf_args; | 183 | unshift(@ARGV, @conf_args) if @conf_args; |
| 183 | } | 184 | } |
| 184 | 185 | ||
| 186 | # Perl's Getopt::Long allows options to take optional arguments after a space. | ||
| 187 | # Prevent --color by itself from consuming other arguments | ||
| 188 | foreach (@ARGV) { | ||
| 189 | if ($_ eq "--color" || $_ eq "-color") { | ||
| 190 | $_ = "--color=$color"; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 185 | GetOptions( | 194 | GetOptions( |
| 186 | 'q|quiet+' => \$quiet, | 195 | 'q|quiet+' => \$quiet, |
| 187 | 'tree!' => \$tree, | 196 | 'tree!' => \$tree, |
| @@ -212,7 +221,9 @@ GetOptions( | |||
| 212 | 'codespell!' => \$codespell, | 221 | 'codespell!' => \$codespell, |
| 213 | 'codespellfile=s' => \$codespellfile, | 222 | 'codespellfile=s' => \$codespellfile, |
| 214 | 'typedefsfile=s' => \$typedefsfile, | 223 | 'typedefsfile=s' => \$typedefsfile, |
| 215 | 'color!' => \$color, | 224 | 'color=s' => \$color, |
| 225 | 'no-color' => \$color, #keep old behaviors of -nocolor | ||
| 226 | 'nocolor' => \$color, #keep old behaviors of -nocolor | ||
| 216 | 'h|help' => \$help, | 227 | 'h|help' => \$help, |
| 217 | 'version' => \$help | 228 | 'version' => \$help |
| 218 | ) or help(1); | 229 | ) or help(1); |
| @@ -238,6 +249,18 @@ if ($#ARGV < 0) { | |||
| 238 | push(@ARGV, '-'); | 249 | push(@ARGV, '-'); |
| 239 | } | 250 | } |
| 240 | 251 | ||
| 252 | if ($color =~ /^[01]$/) { | ||
| 253 | $color = !$color; | ||
| 254 | } elsif ($color =~ /^always$/i) { | ||
| 255 | $color = 1; | ||
| 256 | } elsif ($color =~ /^never$/i) { | ||
| 257 | $color = 0; | ||
| 258 | } elsif ($color =~ /^auto$/i) { | ||
| 259 | $color = (-t STDOUT); | ||
| 260 | } else { | ||
| 261 | die "Invalid color mode: $color\n"; | ||
| 262 | } | ||
| 263 | |||
| 241 | sub hash_save_array_words { | 264 | sub hash_save_array_words { |
| 242 | my ($hashRef, $arrayRef) = @_; | 265 | my ($hashRef, $arrayRef) = @_; |
| 243 | 266 | ||
| @@ -1883,7 +1906,7 @@ sub report { | |||
| 1883 | return 0; | 1906 | return 0; |
| 1884 | } | 1907 | } |
| 1885 | my $output = ''; | 1908 | my $output = ''; |
| 1886 | if (-t STDOUT && $color) { | 1909 | if ($color) { |
| 1887 | if ($level eq 'ERROR') { | 1910 | if ($level eq 'ERROR') { |
| 1888 | $output .= RED; | 1911 | $output .= RED; |
| 1889 | } elsif ($level eq 'WARNING') { | 1912 | } elsif ($level eq 'WARNING') { |
| @@ -1894,10 +1917,10 @@ sub report { | |||
| 1894 | } | 1917 | } |
| 1895 | $output .= $prefix . $level . ':'; | 1918 | $output .= $prefix . $level . ':'; |
| 1896 | if ($show_types) { | 1919 | if ($show_types) { |
| 1897 | $output .= BLUE if (-t STDOUT && $color); | 1920 | $output .= BLUE if ($color); |
| 1898 | $output .= "$type:"; | 1921 | $output .= "$type:"; |
| 1899 | } | 1922 | } |
| 1900 | $output .= RESET if (-t STDOUT && $color); | 1923 | $output .= RESET if ($color); |
| 1901 | $output .= ' ' . $msg . "\n"; | 1924 | $output .= ' ' . $msg . "\n"; |
| 1902 | 1925 | ||
| 1903 | if ($showfile) { | 1926 | if ($showfile) { |
