2005-10-28 18:14:14 +02:00
|
|
|
/*
|
|
|
|
* This little program is used to parse the FreeType headers and
|
2006-01-27 13:11:22 +01:00
|
|
|
* find the declaration of all public APIs. This is easy, because
|
2005-10-28 18:14:14 +02:00
|
|
|
* they all look like the following:
|
|
|
|
*
|
|
|
|
* FT_EXPORT( return_type )
|
|
|
|
* function_name( function arguments );
|
|
|
|
*
|
|
|
|
* You must pass the list of header files as arguments. Wildcards are
|
|
|
|
* accepted if you are using GCC for compilation (and probably by
|
|
|
|
* other compilers too).
|
|
|
|
*
|
2015-05-28 10:58:40 +02:00
|
|
|
* Author: David Turner, 2005, 2006, 2008-2013, 2015
|
2005-10-28 18:14:14 +02:00
|
|
|
*
|
|
|
|
* This code is explicitly placed into the public domain.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-01-27 13:11:22 +01:00
|
|
|
#include <ctype.h>
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
#define PROGRAM_NAME "apinames"
|
2018-01-24 04:29:45 +01:00
|
|
|
#define PROGRAM_VERSION "0.3"
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
#define LINEBUFF_SIZE 1024
|
|
|
|
|
2008-05-29 00:17:28 +02:00
|
|
|
typedef enum OutputFormat_
|
2005-10-28 18:14:14 +02:00
|
|
|
{
|
|
|
|
OUTPUT_LIST = 0, /* output the list of names, one per line */
|
|
|
|
OUTPUT_WINDOWS_DEF, /* output a Windows .DEF file for Visual C++ or Mingw */
|
|
|
|
OUTPUT_BORLAND_DEF, /* output a Windows .DEF file for Borland C++ */
|
2013-05-24 11:38:09 +02:00
|
|
|
OUTPUT_WATCOM_LBC, /* output a Watcom Linker Command File */
|
2018-01-24 04:29:45 +01:00
|
|
|
OUTPUT_NETWARE_IMP, /* output a NetWare ImportFile */
|
|
|
|
OUTPUT_GNU_VERMAP /* output a version map for GNU or Solaris linker */
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
} OutputFormat;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
panic( const char* message )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "PANIC: %s\n", message );
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-29 00:17:28 +02:00
|
|
|
typedef struct NameRec_
|
2005-10-28 18:14:14 +02:00
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
unsigned int hash;
|
|
|
|
|
|
|
|
} NameRec, *Name;
|
|
|
|
|
|
|
|
static Name the_names;
|
|
|
|
static int num_names;
|
|
|
|
static int max_names;
|
|
|
|
|
|
|
|
static void
|
|
|
|
names_add( const char* name,
|
|
|
|
const char* end )
|
|
|
|
{
|
2011-11-30 14:40:43 +01:00
|
|
|
unsigned int h;
|
|
|
|
int nn, len;
|
|
|
|
Name nm;
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
if ( end <= name )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* compute hash value */
|
|
|
|
len = (int)(end - name);
|
|
|
|
h = 0;
|
|
|
|
for ( nn = 0; nn < len; nn++ )
|
|
|
|
h = h*33 + name[nn];
|
|
|
|
|
|
|
|
/* check for an pre-existing name */
|
|
|
|
for ( nn = 0; nn < num_names; nn++ )
|
|
|
|
{
|
|
|
|
nm = the_names + nn;
|
|
|
|
|
2006-01-27 13:11:22 +01:00
|
|
|
if ( (int)nm->hash == h &&
|
2005-10-28 18:14:14 +02:00
|
|
|
memcmp( name, nm->name, len ) == 0 &&
|
|
|
|
nm->name[len] == 0 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new name */
|
|
|
|
if ( num_names >= max_names )
|
|
|
|
{
|
|
|
|
max_names += (max_names >> 1) + 4;
|
2011-11-30 10:46:53 +01:00
|
|
|
the_names = (NameRec*)realloc( the_names,
|
|
|
|
sizeof ( the_names[0] ) * max_names );
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !the_names )
|
2005-10-28 18:14:14 +02:00
|
|
|
panic( "not enough memory" );
|
|
|
|
}
|
|
|
|
nm = &the_names[num_names++];
|
|
|
|
|
|
|
|
nm->hash = h;
|
2006-02-25 13:49:40 +01:00
|
|
|
nm->name = (char*)malloc( len+1 );
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !nm->name )
|
2005-10-28 18:14:14 +02:00
|
|
|
panic( "not enough memory" );
|
|
|
|
|
|
|
|
memcpy( nm->name, name, len );
|
|
|
|
nm->name[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
name_compare( const void* name1,
|
|
|
|
const void* name2 )
|
|
|
|
{
|
|
|
|
Name n1 = (Name)name1;
|
|
|
|
Name n2 = (Name)name2;
|
|
|
|
|
|
|
|
return strcmp( n1->name, n2->name );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
names_sort( void )
|
|
|
|
{
|
2011-11-30 10:46:53 +01:00
|
|
|
qsort( the_names, (size_t)num_names,
|
|
|
|
sizeof ( the_names[0] ), name_compare );
|
2005-10-28 18:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
names_dump( FILE* out,
|
|
|
|
OutputFormat format,
|
|
|
|
const char* dll_name )
|
|
|
|
{
|
|
|
|
int nn;
|
|
|
|
|
2010-07-11 09:28:21 +02:00
|
|
|
|
2005-10-28 18:14:14 +02:00
|
|
|
switch ( format )
|
|
|
|
{
|
|
|
|
case OUTPUT_WINDOWS_DEF:
|
|
|
|
if ( dll_name )
|
|
|
|
fprintf( out, "LIBRARY %s\n", dll_name );
|
|
|
|
|
|
|
|
fprintf( out, "DESCRIPTION FreeType 2 DLL\n" );
|
|
|
|
fprintf( out, "EXPORTS\n" );
|
|
|
|
for ( nn = 0; nn < num_names; nn++ )
|
|
|
|
fprintf( out, " %s\n", the_names[nn].name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OUTPUT_BORLAND_DEF:
|
|
|
|
if ( dll_name )
|
|
|
|
fprintf( out, "LIBRARY %s\n", dll_name );
|
|
|
|
|
|
|
|
fprintf( out, "DESCRIPTION FreeType 2 DLL\n" );
|
|
|
|
fprintf( out, "EXPORTS\n" );
|
|
|
|
for ( nn = 0; nn < num_names; nn++ )
|
|
|
|
fprintf( out, " _%s\n", the_names[nn].name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OUTPUT_WATCOM_LBC:
|
|
|
|
{
|
2010-07-11 09:28:21 +02:00
|
|
|
const char* dot;
|
2015-05-28 10:58:40 +02:00
|
|
|
char temp[512];
|
2010-07-11 09:28:21 +02:00
|
|
|
|
2005-10-28 18:14:14 +02:00
|
|
|
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !dll_name )
|
2005-10-28 18:14:14 +02:00
|
|
|
{
|
|
|
|
fprintf( stderr,
|
2010-07-11 09:28:21 +02:00
|
|
|
"you must provide a DLL name with the -d option!\n" );
|
|
|
|
exit( 4 );
|
2005-10-28 18:14:14 +02:00
|
|
|
}
|
|
|
|
|
2013-06-04 10:30:48 +02:00
|
|
|
/* we must omit the .dll suffix from the library name */
|
2005-10-28 18:14:14 +02:00
|
|
|
dot = strchr( dll_name, '.' );
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( dot )
|
2005-10-28 18:14:14 +02:00
|
|
|
{
|
2015-05-28 10:58:40 +02:00
|
|
|
int len = dot - dll_name;
|
2010-07-11 09:28:21 +02:00
|
|
|
|
|
|
|
|
2011-11-30 10:46:53 +01:00
|
|
|
if ( len > (int)( sizeof ( temp ) - 1 ) )
|
2010-07-11 09:28:21 +02:00
|
|
|
len = sizeof ( temp ) - 1;
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
memcpy( temp, dll_name, len );
|
|
|
|
temp[len] = 0;
|
|
|
|
|
|
|
|
dll_name = (const char*)temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( nn = 0; nn < num_names; nn++ )
|
|
|
|
fprintf( out, "++_%s.%s.%s\n", the_names[nn].name, dll_name,
|
|
|
|
the_names[nn].name );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-24 11:38:09 +02:00
|
|
|
case OUTPUT_NETWARE_IMP:
|
|
|
|
{
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( dll_name )
|
2013-05-24 11:38:09 +02:00
|
|
|
fprintf( out, " (%s)\n", dll_name );
|
|
|
|
for ( nn = 0; nn < num_names - 1; nn++ )
|
|
|
|
fprintf( out, " %s,\n", the_names[nn].name );
|
|
|
|
fprintf( out, " %s\n", the_names[num_names - 1].name );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-01-24 04:29:45 +01:00
|
|
|
case OUTPUT_GNU_VERMAP:
|
|
|
|
{
|
|
|
|
fprintf( out, "{\n\tglobal:\n" );
|
|
|
|
for ( nn = 0; nn < num_names; nn++ )
|
|
|
|
fprintf( out, "\t\t%s;\n", the_names[nn].name );
|
|
|
|
fprintf( out, "\tlocal:\n\t\t*;\n};\n" );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-10-28 18:14:14 +02:00
|
|
|
default: /* LIST */
|
|
|
|
for ( nn = 0; nn < num_names; nn++ )
|
|
|
|
fprintf( out, "%s\n", the_names[nn].name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* states of the line parser */
|
|
|
|
|
2008-05-29 00:17:28 +02:00
|
|
|
typedef enum State_
|
2005-10-28 18:14:14 +02:00
|
|
|
{
|
|
|
|
STATE_START = 0, /* waiting for FT_EXPORT keyword and return type */
|
2006-12-09 08:29:54 +01:00
|
|
|
STATE_TYPE /* type was read, waiting for function name */
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
} State;
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_header_file( FILE* file, int verbose )
|
|
|
|
{
|
2012-02-26 08:47:20 +01:00
|
|
|
static char buff[LINEBUFF_SIZE + 1];
|
2005-10-28 18:14:14 +02:00
|
|
|
State state = STATE_START;
|
|
|
|
|
|
|
|
while ( !feof( file ) )
|
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
if ( !fgets( buff, LINEBUFF_SIZE, file ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
p = buff;
|
|
|
|
|
|
|
|
while ( *p && (*p == ' ' || *p == '\\') ) /* skip leading whitespace */
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if ( *p == '\n' || *p == '\r' ) /* skip empty lines */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch ( state )
|
|
|
|
{
|
|
|
|
case STATE_START:
|
|
|
|
{
|
|
|
|
if ( memcmp( p, "FT_EXPORT(", 10 ) != 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
p += 10;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if ( *p == 0 || *p == '\n' || *p == '\r' )
|
|
|
|
goto NextLine;
|
|
|
|
|
|
|
|
if ( *p == ')' )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = STATE_TYPE;
|
|
|
|
|
|
|
|
/* sometimes, the name is just after the FT_EXPORT(...), so
|
|
|
|
* skip whitespace, and fall-through if we find an alphanumeric
|
|
|
|
* character
|
|
|
|
*/
|
|
|
|
while ( *p == ' ' || *p == '\t' )
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if ( !isalpha(*p) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall-through */
|
|
|
|
|
|
|
|
case STATE_TYPE:
|
|
|
|
{
|
|
|
|
char* name = p;
|
|
|
|
|
|
|
|
while ( isalnum(*p) || *p == '_' )
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if ( p > name )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
2009-11-04 12:18:48 +01:00
|
|
|
fprintf( stderr, ">>> %.*s\n", (int)(p - name), name );
|
2005-10-28 18:14:14 +02:00
|
|
|
|
|
|
|
names_add( name, p );
|
|
|
|
}
|
|
|
|
|
|
|
|
state = STATE_START;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
NextLine:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage( void )
|
|
|
|
{
|
2006-02-25 13:49:40 +01:00
|
|
|
static const char* const format =
|
|
|
|
"%s %s: extract FreeType API names from header files\n\n"
|
|
|
|
"this program is used to extract the list of public FreeType API\n"
|
|
|
|
"functions. It receives the list of header files as argument and\n"
|
|
|
|
"generates a sorted list of unique identifiers\n\n"
|
|
|
|
|
|
|
|
"usage: %s header1 [options] [header2 ...]\n\n"
|
|
|
|
|
|
|
|
"options: - : parse the content of stdin, ignore arguments\n"
|
|
|
|
" -v : verbose mode, output sent to standard error\n"
|
|
|
|
" -oFILE : write output to FILE instead of standard output\n"
|
|
|
|
" -dNAME : indicate DLL file name, 'freetype.dll' by default\n"
|
|
|
|
" -w : output .DEF file for Visual C++ and Mingw\n"
|
|
|
|
" -wB : output .DEF file for Borland C++\n"
|
|
|
|
" -wW : output Watcom Linker Response File\n"
|
2013-05-24 11:38:09 +02:00
|
|
|
" -wN : output NetWare Import File\n"
|
2018-01-24 04:29:45 +01:00
|
|
|
" -wL : output version map for GNU or Solaris linker\n"
|
2006-02-25 13:49:40 +01:00
|
|
|
"\n";
|
|
|
|
|
2005-10-28 18:14:14 +02:00
|
|
|
fprintf( stderr,
|
2006-02-25 13:49:40 +01:00
|
|
|
format,
|
2005-10-28 18:14:14 +02:00
|
|
|
PROGRAM_NAME,
|
|
|
|
PROGRAM_VERSION,
|
|
|
|
PROGRAM_NAME
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main( int argc, const char* const* argv )
|
|
|
|
{
|
|
|
|
int from_stdin = 0;
|
|
|
|
int verbose = 0;
|
|
|
|
OutputFormat format = OUTPUT_LIST; /* the default */
|
|
|
|
FILE* out = stdout;
|
|
|
|
const char* library_name = NULL;
|
|
|
|
|
|
|
|
if ( argc < 2 )
|
|
|
|
usage();
|
|
|
|
|
|
|
|
/* '-' used as a single argument means read source file from stdin */
|
|
|
|
while ( argc > 1 && argv[1][0] == '-' )
|
|
|
|
{
|
|
|
|
const char* arg = argv[1];
|
|
|
|
|
|
|
|
switch ( arg[1] )
|
|
|
|
{
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
if ( arg[2] == 0 )
|
|
|
|
{
|
|
|
|
if ( argc < 2 )
|
|
|
|
usage();
|
|
|
|
|
|
|
|
arg = argv[2];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
arg += 2;
|
|
|
|
|
|
|
|
out = fopen( arg, "wt" );
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !out )
|
2005-10-28 18:14:14 +02:00
|
|
|
{
|
|
|
|
fprintf( stderr, "could not open '%s' for writing\n", argv[2] );
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
if ( arg[2] == 0 )
|
|
|
|
{
|
|
|
|
if ( argc < 2 )
|
|
|
|
usage();
|
|
|
|
|
|
|
|
arg = argv[2];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
arg += 2;
|
|
|
|
|
|
|
|
library_name = arg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
format = OUTPUT_WINDOWS_DEF;
|
|
|
|
switch ( arg[2] )
|
|
|
|
{
|
|
|
|
case 'B':
|
|
|
|
format = OUTPUT_BORLAND_DEF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'W':
|
|
|
|
format = OUTPUT_WATCOM_LBC;
|
|
|
|
break;
|
|
|
|
|
2013-05-24 11:38:09 +02:00
|
|
|
case 'N':
|
|
|
|
format = OUTPUT_NETWARE_IMP;
|
|
|
|
break;
|
|
|
|
|
2018-01-24 04:29:45 +01:00
|
|
|
case 'L':
|
|
|
|
format = OUTPUT_GNU_VERMAP;
|
|
|
|
break;
|
|
|
|
|
2005-10-28 18:14:14 +02:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
from_stdin = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( from_stdin )
|
|
|
|
{
|
|
|
|
read_header_file( stdin, verbose );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( --argc, argv++; argc > 0; argc--, argv++ )
|
|
|
|
{
|
|
|
|
FILE* file = fopen( argv[0], "rb" );
|
|
|
|
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !file )
|
2005-10-28 18:14:14 +02:00
|
|
|
fprintf( stderr, "unable to open '%s'\n", argv[0] );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
fprintf( stderr, "opening '%s'\n", argv[0] );
|
|
|
|
|
|
|
|
read_header_file( file, verbose );
|
|
|
|
fclose( file );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( num_names == 0 )
|
|
|
|
panic( "could not find exported functions !!\n" );
|
|
|
|
|
|
|
|
names_sort();
|
|
|
|
names_dump( out, format, library_name );
|
|
|
|
|
|
|
|
if ( out != stdout )
|
|
|
|
fclose( out );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|