From 9fae1a8a256c462e0a22e3b2a93bd71c7c650cc8 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Sat, 3 Jun 2006 06:24:55 +0000 Subject: [PATCH] Fixing bug #1480977: Defining _GNU_SOURCE before including any headers, then checking if __USE_GNU was set, in which case strcasestr() is almost definitely available, otherwise we define it in tuxpaint.c For non-GNU systems which DO have strcasestr() defined, HAVE_STRCASESTR can be set to prevent redefinition within tuxpaint.c. --- Makefile | 2 +- docs/CHANGES.txt | 4 +++- src/tuxpaint.c | 50 ++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5e0f53909..2fbdf005b 100644 --- a/Makefile +++ b/Makefile @@ -1028,7 +1028,7 @@ obj/tuxpaint.o: src/tuxpaint.c \ $(ARCH_HEADERS) @echo @echo "...Compiling Tux Paint from source..." - @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(MOUSE_CFLAGS) $(DEFS) \ + $(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(MOUSE_CFLAGS) $(DEFS) \ -c src/tuxpaint.c -o obj/tuxpaint.o obj/i18n.o: src/i18n.c src/i18n.h src/debug.h diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 22eb287e9..7ecc76d13 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -9,7 +9,7 @@ http://www.newbreedsoftware.com/tuxpaint/ $Id$ -2006.May.14 (0.9.16) +2006.June.02 (0.9.16) * Interface improvements: ----------------------- * Modified "Text" tool so that it correctly handles the 16-bit unicode @@ -155,6 +155,8 @@ $Id$ * Silencing any errors when running kde- or gnome-config during install. + * Implemented strcasestr() for systems which don't have it. + * Bug Fixes: ---------- * Tux Paint's scalable icon (tuxpaint-icon.svg) caused Gnome panel to diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 8a5813a99..e6ba76488 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - April 2, 2006 + June 14, 2002 - June 2, 2006 $Id$ */ @@ -168,13 +168,47 @@ static scaleparams scaletable[] = { #define REPEAT_SPEED 300 /* Initial repeat speed for scrollbars */ #define CURSOR_BLINK_SPEED 500 /* Initial repeat speed for cursor */ + +#define _GNU_SOURCE /* for strcasestr() */ + #include #include -#define __USE_GNU /* for strcasestr() */ #include #include #include + +/* Check if features.h did its 'magic', in which case strcasestr() is + likely available; if not using GNU, you can set HAVE_STRCASESTR to + avoid trying to redefine it -bjk 2006.06.02 */ + +#if !defined(__USE_GNU) && !defined(HAVE_STRCASESTR) +#warning "Attempting to define strcasestr(); if errors, build with -DHAVE_STRCASESTR" + +char * strcasestr(const char *haystack, const char *needle) +{ + char * uphaystack, * upneedle, * result; + unsigned int i; + + uphaystack = strdup(haystack); + upneedle = strdup(needle); + + if (uphaystack == NULL || upneedle == NULL) + return(NULL); + + for (i = 0; i < strlen(uphaystack); i++) + uphaystack[i] = toupper(uphaystack[i]); + + for (i = 0; i < strlen(upneedle); i++) + upneedle[i] = toupper(upneedle[i]); + + result = strstr(uphaystack, upneedle); + + return(result - uphaystack + (char *) haystack); +} + +#endif + /* kluge; 2006.01.15 */ //#define __APPLE_10_2_8__ @@ -1152,6 +1186,11 @@ static void do_wait(int counter) // This lets us exit quickly; perhaps the system is swapping to death // or the user started Tux Paint by accident. It also lets the user // more easily bypass the splash screen wait. + +/* Was used in progressbar.c, but is currently commented out! + -bjk 2006.06.02 */ + +#if 0 static void eat_sdl_events(void) { SDL_Event event; @@ -1191,6 +1230,7 @@ static void eat_sdl_events(void) bypass_splash_wait = 1; } } +#endif /* --- MAIN --- */ @@ -3665,7 +3705,7 @@ static void tint_surface(SDL_Surface * tmp_surf, SDL_Surface * surf_ptr) key_color_ptr = find_most_saturated(initial_hue, work, width * height, &hue_range); - printf("key_color_ptr = %d\n", key_color_ptr); + printf("key_color_ptr = %d\n", (int) key_color_ptr); if (key_color_ptr) @@ -5308,11 +5348,13 @@ static void load_stamps(SDL_Surface * screen) free(homedirdir); } - +#ifndef FORKED_FONTS static int load_user_fonts_stub(void *vp) { return load_user_fonts(screen, vp); } +#endif + //////////////////////////////////////////////////////////////////////////////// /* Setup: */