6972 lines · 205.6 KB · Perl
RawDownload
	return ($id, $desc);} $chk_signoff = 0 if ($file); my @rawlines = ();my @lines = ();my @fixed = ();my @fixed_inserted = ();my @fixed_deleted = ();my $fixlinenr = -1; # If input is git commits, extract all commits from the commit expressions.# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.die "$P: No git repository found\n" if ($git && !-e ".git"); if ($git) {	my @commits = ();	foreach my $commit_expr (@ARGV) {		my $git_range;		if ($commit_expr =~ m/^(.*)-(\d+)$/) {			$git_range = "-$2 $1";		} elsif ($commit_expr =~ m/\.\./) {			$git_range = "$commit_expr";		} else {			$git_range = "-1 $commit_expr";		}		my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;		foreach my $line (split(/\n/, $lines)) {			$line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;			next if (!defined($1) || !defined($2));			my $sha1 = $1;			my $subject = $2;			unshift(@commits, $sha1);			$git_commits{$sha1} = $subject;		}	}	die "$P: no git commits after extraction!\n" if (@commits == 0);	@ARGV = @commits;} my $vname;$allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};for my $filename (@ARGV) {	my $FILE;	if ($git) {		open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||			die "$P: $filename: git format-patch failed - $!\n";	} elsif ($file) {		open($FILE, '-|', "diff -u /dev/null $filename") ||			die "$P: $filename: diff failed - $!\n";	} elsif ($filename eq '-') {		open($FILE, '<&STDIN');	} else {		open($FILE, '<', "$filename") ||			die "$P: $filename: open failed - $!\n";	}	if ($filename eq '-') {		$vname = 'Your patch';	} elsif ($git) {		$vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';	} else {		$vname = $filename;	}	while (<$FILE>) {		chomp;		push(@rawlines, $_);		$vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);	}	close($FILE); 	if ($#ARGV > 0 && $quiet == 0) {		print '-' x length($vname) . "\n";		print "$vname\n";		print '-' x length($vname) . "\n";	} 	if (!process($filename)) {		$exit = 1;	}	@rawlines = ();	@lines = ();	@fixed = ();	@fixed_inserted = ();	@fixed_deleted = ();	$fixlinenr = -1;	@modifierListFile = ();	@typeListFile = ();	build_types();} if (!$quiet) {	hash_show_words(\%use_type, "Used");	hash_show_words(\%ignore_type, "Ignored"); 	if (!$perl_version_ok) {		print << "EOM" NOTE: perl $^V is not modern enough to detect all possible issues.      An upgrade to at least perl $minimum_perl_version is suggested.EOM	}	if ($exit) {		print << "EOM" NOTE: If any of the errors are false positives, please report      them to the maintainer, see CHECKPATCH in MAINTAINERS.EOM	}} exit($exit); sub top_of_kernel_tree {	my ($root) = @_; 	my @tree_check = (		"COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",		"README", "Documentation", "arch", "include", "drivers",		"fs", "init", "ipc", "kernel", "lib", "scripts",	); 	foreach my $check (@tree_check) {		if (! -e $root . '/' . $check) {			return 0;		}	}	return 1;} sub parse_email {	my ($formatted_email) = @_; 	my $name = "";	my $name_comment = "";	my $address = "";	my $comment = ""; 	if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {		$name = $1;		$address = $2;		$comment = $3 if defined $3;	} elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {		$address = $1;		$comment = $2 if defined $2;	} elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {		$address = $1;		$comment = $2 if defined $2;		$formatted_email =~ s/\Q$address\E.*$//;		$name = $formatted_email;		$name = trim($name);		$name =~ s/^\"|\"$//g;		# If there's a name left after stripping spaces and		# leading quotes, and the address doesn't have both		# leading and trailing angle brackets, the address		# is invalid. ie:		#   "joe smith joe@smith.com" bad		#   "joe smith <joe@smith.com" bad		if ($name ne "" && $address !~ /^<[^>]+>$/) {			$name = "";			$address = "";			$comment = "";		}	} 	$name = trim($name);	$name =~ s/^\"|\"$//g;	$name =~ s/(\s*\([^\)]+\))\s*//;	if (defined($1)) {		$name_comment = trim($1);	}	$address = trim($address);	$address =~ s/^\<|\>$//g; 	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes		$name = "\"$name\"";	} 	return ($name, $name_comment, $address, $comment);} sub format_email {	my ($name, $address) = @_; 	my $formatted_email; 	$name = trim($name);	$name =~ s/^\"|\"$//g;	$address = trim($address); 	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes		$name = "\"$name\"";	} 	if ("$name" eq "") {		$formatted_email = "$address";	} else {		$formatted_email = "$name <$address>";	} 	return $formatted_email;} sub reformat_email {	my ($email) = @_; 	my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);	return format_email($email_name, $email_address);} sub same_email_addresses {	my ($email1, $email2) = @_; 	my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);	my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2); 	return $email1_name eq $email2_name &&	       $email1_address eq $email2_address;} sub which {	my ($bin) = @_; 	foreach my $path (split(/:/, $ENV{PATH})) {		if (-e "$path/$bin") {			return "$path/$bin";		}	} 	return "";} sub which_conf {	my ($conf) = @_; 	foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {		if (-e "$path/$conf") {			return "$path/$conf";		}	} 	return "";} sub expand_tabs {	my ($str) = @_; 	my $res = '';	my $n = 0;	for my $c (split(//, $str)) {		if ($c eq "\t") {			$res .= ' ';			$n++;			for (; ($n % $tabsize) != 0; $n++) {				$res .= ' ';			}			next;		}		$res .= $c;		$n++;	} 	return $res;}sub copy_spacing {	(my $res = shift) =~ tr/\t/ /c;	return $res;} sub line_stats {	my ($line) = @_; 	# Drop the diff line leader and expand tabs	$line =~ s/^.//;	$line = expand_tabs($line); 	# Pick the indent from the front of the line.	my ($white) = ($line =~ /^(\s*)/); 	return (length($line), length($white));} my $sanitise_quote = ''; sub sanitise_line_reset {	my ($in_comment) = @_; 	if ($in_comment) {		$sanitise_quote = '*/';	} else {		$sanitise_quote = '';	}}sub sanitise_line {	my ($line) = @_; 	my $res = '';	my $l = ''; 	my $qlen = 0;	my $off = 0;	my $c; 	# Always copy over the diff marker.	$res = substr($line, 0, 1); 	for ($off = 1; $off < length($line); $off++) {		$c = substr($line, $off, 1); 		# Comments we are whacking completely including the begin		# and end, all to $;.		if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {			$sanitise_quote = '*/'; 			substr($res, $off, 2, "$;$;");			$off++;			next;		}		if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {			$sanitise_quote = '';			substr($res, $off, 2, "$;$;");			$off++;			next;		}		if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {			$sanitise_quote = '//'; 			substr($res, $off, 2, $sanitise_quote);			$off++;			next;		} 		# A \ in a string means ignore the next character.		if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&		    $c eq "\\") {			substr($res, $off, 2, 'XX');			$off++;			next;		}		# Regular quotes.		if ($c eq "'" || $c eq '"') {			if ($sanitise_quote eq '') {				$sanitise_quote = $c; 				substr($res, $off, 1, $c);				next;			} elsif ($sanitise_quote eq $c) {				$sanitise_quote = '';			}		} 		#print "c<$c> SQ<$sanitise_quote>\n";		if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {			substr($res, $off, 1, $;);		} elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {			substr($res, $off, 1, $;);		} elsif ($off != 0 && $sanitise_quote && $c ne "\t") {			substr($res, $off, 1, 'X');		} else {			substr($res, $off, 1, $c);		}	} 	if ($sanitise_quote eq '//') {		$sanitise_quote = '';	} 	# The pathname on a #include may be surrounded by '<' and '>'.	if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {		my $clean = 'X' x length($1);		$res =~ s@\<.*\>@<$clean>@; 	# The whole of a #error is a string.	} elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {		my $clean = 'X' x length($1);		$res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;	} 	if ($allow_c99_comments && $res =~ m@(//.*$)@) {		my $match = $1;		$res =~ s/\Q$match\E/"$;" x length($match)/e;	} 	return $res;} sub get_quoted_string {	my ($line, $rawline) = @_; 	return "" if (!defined($line) || !defined($rawline));	return "" if ($line !~ m/($String)/g);	return substr($rawline, $-[0], $+[0] - $-[0]);} sub ctx_statement_block {	my ($linenr, $remain, $off) = @_;	my $line = $linenr - 1;	my $blk = '';	my $soff = $off;	my $coff = $off - 1;	my $coff_set = 0; 	my $loff = 0; 	my $type = '';	my $level = 0;	my @stack = ();	my $p;	my $c;	my $len = 0; 	my $remainder;	while (1) {		@stack = (['', 0]) if ($#stack == -1); 		#warn "CSB: blk<$blk> remain<$remain>\n";		# If we are about to drop off the end, pull in more		# context.		if ($off >= $len) {			for (; $remain > 0; $line++) {				last if (!defined $lines[$line]);				next if ($lines[$line] =~ /^-/);				$remain--;				$loff = $len;				$blk .= $lines[$line] . "\n";				$len = length($blk);				$line++;				last;			}			# Bail if there is no further context.			#warn "CSB: blk<$blk> off<$off> len<$len>\n";			if ($off >= $len) {				last;			}			if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {				$level++;				$type = '#';			}		}		$p = $c;		$c = substr($blk, $off, 1);		$remainder = substr($blk, $off); 		#warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n"; 		# Handle nested #if/#else.		if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {			push(@stack, [ $type, $level ]);		} elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {			($type, $level) = @{$stack[$#stack - 1]};		} elsif ($remainder =~ /^#\s*endif\b/) {			($type, $level) = @{pop(@stack)};		} 		# Statement ends at the ';' or a close '}' at the		# outermost level.		if ($level == 0 && $c eq ';') {			last;		} 		# An else is really a conditional as long as its not else if		if ($level == 0 && $coff_set == 0 &&				(!defined($p) || $p =~ /(?:\s|\}|\+)/) &&				$remainder =~ /^(else)(?:\s|{)/ &&				$remainder !~ /^else\s+if\b/) {			$coff = $off + length($1) - 1;			$coff_set = 1;			#warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";			#warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";		} 		if (($type eq '' || $type eq '(') && $c eq '(') {			$level++;			$type = '(';		}		if ($type eq '(' && $c eq ')') {			$level--;			$type = ($level != 0)? '(' : ''; 			if ($level == 0 && $coff < $soff) {				$coff = $off;				$coff_set = 1;				#warn "CSB: mark coff<$coff>\n";			}		}		if (($type eq '' || $type eq '{') && $c eq '{') {			$level++;			$type = '{';		}		if ($type eq '{' && $c eq '}') {			$level--;			$type = ($level != 0)? '{' : ''; 			if ($level == 0) {				if (substr($blk, $off + 1, 1) eq ';') {					$off++;				}				last;

Lines 1001–1500 of 6972. Previous lines