1 /*
2 * Generate a C file containing a list of tests
3 *
4 * Copyright 2002, 2005 Alexandre Julliard
5 * Copyright 2002 Dimitrie O. Paun
6 * Copyright 2005 Royce Mitchell III for the ReactOS Project
7 *
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.
12 *
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.
17 *
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
21 *
22 ****** Keep in sync with tools/winapi/msvcmaker:_generate_testlist_c *****
23 */
24
25 #include "config.h"
26
27 #include <signal.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35
36 static const char *output_file;
37
38 static void cleanup_files(void)
39 {
40 if (output_file) unlink( output_file );
41 }
42
43 static void exit_on_signal( int sig )
44 {
45 exit(1); /* this will call the atexit functions */
46 }
47
48 static void fatal_error( const char *msg, ... )
49 {
50 va_list valist;
51 va_start( valist, msg );
52 fprintf( stderr, "make_ctests: " );
53 vfprintf( stderr, msg, valist );
54 va_end( valist );
55 exit(1);
56 }
57
58 static void fatal_perror( const char *msg, ... )
59 {
60 va_list valist;
61 va_start( valist, msg );
62 fprintf( stderr, "make_ctests: " );
63 vfprintf( stderr, msg, valist );
64 perror( " " );
65 va_end( valist );
66 exit(1);
67 }
68
69 static void *xmalloc( size_t size )
70 {
71 void *res = malloc (size ? size : 1);
72 if (!res) fatal_error( "virtual memory exhausted.\n" );
73 return res;
74 }
75
76 static char* basename( const char* filename )
77 {
78 const char *p, *p2;
79 char *out;
80 size_t out_len;
81
82 p = strrchr ( filename, '/' );
83 if ( !p )
84 p = filename;
85 else
86 ++p;
87
88 /* look for backslashes, too... */
89 p2 = strrchr ( p, '\\' );
90 if ( p2 ) p = p2 + 1;
91
92 /* find extension... */
93 p2 = strrchr ( p, '.' );
94 if ( !p2 )
95 p2 = p + strlen(p);
96
97 /* malloc a copy */
98 out_len = p2-p;
99 out = xmalloc ( out_len+1 );
100 memcpy ( out, p, out_len );
101 out[out_len] = '\0';
102 return out;
103 }
104
105 int main( int argc, const char** argv )
106 {
107 int i, count = 0;
108 FILE *out = stdout;
109 char **tests = xmalloc( argc * sizeof(*tests) );
110
111 for (i = 1; i < argc; i++)
112 {
113 if (!strcmp( argv[i], "-o" ) && i < argc-1)
114 {
115 output_file = argv[++i];
116 continue;
117 }
118 tests[count++] = basename( argv[i] );
119 }
120
121 atexit( cleanup_files );
122 signal( SIGTERM, exit_on_signal );
123 signal( SIGINT, exit_on_signal );
124 #ifdef SIGHUP
125 signal( SIGHUP, exit_on_signal );
126 #endif
127
128 if (output_file)
129 {
130 if (!(out = fopen( output_file, "w" )))
131 fatal_perror( "cannot create %s", output_file );
132 }
133
134 fprintf( out,
135 "/* Automatically generated file; DO NOT EDIT!! */\n"
136 "\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" );
141
142 for (i = 0; i < count; i++) fprintf( out, "extern void func_%s(void);\n", tests[i] );
143
144 fprintf( out,
145 "\n"
146 "const struct test winetest_testlist[] =\n"
147 "{\n" );
148
149 for (i = 0; i < count; i++) fprintf( out, " { \"%s\", func_%s },\n", tests[i], tests[i] );
150
151 fprintf( out,
152 " { 0, 0 }\n"
153 "};\n" );
154
155 if (output_file && fclose( out ))
156 fatal_perror( "error writing to %s", output_file );
157
158 output_file = NULL;
159 return 0;
160 }
161
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.