#!/usr/bin/python import re, string mathdecl = re.compile( r'^__MATH(\w+)\s*\(([^(]*)\s*,\s*\(([^(]*)\)' + r'(?:,\s*\(\w+\))?\)(?:\s*__attribute__\s*\(\(\w+\)\))?;') def decl(type, function, suffix, args): if function.startswith('__'): print '// NOTICE: %s: skipping internal function' % (function, ) return args = map(string.strip, args.split(',')) for i in range(0, len(args)): if args[i].find(' ') < 0: args[i] = '%s x%d' % (args[i], i) args = ', '.join(args) for m in re.findall(r'(long (int|double))', type + ', ' + args): print '// NOTICE: %s: data type %s is not supported by Vala' % (function, m[0]) return for t, s in (('double', ''), ('float', 'f')): #, ('long double', 'l')): a = args.replace('_Mdouble_', t) a = re.sub(r'__|const ', '', a) t = type.replace('_Mdouble_', t) n = function + suffix + s print ' [CCode(cname = "%s")]' % (n) print ' public static %s %s(%s);' % (t, n, a) print '''\ /* math.vala - Generated from of glibc. * * Copyright (C) 2007 Mathias Hasselmann * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This library 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. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Author: * Mathias Hasselmann */ [CCode(cheader_filename = "math.h")] namespace Math {''' pattern = '' for line in file('/usr/include/bits/mathcalls.h'): pattern += line.rstrip() match = mathdecl.match(pattern) if match: tag, attrs, args = match.groups() attrs = map(string.strip, attrs.split(',')) if tag in ('CALL', 'CALLX'): decl('_Mdouble_', *(attrs + [args])) pattern = '' continue if tag in ('DECL', 'DECL_1'): decl(attrs[0], *(attrs[1:] + [args])) pattern = '' continue raise Exception, 'Unsupported declaration: %s' % pattern elif pattern.startswith('__MATH'): if pattern.find(';') < 0: continue print '// WARNING: failed to match: %s' % (pattern, ) pattern = '' print '}' # vim: sw=4 sta et