#NEWLINE# def main( argv = None ) : #NEWLINE# #INDENT# 'A small script which runs h2xml, xml2py (from ctypeslib) and then does \n    basic replacements.\n    ' #NEWLINE# if ( argv is None ) : #NEWLINE# #INDENT# argv = sys . argv #NEWLINE# #UNINDENT# parser = OptionParser ( 'usage: %prog [options]' ) #NEWLINE# parser . add_option ( '-i' , dest = 'chipmunk_includes' , help = ( ( "path to chipmunk include files (if not specified, '" + default_path_to_chipmunk_include ) + "' will be used)" ) , default = default_path_to_chipmunk_include ) #NEWLINE# parser . add_option ( '-o' , dest = 'output' , help = ( ( "output filename (if not specified, '" + default_output ) + "' will be used)" ) , default = default_output ) #NEWLINE# parser . add_option ( '-l' , dest = 'lib' , help = ( ( "chipmunk library path (if not specified, '" + default_path_to_chipmunk_lib ) + "' will be used)" ) , default = default_path_to_chipmunk_lib ) #NEWLINE# ( options , files ) = parser . parse_args ( argv [ 1 : ] ) #NEWLINE# h2xml_args = [ '' , abspath ( join ( options . chipmunk_includes , 'chipmunk.h' ) ) , abspath ( join ( options . chipmunk_includes , 'chipmunk_unsafe.h' ) ) , abspath ( join ( options . chipmunk_includes , 'chipmunk_ffi.h' ) ) , '-c' , '-D' , 'CHIPMUNK_FFI' , '-o' , 'chipmunk.xml' ] #NEWLINE# h2xml . main ( h2xml_args ) #NEWLINE# print ( 'h2xml done' ) #NEWLINE# xml2py_args = [ 'generate_bindings.py' , '-l' , options . lib , '-o' , options . output , '-r' , 'cp.*' , 'chipmunk.xml' ] #NEWLINE# xml2py . main ( argv = xml2py_args ) #NEWLINE# print ( 'xml2py done' ) #NEWLINE# custom_head = '\nfrom ctypes import * \nfrom .vec2d import Vec2d\ncpVect = Vec2d\nSTRING = c_char_p\n\nfrom .libload import load_library, platform_specific_functions\ntry:\n    import pymunkoptions\n    _lib_debug = pymunkoptions.options["debug"]\nexcept:\n    _lib_debug = True #Set to True to print the Chipmunk path.\nchipmunk_lib = load_library("chipmunk", debug_lib=_lib_debug)\nfunction_pointer = platform_specific_functions()[\'function_pointer\']\n\n' #NEWLINE# custom_uintptr_size = '\nif sizeof(c_void_p) == 4: uintptr_t = c_uint \nelse: uintptr_t = c_ulonglong\n' #NEWLINE# bad_symbols = [ 'free' , 'calloc' , 'realloc' ] #NEWLINE# chipmunkpy = open ( options . output , 'r' ) . read ( ) #NEWLINE# head_match = re . compile ( 'from.*?\\)' , re . DOTALL ) #NEWLINE# cpVect_classdef_match = re . compile ( 'class cpVect.*?pass' , re . DOTALL ) #NEWLINE# cpVect_fields_match = re . compile ( 'cpVect._fields_.*?]' , re . DOTALL ) #NEWLINE# lib_match = re . compile ( '_libraries.*?]' ) #NEWLINE# function_pointer_cdecl = re . compile ( 'CFUNCTYPE' , re . DOTALL ) #NEWLINE# function_pointer_stddecl = re . compile ( 'WINFUNCTYPE' , re . DOTALL ) #NEWLINE# pack = re . compile ( '(\\w+\\._pack_ = 4)' , re . DOTALL ) #NEWLINE# py3k_long = re . compile ( '4294967295L' , re . DOTALL ) #NEWLINE# py3k_long2 = re . compile ( '0L' , re . DOTALL ) #NEWLINE# uintptr_size = re . compile ( 'uintptr_t = c_uint' , re . DOTALL ) #NEWLINE# symbol_match = re . compile ( ( ( '^(?P<n>' + '|' . join ( bad_symbols ) ) + ').*' ) , re . MULTILINE ) #NEWLINE# chipmunkpy = head_match . sub ( custom_head , parser ) #NEWLINE# chipmunkpy = cpVect_classdef_match . sub ( '#cpVect class def removed' , chipmunkpy ) #NEWLINE# chipmunkpy = cpVect_fields_match . sub ( '#cpVect _fields_ def removed' , chipmunkpy ) #NEWLINE# chipmunkpy = lib_match . sub ( 'chipmunk_lib' , chipmunkpy ) #NEWLINE# chipmunkpy = function_pointer_cdecl . sub ( 'function_pointer' , chipmunkpy ) #NEWLINE# chipmunkpy = function_pointer_stddecl . sub ( 'function_pointer' , chipmunkpy ) #NEWLINE# chipmunkpy = pack . sub ( '#\\1' , chipmunkpy ) #NEWLINE# chipmunkpy = py3k_long . sub ( '4294967295' , chipmunkpy ) #NEWLINE# chipmunkpy = py3k_long2 . sub ( '0' , chipmunkpy ) #NEWLINE# chipmunkpy = uintptr_size . sub ( custom_uintptr_size , chipmunkpy ) #NEWLINE# chipmunkpy = symbol_match . sub ( '\\g<n> = None # symbol removed' , chipmunkpy ) #NEWLINE# f = open ( options . output , 'w' ) . write ( chipmunkpy ) #NEWLINE# print ( 'replacement done' )