svn commit: samba r13982 - in branches/SAMBA_4_0/source/script: .

jelmer at samba.org jelmer at samba.org
Tue Mar 7 20:22:26 GMT 2006


Author: jelmer
Date: 2006-03-07 20:22:26 +0000 (Tue, 07 Mar 2006)
New Revision: 13982

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=13982

Log:
Add support for prototypes spread across multiple lines. Try to keep line 
empty after inserting new prototypes.

Modified:
   branches/SAMBA_4_0/source/script/update-proto.pl


Changeset:
Modified: branches/SAMBA_4_0/source/script/update-proto.pl
===================================================================
--- branches/SAMBA_4_0/source/script/update-proto.pl	2006-03-07 20:14:47 UTC (rev 13981)
+++ branches/SAMBA_4_0/source/script/update-proto.pl	2006-03-07 20:22:26 UTC (rev 13982)
@@ -3,9 +3,6 @@
 #
 # Copyright (C) 2006 Jelmer Vernooij <jelmer at samba.org>
 # Published under the GNU GPL
-#
-# TODO:
-#  - update for prototypes that span lines
 
 use strict;
 use warnings;
@@ -52,8 +49,8 @@
 
 =head1 BUGS
 
-Prototypes must appear on one line - they can't be split across multiple lines.
-Some things are erroneously recognized as functions
+Strange complex functions are not recognized. In particular those 
+created by macros or returning (without typedef) function pointers.
 
 =head1 LICENSE
 
@@ -89,6 +86,14 @@
 	'v|verbose' => sub { $verbose += 1; }
 ) or Usage();
 
+sub count($$)
+{
+	my ($t, $s) = @_;
+	my $count = 0;
+	while($s =~ s/^(.)//) { $count++ if $1 eq $t; }
+	return $count;
+}
+
 my $header = shift @ARGV;
 
 sub process_file($)
@@ -96,18 +101,33 @@
 	my $file = shift;
 	open (IN, "<$file");
 	while (my $line = <IN>) {
-		next if ($line =~ /^\s/);
-		next unless ($line =~ /\(/);
-		next if ($line =~ /^\/|[;]|^#|}|^\s*static/);
-		next unless ($line =~ /^([^(]+)(\s+)(\w+)\s*\((.*)\)\s*{*\s*$/);
+		$_ = $line;
+		next if /^\s/;
+		next unless /\(/;
+		next if /^\/|[;]|^#|}|^\s*static/;
+		s/\/\*(.*?)\*\///g;
+		my $public = s/_PUBLIC_//g;
+		s/_PRINTF_ATTRIBUTE\([^)]+\)//g;
+		next unless /^(struct\s+\w+|union\s+\w+|\w+)\s+\**\s*(\w+)\s*\((.*)$/;
 
-		my $name = $3;
+		my $name = $2;
 
 		next if ($name eq "main");
-		next unless ($1 =~ /^[\*\w\s]+$/);
 
-		$line =~ s/}\s*$//g;
-		$line =~ s/\n//g;
+		# Read continuation lines if any
+		my $prn = 1 + count("(", $3) - count(")", $3);
+
+		while ($prn) {
+			my $l = <IN>;
+			$l or die("EOF while parsing function prototype");
+			$line .= $l;
+			$prn += count("(", $l) - count(")", $l);
+		}
+
+		$line =~ s/\n$//;
+
+		# Strip off possible start of function
+		$line =~ s/{\s*$//g;
 		
 		$new_protos{$name} = "$line;";
 	}
@@ -131,35 +151,65 @@
 	%new_protos = ();
 }
 
+my $blankline_due = 0;
+
 open (HDR, "<$header");
 while (my $line = <HDR>) {
-	# Insert prototypes that weren't in the header before
-	if ($line =~ /^\/\* New prototypes are inserted above this line.*\*\/\s*$/) {
-		insert_new_protos();
-		print "$line\n";
-		next;
+	if ($line eq "\n") {
+		$blankline_due = 1;
+		$line = <HDR>;
 	}
 
 	# Recognize C files that prototypes came from
-	if ($line =~ /^\/\* The following definitions come from (.*) \*\//) {
+	if ($line =~ /\/\* The following definitions come from (.*) \*\//) {
 		insert_new_protos();
+		if ($blankline_due) {
+			print "\n";
+			$blankline_due = 0;
+		}
 		process_file($1);
 		print "$line";
 		next;
 	}
+
+	if ($blankline_due) {
+		print "\n";
+		$blankline_due = 0;
+	}
+
+	# Insert prototypes that weren't in the header before
+	if ($line =~ /\/\* New prototypes are inserted above this line.*\*\/\s*/) {
+		insert_new_protos();
+		print "$line\n";
+		next;
+	}
 	
 	if ($line =~ /^\s*typedef |^\#|^\s*static/) {
 		print "$line";
 		next;
 	}
 
-	unless ($line =~ /^([^(]+)(\s+)(\w+)\s*\((.*)\)\s*;\s*$/)  {
+	$_ = $line;
+	s/\/\*(.*?)\*\///g;
+	my $public = s/_PUBLIC_//g;
+	s/_PRINTF_ATTRIBUTE\([^)]+\)//g;
+	unless (/^(struct\s+\w+|union\s+\w+|\w+)\s+\**\s*(\w+)\s*\((.*)$/) {
 		print "$line";
 		next;
 	}
 
-	my $name = $3;
+	# Read continuation lines if any
+	my $prn = 1 + count("(", $3) - count(")", $3);
 
+	while ($prn) {
+		my $l = <HDR>;
+		$l or die("EOF while parsing function prototype");
+		$line .= $l;
+		$prn += count("(", $l) - count(")", $l);
+	}
+
+	my $name = $2;
+
 	# This prototype is for a function that was removed
 	unless (defined($new_protos{$name})) {
 		$deleted+=1;



More information about the samba-cvs mailing list