]> git.sesse.net Git - vlc/blob - bindings/java/extras/convert.py
input: Expose input_ItemHasErrorWhenReading.
[vlc] / bindings / java / extras / convert.py
1 #!/usr/bin/python
2 """
3 vlc to jna almost-automatized interface converter.
4
5 This program is free software. It comes without any warranty, to
6 the extent permitted by applicable law. You can redistribute it
7 and/or modify it under the terms of the Do What The Fuck You Want
8 To Public License, Version 2, as published by Sam Hocevar. See
9 http://sam.zoy.org/wtfpl/COPYING for more details. 
10
11 """
12
13 import sys
14
15 file = open('libvlc.h', 'r')
16
17 parameter_parsing = False
18 prototype_parsing = False
19
20 types_map = [
21         ["const ", ""],
22         ["VLC_PUBLIC_API ", ""],
23         ["char**", "String[] "],
24         ["char **" , "String[] "],
25         ["char*" , "String "],
26         ["char *" , "String "],
27         ["libvlc_instance_t *", "LibVlcInstance "],
28         ["libvlc_exception_t *", "libvlc_exception_t "],
29         ["libvlc_log_t *", "LibVlcLog "],
30         ["libvlc_log_iterator_t *", "LibVlcLogIterator "],
31         ["libvlc_log_message_t *", "libvlc_log_message_t "],
32         ["unsigned", "int"],
33 ]
34
35 def convert_prototype(proto, parameters):
36         #print proto
37         #print parameters
38         tokens = proto.split(",")
39         last = tokens.pop().split(")")
40         res = ''
41         for i in tokens:
42                 param = parameters.pop(0)
43                 if i.find(param)==-1:
44                         res += i + " " + param + ","
45                 else:
46                         res += i + " ,"
47         if len(parameters):
48                 param = parameters.pop(0)
49                 if last[0].find(param)==-1:
50                         res += last[0] + " " + param + ")" + last[1]
51                 else:
52                         res += last[0] + ")" + last[1]
53
54         for k,v in types_map:
55                 res = res.replace(k,v)
56         print res
57
58 for line in file.readlines():
59         if line.find("/**")!=-1:
60                 parameters = []
61                 parameter_parsing = True
62
63         if line.find("VLC_PUBLIC_API")!=-1:
64                 if not parameters:
65                         continue
66                 prototype_line = ''
67                 prototype_parsing = True
68
69         if parameter_parsing:
70                 param_index = line.find("\param ")
71                 if not param_index==-1:
72                         parameter = line.split()[2]
73                         parameters.append(parameter)
74                 if line.find("*/")!=-1:
75                         parameter_parsing = False
76
77         if prototype_parsing:
78                 prototype_line += line.strip()
79                 if line.find(");")!=-1:
80                         prototype_parsing = False
81                         convert_prototype(prototype_line, parameters)
82                         parameters = None
83                 continue
84
85         #sys.stdout.write(line)
86
87 # vi:ts=4