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