From 2982961f38cfe48e45c94405575ea038f7a2d401 Mon Sep 17 00:00:00 2001 From: John Popplewell Date: Mon, 20 Feb 2006 04:12:27 +0000 Subject: [PATCH] Various fixes for win32, mostly as a result of the splits. --- src/compiler.h | 26 +++++++++++--------------- src/dirwalk.c | 5 ----- src/fonts.c | 5 ++++- src/fonts.h | 15 ++++++++++++++- src/i18n.c | 3 +++ src/tuxpaint.c | 23 ++++++++--------------- src/win32_print.c | 2 +- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/compiler.h b/src/compiler.h index 90f7d2390..24ad75fde 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -29,30 +29,24 @@ */ #ifdef WIN32 +/* Horrible, dangerous macros. */ /* The SDL stderr redirection trick doesn't seem to work for perror(). This does pretty much the same thing. */ -static void win32_perror(const char * const str) -{ - if ( str && *str ) - fprintf(stderr,"%s : ",str); - fprintf(stderr, - "%s [%d]\n", - (errno<_sys_nerr)?_sys_errlist[errno]:"unknown",errno ); -} -#define perror win32_perror +#define perror(str) ({ \ + if ( (str) && *(str) ) \ + fprintf(stderr,"%s : ",(str)); \ + fprintf(stderr, \ + "%s [%d]\n", \ + (errno<_sys_nerr)?_sys_errlist[errno]:"unknown",errno ); \ +}) /* MinGW implementation of isspace() crashes on some Win98 boxes if c is 'out-of-range'. */ - -static int win32_isspace(int c) -{ - return (c == 0x20) || (c >= 0x09 && c <= 0x0D); -} -#define isspace win32_isspace +#define isspace(c) (((c) == 0x20) || ((c) >= 0x09 && (c) <= 0x0D)) /* WIN32 and MINGW don't have strcasestr(). @@ -109,7 +103,9 @@ static int win32_isspace(int c) // won't alias anything, and aligned enough for anything #define MALLOC __attribute__ ((__malloc__)) // no side effect, may read globals +#ifndef WIN32 #define PURE __attribute__ ((__pure__)) +#endif // tell gcc what to expect: if(unlikely(err)) die(err); #define likely(x) __builtin_expect(!!(x),1) #define unlikely(x) __builtin_expect(!!(x),0) diff --git a/src/dirwalk.c b/src/dirwalk.c index 0014ab5c4..e1d16030b 100644 --- a/src/dirwalk.c +++ b/src/dirwalk.c @@ -11,12 +11,7 @@ #include #include #include - - -#ifndef WIN32 -#include #include -#endif #include "SDL_ttf.h" diff --git a/src/fonts.c b/src/fonts.c index 9d35aa6bd..f79558bb8 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -22,6 +22,9 @@ #include "get_fname.h" #include "debug.h" +#ifdef WIN32 +#include "win32_print.h" +#endif #ifdef FORKED_FONTS @@ -446,7 +449,7 @@ int load_user_fonts(SDL_Surface * screen, void *vp) { #ifdef WIN32 homedirdir = GetSystemFontDir(); - loadfonts(homedirdir); + loadfonts(screen, homedirdir); free(homedirdir); #elif defined(__BEOS__) loadfonts(screen, "/boot/home/config/font/ttffonts"); diff --git a/src/fonts.h b/src/fonts.h index ca3b754ba..73929ed53 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -22,9 +22,22 @@ #ifndef FORKED_FONTS #include "SDL_thread.h" #include "SDL_mutex.h" +#else +/* This shouldn't really be here :-) + * Move into 'fonts.c' and the code in 'tuxpaint.c' + * that uses this lot should be put into 'fonts.c' as well. + */ +#define SDL_CreateThread(fn,vp) (void*)(long)(fn(vp)) +#define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0) +#define SDL_Thread int +#define SDL_mutex int +#define SDL_CreateMutex() 0 // creates in released state +#define SDL_DestroyMutex(lock) +#define SDL_mutexP(lock) // take lock +#define SDL_mutexV(lock) // release lock +#endif extern SDL_Thread *font_thread; -#endif extern volatile long font_thread_done, font_thread_aborted; extern volatile long waiting_for_fonts; diff --git a/src/i18n.c b/src/i18n.c index fffe04fe8..47bfb5075 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -34,6 +34,9 @@ #include "i18n.h" #include "debug.h" +#ifdef WIN32 +#include +#endif /* Globals: */ diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 580dcb75c..91a80bd14 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -309,20 +309,6 @@ extern WrapperData macosx; #define FNAME_EXTENSION ".bmp" #endif -#if defined(THREADED_FONTS) || defined(THREADED_STAMPS) -#include "SDL_thread.h" -#include "SDL_mutex.h" -#else -#define SDL_CreateThread(fn,vp) (void*)(long)(fn(vp)) -#define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0) -#define SDL_Thread int -#define SDL_mutex int -#define SDL_CreateMutex() 0 // creates in released state -#define SDL_DestroyMutex(lock) -#define SDL_mutexP(lock) // take lock -#define SDL_mutexV(lock) // release lock -#endif - #include "SDL_getenv.h" #include "i18n.h" @@ -5307,6 +5293,11 @@ static void load_stamps(SDL_Surface * screen) } +static int load_user_fonts_stub(void *vp) +{ + return load_user_fonts(screen, vp); +} + //////////////////////////////////////////////////////////////////////////////// /* Setup: */ @@ -6189,7 +6180,7 @@ static void setup(int argc, char * argv[]) #ifdef FORKED_FONTS reliable_write(font_socket_fd, &no_system_fonts, sizeof no_system_fonts); #else - font_thread = SDL_CreateThread(load_user_fonts, NULL); + font_thread = SDL_CreateThread(load_user_fonts_stub, NULL); #endif // continuing on with the rest of the cursors... @@ -6711,8 +6702,10 @@ static void create_button_labels(void) static void seticon(void) { +#ifndef WIN32 int masklen; Uint8 * mask; +#endif SDL_Surface * icon; /* Load icon into a surface: */ diff --git a/src/win32_print.c b/src/win32_print.c index 2abeeafe8..069ab0b52 100644 --- a/src/win32_print.c +++ b/src/win32_print.c @@ -538,7 +538,7 @@ char *GetDefaultSaveDir(const char *suffix) Returns heap string containing system font directory. E.g. 'C:\Windows\Fonts' */ -char *GetSystemFontDir() +char *GetSystemFontDir(void) { char path[MAX_PATH]; const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";