From e769374096427079a63c2068407b53d66529c65a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 24 Nov 2013 23:35:38 -0500 Subject: [PATCH] Added SDL_vsscanf(). --- CMakeLists.txt | 3 +- configure | 2 +- configure.in | 3 +- include/SDL_config.h.cmake | 2 +- include/SDL_config.h.in | 1 + include/SDL_config_android.h | 2 +- include/SDL_config_iphoneos.h | 2 +- include/SDL_config_macosx.h | 2 +- include/SDL_config_pandora.h | 2 +- include/SDL_config_psp.h | 2 +- include/SDL_config_windows.h | 2 +- include/SDL_config_wiz.h | 2 +- include/SDL_stdinc.h | 1 + premake/Linux/SDL_config_premake.h | 2 +- premake/MinGW/SDL_config_premake.h | 2 +- premake/VisualC/VS2008/SDL_config_premake.h | 2 +- premake/VisualC/VS2010/SDL_config_premake.h | 2 +- premake/VisualC/VS2012/SDL_config_premake.h | 2 +- premake/Xcode-iOS/SDL_config_premake.h | 2 +- premake/Xcode/Xcode3/SDL_config_premake.h | 2 +- premake/Xcode/Xcode4/SDL_config_premake.h | 2 +- premake/config/SDL_config_cygwin.template.h | 2 +- premake/config/SDL_config_iphoneos.template.h | 2 +- premake/config/SDL_config_linux.template.h | 2 +- premake/config/SDL_config_macosx.template.h | 2 +- premake/config/SDL_config_windows.template.h | 2 +- src/stdlib/SDL_string.c | 29 ++++++++++--------- 27 files changed, 44 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb90299fc..30cbaa497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -503,13 +503,14 @@ if(LIBC) check_c_source_compiles("#include #include int main() { }" HAVE_MPROTECT) + # FIXME: we don't care if you have snprintf, etc, any more. We only care if you have vsnprintf. Clean this up. foreach(_FN strtod malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp - sscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp + vsscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname ) string(TOUPPER ${_FN} _UPPER) diff --git a/configure b/configure index 9f88235cc..45c32cc3e 100755 --- a/configure +++ b/configure @@ -16581,7 +16581,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi - for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname + for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.in b/configure.in index f0d5f49a9..423620a22 100644 --- a/configure.in +++ b/configure.in @@ -268,7 +268,8 @@ if test x$enable_libc = xyes; then AC_DEFINE(HAVE_MPROTECT, 1, [ ]) ]), ) - AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname) + dnl FIXME: we don't care if you have snprintf, etc, any more. We only care if you have vsnprintf. Clean this up. + AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_FUNCS(atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 66a530b80..d0b025d4d 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -124,7 +124,7 @@ #cmakedefine HAVE_STRCASECMP 1 #cmakedefine HAVE__STRNICMP 1 #cmakedefine HAVE_STRNCASECMP 1 -#cmakedefine HAVE_SSCANF 1 +#cmakedefine HAVE_VSSCANF 1 #cmakedefine HAVE_SNPRINTF 1 #cmakedefine HAVE_VSNPRINTF 1 #cmakedefine HAVE_M_PI 1 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index c79dca89a..e96bdfaa1 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -128,6 +128,7 @@ #undef HAVE__STRNICMP #undef HAVE_STRNCASECMP #undef HAVE_SSCANF +#undef HAVE_VSSCANF #undef HAVE_SNPRINTF #undef HAVE_VSNPRINTF #undef HAVE_M_PI diff --git a/include/SDL_config_android.h b/include/SDL_config_android.h index 2ed65d59b..b0c99fc84 100644 --- a/include/SDL_config_android.h +++ b/include/SDL_config_android.h @@ -81,7 +81,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h index ae8a12bd8..abe18f14c 100644 --- a/include/SDL_config_iphoneos.h +++ b/include/SDL_config_iphoneos.h @@ -79,7 +79,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h index 7825e702c..b89b5534b 100644 --- a/include/SDL_config_macosx.h +++ b/include/SDL_config_macosx.h @@ -82,7 +82,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_CEIL 1 diff --git a/include/SDL_config_pandora.h b/include/SDL_config_pandora.h index 4bfad4861..eab66cb40 100644 --- a/include/SDL_config_pandora.h +++ b/include/SDL_config_pandora.h @@ -81,7 +81,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/include/SDL_config_psp.h b/include/SDL_config_psp.h index 989f7d8c7..a62477d36 100644 --- a/include/SDL_config_psp.h +++ b/include/SDL_config_psp.h @@ -79,7 +79,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index aa2f98451..167e26a67 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -132,7 +132,7 @@ typedef unsigned int uintptr_t; #define HAVE_SQRT 1 #if _MSC_VER >= 1800 #define HAVE_STRTOLL 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_COPYSIGN 1 #define HAVE_SCALBN 1 #endif diff --git a/include/SDL_config_wiz.h b/include/SDL_config_wiz.h index 9be04d92a..149446e57 100644 --- a/include/SDL_config_wiz.h +++ b/include/SDL_config_wiz.h @@ -75,7 +75,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 9a421ba63..2a2171494 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -331,6 +331,7 @@ extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len); extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); +extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap); extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); diff --git a/premake/Linux/SDL_config_premake.h b/premake/Linux/SDL_config_premake.h index dfb017ab8..40727f13f 100644 --- a/premake/Linux/SDL_config_premake.h +++ b/premake/Linux/SDL_config_premake.h @@ -128,7 +128,7 @@ #define HAVE_STRCASECMP 1 /* #undef HAVE__STRNICMP */ #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI /**/ diff --git a/premake/MinGW/SDL_config_premake.h b/premake/MinGW/SDL_config_premake.h index c696dd20f..86bc2502b 100644 --- a/premake/MinGW/SDL_config_premake.h +++ b/premake/MinGW/SDL_config_premake.h @@ -118,7 +118,7 @@ typedef unsigned int uintptr_t; #define HAVE_STRNCMP 1 #define HAVE__STRICMP 1 #define HAVE__STRNICMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_M_PI 1 #define HAVE_ATAN 1 #define HAVE_ATAN2 1 diff --git a/premake/VisualC/VS2008/SDL_config_premake.h b/premake/VisualC/VS2008/SDL_config_premake.h index be158a4f0..005c9ac60 100644 --- a/premake/VisualC/VS2008/SDL_config_premake.h +++ b/premake/VisualC/VS2008/SDL_config_premake.h @@ -118,7 +118,7 @@ typedef unsigned int uintptr_t; #define HAVE_STRNCMP 1 #define HAVE__STRICMP 1 #define HAVE__STRNICMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_M_PI 1 #define HAVE_ATAN 1 #define HAVE_ATAN2 1 diff --git a/premake/VisualC/VS2010/SDL_config_premake.h b/premake/VisualC/VS2010/SDL_config_premake.h index be158a4f0..005c9ac60 100644 --- a/premake/VisualC/VS2010/SDL_config_premake.h +++ b/premake/VisualC/VS2010/SDL_config_premake.h @@ -118,7 +118,7 @@ typedef unsigned int uintptr_t; #define HAVE_STRNCMP 1 #define HAVE__STRICMP 1 #define HAVE__STRNICMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_M_PI 1 #define HAVE_ATAN 1 #define HAVE_ATAN2 1 diff --git a/premake/VisualC/VS2012/SDL_config_premake.h b/premake/VisualC/VS2012/SDL_config_premake.h index be158a4f0..005c9ac60 100644 --- a/premake/VisualC/VS2012/SDL_config_premake.h +++ b/premake/VisualC/VS2012/SDL_config_premake.h @@ -118,7 +118,7 @@ typedef unsigned int uintptr_t; #define HAVE_STRNCMP 1 #define HAVE__STRICMP 1 #define HAVE__STRNICMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_M_PI 1 #define HAVE_ATAN 1 #define HAVE_ATAN2 1 diff --git a/premake/Xcode-iOS/SDL_config_premake.h b/premake/Xcode-iOS/SDL_config_premake.h index bc3e08328..fc4478a67 100644 --- a/premake/Xcode-iOS/SDL_config_premake.h +++ b/premake/Xcode-iOS/SDL_config_premake.h @@ -79,7 +79,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/premake/Xcode/Xcode3/SDL_config_premake.h b/premake/Xcode/Xcode3/SDL_config_premake.h index cb1725a27..1aeefc3d1 100644 --- a/premake/Xcode/Xcode3/SDL_config_premake.h +++ b/premake/Xcode/Xcode3/SDL_config_premake.h @@ -85,7 +85,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_CEIL 1 diff --git a/premake/Xcode/Xcode4/SDL_config_premake.h b/premake/Xcode/Xcode4/SDL_config_premake.h index cb1725a27..1aeefc3d1 100644 --- a/premake/Xcode/Xcode4/SDL_config_premake.h +++ b/premake/Xcode/Xcode4/SDL_config_premake.h @@ -85,7 +85,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_CEIL 1 diff --git a/premake/config/SDL_config_cygwin.template.h b/premake/config/SDL_config_cygwin.template.h index 1beb3ae53..d90122ce8 100644 --- a/premake/config/SDL_config_cygwin.template.h +++ b/premake/config/SDL_config_cygwin.template.h @@ -124,7 +124,7 @@ #define HAVE_STRCASECMP 1 /* #undef HAVE__STRNICMP */ #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI /**/ diff --git a/premake/config/SDL_config_iphoneos.template.h b/premake/config/SDL_config_iphoneos.template.h index 6383cabbb..645017356 100644 --- a/premake/config/SDL_config_iphoneos.template.h +++ b/premake/config/SDL_config_iphoneos.template.h @@ -79,7 +79,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI 1 diff --git a/premake/config/SDL_config_linux.template.h b/premake/config/SDL_config_linux.template.h index 5a58f7d16..5897057ea 100644 --- a/premake/config/SDL_config_linux.template.h +++ b/premake/config/SDL_config_linux.template.h @@ -128,7 +128,7 @@ #define HAVE_STRCASECMP 1 /* #undef HAVE__STRNICMP */ #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_M_PI /**/ diff --git a/premake/config/SDL_config_macosx.template.h b/premake/config/SDL_config_macosx.template.h index a22843f55..654b2c1df 100644 --- a/premake/config/SDL_config_macosx.template.h +++ b/premake/config/SDL_config_macosx.template.h @@ -85,7 +85,7 @@ #define HAVE_STRNCMP 1 #define HAVE_STRCASECMP 1 #define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_CEIL 1 diff --git a/premake/config/SDL_config_windows.template.h b/premake/config/SDL_config_windows.template.h index 915ac89d2..04c0b48e6 100644 --- a/premake/config/SDL_config_windows.template.h +++ b/premake/config/SDL_config_windows.template.h @@ -118,7 +118,7 @@ typedef unsigned int uintptr_t; #define HAVE_STRNCMP 1 #define HAVE__STRICMP 1 #define HAVE__STRNICMP 1 -#define HAVE_SSCANF 1 +#define HAVE_VSSCANF 1 #define HAVE_M_PI 1 #define HAVE_ATAN 1 #define HAVE_ATAN2 1 diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index f923ae7cb..d291f3828 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -43,7 +43,7 @@ static int UTF8_TrailingBytes(unsigned char c) return 0; } -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) +#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) static size_t SDL_ScanLong(const char *text, int radix, long *valuep) { @@ -84,7 +84,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) +#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) { @@ -116,7 +116,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) } #endif -#ifndef HAVE_SSCANF +#ifndef HAVE_VSSCANF static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) { @@ -148,7 +148,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) +#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL) static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) { @@ -189,7 +189,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) +#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL) static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) { @@ -221,7 +221,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) +#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOD) static size_t SDL_ScanFloat(const char *text, double *valuep) { @@ -967,25 +967,29 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) #endif /* HAVE_STRNCASECMP */ } -#ifdef HAVE_SSCANF int SDL_sscanf(const char *text, const char *fmt, ...) { int rc; va_list ap; va_start(ap, fmt); - rc = vsscanf(text, fmt, ap); + rc = SDL_vsscanf(text, fmt, ap); va_end(ap); return rc; } + +#ifdef HAVE_VSSCANF +int +SDL_vsscanf(const char *text, const char *fmt, va_list ap) +{ + return vsscanf(text, fmt, ap); +} #else int -SDL_sscanf(const char *text, const char *fmt, ...) +SDL_vsscanf(const char *text, const char *fmt, ...) { - va_list ap; int retval = 0; - va_start(ap, fmt); while (*fmt) { if (*fmt == ' ') { while (SDL_isspace((unsigned char) *text)) { @@ -1239,11 +1243,10 @@ SDL_sscanf(const char *text, const char *fmt, ...) /* Text didn't match format specifier */ break; } - va_end(ap); return retval; } -#endif /* HAVE_SSCANF */ +#endif /* HAVE_VSSCANF */ int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)