]> git.sesse.net Git - vlc/blob - vlc-api.pl
* ALL: extention -> extension
[vlc] / vlc-api.pl
1 #!/usr/bin/perl
2 #*****************************************************************************
3 #* vlc-api.pl: VLC API maintenance script
4 #*****************************************************************************
5 #* Copyright (C) 2005 the VideoLAN team
6 #* $Id$
7 #*
8 #* Authors: RĂ©mi Denis-Courmont <rem # videolan.org>
9 #*
10 #* This program is free software; you can redistribute it and/or modify
11 #* it under the terms of the GNU General Public License as published by
12 #* the Free Software Foundation; either version 2 of the License, or
13 #* (at your option) any later version.
14 #*
15 #* This program is distributed in the hope that it will be useful,
16 #* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #* GNU General Public License for more details.
19 #*
20 #* You should have received a copy of the GNU General Public License
21 #* along with this program; if not, write to the Free Software
22 #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 #*****************************************************************************/
24
25 use IO::Handle;
26 use strict;
27
28 my $srcdir = $ENV{'top_srcdir'};
29
30 #
31 # Reads to-be exported APIs
32 #
33 my %new_APIs;
34
35 while (<STDIN>)
36 {
37         if (/VLC_EXPORT\(\s*(\w.*\S)\s*,\s*(\w*)\s*,\s*\(\s*(\w.*\S)\s*\)\s*\)[^)]*$/)
38         {
39                 $new_APIs{$2} = [ ( $1, $3 ) ];
40         } 
41 }
42
43 #
44 # Write header's header
45 #
46 my $new_sym=IO::Handle->new();
47 open $new_sym, '> vlc_symbols.h.new' or die "$!";
48 print { $new_sym }
49         "/*\n".
50         " * This file is automatically generated. DO NOT EDIT!\n".
51         " * You can force an update with \"make stamp-api\".\n".
52         " */\n".
53         "\n".
54         "#ifndef __VLC_SYMBOLS_H\n".
55         "# define __VLC_SYMBOLS_H\n".
56         "\n".
57         "# ifdef HAVE_SHARED_LIBVLC\n".
58         "#  error You are not supposed to include this file!\n".
59         "# endif\n".
60         "/*\n".
61         " * This is the big VLC API structure for plugins :\n".
62         " * Changing its layout breaks plugin's binary compatibility,\n".
63         " * so DO NOT DO THAT.\n".
64         " * In case of conflict with SVN, add your uncommited APIs\n".
65         " * at the *end* of the structure so they don't mess the other's\n".
66         " * offset in the structure.\n".
67         " */\n".
68         "struct module_symbols_t\n".
69         "{\n";
70
71 my $changes = 0;
72
73 #
74 # Compares new APIs with currently exported APIs
75 #
76 my @API;
77 my @deprecated_API;
78 my $parse = 0;
79
80 my $oldfd = IO::Handle->new();
81 open $oldfd, "< $srcdir/include/vlc_symbols.h";
82
83 while (<$oldfd>)
84 {
85         if (/^struct module_symbols_t/)
86         {
87                 $parse = 1;
88         }
89         elsif ($parse == 0)
90         {
91         }
92         elsif (/^    void \*(\w*)_deprecated;$/)
93         {
94                 if (defined $new_APIs{$1})
95                 {
96                         print "[info] $1 was RESTORED!\n";
97                         print { $new_sym }
98                                 "    ".$new_APIs{$1}[0]." (*$1_inner) (".$new_APIs{$1}[1].");\n";
99                         delete $new_APIs{$1};
100                         push (@API, $1);
101                         $changes++;
102                 }
103                 else
104                 {
105                         print { $new_sym } $_;
106                         push (@deprecated_API, $1);
107                 }
108         }
109         elsif (/^\s*(\w.*\S)\s*\(\*\s*(\w*)_inner\)\s*\(\s*(\w.*\S)\s*\)\s*;\s*$/)
110         {
111                 if (!defined $new_APIs{$2})
112                 {
113                         print "[warn] $2 was REMOVED!\n";
114                         print { $new_sym } "    void *$2_deprecated;\n";
115                         push (@deprecated_API, $2);
116                         $changes++;
117                 }
118                 elsif (($new_APIs{$2}[0] ne $1)
119                     || ($new_APIs{$2}[1] ne $3))
120                 {
121                         print
122                                 "[warn] $2 was CHANGED!\n".
123                                 "       Old argument(s) : \"$3\"\n".
124                                 "       New argument(s) : \"".$new_APIs{$2}[1]."\"\n".
125                                 "       Old return type : \"$1\"\n".
126                                 "       New return type : \"".$new_APIs{$2}[0]."\"\n";
127
128                         print { $new_sym }
129                                 "    ".$new_APIs{$2}[0]." (*$2_inner) (".$new_APIs{$2}[1].");\n";
130                         delete $new_APIs{$2};
131                         push (@API, $2);
132                         $changes++;
133                 }
134                 else
135                 {
136                         print { $new_sym } "    $1 (*$2_inner) ($3);\n";
137                         push (@API, $2);
138                         delete $new_APIs{$2};
139                 }
140         }
141 }
142 close $oldfd;
143
144 #
145 # Adds brand-new APIs
146 #
147 foreach (keys %new_APIs)
148 {
149         print "[info] $_ was ADDED!\n";
150         print { $new_sym }
151                 "    ".$new_APIs{$_}[0]." (*${_}_inner) (".$new_APIs{$_}[1].");\n";
152         push (@API, $_);
153         $changes++;
154 }
155
156 #
157 # Writes #defines
158 #
159 print { $new_sym }
160         "};\n".
161         "# if defined (__PLUGIN__)\n";
162
163 foreach (@API)
164 {
165         print { $new_sym } "#  define $_ (p_symbols)->${_}_inner\n";
166 }
167
168 print { $new_sym }
169         "# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)\n".
170         "/******************************************************************\n".
171         " * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.\n".
172         " ******************************************************************/\n".
173         "#  define STORE_SYMBOLS( p_symbols ) \\\n";
174
175 foreach (@API)
176 {
177         print { $new_sym } "    ((p_symbols)->${_}_inner) = $_; \\\n";
178 }
179 foreach (@deprecated_API)
180 {
181         print { $new_sym } "    (p_symbols)->${_}_deprecated = NULL; \\\n";
182 }
183
184 print { $new_sym }
185         "\n".
186         "# endif /* __PLUGIN__ */\n".
187         "#endif /* __VLC_SYMBOLS_H */\n";
188 close $new_sym;
189
190 #
191 # Replace headers if needed
192 #
193 if ($changes != 0)
194 {
195         rename 'vlc_symbols.h.new', "$srcdir/include/vlc_symbols.h";
196         print "$changes API(s) changed.\n";
197 }
198 else
199 {
200         unlink 'vlc_symbols.h.new';
201 }