forked from WiringPi/WiringPi-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-bindings.py
40 lines (34 loc) · 1.11 KB
/
generate-bindings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
HEADERS = []
src = open("wiringpi.i").read().split('\n')
for line in src:
line = line.strip()
if line.startswith('#include') and line.endswith('.h"'):
HEADERS.append(line.replace('#include','').replace('"','').strip())
#print(HEADERS)
def is_c_decl(line):
for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']:
if fn in line:
return False
for prefix in ['extern','void','int','uint8_t']:
if line.startswith(prefix):
return True
print("// Generated by generate-bindings.py - do not edit manually!")
for file in HEADERS:
print("\n// Header file {}".format(file))
h = open(file).read().split('\n')
extern = False
cont = False
if 'extern "C" {' not in h:
extern = True
for line in h:
line = line.strip()
if cont:
print("\t{}".format(line))
cont = ";" not in line
continue
if line.startswith('extern "C"'):
extern = True
continue
if is_c_decl(line) and extern:
print(line)
cont = ";" not in line