* Fix shoutcast SD Delete. playlist is not locked.
[vlc.git] / 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 my $new_sym = IO::Handle->new();
35 open $new_sym, '> libvlc.sym' or die "libvlc.sym: $!\n";
36
37 while (<STDIN>)
38 {
39         if (/VLC_EXPORT\(\s*(\w.*\S)\s*,\s*(\w*)\s*,\s*\(\s*(\w.*\S)\s*\)\s*\)[^)]*$/)
40         {
41                 $new_APIs{$2} = [ ( $1, $3 ) ];
42                 print { $new_sym } "$2\n";
43         } 
44 }
45
46 close $new_sym;
47
48 #
49 # Write header's header
50 #
51 open $new_sym, '> vlc_symbols.h.new' or die "vlc_symbols.h.new: $!\n";
52 print { $new_sym }
53         "/*\n".
54         " * This file is automatically generated. DO NOT EDIT!\n".
55         " * You can force an update with \"make stamp-api\".\n".
56         " */\n".
57         "\n".
58         "#ifndef __VLC_SYMBOLS_H\n".
59         "# define __VLC_SYMBOLS_H\n".
60         "\n".
61         "# ifdef HAVE_SHARED_LIBVLC\n".
62         "#  error You are not supposed to include this file!\n".
63         "# endif\n".
64         "/*\n".
65         " * This is the big VLC API structure for plugins :\n".
66         " * Changing its layout breaks plugin's binary compatibility,\n".
67         " * so DO NOT DO THAT.\n".
68         " * In case of conflict with SVN, add your uncommited APIs\n".
69         " * at the *end* of the structure so they don't mess the other's\n".
70         " * offset in the structure.\n".
71         " */\n".
72         "struct module_symbols_t\n".
73         "{\n";
74
75 my $changes = 0;
76
77 #
78 # Compares new APIs with currently exported APIs
79 #
80 my @API;
81 my @deprecated_API;
82 my $parse = 0;
83
84 my $oldfd = IO::Handle->new();
85 open $oldfd, "< $srcdir/include/vlc_symbols.h";
86
87 while (<$oldfd>)
88 {
89         if (/^struct module_symbols_t/)
90         {
91                 $parse = 1;
92         }
93         elsif ($parse == 0)
94         {
95         }
96         elsif (/^    void \*(\w*)_deprecated;$/)
97         {
98                 if (defined $new_APIs{$1})
99                 {
100                         print "[info] $1 was RESTORED!\n";
101                         print { $new_sym }
102                                 "    ".$new_APIs{$1}[0]." (*$1_inner) (".$new_APIs{$1}[1].");\n";
103                         delete $new_APIs{$1};
104                         push (@API, $1);
105                         $changes++;
106                 }
107                 else
108                 {
109                         print { $new_sym } $_;
110                         push (@deprecated_API, $1);
111                 }
112         }
113         elsif (/^\s*(\w.*\S)\s*\(\*\s*(\w*)_inner\)\s*\(\s*(\w.*\S)\s*\)\s*;\s*$/)
114         {
115                 if (!defined $new_APIs{$2})
116                 {
117                         print "[warn] $2 was REMOVED!\n";
118                         print { $new_sym } "    void *$2_deprecated;\n";
119                         push (@deprecated_API, $2);
120                         $changes++;
121                 }
122                 elsif (($new_APIs{$2}[0] ne $1)
123                     || ($new_APIs{$2}[1] ne $3))
124                 {
125                         print
126                                 "[warn] $2 was CHANGED!\n".
127                                 "       Old argument(s) : \"$3\"\n".
128                                 "       New argument(s) : \"".$new_APIs{$2}[1]."\"\n".
129                                 "       Old return type : \"$1\"\n".
130                                 "       New return type : \"".$new_APIs{$2}[0]."\"\n";
131
132                         print { $new_sym }
133                                 "    ".$new_APIs{$2}[0]." (*$2_inner) (".$new_APIs{$2}[1].");\n";
134                         delete $new_APIs{$2};
135                         push (@API, $2);
136                         $changes++;
137                 }
138                 else
139                 {
140                         print { $new_sym } "    $1 (*$2_inner) ($3);\n";
141                         push (@API, $2);
142                         delete $new_APIs{$2};
143                 }
144         }
145 }
146 close $oldfd;
147
148 #
149 # Adds brand-new APIs
150 #
151 foreach (keys %new_APIs)
152 {
153         print "[info] $_ was ADDED!\n";
154         print { $new_sym }
155                 "    ".$new_APIs{$_}[0]." (*${_}_inner) (".$new_APIs{$_}[1].");\n";
156         push (@API, $_);
157         $changes++;
158 }
159
160 #
161 # Writes #defines
162 #
163 print { $new_sym }
164         "};\n".
165         "# if defined (__PLUGIN__)\n";
166
167 foreach (@API)
168 {
169         print { $new_sym } "#  define $_ (p_symbols)->${_}_inner\n";
170 }
171
172 print { $new_sym }
173         "# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)\n".
174         "/******************************************************************\n".
175         " * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.\n".
176         " ******************************************************************/\n".
177         "#  define STORE_SYMBOLS( p_symbols ) \\\n";
178
179 foreach (@API)
180 {
181         print { $new_sym } "    ((p_symbols)->${_}_inner) = $_; \\\n";
182 }
183 foreach (@deprecated_API)
184 {
185         print { $new_sym } "    (p_symbols)->${_}_deprecated = NULL; \\\n";
186 }
187
188 print { $new_sym }
189         "\n".
190         "# endif /* __PLUGIN__ */\n".
191         "#endif /* __VLC_SYMBOLS_H */\n";
192 close $new_sym;
193
194 #
195 # Replace headers if needed
196 #
197 if ($changes != 0)
198 {
199         rename 'vlc_symbols.h.new', "$srcdir/include/vlc_symbols.h";
200         print "$changes API(s) changed.\n";
201 }
202 else
203 {
204         unlink 'vlc_symbols.h.new';
205 }