Lines Matching +full:0 +full:- +full:9 +full:a +full:- +full:f

2 # SPDX-License-Identifier: GPL-2.0
4 # Clean a patch file -- or directory of patch files -- of stealth whitespace.
5 # WARNING: this can be a highly destructive operation. Use with caution.
15 # Clean up space-tab sequences, either by removing spaces or
23 my $pos = 0;
24 my $nsp = 0;
27 for ($i = 0; $i < length($li); $i++) {
31 my $ntab = ($npos >> 3) - ($pos >> 3);
34 $nsp = 0;
38 $nsp = 0;
40 $pos = 0;
46 $nsp = 0;
55 # Compute the visual width of a string
61 my $pos = 0;
62 my $mlen = 0;
64 for ($i = 0; $i < length($li); $i++) {
70 $pos = 0;
80 $name = basename($0);
84 while (defined($a = shift(@ARGV))) {
85 if ($a =~ /^-/) {
86 if ($a eq '-width' || $a eq '-w') {
87 $max_width = shift(@ARGV)+0;
89 print STDERR "Usage: $name [-width #] files...\n";
93 push(@files, $a);
97 foreach $f ( @files ) {
98 print STDERR "$name: $f\n";
100 if (! -f $f) {
101 print STDERR "$f: not a file\n";
105 if (!open(FILE, '+<', $f)) {
106 print STDERR "$name: Cannot open file: $f: $!\n";
112 # First, verify that it is not a binary file; consider any file
113 # with a zero byte to be a binary file. Is there any better, or
115 $is_binary = 0;
117 while (read(FILE, $data, 65536) > 0) {
118 if ($data =~ /\0/) {
125 print STDERR "$name: $f: binary file\n";
129 seek(FILE, 0, 0);
131 $in_bytes = 0;
132 $out_bytes = 0;
133 $lineno = 0;
137 $in_hunk = 0;
138 $err = 0;
146 /^\@\@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)\s\@\@/) {
158 # We're in a hunk
161 $plus_lines--;
170 "$f:$lineno: adds line exceeds $max_width ",
175 } elsif ($line =~ /^\-/) {
176 $minus_lines--;
179 $plus_lines--;
180 $minus_lines--;
183 print STDERR "$name: $f: malformed patch\n";
188 if ($plus_lines < 0 || $minus_lines < 0) {
189 print STDERR "$name: $f: malformed patch\n";
192 } elsif ($plus_lines == 0 && $minus_lines == 0) {
193 # End of a hunk. Process this hunk.
197 my $adj = 0;
198 my $done = 0;
200 for ($i = scalar(@hunk_lines)-1; $i > 0; $i--) {
212 $l = $hunk_lines[0]; # Hunk header
217 ($l =~ /^\@\@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)\s\@\@(.*)$/);
224 $l = sprintf("@@ -%d,%d +%d,%d @@%s\n",
225 $mstart, $mlin, $pstart, $plin-$adj,
236 $in_hunk = 0;
242 print STDERR "$name: $f: malformed patch\n";
249 seek(FILE, 0, 0);
254 die "$name: Failed to truncate modified file: $f: $!\n";