2 * Generate a C file containing a list of tests
4 * Copyright 2002, 2005 Alexandre Julliard
5 * Copyright 2002 Dimitrie O. Paun
6 * Copyright 2005 Royce Mitchell III for the ReactOS Project
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 ****** Keep in sync with tools/winapi/msvcmaker:_generate_testlist_c *****
36 static const char *output_file;
38 static void cleanup_files(void)
40 if (output_file) unlink( output_file );
43 static void exit_on_signal( int sig )
45 exit(1); /* this will call the atexit functions */
48 static void fatal_error( const char *msg, ... )
51 va_start( valist, msg );
52 fprintf( stderr, "make_ctests: " );
53 vfprintf( stderr, msg, valist );
58 static void fatal_perror( const char *msg, ... )
61 va_start( valist, msg );
62 fprintf( stderr, "make_ctests: " );
63 vfprintf( stderr, msg, valist );
69 static void *xmalloc( size_t size )
71 void *res = malloc (size ? size : 1);
72 if (!res) fatal_error( "virtual memory exhausted.\n" );
76 static char* basename( const char* filename )
82 p = strrchr ( filename, '/' );
88 /* look for backslashes, too... */
89 p2 = strrchr ( p, '\\' );
92 /* find extension... */
93 p2 = strrchr ( p, '.' );
99 out = xmalloc ( out_len+1 );
100 memcpy ( out, p, out_len );
105 int main( int argc, const char** argv )
109 char **tests = xmalloc( argc * sizeof(*tests) );
111 for (i = 1; i < argc; i++)
113 if (!strcmp( argv[i], "-o" ) && i < argc-1)
115 output_file = argv[++i];
118 tests[count++] = basename( argv[i] );
121 atexit( cleanup_files );
122 signal( SIGTERM, exit_on_signal );
123 signal( SIGINT, exit_on_signal );
125 signal( SIGHUP, exit_on_signal );
130 if (!(out = fopen( output_file, "w" )))
131 fatal_perror( "cannot create %s", output_file );
135 "/* Automatically generated file; DO NOT EDIT!! */\n"
137 "#define WIN32_LEAN_AND_MEAN\n"
138 "#include <windows.h>\n\n"
139 "#define STANDALONE\n"
140 "#include \"wine/test.h\"\n\n" );
142 for (i = 0; i < count; i++) fprintf( out, "extern void func_%s(void);\n", tests[i] );
146 "const struct test winetest_testlist[] =\n"
149 for (i = 0; i < count; i++) fprintf( out, " { \"%s\", func_%s },\n", tests[i], tests[i] );
155 if (output_file && fclose( out ))
156 fatal_perror( "error writing to %s", output_file );