| 1 |
|
|---|
| 2 |
""" |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 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 |
|
|---|
| 37 |
|
|---|
| 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 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|