Subject: mklocale, take 2
To: None <tech-userlevel@netbsd.org, tech-toolchain@netbsd.org>
From: James Chacon <jchacon@genuity.net>
List: tech-userlevel
Date: 10/17/2001 16:47:29
Ok, after reviewing some of the things Todd and I "discussed" earlier I've got
a different set of patchs to the locale code in order to clean up mklocale
so it's not tied to -current so tightly.

Basically the changes are:

Define _DEFAULT_INVALID_RUNE (currently -3)

In runetable.c use this instead of the magic -3 definition there now

In mklocale/yacc.y change _INVALID_RUNE to _DEFAULT_INVALID_RUNE so it's not
tied to -current libraries. (and it also guarentee's mklocale gives the
same output no matter what your current locale settings are).

In runetype.h bring in inttypes.h and remove the reference to 
machine/int_types.h. Also change the machine/ansi.h to sys/types.h and also
include wchar.h. This way most of the duplication for setting wint_t, size_t,
etc can be removed. Finally, change all __*int* ref's to the corresponding
inttypes.h standard ones. 

Except for sys/cdefs.h this code should compile anywhere now.

I've attached diffs and would like comments since I beleive this is both
clean and correct now. This will allow locale stuff to be use correctly
with USE_NEW_TOOLCHAIN

James






Index: lib/libc/locale/rune.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/locale/rune.h,v
retrieving revision 1.3
diff -u -r1.3 rune.h
--- lib/libc/locale/rune.h      2000/12/28 05:22:27     1.3
+++ lib/libc/locale/rune.h      2001/10/17 20:45:09
@@ -63,4 +63,6 @@
 #define __rune_packstate       ___rune_packstate(_CurrentRuneLocale)
 #define __rune_unpackstate     ___rune_unpackstate(_CurrentRuneLocale)
 
+#define _DEFAULT_INVALID_RUNE  -3
+
 #endif /*! _RUNE_H_ */
Index: lib/libc/locale/runetable.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/locale/runetable.c,v
retrieving revision 1.6
diff -u -r1.6 runetable.c
--- lib/libc/locale/runetable.c 2001/03/26 19:55:42     1.6
+++ lib/libc/locale/runetable.c 2001/10/17 20:45:09
@@ -67,7 +67,7 @@
 _RuneLocale _DefaultRuneLocale = {
     _RUNE_MAGIC_1,
     "NONE",
-    -3,
+    _DEFAULT_INVALID_RUNE,
 
     {  /*00*/  _CTYPE_C,
                _CTYPE_C,
Index: lib/libc/locale/runetype.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/locale/runetype.h,v
retrieving revision 1.5
diff -u -r1.5 runetype.h
--- lib/libc/locale/runetype.h  2001/03/26 19:55:43     1.5
+++ lib/libc/locale/runetype.h  2001/10/17 20:45:09
@@ -41,31 +41,13 @@
 #ifndef        _RUNETYPE_H_
 #define        _RUNETYPE_H_
 
-#include <sys/cdefs.h>
-#include <machine/ansi.h>
-
-#include <machine/int_types.h>
-typedef __uint64_t     __runepad_t;
+#include <inttypes.h>
+#include <wchar.h>
 
-#ifdef _BSD_SIZE_T_
-typedef        _BSD_SIZE_T_    size_t;
-#undef _BSD_SIZE_T_
-#endif
-
-#ifdef _BSD_WCHAR_T_
-typedef        _BSD_WCHAR_T_   wchar_t;
-#undef _BSD_WCHAR_T_
-#endif
-
-#ifdef _BSD_WINT_T_
-typedef        _BSD_WINT_T_    wint_t;
-#undef _BSD_WINT_T_
-#endif
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-#ifdef _BSD_MBSTATE_T_
-typedef        _BSD_MBSTATE_T_ mbstate_t;
-#undef _BSD_MBSTATE_T_
-#endif
+typedef uint64_t       __runepad_t;
 
 #ifdef _BSD_RUNE_T_
 typedef        _BSD_RUNE_T_    rune_t;
@@ -82,7 +64,7 @@
 /*
  * The lower 8 bits of runetype[] contain the digit value of the rune.
  */
-typedef __uint32_t _RuneType;
+typedef uint32_t _RuneType;
 #define        _CTYPE_A        0x00000100L     /* Alpha */
 #define        _CTYPE_C        0x00000200L     /* Control */
 #define        _CTYPE_D        0x00000400L     /* Digit */
@@ -109,17 +91,17 @@
  * rune file format.  network endian.
  */
 typedef struct {
-       __int32_t       __min;          /* First rune of the range */
-       __int32_t       __max;          /* Last rune (inclusive) of the range */
-       __int32_t       __map;          /* What first maps to in maps */
-       __uint32_t      __pad1;         /* backward compatibility */
+       int32_t         __min;          /* First rune of the range */
+       int32_t         __max;          /* Last rune (inclusive) of the range */
+       int32_t         __map;          /* What first maps to in maps */
+       uint32_t        __pad1;         /* backward compatibility */
        __runepad_t     __pad2;         /* backward compatibility */
 } _FileRuneEntry __attribute__((__packed__));
 
 
 typedef struct {
-       __uint32_t      __nranges;      /* Number of ranges stored */
-       __uint32_t      __pad1;         /* backward compatibility */
+       uint32_t        __nranges;      /* Number of ranges stored */
+       uint32_t        __pad1;         /* backward compatibility */
        __runepad_t     __pad2;         /* backward compatibility */
 } _FileRuneRange __attribute__((__packed__));
 
@@ -130,12 +112,12 @@
 
        __runepad_t     __pad1;         /* backward compatibility */
        __runepad_t     __pad2;         /* backward compatibility */
-       __int32_t       __invalid_rune;
-       __uint32_t      __pad3;         /* backward compatibility */
+       int32_t         __invalid_rune;
+       uint32_t        __pad3;         /* backward compatibility */
 
        _RuneType       __runetype[_CACHED_RUNES];
-       __int32_t       __maplower[_CACHED_RUNES];
-       __int32_t       __mapupper[_CACHED_RUNES];
+       int32_t         __maplower[_CACHED_RUNES];
+       int32_t         __mapupper[_CACHED_RUNES];
 
        /*
         * The following are to deal with Runes larger than _CACHED_RUNES - 1.
@@ -147,8 +129,8 @@
        _FileRuneRange  __mapupper_ext;
 
        __runepad_t     __pad4;         /* backward compatibility */
-       __int32_t       __variable_len; /* how long that data is */
-       __uint32_t      __pad5;         /* backward compatibility */
+       int32_t         __variable_len; /* how long that data is */
+       uint32_t        __pad5;         /* backward compatibility */
 
        /* variable size data follows */
 } _FileRuneLocale __attribute__((__packed__));
@@ -166,7 +148,7 @@
 
 
 typedef struct {
-       __uint32_t      __nranges;      /* Number of ranges stored */
+       uint32_t        __nranges;      /* Number of ranges stored */
        _RuneEntry      *__rune_ranges;
 } _RuneRange;
 
Index: usr.bin/mklocale/yacc.y
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/mklocale/yacc.y,v
retrieving revision 1.5
diff -u -r1.5 yacc.y
--- usr.bin/mklocale/yacc.y     2001/01/28 00:50:04     1.5
+++ usr.bin/mklocale/yacc.y     2001/10/17 20:45:52
@@ -294,7 +294,7 @@
        mapupper.map[x] = x;
        maplower.map[x] = x;
     }
-    new_locale.__invalid_rune = _INVALID_RUNE;
+    new_locale.__invalid_rune = _DEFAULT_INVALID_RUNE;
     memcpy(new_locale.__magic, _RUNE_MAGIC_1, sizeof(new_locale.__magic));
 
     yyparse();