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