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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ****** Keep in sync with tools/winapi/msvcmaker:_generate_testlist_c *****
35 static const char *output_file
;
37 static void fatal_error( const char *msg
, ... )
40 va_start( valist
, msg
);
41 fprintf( stderr
, "make_ctests: " );
42 vfprintf( stderr
, msg
, valist
);
44 if (output_file
) unlink( output_file
);
48 static void fatal_perror( const char *msg
, ... )
51 va_start( valist
, msg
);
52 fprintf( stderr
, "make_ctests: " );
53 vfprintf( stderr
, msg
, valist
);
59 static void *xmalloc( size_t size
)
61 void *res
= malloc (size
? size
: 1);
62 if (!res
) fatal_error( "virtual memory exhausted.\n" );
66 static char* basename( const char* filename
)
72 p
= strrchr ( filename
, '/' );
78 /* look for backslashes, too... */
79 p2
= strrchr ( p
, '\\' );
82 /* find extension... */
83 p2
= strrchr ( p
, '.' );
89 out
= xmalloc ( out_len
+1 );
90 memcpy ( out
, p
, out_len
);
95 int main( int argc
, const char** argv
)
99 char **tests
= xmalloc( argc
* sizeof(*tests
) );
101 for (i
= 1; i
< argc
; i
++)
103 if (!strcmp( argv
[i
], "-o" ) && i
< argc
-1)
105 output_file
= argv
[++i
];
108 tests
[count
++] = basename( argv
[i
] );
113 if (!(out
= fopen( output_file
, "w" )))
114 fatal_perror( "cannot create %s", output_file
);
118 "/* Automatically generated file; DO NOT EDIT!! */\n"
120 "/* stdarg.h is needed for Winelib */\n"
121 "#include <stdarg.h>\n"
122 "#include <stdio.h>\n"
123 "#include <stdlib.h>\n"
124 "#include \"windef.h\"\n"
125 "#include \"winbase.h\"\n\n"
126 "#define STANDALONE\n"
127 "#include \"wine/test.h\"\n\n" );
129 for (i
= 0; i
< count
; i
++) fprintf( out
, "extern void func_%s(void);\n", tests
[i
] );
133 "const struct test winetest_testlist[] =\n"
136 for (i
= 0; i
< count
; i
++) fprintf( out
, " { \"%s\", func_%s },\n", tests
[i
], tests
[i
] );
142 if (output_file
&& fclose( out
))
143 fatal_perror( "error writing to %s", output_file
);