Formatting.

This commit is contained in:
Werner Lemberg 2012-02-11 08:29:47 +01:00
parent e343e87d4f
commit 02c0e526b2
1 changed files with 53 additions and 33 deletions

View File

@ -4,7 +4,7 @@
/* */ /* */
/* FreeType initialization layer (body). */ /* FreeType initialization layer (body). */
/* */ /* */
/* Copyright 1996-2001, 2002, 2005, 2007, 2009 by */ /* Copyright 1996-2001, 2002, 2005, 2007, 2009, 2012 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -54,8 +54,10 @@
#undef FT_COMPONENT #undef FT_COMPONENT
#define FT_COMPONENT trace_init #define FT_COMPONENT trace_init
#ifndef FT_CONFIG_OPTION_PIC #ifndef FT_CONFIG_OPTION_PIC
#undef FT_USE_MODULE #undef FT_USE_MODULE
#ifdef __cplusplus #ifdef __cplusplus
#define FT_USE_MODULE( type, x ) extern "C" const type x; #define FT_USE_MODULE( type, x ) extern "C" const type x;
@ -63,10 +65,8 @@
#define FT_USE_MODULE( type, x ) extern const type x; #define FT_USE_MODULE( type, x ) extern const type x;
#endif #endif
#include FT_CONFIG_MODULES_H #include FT_CONFIG_MODULES_H
#undef FT_USE_MODULE #undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
@ -77,8 +77,10 @@
0 0
}; };
#else /* FT_CONFIG_OPTION_PIC */ #else /* FT_CONFIG_OPTION_PIC */
#ifdef __cplusplus #ifdef __cplusplus
#define FT_EXTERNC extern "C" #define FT_EXTERNC extern "C"
#else #else
@ -87,16 +89,19 @@
/* declare the module's class creation/destruction functions */ /* declare the module's class creation/destruction functions */
#undef FT_USE_MODULE #undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) \ #define FT_USE_MODULE( type, x ) \
FT_EXTERNC FT_Error FT_Create_Class_##x( FT_Library library, FT_Module_Class** output_class ); \ FT_EXTERNC FT_Error \
FT_EXTERNC void FT_Destroy_Class_##x( FT_Library library, FT_Module_Class* clazz ); FT_Create_Class_ ## x( FT_Library library, \
FT_Module_Class* *output_class ); \
FT_EXTERNC void \
FT_Destroy_Class_ ## x( FT_Library library, \
FT_Module_Class* clazz );
#include FT_CONFIG_MODULES_H #include FT_CONFIG_MODULES_H
/* count all module classes */ /* count all module classes */
#undef FT_USE_MODULE #undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) MODULE_CLASS_##x, #define FT_USE_MODULE( type, x ) MODULE_CLASS_ ## x,
enum enum
{ {
@ -106,24 +111,29 @@
/* destroy all module classes */ /* destroy all module classes */
#undef FT_USE_MODULE #undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) \ #define FT_USE_MODULE( type, x ) \
if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \ if ( classes[i] ) \
i++; \ { \
FT_Destroy_Class_ ## x( library, classes[i] ); \
} \
i++;
FT_BASE_DEF( void ) FT_BASE_DEF( void )
ft_destroy_default_module_classes( FT_Library library ) ft_destroy_default_module_classes( FT_Library library )
{ {
FT_Module_Class** classes; FT_Module_Class* *classes;
FT_Memory memory; FT_Memory memory;
FT_UInt i; FT_UInt i;
BasePIC* pic_container = (BasePIC*)library->pic_container.base; BasePIC* pic_container = (BasePIC*)library->pic_container.base;
if ( !pic_container->default_module_classes ) if ( !pic_container->default_module_classes )
return; return;
memory = library->memory; memory = library->memory;
classes = pic_container->default_module_classes; classes = pic_container->default_module_classes;
i = 0; i = 0;
#include FT_CONFIG_MODULES_H #include FT_CONFIG_MODULES_H
@ -131,30 +141,37 @@
pic_container->default_module_classes = 0; pic_container->default_module_classes = 0;
} }
/* initialize all module classes and the pointer table */ /* initialize all module classes and the pointer table */
#undef FT_USE_MODULE #undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) \ #define FT_USE_MODULE( type, x ) \
error = FT_Create_Class_##x(library, &clazz); \ error = FT_Create_Class_ ## x( library, &clazz ); \
if (error) goto Exit; \ if ( error ) \
goto Exit; \
classes[i++] = clazz; classes[i++] = clazz;
FT_BASE_DEF( FT_Error ) FT_BASE_DEF( FT_Error )
ft_create_default_module_classes( FT_Library library ) ft_create_default_module_classes( FT_Library library )
{ {
FT_Error error; FT_Error error;
FT_Memory memory; FT_Memory memory;
FT_Module_Class** classes; FT_Module_Class* *classes;
FT_Module_Class* clazz; FT_Module_Class* clazz;
FT_UInt i; FT_UInt i;
BasePIC* pic_container = (BasePIC*)library->pic_container.base; BasePIC* pic_container = (BasePIC*)library->pic_container.base;
memory = library->memory; memory = library->memory;
pic_container->default_module_classes = 0; pic_container->default_module_classes = 0;
if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1) ) ) if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) *
( FT_NUM_MODULE_CLASSES + 1 ) ) )
return error; return error;
/* initialize all pointers to 0, especially the last one */ /* initialize all pointers to 0, especially the last one */
for (i = 0; i < FT_NUM_MODULE_CLASSES; i++) for ( i = 0; i < FT_NUM_MODULE_CLASSES; i++ )
classes[i] = 0; classes[i] = 0;
classes[FT_NUM_MODULE_CLASSES] = 0; classes[FT_NUM_MODULE_CLASSES] = 0;
@ -162,9 +179,11 @@
#include FT_CONFIG_MODULES_H #include FT_CONFIG_MODULES_H
Exit: Exit:
if (error) ft_destroy_default_module_classes( library ); if ( error )
else pic_container->default_module_classes = classes; ft_destroy_default_module_classes( library );
else
pic_container->default_module_classes = classes;
return error; return error;
} }
@ -172,6 +191,7 @@ Exit:
#endif /* FT_CONFIG_OPTION_PIC */ #endif /* FT_CONFIG_OPTION_PIC */
/* documentation is in ftmodapi.h */ /* documentation is in ftmodapi.h */
FT_EXPORT_DEF( void ) FT_EXPORT_DEF( void )
@ -181,7 +201,7 @@ Exit:
const FT_Module_Class* const* cur; const FT_Module_Class* const* cur;
/* FT_DEFAULT_MODULES_GET derefers `library' in PIC mode */ /* FT_DEFAULT_MODULES_GET dereferences `library' in PIC mode */
#ifdef FT_CONFIG_OPTION_PIC #ifdef FT_CONFIG_OPTION_PIC
if ( !library ) if ( !library )
return; return;
@ -190,7 +210,7 @@ Exit:
/* GCC 4.6 warns the type difference: /* GCC 4.6 warns the type difference:
* FT_Module_Class** != const FT_Module_Class* const* * FT_Module_Class** != const FT_Module_Class* const*
*/ */
cur = ( const FT_Module_Class* const* )FT_DEFAULT_MODULES_GET; cur = (const FT_Module_Class* const*)FT_DEFAULT_MODULES_GET;
/* test for valid `library' delayed to FT_Add_Module() */ /* test for valid `library' delayed to FT_Add_Module() */
while ( *cur ) while ( *cur )