stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r548191 - in /incubator/stdcxx/trunk/tests: include/rw_locale.h src/locale.cpp
Date Mon, 18 Jun 2007 03:33:19 GMT
Author: sebor
Date: Sun Jun 17 20:33:18 2007
New Revision: 548191

URL: http://svn.apache.org/viewvc?view=rev&rev=548191
Log:
2007-06-17  Scott Zhong  <scottz@roguewave.com>
	    Martin Sebor <sebor@roguewave.com>

	* rw_locale.h (rw_create_locale): New helper function to invoke
	the stdcxx localedef utility to create a stdcxx locale.
	* locale.cpp ((rw_create_locale): Defined.

Modified:
    incubator/stdcxx/trunk/tests/include/rw_locale.h
    incubator/stdcxx/trunk/tests/src/locale.cpp

Modified: incubator/stdcxx/trunk/tests/include/rw_locale.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/include/rw_locale.h?view=diff&rev=548191&r1=548190&r2=548191
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_locale.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_locale.h Sun Jun 17 20:33:18 2007
@@ -83,5 +83,13 @@
 rw_find_mb_locale (_RWSTD_SIZE_T* /* mb_cur_max */,
                    rw_mbchar_array_t /* mb_chars */);
 
+// invokes localedef with charmap and locale def to create a locale database 
+// in a directory specified by the RWSTD_LOCALE_ROOT environment
+// variable, if it is defined, otherwise in the current working
+// directory
+// returns the name of the locale
+_TEST_EXPORT const char*
+rw_create_locale (const char *charmap, const char *locale);
+
 
 #endif   // RW_LOCALE_H_INCLUDED

Modified: incubator/stdcxx/trunk/tests/src/locale.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/locale.cpp?view=diff&rev=548191&r1=548190&r2=548191
==============================================================================
--- incubator/stdcxx/trunk/tests/src/locale.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/locale.cpp Sun Jun 17 20:33:18 2007
@@ -36,14 +36,15 @@
 #include <file.h>         // for SHELL_RM_RF, rw_tmpnam
 #include <rw_printf.h>    // for rw_fprintf()
 #include <rw_process.h>   // for rw_system()
+#include <cstdio>
 
 
-#if defined __linux__
+#if defined (_RWSTD_OS_LINUX) && !defined (_XOPEN_SOURCE)
    // on Linux define _XOPEN_SOURCE to get CODESET defined in <langinfo.h>
 #  define _XOPEN_SOURCE   500   /* Single Unix conformance */
    // bring __int32_t into scope (otherwise <wctype.h> fails to compile)
 #  include <sys/types.h>
-#endif   // __linux__
+#endif   // Linux
 
 #include <fcntl.h>
 #include <sys/stat.h>   // for stat
@@ -649,3 +650,63 @@
     return mb_locale_name;
 }
 
+
+/**************************************************************************/
+
+_TEST_EXPORT const char*
+rw_create_locale (const char *charmap, const char *locale)
+{
+    // only one locale is enough (avoid invoking localedef more than once)
+    static const char* locname;
+    const char* locale_root;
+
+    if (locname)
+        return locname;
+
+    // set up RWSTD_LOCALE_ROOT and other environment variables
+    locale_root = rw_set_locale_root ();
+
+    if (0 == locale_root)
+        return 0;
+
+    // create a temporary locale definition file that exercises as
+    // many different parts of the collate standard as possible
+    char srcfname [256];
+    std::sprintf (srcfname, "%s%slocale.src", locale_root, SLASH);
+
+    std::FILE *fout = std::fopen (srcfname, "w");
+
+    if (!fout) {
+        std::fprintf (stderr, "%s:%d: fopen(\"%s\", \"w\") failed\n",
+                      __FILE__, __LINE__, srcfname);
+        return 0;
+    }
+
+       std::fprintf (fout, "%s", locale);
+
+    std::fclose (fout);
+
+    // create a temporary character map file
+    char cmfname [256];
+    std::sprintf (cmfname, "%s%scharmap.src", locale_root, SLASH);
+
+    fout = std::fopen (cmfname, "w");
+
+    if (!fout) {
+        std::fprintf (stderr, "%s:%d: fopen(\"%s\", \"w\") failed\n",
+                      __FILE__, __LINE__, cmfname);
+        return 0;
+    }
+
+       std::fprintf (fout, "%s", charmap);
+
+    std::fclose (fout);
+
+       locname = "test-locale";
+
+    // process the locale definition file and character map
+    if (0 == rw_localedef ("-w", srcfname, cmfname, locname))
+        locname = 0;
+
+    return locname;
+}



Mime
View raw message