+/* Two parallel arrays; first the locale categories Perl uses on this system;
+ * the second array is their names. These arrays are in mostly arbitrary
+ * order. */
+
+const int categories[] = {
+
+# ifdef USE_LOCALE_NUMERIC
+ LC_NUMERIC,
+# endif
+# ifdef USE_LOCALE_CTYPE
+ LC_CTYPE,
+# endif
+# ifdef USE_LOCALE_COLLATE
+ LC_COLLATE,
+# endif
+# ifdef USE_LOCALE_TIME
+ LC_TIME,
+# endif
+# ifdef USE_LOCALE_MESSAGES
+ LC_MESSAGES,
+# endif
+# ifdef USE_LOCALE_MONETARY
+ LC_MONETARY,
+# endif
+# ifdef LC_ALL
+ LC_ALL,
+# endif
+ -1 /* Placeholder because C doesn't allow a
+ trailing comma, and it would get complicated
+ with all the #ifdef's */
+};
+
+/* The top-most real element is LC_ALL */
+
+const char * category_names[] = {
+
+# ifdef USE_LOCALE_NUMERIC
+ "LC_NUMERIC",
+# endif
+# ifdef USE_LOCALE_CTYPE
+ "LC_CTYPE",
+# endif
+# ifdef USE_LOCALE_COLLATE
+ "LC_COLLATE",
+# endif
+# ifdef USE_LOCALE_TIME
+ "LC_TIME",
+# endif
+# ifdef USE_LOCALE_MESSAGES
+ "LC_MESSAGES",
+# endif
+# ifdef USE_LOCALE_MONETARY
+ "LC_MONETARY",
+# endif
+# ifdef LC_ALL
+ "LC_ALL",
+# endif
+ NULL /* Placeholder */
+ };
+
+# ifdef LC_ALL
+
+ /* On systems with LC_ALL, it is kept in the highest index position. (-2
+ * to account for the final unused placeholder element.) */
+# define NOMINAL_LC_ALL_INDEX (C_ARRAY_LENGTH(categories) - 2)
+
+# else
+
+ /* On systems without LC_ALL, we pretend it is there, one beyond the real
+ * top element, hence in the unused placeholder element. */
+# define NOMINAL_LC_ALL_INDEX (C_ARRAY_LENGTH(categories) - 1)
+
+# endif
+
+/* Pretending there is an LC_ALL element just above allows us to avoid most
+ * special cases. Most loops through these arrays in the code below are
+ * written like 'for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++)'. They will work
+ * on either type of system. But the code must be written to not access the
+ * element at 'LC_ALL_INDEX' except on platforms that have it. This can be
+ * checked for at compile time by using the #define LC_ALL_INDEX which is only
+ * defined if we do have LC_ALL. */
+
+/* Now create LC_foo_INDEX #defines for just those categories on this system */
+# ifdef USE_LOCALE_NUMERIC
+# define LC_NUMERIC_INDEX 0
+# define _DUMMY_NUMERIC LC_NUMERIC_INDEX
+# else
+# define _DUMMY_NUMERIC -1
+# endif
+# ifdef USE_LOCALE_CTYPE
+# define LC_CTYPE_INDEX _DUMMY_NUMERIC + 1
+# define _DUMMY_CTYPE LC_CTYPE_INDEX
+# else
+# define _DUMMY_CTYPE _DUMMY_NUMERIC
+# endif
+# ifdef USE_LOCALE_COLLATE
+# define LC_COLLATE_INDEX _DUMMY_CTYPE + 1
+# define _DUMMY_COLLATE LC_COLLATE_INDEX
+# else
+# define _DUMMY_COLLATE _DUMMY_COLLATE
+# endif
+# ifdef USE_LOCALE_TIME
+# define LC_TIME_INDEX _DUMMY_COLLATE + 1
+# define _DUMMY_TIME LC_TIME_INDEX
+# else
+# define _DUMMY_TIME _DUMMY_COLLATE
+# endif
+# ifdef USE_LOCALE_MESSAGES
+# define LC_MESSAGES_INDEX _DUMMY_TIME + 1
+# define _DUMMY_MESSAGES LC_MESSAGES_INDEX
+# else
+# define _DUMMY_MESSAGES _DUMMY_TIME
+# endif
+# ifdef USE_LOCALE_MONETARY
+# define LC_MONETARY_INDEX _DUMMY_MESSAGES + 1
+# define _DUMMY_MONETARY LC_MONETARY_INDEX
+# else
+# define _DUMMY_MONETARY _DUMMY_MESSAGES
+# endif
+# ifdef LC_ALL
+# define LC_ALL_INDEX _DUMMY_MONETARY + 1
+# endif
+#endif /* ifdef USE_LOCALE */
+
+/* Windows requres a customized base-level setlocale() */
+# ifdef WIN32
+# define my_setlocale(cat, locale) win32_setlocale(cat, locale)
+# else
+# define my_setlocale(cat, locale) setlocale(cat, locale)
+# endif
+
+/* Just placeholders for now. "_c" is intended to be called when the category
+ * is a constant known at compile time; "_r", not known until run time */
+# define do_setlocale_c(category, locale) my_setlocale(category, locale)
+# define do_setlocale_r(category, locale) my_setlocale(category, locale)