From bcb7591e416839f6980a5c50c4641eea0f25b953 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 16 Mar 2005 20:02:17 +0000 Subject: [PATCH] Converted the make_ctests script to C (based on a patch by Royce Mitchell III). --- Make.rules.in | 1 + dlls/Maketest.rules.in | 4 +- tools/.cvsignore | 1 + tools/Makefile.in | 5 ++ tools/make_ctests | 65 --------------------- tools/make_ctests.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 163 insertions(+), 67 deletions(-) delete mode 100755 tools/make_ctests create mode 100644 tools/make_ctests.c diff --git a/Make.rules.in b/Make.rules.in index 6a93cc77693..eb6bf268707 100644 --- a/Make.rules.in +++ b/Make.rules.in @@ -64,6 +64,7 @@ C2MAN = $(TOPSRCDIR)/tools/c2man.pl RUNTEST = $(TOPSRCDIR)/tools/runtest WINEBUILD = $(TOOLSDIR)/tools/winebuild/winebuild MAKEDEP = $(TOOLSDIR)/tools/makedep +MAKECTESTS = $(TOOLSDIR)/tools/make_ctests WRC = $(TOOLSDIR)/tools/wrc/wrc BIN2RES = $(TOOLSDIR)/tools/bin2res WMC = $(TOOLSDIR)/tools/wmc/wmc diff --git a/dlls/Maketest.rules.in b/dlls/Maketest.rules.in index b76216be0b5..4fdf388d373 100644 --- a/dlls/Maketest.rules.in +++ b/dlls/Maketest.rules.in @@ -46,8 +46,8 @@ $(MODULE): $(OBJS) $(RCOBJS) Makefile.in # Rules for building test list -$(TESTLIST): Makefile.in $(TOPSRCDIR)/tools/make_ctests - $(TOPSRCDIR)/tools/make_ctests $(CTESTS) >$(TESTLIST) || $(RM) $(TESTLIST) +$(TESTLIST): Makefile.in $(MAKECTESTS) + $(MAKECTESTS) -o $@ $(CTESTS) depend: $(TESTLIST) diff --git a/tools/.cvsignore b/tools/.cvsignore index 7e499c2a173..c01b5af3717 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -2,6 +2,7 @@ Makefile bin2res fnt2bdf fnt2fon +make_ctests makedep sfnt2fnt wineprefixcreate diff --git a/tools/Makefile.in b/tools/Makefile.in index fe08006b018..1ac3e02976b 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -11,6 +11,7 @@ PROGRAMS = \ bin2res \ fnt2bdf \ fnt2fon \ + make_ctests \ makedep \ sfnt2fnt \ wineprefixcreate @@ -19,6 +20,7 @@ C_SRCS = \ bin2res.c \ fnt2bdf.c \ fnt2fon.c \ + make_ctests.c \ makedep.c \ sfnt2fnt.c \ @@ -43,6 +45,9 @@ all: $(PROGRAMS) $(SUBDIRS) makedep: makedep.o $(CC) $(CFLAGS) -o makedep makedep.o +make_ctests: make_ctests.o + $(CC) $(CFLAGS) -o make_ctests make_ctests.o + fnt2bdf: fnt2bdf.o $(CC) $(CFLAGS) -o fnt2bdf fnt2bdf.o $(LIBPORT) diff --git a/tools/make_ctests b/tools/make_ctests deleted file mode 100755 index 9da393d2091..00000000000 --- a/tools/make_ctests +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/sh -# -# Script to generate a C file containing a list of tests -# -# Copyright 2002 Alexandre Julliard -# Copyright 2002 Dimitrie O. Paun -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -# ***** Keep in sync with tools/winapi/msvcmaker:_generate_testlist_c ***** - -cat < -#include -#include -#include "windef.h" -#include "winbase.h" - -EOF - -for file in "$@"; do - test=`basename "$file" .c` - echo "extern void func_$test(void);" -done - -cat < +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif + +static const char *output_file; + +static void fatal_error( const char *msg, ... ) +{ + va_list valist; + va_start( valist, msg ); + fprintf( stderr, "make_ctests: " ); + vfprintf( stderr, msg, valist ); + va_end( valist ); + if (output_file) unlink( output_file ); + exit(1); +} + +static void fatal_perror( const char *msg, ... ) +{ + va_list valist; + va_start( valist, msg ); + fprintf( stderr, "make_ctests: " ); + vfprintf( stderr, msg, valist ); + perror( " " ); + va_end( valist ); + exit(1); +} + +static void *xmalloc( size_t size ) +{ + void *res = malloc (size ? size : 1); + if (!res) fatal_error( "virtual memory exhausted.\n" ); + return res; +} + +static char* basename( const char* filename ) +{ + const char *p, *p2; + char *out; + size_t out_len; + + p = strrchr ( filename, '/' ); + if ( !p ) + p = filename; + else + ++p; + + /* look for backslashes, too... */ + p2 = strrchr ( p, '\\' ); + if ( p2 ) p = p2 + 1; + + /* find extension... */ + p2 = strrchr ( p, '.' ); + if ( !p2 ) + p2 = p + strlen(p); + + /* malloc a copy */ + out_len = p2-p; + out = xmalloc ( out_len+1 ); + memcpy ( out, p, out_len ); + out[out_len] = '\0'; + return out; +} + +int main( int argc, const char** argv ) +{ + int i, count = 0; + FILE *out = stdout; + char **tests = xmalloc( argc * sizeof(*tests) ); + + for (i = 1; i < argc; i++) + { + if (!strcmp( argv[i], "-o" ) && i < argc-1) + { + output_file = argv[++i]; + continue; + } + tests[count++] = basename( argv[i] ); + } + + if (output_file) + { + if (!(out = fopen( output_file, "w" ))) + fatal_perror( "cannot create %s", output_file ); + } + + fprintf( out, + "/* Automatically generated file; DO NOT EDIT!! */\n" + "\n" + "/* stdarg.h is needed for Winelib */\n" + "#include \n" + "#include \n" + "#include \n" + "#include \"windef.h\"\n" + "#include \"winbase.h\"\n" + "\n" ); + + for (i = 0; i < count; i++) fprintf( out, "extern void func_%s(void);\n", tests[i] ); + + fprintf( out, + "\n" + "struct test\n" + "{\n" + " const char *name;\n" + " void (*func)(void);\n" + "};\n" + "\n" + "static const struct test winetest_testlist[] =\n" + "{\n" ); + + for (i = 0; i < count; i++) fprintf( out, " { \"%s\", func_%s },\n", tests[i], tests[i] ); + + fprintf( out, + " { 0, 0 }\n" + "};\n" + "\n" + "#define WINETEST_WANT_MAIN\n" + "#include \"wine/test.h\"\n" ); + + if (output_file && fclose( out )) + fatal_perror( "error writing to %s", output_file ); + + return 0; +} -- 2.11.4.GIT