From dca1de8dc80d8b78680719a1d2f74d6b9c99390c Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Tue, 30 Apr 2013 11:25:35 -0700 Subject: [PATCH] add doxygen support and json export document support --- cf/make-proto.pl | 74 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/cf/make-proto.pl b/cf/make-proto.pl index bf83e4c5d..2db4f421e 100644 --- a/cf/make-proto.pl +++ b/cf/make-proto.pl @@ -4,7 +4,11 @@ use Getopt::Std; use File::Compare; +use JSON; + my $comment = 0; +my $doxygen = 0; +my $funcdoc = 0; my $if_0 = 0; my $brace = 0; my $line = ""; @@ -12,8 +16,19 @@ my $debug = 0; my $oproto = 1; my $private_func_re = "^_"; my %depfunction = (); +my %exported = {}; +my %deprecated = {}; +my $apple = 0; +my %documentation = {}; getopts('x:m:o:p:dqE:R:P:') || die "foo"; +if($opt_a) { + $apple = 1; +} + +if($opt_a) { + $apple = 1; +} if($opt_d) { $debug = 1; @@ -52,18 +67,20 @@ if($opt_m) { } if($opt_x) { - open(EXP, $opt_x); - while() { - chomp; - s/\#.*//g; - s/\s+/ /g; - if(/^([a-zA-Z0-9_]+)\s?(.*)$/) { - $exported{$1} = $2; - } else { - print $_, "\n"; + my $EXP; + local $/; + open(EXP, '<', $opt_x) || die "open ${opt_x}"; + my $obj = JSON->new->utf8->decode(); + close $EXP; + + foreach my $x (keys %$obj) { + if (defined $obj->{$x}->{"export"}) { + $exported{$x} = $obj->{$x}; + } + if (defined $obj->{$x}->{"deprecated"}) { + $deprecated{$x} = $obj->{$x}->{"deprecated"}; } } - close EXP; } while(<>) { @@ -72,8 +89,10 @@ while(<>) { # Handle C comments s@/\*.*\*/@@; s@//.*/@@; - if ( s@/\*.*@@) { $comment = 1; - } elsif ($comment && s@.*\*/@@) { $comment = 0; + if ( s@/\*\*(.*)@@) { $comment = 1; $doxygen = 1; $funcdoc = $1; + } elsif ( s@/\*.*@@) { $comment = 1; + } elsif ($comment && s@.*\*/@@) { $comment = 0; $doxygen = 0; + } elsif ($doxygen) { $funcdoc .= $_; next; } elsif ($comment) { next; } if(/^\#if 0/) { @@ -165,6 +184,22 @@ while(<>) { if($attr ne "") { $_ .= "\n $attr"; } + if ($funcdoc) { + $documentation{$f} = $funcdoc; + } + $funcdoc = undef; + if ($apple && exists $exported{$f}) { + $ios = $exported{$f}{ios}; + $ios = "NA" if (!defined $ios); + $mac = $exported{$f}{macos}; + $mac = "NA" if (!defined $mac); + die "$f neither" if ($mac eq "NA" and $ios eq "NA"); + $_ = $_ . " __OSX_AVAILABLE_STARTING(__MAC_${mac}, __IPHONE_${ios})"; + } + if (exists $deprecated{$f}) { + $_ = $_ . " GSSAPI_DEPRECATED_FUNCTION(\"$deprecated{$f}\")"; + $depfunction{GSSAPI_DEPRECATED_FUNCTION} = 1; + } $_ = $_ . ";"; $funcs{$f} = $_; } @@ -182,6 +217,9 @@ while(<>) { } } +die "reached end of code and still in doxygen comment" if ($doxygen); +die "reached end of code and still in comment" if ($comment); + sub foo { local ($arg) = @_; $_ = $arg; @@ -266,12 +304,20 @@ foreach(sort keys %funcs){ } else { $beginblock = $endblock = ""; } - if(!defined($exported{$_}) && /$private_func_re/) { - $private_h .= $beginblock . $funcs{$_} . "\n" . $endblock . "\n"; + # if we have an export table and doesn't have content, or matches private RE + if(($#exported ne 0 && !exists $exported{$_} ) || /$private_func_re/) { + $private_h .= $beginblock; + $private_h .= $funcs{$_} . "\n" ; + $private_h .= $endblock . "\n"; if($funcs{$_} =~ /__attribute__/) { $private_attribute_seen = 1; } } else { + if($documentation{$_}) { + $public_h .= "/**\n"; + $public_h .= "$documentation{$_}"; + $public_h .= " */\n"; + } if($flags{"function-blocking"}) { $fupper = uc $_; if($exported{$_} =~ /proto/) {