<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39849 >

William Allen Simpson wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=39849 >
> 
> Naive trunk implementation:

Naive is fine but you forgot to add the check to configure.ac.  Attached 
patch does that.

But now it still won't compile, and I don't understand why.

if gcc -DHAVE_CONFIG_H -I. -I. -I.. 
-DLOCALEDIR="\"/usr/local/share/locale\"" 
-DDEFAULT_DATA_PATH="\".:data:~/.freeciv:/usr/local/share/freeciv\""  -g 
-O0 -Wall -Werror -Wcast-align -Wmissing-prototypes 
-Wmissing-declarations -MT support.o -MD -MP -MF ".deps/support.Tpo" -c 
-o support.o support.c; \
         then mv -f ".deps/support.Tpo" ".deps/support.Po"; else rm -f 
".deps/support.Tpo"; exit 1; fi
cc1: warnings being treated as errors
support.c: In function 'mystrcasestr':
support.c:167: warning: implicit declaration of function 'strcasestr'
support.c:167: warning: return makes pointer from integer without a cast

Of course I have strcasestr, it's detected properly so HAVE_STRCASESTR 
is defined.  The function is in string.h which is properly included. 
Yet in compiling the prototype is apparently not being included.

This is on debian testing.

-jason

Index: utility/support.c
===================================================================
--- utility/support.c	(revision 13930)
+++ utility/support.c	(working copy)
@@ -156,6 +156,40 @@
 }
 
 /***************************************************************
+  Return the needle in the haystack (or NULL).
+  Naive implementation.
+***************************************************************/
+char *mystrcasestr(const char *haystack, const char *needle)
+{
+#ifdef HAVE_STRCASESTR
+  return strcasestr(haystack, needle);
+#else
+  size_t haystacks;
+  size_t needles;
+  const char *p;
+
+  if (NULL == needle || '\0' == *needle) {
+    return (char *)haystack;
+  }
+  if (NULL == haystack || '\0' == *haystack) {
+    return NULL;
+  }
+  haystacks = strlen(haystack);
+  needles = strlen(needle);
+  if (haystacks < needles) {
+    return NULL;
+  }
+
+  for (p = haystack; p <= &haystack[haystacks - needles]; p++) {
+    if (0 == mystrncasecmp(p, needle, needles)) {
+      return (char *)p;
+    }
+  }
+  return NULL;
+#endif
+}
+
+/***************************************************************
   Return a string which describes a given error (errno-style.)
 ***************************************************************/
 const char *mystrerror(void)
Index: utility/support.h
===================================================================
--- utility/support.h	(revision 13930)
+++ utility/support.h	(working copy)
@@ -74,6 +74,8 @@
 int mystrncasecmp(const char *str0, const char *str1, size_t n);
 int mystrncasequotecmp(const char *str0, const char *str1, size_t n);
 
+char *mystrcasestr(const char *haystack, const char *needle);
+
 const char *mystrerror(void);
 void myusleep(unsigned long usec);
 
Index: configure.ac
===================================================================
--- configure.ac	(revision 13930)
+++ configure.ac	(working copy)
@@ -607,7 +607,7 @@
 
 AC_CHECK_FUNCS([fileno ftime gethostname getpwuid inet_aton \
 		select snooze strerror strcasecmp strncasecmp \
-		strlcat strlcpy strstr usleep uname flock \
+		strcasestr strlcat strlcpy strstr usleep uname flock \
 		gethostbyname connect bind])
 
 AC_MSG_CHECKING(for working gettimeofday)
Index: server/ruleset.c
===================================================================
--- server/ruleset.c	(revision 13930)
+++ server/ruleset.c	(working copy)
@@ -2286,7 +2286,7 @@
                * Note that the section name is unique (by definition).
                * The sub-strings are carefully crafted for this function.
                */
-	      if (NULL != strcasestr(isection, name)) {
+	      if (NULL != mystrcasestr(isection, name)) {
 	        city_names[j].terrain[i] = setting;
 	        handled = TRUE;
 		break;
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to