24 #define PROGRAM_NAME "apinames" 25 #define PROGRAM_VERSION "0.1" 27 #define LINEBUFF_SIZE 1024 42 fprintf( stderr,
"PANIC: %s\n", message );
47 typedef struct NameRec_
54 static Name the_names;
59 names_add(
const char*
name,
72 for ( nn = 0; nn <
len; nn++ )
76 for ( nn = 0; nn < num_names; nn++ )
80 if ( (
int)nm->hash == h &&
81 memcmp(
name, nm->name, len ) == 0 &&
87 if ( num_names >= max_names )
89 max_names += (max_names >> 1) + 4;
90 the_names = (
NameRec*)realloc( the_names,
91 sizeof ( the_names[0] ) * max_names );
92 if ( the_names ==
NULL )
93 panic(
"not enough memory" );
95 nm = &the_names[num_names++];
98 nm->name = (
char*)
malloc( len+1 );
99 if ( nm->name ==
NULL )
100 panic(
"not enough memory" );
102 memcpy( nm->name,
name, len );
108 name_compare(
const void* name1,
114 return strcmp( n1->name, n2->name );
120 qsort( the_names, (
size_t)num_names,
121 sizeof ( the_names[0] ), name_compare );
126 names_dump( FILE*
out,
128 const char* dll_name )
137 fprintf(
out,
"LIBRARY %s\n", dll_name );
139 fprintf(
out,
"DESCRIPTION FreeType 2 DLL\n" );
140 fprintf(
out,
"EXPORTS\n" );
141 for ( nn = 0; nn < num_names; nn++ )
142 fprintf(
out,
" %s\n", the_names[nn].
name );
147 fprintf(
out,
"LIBRARY %s\n", dll_name );
149 fprintf(
out,
"DESCRIPTION FreeType 2 DLL\n" );
150 fprintf(
out,
"EXPORTS\n" );
151 for ( nn = 0; nn < num_names; nn++ )
152 fprintf(
out,
" _%s\n", the_names[nn].name );
162 if ( dll_name ==
NULL )
165 "you must provide a DLL name with the -d option!\n" );
169 dot = strchr( dll_name,
'.' );
172 int len = dot - dll_name;
175 if ( len > (
int)(
sizeof ( temp ) - 1 ) )
176 len =
sizeof ( temp ) - 1;
178 memcpy( temp, dll_name, len );
181 dll_name = (
const char*)temp;
184 for ( nn = 0; nn < num_names; nn++ )
185 fprintf(
out,
"++_%s.%s.%s\n", the_names[nn].name, dll_name,
186 the_names[nn].name );
191 for ( nn = 0; nn < num_names; nn++ )
192 fprintf(
out,
"%s\n", the_names[nn].name );
209 read_header_file( FILE* file,
int verbose )
214 while ( !feof( file ) )
223 while ( *p && (*p ==
' ' || *p ==
'\\') )
226 if ( *p ==
'\n' || *p ==
'\r' )
233 if ( memcmp( p,
"FT_EXPORT(", 10 ) != 0 )
239 if ( *p == 0 || *p ==
'\n' || *p ==
'\r' )
257 while ( *p ==
' ' || *p ==
'\t' )
269 while ( isalnum(*p) || *p ==
'_' )
275 fprintf( stderr,
">>> %.*s\n", (
int)(p - name), name );
277 names_add( name, p );
299 static const char*
const format =
300 "%s %s: extract FreeType API names from header files\n\n" 301 "this program is used to extract the list of public FreeType API\n" 302 "functions. It receives the list of header files as argument and\n" 303 "generates a sorted list of unique identifiers\n\n" 305 "usage: %s header1 [options] [header2 ...]\n\n" 307 "options: - : parse the content of stdin, ignore arguments\n" 308 " -v : verbose mode, output sent to standard error\n" 309 " -oFILE : write output to FILE instead of standard output\n" 310 " -dNAME : indicate DLL file name, 'freetype.dll' by default\n" 311 " -w : output .DEF file for Visual C++ and Mingw\n" 312 " -wB : output .DEF file for Borland C++\n" 313 " -wW : output Watcom Linker Response File\n" 326 int main(
int argc,
const char*
const* argv )
332 const char* library_name =
NULL;
338 while ( argc > 1 && argv[1][0] ==
'-' )
340 const char*
arg = argv[1];
361 out = fopen( arg,
"wt" );
364 fprintf( stderr,
"could not open '%s' for writing\n", argv[2] );
419 read_header_file( stdin, verbose );
423 for ( --argc, argv++; argc > 0; argc--, argv++ )
425 FILE* file = fopen( argv[0],
"rb" );
428 fprintf( stderr,
"unable to open '%s'\n", argv[0] );
432 fprintf( stderr,
"opening '%s'\n", argv[0] );
434 read_header_file( file, verbose );
440 if ( num_names == 0 )
441 panic(
"could not find exported functions !!\n" );
444 names_dump( out, format, library_name );
int main(int argc, const char *const *argv)
GLfloat GLfloat GLfloat GLfloat h
enum OutputFormat_ OutputFormat
GLsizeiptr const GLvoid GLenum usage
float dot(float a, float b)
local int out(void *out_desc, unsigned char *buf, unsigned len)
GLuint const GLchar * name
GLenum GLuint GLenum GLsizei const GLchar * message
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format