c version of wine's 'make_ctests' script
[reactos.git] / reactos / tools / make_ctests.c
1 /* make_ctests.c
2
3 * This program is a port of wine project's make_ctests script
4
5 # Script to generate a C file containing a list of tests
6 #
7 # Copyright 2002 Alexandre Julliard
8 # Copyright 2002 Dimitrie O. Paun
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #
24
25 # ***** Keep in sync with tools/winapi/msvcmaker:_generate_testlist_c *****
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 const char* header =
32 "/* Automatically generated file; DO NOT EDIT!! */\n"
33 "\n"
34 "/* stdarg.h is needed for Winelib */\n"
35 "#include <stdarg.h>\n"
36 "#include <stdio.h>\n"
37 "#include <stdlib.h>\n"
38 "#include \"windef.h\"\n"
39 "#include \"winbase.h\"\n"
40 "\n";
41
42 const char* middle =
43 "\n"
44 "struct test\n"
45 "{\n"
46 " const char *name;\n"
47 " void (*func)(void);\n"
48 "};\n"
49 "\n"
50 "static const struct test winetest_testlist[] =\n"
51 "{\n";
52
53 const char* end =
54 " { 0, 0 }\n"
55 "};\n"
56 "\n"
57 "#define WINETEST_WANT_MAIN\n"
58 "#include \"wine/test.h\"\n"
59 "\n";
60
61 char*
62 basename ( const char* filename )
63 {
64 const char *p, *p2;
65 char *out;
66 size_t out_len;
67
68 if ( filename == NULL )
69 {
70 fprintf ( stderr, "basename() called with null filename\n" );
71 return NULL;
72 }
73 p = strrchr ( filename, '/' );
74 if ( !p )
75 p = filename;
76 else
77 ++p;
78
79 /* look for backslashes, too... */
80 p2 = strrchr ( filename, '\\' );
81 if ( p2 > p )
82 p = p2 + 1;
83
84 /* find extension... */
85 p2 = strrchr ( filename, '.' );
86 if ( !p2 )
87 p2 = p + strlen(p);
88
89 /* malloc a copy */
90 out_len = p2-p;
91 out = malloc ( out_len+1 );
92 if ( out == NULL )
93 {
94 fprintf ( stderr, "malloc() failed\n" );
95 return NULL;
96 }
97 memmove ( out, p, out_len );
98 out[out_len] = '\0';
99 return out;
100 }
101
102 int
103 main ( int argc, const char** argv )
104 {
105 size_t i;
106
107 printf ( "%s", header );
108
109 for ( i = 1; i < argc; i++ )
110 {
111 char* test = basename(argv[i]);
112 if ( test == NULL )
113 return 255;
114 printf ( "extern void func_%s(void);\n", test );
115 free ( test );
116 }
117
118 printf ( "%s", middle );
119
120 for ( i = 1; i < argc; i++ )
121 {
122 char* test = basename(argv[i]);
123 if ( test == NULL )
124 return 255;
125 printf ( " { \"%s\", func_%s },\n", test, test );
126 free ( test );
127 }
128
129 printf ( "%s", end );
130
131 return 0;
132 }