Phil Howard | 95c6d56 | 2016-02-29 12:07:24 +0000 | [diff] [blame^] | 1 | HEADERS = [] |
Phil Howard | aee4f5d | 2016-02-28 09:54:53 +0000 | [diff] [blame] | 2 | |
Phil Howard | 95c6d56 | 2016-02-29 12:07:24 +0000 | [diff] [blame^] | 3 | src = open("wiringpi.i").read().split('\n') |
Phil Howard | aee4f5d | 2016-02-28 09:54:53 +0000 | [diff] [blame] | 4 | |
Phil Howard | 95c6d56 | 2016-02-29 12:07:24 +0000 | [diff] [blame^] | 5 | for line in src: |
| 6 | line = line.strip() |
| 7 | if line.startswith('#include') and line.endswith('.h"'): |
| 8 | HEADERS.append(line.replace('#include','').replace('"','').strip()) |
| 9 | |
| 10 | #print(HEADERS) |
| 11 | |
Phil Howard | aee4f5d | 2016-02-28 09:54:53 +0000 | [diff] [blame] | 12 | def is_c_decl(line): |
Phil Howard | 8e29d40 | 2016-02-28 10:50:21 +0000 | [diff] [blame] | 13 | for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']: |
| 14 | if fn in line: |
| 15 | return False |
Phil Howard | aee4f5d | 2016-02-28 09:54:53 +0000 | [diff] [blame] | 16 | for prefix in ['extern','void','int','uint8_t']: |
| 17 | if line.startswith(prefix): |
| 18 | return True |
| 19 | |
Phil Howard | 8e29d40 | 2016-02-28 10:50:21 +0000 | [diff] [blame] | 20 | print("// Generated by generate-bindings.py - do not edit manually!") |
| 21 | |
Phil Howard | aee4f5d | 2016-02-28 09:54:53 +0000 | [diff] [blame] | 22 | for file in HEADERS: |
| 23 | print("\n// Header file {}".format(file)) |
| 24 | h = open(file).read().split('\n') |
| 25 | extern = False |
| 26 | cont = False |
| 27 | if 'extern "C" {' not in h: |
| 28 | extern = True |
| 29 | for line in h: |
| 30 | line = line.strip() |
| 31 | if cont: |
| 32 | print("\t{}".format(line)) |
| 33 | cont = ";" not in line |
| 34 | continue |
| 35 | if line.startswith('extern "C"'): |
| 36 | extern = True |
| 37 | continue |
| 38 | if is_c_decl(line) and extern: |
| 39 | print(line) |
| 40 | cont = ";" not in line |