#NEWLINE# def generate_config_h( conf_res , name ) : #NEWLINE# #INDENT# def value_to_string( value ) : #NEWLINE# #INDENT# s = value . upper ( ) #NEWLINE# return VALUE_SUB . sub ( '_' , s ) #NEWLINE# #UNINDENT# def var_name( entry ) : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'header' ) : #NEWLINE# #INDENT# return ( 'HAVE_%s 1' % entry [ 'value' ] . upper ( ) . replace ( '.' , '_' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'type' ) : #NEWLINE# #INDENT# return ( 'HAVE_%s 1' % entry [ 'value' ] . upper ( ) . replace ( ' ' , '_' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'type_size' ) : #NEWLINE# #INDENT# return ( 'SIZEOF_%s %s' % ( value_to_string ( entry [ 'value' ] ) , entry [ 'result' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'lib' ) : #NEWLINE# #INDENT# return ( 'HAVE_LIB%s 1' % entry [ 'value' ] . upper ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'func' ) : #NEWLINE# #INDENT# return ( 'HAVE_%s 1' % entry [ 'value' ] . upper ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'decl' ) : #NEWLINE# #INDENT# return ( 'HAVE_DECL_%s 1' % entry [ 'value' ] . upper ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Bug: entry %s not handled' % entry ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# def comment( entry ) : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'header' ) : #NEWLINE# #INDENT# return ( '\n/* Define to 1 if you have the <%s> header file. */\n' % entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'lib' ) : #NEWLINE# #INDENT# return ( "\n/* Define to 1 if you have the `%s' library. */\n" % entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'func' ) : #NEWLINE# #INDENT# return ( "\n/* Define to 1 if you have the `%s' function. */\n" % entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'decl' ) : #NEWLINE# #INDENT# return ( '\n/* Set to 1 if %s is defined. */\n' % entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'type' ) : #NEWLINE# #INDENT# return ( '\n/* Define if your compiler provides %s */\n' % entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'type_size' ) : #NEWLINE# #INDENT# return ( "\n/* The size of `%s', as computed by sizeof. */\n" % entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Bug: entry %s not handled' % entry ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# buf = StringIO ( ) #NEWLINE# for entry in conf_res : #NEWLINE# #INDENT# if ( entry [ 'type' ] == 'define' ) : #NEWLINE# #INDENT# buf . write ( entry [ 'value' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# var = var_name ( entry ) #NEWLINE# if entry [ 'result' ] : #NEWLINE# #INDENT# buf . write ( comment ( entry ) ) #NEWLINE# buf . write ( ( '#define %s\n' % var ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ensure_dir ( value_to_string ) #NEWLINE# fid = open ( name , 'w' ) #NEWLINE# try : #NEWLINE# #INDENT# fid . write ( buf . getvalue ( ) ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# fid . close ( )