5350d914a6390aa8f14c5af002a7f83c3a2cbdf8
[opencv] / utils / extract_constants.py
1 #! /usr/bin/env python
2 """
3 This script extracts #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).
6 """
7
8 import sys, re
9
10 for fn in sys.argv[1:]:
11     f = open( fn, "r" )
12     in_define = 0
13     for l in f.xreadlines():
14         if re.match( r"^#define\s+(CV_|IPL_|cv)\w+\s+", l ):
15             in_define = 1
16         if re.match (r"^#define\s+CV_MAKETYPE", l):
17             in_define = 1
18         if in_define:
19             print l[:l.find ('/*')]
20             if not l.endswith( "\\\n" ):
21                 in_define = 0
22                 print
23     f.close()
24