summaryrefslogtreecommitdiff
path: root/extra/locale/lmmtolso.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-05-06 07:37:32 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-05-06 07:37:32 +0000
commitd07fdf8b9ece2c4339b325921add50792077bf97 (patch)
treeb0886656bdd854728f2d1c05597368c4739ecc1b /extra/locale/lmmtolso.c
parent7f09a14cabbec158d683542e53f53ccfe75031fa (diff)
New locale support (in development). Supports LC_CTYPE, LC_NUMERIC,
LC_TIME, LC_MONETARY, and LC_MESSAGES for the SUSv3 items. Also, nl_langinfo() when real locale support is enabled. New implementation of ctype.h. New implementation of wctype.h. New implementation of most of the string functions (smaller). New implementation of the wcs/wmem functions. These are untested, but they're also just preprocessor-modified versions ot the corresponding str/mem functions. Tweaked qsort and new bsearch. Stuff still pending: stdlib.h and wchar.h mb<->wc functions. I actually have working versions of the stdlib ones, but the reentrant versions from wchar.h require some reworking. Basic replacement and translit support for wc->mb conversions. (groundwork laid). Simple-minded collate support such as was provided by the previous locale implementation. (mostly done -- 8-bit codesets only) Shared mmaping of the locale data and strerror message text.
Diffstat (limited to 'extra/locale/lmmtolso.c')
-rw-r--r--extra/locale/lmmtolso.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/extra/locale/lmmtolso.c b/extra/locale/lmmtolso.c
new file mode 100644
index 000000000..a1876a7dc
--- /dev/null
+++ b/extra/locale/lmmtolso.c
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int main(void)
+{
+ FILE *lmm; /* mmap-able file */
+ FILE *lso; /* static object */
+ struct stat fd_stat;
+ int c;
+ size_t i;
+
+ if (!(lmm = fopen("locale.mmap", "r"))) {
+ printf("can't open locale.mmap!\n");
+ return EXIT_FAILURE;
+ }
+
+ if (fstat(fileno(lmm), &fd_stat)) {
+ printf("can't stat locale.mmap!\n");
+ fclose(lmm);
+ return EXIT_FAILURE;
+ }
+
+ if (!(lso = fopen("locale_data.c", "w"))) {
+ printf("can't open locale_data.c!\n");
+ fclose(lmm);
+ return EXIT_FAILURE;
+ }
+
+ fprintf(lso,
+ "#include <stddef.h>\n"
+ "#include <stdint.h>\n"
+ "#include \"lt_defines.h\"\n"
+ "#include \"locale_mmap.h\"\n\n"
+ "typedef union {\n"
+ "\tunsigned char buf[%zu];\n"
+ "\t__locale_mmap_t lmm;\n"
+ "} locale_union_t;\n\n"
+ "static const locale_union_t locale_union = { {",
+ (size_t) fd_stat.st_size
+ );
+
+ i = 0;
+ while ((c = getc(lmm)) != EOF) {
+ if (!(i & 0x7)) {
+ fprintf(lso, "\n\t");
+ }
+ fprintf(lso, "%#04x, ", c);
+ ++i;
+ }
+ fprintf(lso,
+ "\n} };\n\n"
+ "const __locale_mmap_t *__locale_mmap = &locale_union.lmm;\n\n"
+ );
+
+ if (ferror(lmm)) {
+ printf("error reading!\n");
+ return EXIT_FAILURE;
+ }
+
+ if (ferror(lso) || fclose(lso)) {
+ printf("error writing!\n");
+ return EXIT_FAILURE;
+ }
+
+ fclose(lmm);
+
+ return EXIT_SUCCESS;
+}