-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswigify.py
More file actions
executable file
·49 lines (41 loc) · 1.77 KB
/
swigify.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.77 KB
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
41
42
43
44
45
46
47
48
#!/usr/bin/env python
#
# (C) Copyright IBM Corp. 2006
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This
# file and program are licensed under a BSD style license. See
# the Copying file included with the OpenHPI distribution for
# full licensing terms.
#
"""
Filter a given header file into a clean swig interface file
This script takes the name of a header file as argument, and
produces a clean interface file ready to be parsed by SWIG. The
output file will be sent to standard output.
This script does two things to clean a header file into a
SWIG-ready interface file:
1. Eliminate the gcc __attribute__* directives. These confuse
SWIG (at version 1.3.29).
2. Convert typecasted #define-s to const globals. Typecasted
#define-s get dropped by SWIG (at version 1.3.29).
3. Remove #warning lines.
You won't need to call this script often at all. Only if the
header file for which you are creating a swig interface changes,
then this script will help you to quickly create a new swig
interface file for it.
"""
__author__ = 'Renier Morales <renierm@users.sf.net>'
import sys, re
for arg in sys.argv[1:]:
header_file = open(sys.argv[1], 'r')
header_content = header_file.read()
header_file.close()
# Eliminage __attribute__* directives
header_content = re.sub(r' __attribute__\(.+\)([^()])', r'\1',header_content)
# Convert typecasted defines to const globals
header_content = re.sub(r'#define ([A-Z0-9_]+)[ \t\\\n]+\((\w+)\)[ ]*([-A-Za-z0-9_() +]+)', r'const \2 \1 = \3;', header_content)
# Remove #warning preproccesor lines
header_content = re.sub(r'^#warning .*', r'', header_content)
print header_content