From: Jon Purdy Date: Tue, 21 Feb 2017 23:40:59 +0000 (-0800) Subject: [exdoc] Enable 'warnings' and 'strict'. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=3830a53dc49ad933c0a236092cff28841b2c37b3 [exdoc] Enable 'warnings' and 'strict'. --- diff --git a/docs/exdoc b/docs/exdoc index d7390d9a9ec..76da62004af 100644 --- a/docs/exdoc +++ b/docs/exdoc @@ -1,5 +1,22 @@ #!/usr/bin/perl +use warnings; +use strict; + +my $sourcedir = ''; +my $dir = ''; +my $html = 0; +my $css = ''; +my @files = (); +my $filecount = 0; +my @files_content = (); +my @apis = (); +my %deprecated = (); +my %prototype = (); +my %arguments = (); +my %returns = (); +my %bodies = (); + if ($ARGV[0] eq "-h") { $sourcedir = $ARGV[1]; $dir = $sourcedir; @@ -19,14 +36,15 @@ if ($ARGV[0] eq "-t") { if ($html) { opendir (D, "$sourcedir/sources/") || die "Can not open $dir"; - while ($n = readdir (D)) { + while (my $n = readdir (D)) { if ($n =~ /mono-api-.*\.html$/) { open (IN, "$sourcedir/sources/$n") || die "Can not open $n"; $files[$filecount] = $n; + $files_content[$filecount] = ''; while () { - @files_content[$filecount] .= $_; + $files_content[$filecount] .= $_; if (/name="api:(.*?)"/) { - $_ =~ s/.*name="api:(\w+?)".*/\1/; + $_ =~ s/.*name="api:(\w+?)".*/$1/; $apis[$filecount] .= "$_"; } } @@ -45,8 +63,9 @@ while () { } if ($html) { - for ($f = 0; $f < $filecount; $f++) { - $name = $files[$f]; + my $last = ''; + for (my $f = 0; $f < $filecount; $f++) { + my $name = $files[$f]; open (OUT, "> $dir/html/$name") || die "Can not create $dir/html/$name"; print "Merging: $name\n"; print OUT < \n\n"; if ($deprecated{$api}) { @@ -80,10 +98,7 @@ EOF } } $api_shown = 1; - $proto = $prototype{$api}; - if ($proto eq "") { - $proto = "$api"; - } + my $proto = $prototype{$api} // $api; print OUT < @@ -98,18 +113,20 @@ EOF
$proto

EOF - $ppars = $arguments{$api}; - if ($ppars ne "" && (!($ppars =~ /^[ \t]+$/))) { - print OUT "

Parameters
\n"; - print OUT " ".${arguments{$api}}."
"; + if (exists ($arguments{$api})) { + my $ppars = $arguments{$api}; + if ($ppars !~ /^[ \t]+$/) { + print OUT "
Parameters
\n"; + print OUT " ".${arguments{$api}}."
"; + } } &opt_print ("Return value", $returns{$api}, 0); &opt_print ("Description", $bodies{$api}, 0); print OUT " \n \n"; } else { - if ($line =~ /@API_IDX@/) { - $apis_toc = &create_toc ($apis[$f]); + if ($line =~ /\@API_IDX\@/) { + my $apis_toc = &create_toc ($apis[$f]); $line =~ s/\@API_IDX\@/$apis_toc/; } if ($line =~ /^

$dir/deploy/$name" || die "Could not open output"; - $line = 0; - $doprint = 0; + my $line = 0; + my $doprint = 0; while () { print HACKOUT $last if ($doprint); $line++; @@ -166,42 +183,41 @@ EOF } sub process_doc { - $doc = ""; - $func = <>; + my $doc = ""; + my $func = <>; chop $func; $func =~ s/^ \* //; $func =~ s/:$//; print "Function: $func\n" if (!$html); - $args = ""; - $inbody = 0; - $returns = ""; - $body = ""; - $functions[$fn++] = $func; - $deprecated = 0; + my $args = ""; + my $inbody = 0; + my $returns = ""; + my $body = ""; + my $deprecated = 0; # Process arguments while (<>) { s/NULL/NULL<\/code>/g; s/TRUE/TRUE<\/code>/g; s/FALSE/FALSE<\/code>/g; if (/^ \*\*?\//) { - $body =~ s/@(\w+)/\1<\/i>/g; - $returns =~ s/@(\w+)/\1<\/i>/g; - $args =~ s/@(\w+)/\1<\/i>/g; + $body =~ s/\@(\w+)/$1<\/i>/g; + $returns =~ s/\@(\w+)/$1<\/i>/g; + $args =~ s/\@(\w+)/$1<\/i>/g; - $body =~ s/#(\w+)/\1<\/code>/g; - $returns =~ s/#(\w+)/\1<\/code>/g; - $args =~ s/#(\w+)/\1<\/code>/g; + $body =~ s/#(\w+)/$1<\/code>/g; + $returns =~ s/#(\w+)/$1<\/code>/g; + $args =~ s/#(\w+)/$1<\/code>/g; - $returns =~ s/\`([:.\w\*]+)\`/\1<\/code>/g; - $args =~ s/\`([:.\w\*]+)\`/\1<\/code>/g; - $body =~ s/\`([:.\w\*]+)\`/\1<\/code>/g; + $returns =~ s/\`([:.\w\*]+)\`/$1<\/code>/g; + $args =~ s/\`([:.\w\*]+)\`/$1<\/code>/g; + $body =~ s/\`([:.\w\*]+)\`/$1<\/code>/g; $body =~ s/\n/ /; $bodies{$func} = $body; $arguments{$func} = $args; $deprecated{$func} = $deprecated; $returns{$func} = $returns; - $proto = ""; + my $proto = ""; while (<>) { $proto .= $_; last if (/\{/); @@ -210,7 +226,7 @@ sub process_doc { # clean it up a little, remove newlines, empty space at end $proto =~ s/ +$//; # Turn "Type * xxx" into "Type* xxx" - $proto =~ s/^(\w+)\W+\*/\1\*/; + $proto =~ s/^(\w+)\W+\*/$1\*/; $prototype{$func} = $proto; return; } @@ -251,36 +267,38 @@ sub create_toc { my ($apis_listed) = @_; my $type_size = 0; my $name_size = 0; - my $ret, $xname, $args, $line; - $apis_toc = ""; + my ($ret, $xname, $args); + my $apis_toc = ""; # Try to align things, so compute type size, method size, and arguments - foreach $line (split /\n/, $apis_listed) { - $p = $prototype{$line}; - ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/; - $tl = length ($ret); - $pl = length ($xname); - - $type_size = $tl if ($tl > $type_size); - $name_size = $pl if ($pl > $name_size); + foreach my $line (split /\n/, $apis_listed) { + if (exists ($prototype{$line})) { + my $p = $prototype{$line}; + if (my ($ret, $xname, $args) = ($p =~ /(.*)\n(\w+)[ \t](.*)/)) { + my $tl = length ($ret); + my $pl = length ($xname); + $type_size = $tl if ($tl > $type_size); + $name_size = $pl if ($pl > $name_size); + } + } } $type_size++; $name_size++; - foreach $line (split /\n/, $apis_listed) { - chop; - $p = $prototype{$line}; - ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/; - if ($xname eq "") { - $xname = $line; + foreach my $line (split /\n/, $apis_listed) { + chomp($line); + if (exists($prototype{$line})) { + my $p = $prototype{$line}; + if (my ($ret, $xname, $args) = ($p =~ /(.*)\n(\w+)[ \t](.*)/)) { + $xname = $line if $xname eq ""; + my $rspace = " " x ($type_size - length ($ret)); + my $nspace = " " x ($name_size - length ($xname)); + $args = &format ($args, length ($ret . $rspace . $xname . $nspace), 60); + $apis_toc .= "$ret$rspace$xname$nspace$args\n"; + } } - - $rspace = " " x ($type_size - length ($ret)); - $nspace = " " x ($name_size - length ($xname)); - $args = &format ($args, length ($ret . $rspace . $xname . $nspace), 60); - $apis_toc .= "$ret$rspace$xname$nspace$args\n"; } return $apis_toc; } @@ -294,10 +312,10 @@ sub format { # return $args if ((length (args) + size) < $limit); - $remain = $limit - $size; - @sa = split /,/, $args; - $linelen = $size; - foreach $arg (@sa) { + my $remain = $limit - $size; + my @sa = split /,/, $args; + my $linelen = $size; + foreach my $arg (@sa) { if ($sret eq "") { $sret = $arg . ", "; $linelen += length ($sret); @@ -305,8 +323,8 @@ sub format { if ($linelen + length ($arg) < $limit) { $sret .= "FITS" . $arg . ", "; } else { - $newline = " " x ($size) . $arg . ", "; - $linelen = length ($newline); + my $newline = " " x ($size) . $arg . ", "; + my $linelen = length ($newline); $sret .= "\n" . $newline; } } @@ -318,7 +336,7 @@ sub format { sub opt_print { my ($caption, $opttext, $quote) = @_; - if ($opttext ne "" && (!($opttext =~ /^[ \t]+$/))) { + if (defined($opttext) && $opttext !~ /^[ \t]+$/) { print OUT "
$caption
\n"; print OUT "
$opttext
\n"; }