From 09eff7243a6e8e37d9615df7b951ffa3c03c0ae2 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 19 Jan 2022 16:08:29 +0100 Subject: Fixing and upgrading Fl_Preferences (#374) * Added filename function to Fl_Preferences Static function to get filename before opening. Member to get filename after opening. Bug fixes for memory mapped preferences. * ERROR is a macro on Windows, don't use it * Added Fl_Preferences::dirty(). User can now check if the database will be written when flushed or destroyed. Flush returns a crude error code. * Fl_Preferences::get binary data returns # of bytes read. * Verified group deletion code * Fl_Preferences ignores locale. This will make .prefs files interchangeable between different computers. * Updating the Preferences Mode to ignore locale. * Fixes in docs. --- src/drivers/Darwin/Fl_Darwin_System_Driver.cxx | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/drivers/Darwin/Fl_Darwin_System_Driver.cxx') diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx index 511b3b048..dad46dfc7 100644 --- a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx +++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx @@ -116,10 +116,15 @@ int Fl_Darwin_System_Driver::arg_and_value(const char *name, const char *value) return strcmp(name, "NSDocumentRevisionsDebugMode") == 0; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 +static locale_t postscript_locale = NULL; +#endif + int Fl_Darwin_System_Driver::clocale_printf(FILE *output, const char *format, va_list args) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if (fl_mac_os_version >= 100400) { - static locale_t postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); + if (!postscript_locale) + postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); return vfprintf_l(output, postscript_locale, format, args); } #endif @@ -130,6 +135,37 @@ int Fl_Darwin_System_Driver::clocale_printf(FILE *output, const char *format, va return retval; } +int Fl_Darwin_System_Driver::clocale_snprintf(char *output, size_t output_size, const char *format, va_list args) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + if (fl_mac_os_version >= 100400) { + if (!postscript_locale) + postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); + return vsnprintf_l(output, output_size, postscript_locale, format, args); + } +#endif + char *saved_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); + int retval = vsnprintf(output, output_size, format, args); + setlocale(LC_NUMERIC, saved_locale); + return retval; +} + +int Fl_Darwin_System_Driver::clocale_sscanf(const char *input, const char *format, va_list args) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + if (fl_mac_os_version >= 100400) { + if (!postscript_locale) + postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); + return vsscanf_l(input, postscript_locale, format, args); + } +#endif + char *saved_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); + int retval = vsscanf(input, format, args); + setlocale(LC_NUMERIC, saved_locale); + return retval; +} + + /* Returns the address of a Carbon function after dynamically loading the Carbon library if needed. Supports old Mac OS X versions that may use a couple of Carbon calls: GetKeys used by OS X 10.3 or before (in Fl::get_key()) -- cgit v1.2.3