Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / script / make_exp_list.pl
1 #!/usr/bin/perl -w
2 #############################################################################
3 ## Name:        script/make_exp_list.pl
4 ## Purpose:     builds lib/Wx/_Exp.pm (export lists for Wx and Wx::Event)
5 ## Author:      Mattia Barbon
6 ## Modified by:
7 ## Created:     29/10/2000
8 ## RCS-ID:      $Id: make_exp_list.pl 2057 2007-06-18 23:03:00Z mbarbon $
9 ## Copyright:   (c) 2000-2003, 2005 Mattia Barbon
10 ## Licence:     This program is free software; you can redistribute it and/or
11 ##              modify it under the same terms as Perl itself
12 #############################################################################
13
14 #
15 # @EXPORT_OK and %EXPORT_TAGS for Wx.pm (constants in Constant.xs)
16 #
17
18 my $ext = shift @ARGV;
19
20 my $parser;
21 my %packages;
22 my $tag;
23 my $package;
24
25 sub add_to_exports {
26   my( $values, $tags ) = @_;
27
28   foreach my $i ( split '\s+', $values ) {
29     next if $i =~ /^\s*$/;
30
31     foreach my $j ( split '\s+', $tags ) {
32       next if $_ =~ /^\s*$/;
33
34       push @{ $packages{$package}{tags}{$j} }, $i;
35     }
36
37     push @{ $packages{$package}{exp_ok} }, $i;
38   }
39 }
40
41 foreach my $i ( @ARGV ) {
42   open IN, '< ' . $i or die "unable to open '$i'";
43   $tag = '';
44   $package = '';
45   $parser = undef;
46
47   while( <IN> ) {
48     m/^\W+?\!(\w+):\s*(.*)$/ && do {
49       my( $t, $v ) = ( $1, $2 );
50
51       if( $t eq 'parser' ) { $parser = eval "$v"; die if $@ }
52       if( $t eq 'package' ) { $package = $v }
53       if( $t eq 'tag' ) { $tag = $v }
54       if( $t eq 'export' ) { add_to_exports( $v, $tag ); next }
55       next;
56     };
57     next unless $parser;
58
59     my @values = $parser->( $_ );
60     ( defined( $values[0] ) && length( $values[0] ) ) || next;
61     $values[1] ||= '';
62
63     add_to_exports( $values[0], "$values[1] $tag" );
64   }
65 }
66
67 close IN;
68
69 #
70 # write export file
71 #
72
73 local $" = "\n";
74
75 open OUT, '> '. $ext || die "unable to open file '$ext'";
76
77 binmode OUT; # Perl 5.004 on Unix complains for CR
78
79 print OUT <<EOT;
80 #############################################################################
81 ## Name:        lib/Wx/Wx_Exp.pm
82 ## Purpose:     export lists (AUTOGENERATED, DO NOT EDIT)
83 ## Author:      Mattia Barbon
84 ## Modified by:
85 ## Licence:     This program is free software; you can redistribute it and/or
86 ##              modify it under the same terms as Perl itself
87 #############################################################################
88
89 package Wx::Wx_Exp; # for RPM
90
91 EOT
92
93 foreach my $package ( sort keys %packages ) {
94 print OUT <<EOT;
95
96 package ${package};
97
98 push \@EXPORT_OK, qw(@{$packages{$package}{exp_ok}});
99
100 \$EXPORT_TAGS{'everything'} = \\\@EXPORT_OK;
101
102 EOT
103
104   foreach my $tag ( sort keys %{ $packages{$package}{tags} } ) {
105     next unless length $tag;
106     print OUT <<EOT;
107 \$EXPORT_TAGS{'$tag'} = [ qw(@{ $packages{$package}{tags}{$tag} }) ];
108 EOT
109   }
110 }
111
112 print OUT <<EOT;
113 1;
114
115 # Local variables: #
116 # mode: cperl #
117 # End: #
118 EOT
119
120 # Local variables: #
121 # mode: cperl #
122 # End: #
123