Update to 2.0.0 tree from current Fremantle build
[opencv] / utils / extract_aliases.py
1 #! /usr/bin/env python
2 """
3 This script extracts macros #defines from those OpenCV headers that can't be
4 directly parsed by current SWIG versions and must be pre-filtered by
5 the C preprocessor (that erases all #defines).  Type information is missing in the 
6 macros, so C code can't be regenerated.  Instead, try to convert C to Python code.
7 C macros too complicated to represent in python using regexes are listed in EXCLUDE
8 """
9
10 import sys, re
11
12 EXCLUDE = { } 
13
14 # force this to be part of cv module
15 # otherwise becomes cv.cvmacros
16 print "/** This file was automatically generated using util/extract_aliases.py script */"
17 print "%module cv"
18 print "%pythoncode %{"
19 for fn in sys.argv[1:]:
20     f = open( fn, "r" )
21     in_define = 0
22     for l in f.xreadlines():
23         m = re.match( r"^#define\s+((?:CV_|IPL_|cv)\w+)\s+((?:CV|IPL|cv)\w*)\s*$", l )
24         if m and not l.endswith( "\\\n" ) and not EXCLUDE.has_key(m.group(1)):
25             print "%s=%s" % (m.group(1), m.group(2))
26     f.close()
27
28 print "%}"