File: make_exp_list.pl

package info (click to toggle)
libwx-perl 1%3A0.9932-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,300 kB
  • sloc: cpp: 11,064; perl: 8,603; ansic: 711; makefile: 53
file content (130 lines) | stat: -rwxr-xr-x 3,071 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl -w
#############################################################################
## Name:        script/make_exp_list.pl
## Purpose:     builds lib/Wx/_Exp.pm (export lists for Wx and Wx::Event)
## Author:      Mattia Barbon
## Modified by:
## Created:     29/10/2000
## RCS-ID:      $Id: make_exp_list.pl 2927 2010-06-06 08:06:10Z mbarbon $
## Copyright:   (c) 2000-2003, 2005, 2010 Mattia Barbon
## Licence:     This program is free software; you can redistribute it and/or
##              modify it under the same terms as Perl itself
#############################################################################

#
# @EXPORT_OK and %EXPORT_TAGS for Wx.pm (constants in Constant.xs)
#

my $ext = shift @ARGV;

my $parser;
my %packages;
my $tag;
my $package;

sub unique_sorted {
  my %v = %{ { map { ($_ => 1) } @{$_[0]} } };
  sort keys %v;
}

sub add_to_exports {
  my( $values, $tags ) = @_;

  foreach my $i ( split '\s+', $values ) {
    next if $i =~ /^\s*$/;

    foreach my $j ( split '\s+', $tags ) {
      next if $_ =~ /^\s*$/;

      push @{ $packages{$package}{tags}{$j} }, $i;
    }

    push @{ $packages{$package}{exp_ok} }, $i;
  }
}

foreach my $i ( map glob( $_ ), @ARGV ) {
  open IN, '< ' . $i or die "unable to open '$i'";
  $tag = '';
  $package = '';
  $parser = undef;

  while( <IN> ) {
    m/^\W+?\!(\w+):\s*(.*)$/ && do {
      my( $t, $v ) = ( $1, $2 );

      if( $t eq 'parser' ) { $parser = eval "$v"; die if $@ }
      if( $t eq 'package' ) { $package = $v }
      if( $t eq 'tag' ) { $tag = $v }
      if( $t eq 'export' ) { add_to_exports( $v, $tag ); next }
      next;
    };
    next unless $parser;

    my @values = $parser->( $_ );
    ( defined( $values[0] ) && length( $values[0] ) ) || next;
    $values[1] ||= '';

    add_to_exports( $values[0], "$values[1] $tag" );
  }
}

close IN;

#
# write export file
#

local $" = "\n";

open OUT, '> '. $ext || die "unable to open file '$ext'";

binmode OUT; # Perl 5.004 on Unix complains for CR

print OUT <<EOT;
#############################################################################
## Name:        lib/Wx/Wx_Exp.pm
## Purpose:     export lists (AUTOGENERATED, DO NOT EDIT)
## Author:      Mattia Barbon
## Modified by:
## Licence:     This program is free software; you can redistribute it and/or
##              modify it under the same terms as Perl itself
#############################################################################

package Wx::Wx_Exp; # for RPM

EOT

foreach my $package ( sort keys %packages ) {
  my @exp = unique_sorted( $packages{$package}{exp_ok} );
  print OUT <<EOT;

package ${package};

push \@EXPORT_OK, qw(@exp);

\$EXPORT_TAGS{'everything'} = \\\@EXPORT_OK;

EOT

  foreach my $tag ( sort keys %{ $packages{$package}{tags} } ) {
    next unless length $tag;
    my @pkgtags = unique_sorted( $packages{$package}{tags}{$tag} );
    print OUT <<EOT;
\$EXPORT_TAGS{'$tag'} = [ qw(@pkgtags) ];
EOT
  }
}

print OUT <<EOT;
1;

# Local variables: #
# mode: cperl #
# End: #
EOT

# Local variables: #
# mode: cperl #
# End: #