Changeset 11985
- Timestamp:
- 07/24/10 20:19:05 (19 months ago)
- File:
-
- 1 edited
-
trunk/tools/parse_wxwidgets_docs.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/parse_wxwidgets_docs.pl
r11984 r11985 10 10 use HTTP::Request (); 11 11 use Archive::Extract (); 12 use HTML::Parse qw(parse_html);12 use HTML::Parse qw(parse_html); 13 13 use HTML::FormatText (); 14 14 … … 23 23 24 24 # Step 3: Read WX Classes list index file 25 my $wx_dir = File::Spec->join( $dir, 'docs', 'mshtml', 'wx');25 my $wx_dir = File::Spec->join( $dir, 'docs', 'mshtml', 'wx' ); 26 26 my @wxclasses = read_wx_classes_list($wx_dir); 27 27 print "Found " . @wxclasses . " Wx Classes to parse\n"; 28 28 29 29 # Step 4: Write the final POD while processing all html files 30 write_pod( $wx_dir, @wxclasses);30 write_pod( $wx_dir, @wxclasses ); 31 31 32 32 # and we're done … … 37 37 # 38 38 sub download_wxwidgets_html_zip { 39 unless (-e $WX_WIGDETS_HTML_ZIP) {39 unless ( -e $WX_WIGDETS_HTML_ZIP ) { 40 40 my $url = 'http://garr.dl.sourceforge.net/project/wxwindows/Documents/2.8.10/$WX_WIGDETS_HTML_ZIP'; 41 41 print "Downloading $url. Please wait...\n"; 42 my $ua = LWP::UserAgent->new;43 my $req = HTTP::Request->new( GET => $url);42 my $ua = LWP::UserAgent->new; 43 my $req = HTTP::Request->new( GET => $url ); 44 44 my $res = $ua->request($req); 45 if (not $res->is_success) {45 if ( not $res->is_success ) { 46 46 die $res->status_line, "\n"; 47 47 } … … 49 49 # Write download file to disk 50 50 print "Writing $WX_WIGDETS_HTML_ZIP...\n"; 51 if (open FILE, '>:raw', $WX_WIGDETS_HTML_ZIP) {51 if ( open FILE, '>:raw', $WX_WIGDETS_HTML_ZIP ) { 52 52 print FILE $res->content; 53 53 close FILE; … … 67 67 68 68 my $zip = Archive::Extract->new( archive => $WX_WIGDETS_HTML_ZIP ); 69 die "$WX_WIGDETS_HTML_ZIP is not a zip file\n" unless ( $zip->is_zip);69 die "$WX_WIGDETS_HTML_ZIP is not a zip file\n" unless ( $zip->is_zip ); 70 70 print "Extracting $WX_WIGDETS_HTML_ZIP to $dir...\n"; 71 $zip->extract( to => $dir) or die $zip->error;71 $zip->extract( to => $dir ) or die $zip->error; 72 72 } 73 73 … … 79 79 sub read_wx_classes_list { 80 80 my $dir = shift; 81 82 my $wx_classref = File::Spec->join( $dir, 'wx_classref.html');81 82 my $wx_classref = File::Spec->join( $dir, 'wx_classref.html' ); 83 83 84 84 # Stores a list of WX classes filenames … … 86 86 87 87 #Step 1: Read Wx classes list from wx_classref.html 88 if (open(my $fh, $wx_classref)) {88 if ( open( my $fh, $wx_classref ) ) { 89 89 print "Opened $wx_classref\n"; 90 90 my $begin; 91 while (my $line = <$fh>) {92 if ($line =~ /<H2>Alphabetical class reference<\/H2>/) {91 while ( my $line = <$fh> ) { 92 if ( $line =~ /<H2>Alphabetical class reference<\/H2>/ ) { 93 93 $begin = 1; 94 } elsif ($begin && $line =~ /<A HREF="(.+?)#.+?"><B>(.+)?<\/B><\/A><BR>/) {95 my ( $file, $class) = ($1, $2);94 } elsif ( $begin && $line =~ /<A HREF="(.+?)#.+?"><B>(.+)?<\/B><\/A><BR>/ ) { 95 my ( $file, $class ) = ( $1, $2 ); 96 96 $class =~ s/wx(.+?)/Wx::$1/; 97 97 push @wxclasses, { file => $file, class => $class }; … … 107 107 # 108 108 # Process wxClassName HTML file 109 # 109 # 110 110 sub process_class { 111 my ( $class, $file) = @_;112 111 my ( $class, $file ) = @_; 112 113 113 my $oldclass; 114 114 my $pod_text = ''; 115 if (open my $html_file, '<', $file) {115 if ( open my $html_file, '<', $file ) { 116 116 my $desc = ''; 117 117 my $name; 118 while (my $line = <$html_file>) {119 if ($line =~ /<H3>(.+?)<\/H3>/) {118 while ( my $line = <$html_file> ) { 119 if ( $line =~ /<H3>(.+?)<\/H3>/ ) { 120 120 $name = $1; 121 121 $name =~ s/wx(.+?)/Wx::$1/; 122 if ($name =~ /^Wx::(.+?)::(.+?)$/) {122 if ( $name =~ /^Wx::(.+?)::(.+?)$/ ) { 123 123 my $method = $2; 124 if($method eq "wx$1") { 124 if ( $method eq "wx$1" ) { 125 125 126 # Convert C++ constructor to ::new 126 127 $name = $class . '::new'; 127 } elsif($method =~ /^~.+/) { 128 } elsif ( $method =~ /^~.+/ ) { 129 128 130 # Convert C++ destructor to ::DESTROY 129 131 $name = $class . '::DESTROY'; 130 } elsif ($method =~ /^operator.+/) { 132 } elsif ( $method =~ /^operator.+/ ) { 133 131 134 # Ignore operators 132 135 $name = undef; … … 134 137 } 135 138 $desc = ''; 136 } elsif($line =~ /^\s*$/) { 137 if($name) { 138 if(!$oldclass || $class ne $oldclass) { 139 } elsif ( $line =~ /^\s*$/ ) { 140 if ($name) { 141 if ( !$oldclass || $class ne $oldclass ) { 142 139 143 # print out new class header 140 144 $pod_text .= "=head1 $class\n\n"; … … 143 147 144 148 # print out method description 145 $desc = HTML::FormatText->new->format( parse_html($desc));149 $desc = HTML::FormatText->new->format( parse_html($desc) ); 146 150 $pod_text .= "=head2 $name\n$desc\n"; 147 151 … … 154 158 close $html_file; 155 159 } 156 160 157 161 return $pod_text; 158 162 } … … 162 166 # 163 167 sub write_pod { 164 my ( $wx_dir, @wxclasses) = @_;168 my ( $wx_dir, @wxclasses ) = @_; 165 169 my $pod_file = 'wxwidgets.pod'; 166 170 print "Writing $pod_file\n"; 167 if (open(my $pod, '>', 'wxwidgets.pod')) {171 if ( open( my $pod, '>', 'wxwidgets.pod' ) ) { 168 172 my $oldclass; 169 173 foreach my $wxclass (@wxclasses) { 170 my $file = File::Spec->join( $wx_dir, $wxclass->{file});174 my $file = File::Spec->join( $wx_dir, $wxclass->{file} ); 171 175 my $class = $wxclass->{class}; 172 176 print "Processing $class...\n"; 173 print $pod process_class( $class, $file);177 print $pod process_class( $class, $file ); 174 178 } 175 179 close $pod;
Note: See TracChangeset
for help on using the changeset viewer.
