From 3fb3a43079070298675dd0c265850e1d3206a440 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Sat, 26 Feb 2005 21:47:54 +0000 Subject: [PATCH] Make the format of LC_CTYPE files architecture independent by introducing the disk formats for _RuneLocale and friends. The disk formats do not have (useless) pointers and have 32-bit quantities instead of rune_t and long. (htonl(3) only works with 32-bit quantities, so there's no loss). Bootstrap mklocale(1) when necessary. (Bootstrapping from 4.x would be trivial (verified), but we no longer provide pre-5.3 source upgrades and this is the first commit to actually break it.) --- Makefile.inc1 | 5 + include/Makefile | 3 +- include/runefile.h | 61 +++++++++++ lib/libc/locale/rune.c | 224 ++++++++++++++++++++++++++++------------ sys/sys/param.h | 2 +- tools/build/Makefile | 5 + usr.bin/mklocale/ldef.h | 12 ++- usr.bin/mklocale/lex.l | 1 - usr.bin/mklocale/yacc.y | 147 +++++++++++++------------- 9 files changed, 309 insertions(+), 151 deletions(-) create mode 100644 include/runefile.h diff --git a/Makefile.inc1 b/Makefile.inc1 index 9c58c55065f2..f6227c77fd61 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -768,6 +768,10 @@ _cap_mkdb= usr.bin/cap_mkdb _lex= usr.bin/lex .endif +.if ${BOOTSTRAPPING} < 600016 +_mklocale= usr.bin/mklocale +.endif + .if ${BOOTSTRAPPING} < 450005 || \ ${BOOTSTRAPPING} >= 500000 && ${BOOTSTRAPPING} < 500034 _uudecode= usr.bin/uudecode @@ -807,6 +811,7 @@ bootstrap-tools: ${_lex} \ usr.bin/lorder \ usr.bin/makewhatis \ + ${_mklocale} \ usr.bin/rpcgen \ ${_uudecode} \ ${_xargs} \ diff --git a/include/Makefile b/include/Makefile index 2ca0bca48e8b..56653b22bfd8 100644 --- a/include/Makefile +++ b/include/Makefile @@ -15,7 +15,8 @@ INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h _ctype.h ctype.h \ netdb.h nl_types.h nlist.h nss.h nsswitch.h objformat.h paths.h \ proc_service.h pthread.h \ pthread_np.h pwd.h ranlib.h readpassphrase.h regex.h regexp.h \ - resolv.h runetype.h search.h setjmp.h sgtty.h signal.h stab.h \ + resolv.h runefile.h runetype.h search.h setjmp.h sgtty.h \ + signal.h stab.h \ stdbool.h stddef.h stdio.h stdlib.h string.h stringlist.h \ strings.h sysexits.h tar.h tgmath.h \ time.h timeconv.h timers.h ttyent.h \ diff --git a/include/runefile.h b/include/runefile.h new file mode 100644 index 000000000000..ce1e47e5f92d --- /dev/null +++ b/include/runefile.h @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2005 Ruslan Ermilov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _RUNEFILE_H_ +#define _RUNEFILE_H_ + +#include + +#ifndef _CACHED_RUNES +#define _CACHED_RUNES (1 << 8) +#endif + +typedef struct { + int32_t min; + int32_t max; + int32_t map; +} _FileRuneEntry; + +typedef struct { + char magic[8]; + char encoding[32]; + + uint32_t runetype[_CACHED_RUNES]; + int32_t maplower[_CACHED_RUNES]; + int32_t mapupper[_CACHED_RUNES]; + + int32_t runetype_ext_nranges; + int32_t maplower_ext_nranges; + int32_t mapupper_ext_nranges; + + int32_t variable_len; +} _FileRuneLocale; + +#define _FILE_RUNE_MAGIC_1 "RuneMag1" + +#endif /* !_RUNEFILE_H_ */ diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index d179da101acc..4d37f36f6331 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -51,149 +52,238 @@ __FBSDID("$FreeBSD$"); #include #include "un-namespace.h" +_RuneLocale *_Read_RuneMagi(FILE *); + _RuneLocale * -_Read_RuneMagi(fp) - FILE *fp; +_Read_RuneMagi(FILE *fp) { - char *data; + char *fdata, *data; void *lastp; + _FileRuneLocale *frl; _RuneLocale *rl; + _FileRuneEntry *frr; _RuneEntry *rr; struct stat sb; int x, saverr; + void *variable; + _FileRuneEntry *runetype_ext_ranges; + _FileRuneEntry *maplower_ext_ranges; + _FileRuneEntry *mapupper_ext_ranges; + int runetype_ext_len = 0; if (_fstat(fileno(fp), &sb) < 0) return (NULL); - if (sb.st_size < sizeof(_RuneLocale)) { + if ((size_t)sb.st_size < sizeof(_FileRuneLocale)) { errno = EFTYPE; return (NULL); } - if ((data = malloc(sb.st_size)) == NULL) + if ((fdata = malloc(sb.st_size)) == NULL) return (NULL); errno = 0; rewind(fp); /* Someone might have read the magic number once already */ if (errno) { saverr = errno; - free(data); + free(fdata); errno = saverr; return (NULL); } - if (fread(data, sb.st_size, 1, fp) != 1) { + if (fread(fdata, sb.st_size, 1, fp) != 1) { saverr = errno; - free(data); + free(fdata); errno = saverr; return (NULL); } - rl = (_RuneLocale *)data; - lastp = data + sb.st_size; + frl = (_FileRuneLocale *)fdata; + lastp = fdata + sb.st_size; - rl->__variable = rl + 1; + variable = frl + 1; - if (memcmp(rl->__magic, _RUNE_MAGIC_1, sizeof(rl->__magic))) { - free(data); + if (memcmp(frl->magic, _FILE_RUNE_MAGIC_1, sizeof(frl->magic))) { + free(fdata); errno = EFTYPE; return (NULL); } - rl->__invalid_rune = ntohl(rl->__invalid_rune); - rl->__variable_len = ntohl(rl->__variable_len); - rl->__runetype_ext.__nranges = ntohl(rl->__runetype_ext.__nranges); - rl->__maplower_ext.__nranges = ntohl(rl->__maplower_ext.__nranges); - rl->__mapupper_ext.__nranges = ntohl(rl->__mapupper_ext.__nranges); + frl->variable_len = ntohl(frl->variable_len); + frl->runetype_ext_nranges = ntohl(frl->runetype_ext_nranges); + frl->maplower_ext_nranges = ntohl(frl->maplower_ext_nranges); + frl->mapupper_ext_nranges = ntohl(frl->mapupper_ext_nranges); for (x = 0; x < _CACHED_RUNES; ++x) { - rl->__runetype[x] = ntohl(rl->__runetype[x]); - rl->__maplower[x] = ntohl(rl->__maplower[x]); - rl->__mapupper[x] = ntohl(rl->__mapupper[x]); + frl->runetype[x] = ntohl(frl->runetype[x]); + frl->maplower[x] = ntohl(frl->maplower[x]); + frl->mapupper[x] = ntohl(frl->mapupper[x]); } - rl->__runetype_ext.__ranges = (_RuneEntry *)rl->__variable; - rl->__variable = rl->__runetype_ext.__ranges + - rl->__runetype_ext.__nranges; - if (rl->__variable > lastp) { - free(data); + runetype_ext_ranges = (_FileRuneEntry *)variable; + variable = runetype_ext_ranges + frl->runetype_ext_nranges; + if (variable > lastp) { + free(fdata); errno = EFTYPE; return (NULL); } - rl->__maplower_ext.__ranges = (_RuneEntry *)rl->__variable; - rl->__variable = rl->__maplower_ext.__ranges + - rl->__maplower_ext.__nranges; - if (rl->__variable > lastp) { - free(data); + maplower_ext_ranges = (_FileRuneEntry *)variable; + variable = maplower_ext_ranges + frl->maplower_ext_nranges; + if (variable > lastp) { + free(fdata); errno = EFTYPE; return (NULL); } - rl->__mapupper_ext.__ranges = (_RuneEntry *)rl->__variable; - rl->__variable = rl->__mapupper_ext.__ranges + - rl->__mapupper_ext.__nranges; - if (rl->__variable > lastp) { - free(data); + mapupper_ext_ranges = (_FileRuneEntry *)variable; + variable = mapupper_ext_ranges + frl->mapupper_ext_nranges; + if (variable > lastp) { + free(fdata); errno = EFTYPE; return (NULL); } - for (x = 0; x < rl->__runetype_ext.__nranges; ++x) { - rr = rl->__runetype_ext.__ranges; + frr = runetype_ext_ranges; + for (x = 0; x < frl->runetype_ext_nranges; ++x) { + uint32_t *types; - rr[x].__min = ntohl(rr[x].__min); - rr[x].__max = ntohl(rr[x].__max); - if ((rr[x].__map = ntohl(rr[x].__map)) == 0) { - int len = rr[x].__max - rr[x].__min + 1; - rr[x].__types = rl->__variable; - rl->__variable = rr[x].__types + len; - if (rl->__variable > lastp) { - free(data); + frr[x].min = ntohl(frr[x].min); + frr[x].max = ntohl(frr[x].max); + frr[x].map = ntohl(frr[x].map); + if (frr[x].map == 0) { + int len = frr[x].max - frr[x].min + 1; + types = variable; + variable = types + len; + runetype_ext_len += len; + if (variable > lastp) { + free(fdata); errno = EFTYPE; return (NULL); } while (len-- > 0) - rr[x].__types[len] = ntohl(rr[x].__types[len]); - } else - rr[x].__types = 0; + types[len] = ntohl(types[len]); + } } - for (x = 0; x < rl->__maplower_ext.__nranges; ++x) { - rr = rl->__maplower_ext.__ranges; - - rr[x].__min = ntohl(rr[x].__min); - rr[x].__max = ntohl(rr[x].__max); - rr[x].__map = ntohl(rr[x].__map); + frr = maplower_ext_ranges; + for (x = 0; x < frl->maplower_ext_nranges; ++x) { + frr[x].min = ntohl(frr[x].min); + frr[x].max = ntohl(frr[x].max); + frr[x].map = ntohl(frr[x].map); } - for (x = 0; x < rl->__mapupper_ext.__nranges; ++x) { - rr = rl->__mapupper_ext.__ranges; - - rr[x].__min = ntohl(rr[x].__min); - rr[x].__max = ntohl(rr[x].__max); - rr[x].__map = ntohl(rr[x].__map); + frr = mapupper_ext_ranges; + for (x = 0; x < frl->mapupper_ext_nranges; ++x) { + frr[x].min = ntohl(frr[x].min); + frr[x].max = ntohl(frr[x].max); + frr[x].map = ntohl(frr[x].map); } - if (((char *)rl->__variable) + rl->__variable_len > (char *)lastp) { - free(data); + if ((char *)variable + frl->variable_len > (char *)lastp) { + free(fdata); errno = EFTYPE; return (NULL); } + /* + * Convert from disk format to host format. + */ + data = malloc(sizeof(_RuneLocale) + + (frl->runetype_ext_nranges + frl->maplower_ext_nranges + + frl->mapupper_ext_nranges) * sizeof(_RuneEntry) + + runetype_ext_len * sizeof(*rr->__types) + + frl->variable_len); + if (data == NULL) { + saverr = errno; + free(fdata); + errno = saverr; + return (NULL); + } + + rl = (_RuneLocale *)data; + rl->__variable = rl + 1; + + memcpy(rl->__magic, _RUNE_MAGIC_1, sizeof(rl->__magic)); + memcpy(rl->__encoding, frl->encoding, sizeof(rl->__encoding)); + rl->__invalid_rune = 0; + + rl->__variable_len = frl->variable_len; + rl->__runetype_ext.__nranges = frl->runetype_ext_nranges; + rl->__maplower_ext.__nranges = frl->maplower_ext_nranges; + rl->__mapupper_ext.__nranges = frl->mapupper_ext_nranges; + + for (x = 0; x < _CACHED_RUNES; ++x) { + rl->__runetype[x] = frl->runetype[x]; + rl->__maplower[x] = frl->maplower[x]; + rl->__mapupper[x] = frl->mapupper[x]; + } + + rl->__runetype_ext.__ranges = (_RuneEntry *)rl->__variable; + rl->__variable = rl->__runetype_ext.__ranges + + rl->__runetype_ext.__nranges; + + rl->__maplower_ext.__ranges = (_RuneEntry *)rl->__variable; + rl->__variable = rl->__maplower_ext.__ranges + + rl->__maplower_ext.__nranges; + + rl->__mapupper_ext.__ranges = (_RuneEntry *)rl->__variable; + rl->__variable = rl->__mapupper_ext.__ranges + + rl->__mapupper_ext.__nranges; + + variable = mapupper_ext_ranges + frl->mapupper_ext_nranges; + frr = runetype_ext_ranges; + rr = rl->__runetype_ext.__ranges; + for (x = 0; x < rl->__runetype_ext.__nranges; ++x) { + uint32_t *types; + + rr[x].__min = frr[x].min; + rr[x].__max = frr[x].max; + rr[x].__map = frr[x].map; + if (rr[x].__map == 0) { + int len = rr[x].__max - rr[x].__min + 1; + types = variable; + variable = types + len; + rr[x].__types = rl->__variable; + rl->__variable = rr[x].__types + len; + while (len-- > 0) + rr[x].__types[len] = types[len]; + } else + rr[x].__types = NULL; + } + + frr = maplower_ext_ranges; + rr = rl->__maplower_ext.__ranges; + for (x = 0; x < rl->__maplower_ext.__nranges; ++x) { + rr[x].__min = frr[x].min; + rr[x].__max = frr[x].max; + rr[x].__map = frr[x].map; + } + + frr = mapupper_ext_ranges; + rr = rl->__mapupper_ext.__ranges; + for (x = 0; x < rl->__mapupper_ext.__nranges; ++x) { + rr[x].__min = frr[x].min; + rr[x].__max = frr[x].max; + rr[x].__map = frr[x].map; + } + + memcpy(rl->__variable, variable, rl->__variable_len); + free(fdata); + /* * Go out and zero pointers that should be zero. */ if (!rl->__variable_len) - rl->__variable = 0; + rl->__variable = NULL; if (!rl->__runetype_ext.__nranges) - rl->__runetype_ext.__ranges = 0; + rl->__runetype_ext.__ranges = NULL; if (!rl->__maplower_ext.__nranges) - rl->__maplower_ext.__ranges = 0; + rl->__maplower_ext.__ranges = NULL; if (!rl->__mapupper_ext.__nranges) - rl->__mapupper_ext.__ranges = 0; + rl->__mapupper_ext.__ranges = NULL; return (rl); } diff --git a/sys/sys/param.h b/sys/sys/param.h index 59d10df7228f..9117d8ecf47a 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -57,7 +57,7 @@ * is created, otherwise 1. */ #undef __FreeBSD_version -#define __FreeBSD_version 600015 /* Master, propagated to newvers */ +#define __FreeBSD_version 600016 /* Master, propagated to newvers */ #ifndef LOCORE #include diff --git a/tools/build/Makefile b/tools/build/Makefile index 7b25322b5341..885a4c8b46c5 100644 --- a/tools/build/Makefile +++ b/tools/build/Makefile @@ -26,6 +26,11 @@ INCS+= elf-hints.h INCS+= stdbool.h .endif +# usr.bin/mklocale needs . +.if !exists(/usr/include/runefile.h) +INCS+= runefile.h +.endif + # usr.bin/xargs needs . .if !exists(/usr/include/langinfo.h) INCS+= langinfo.h diff --git a/usr.bin/mklocale/ldef.h b/usr.bin/mklocale/ldef.h index 2a253b81a534..f35506b3483b 100644 --- a/usr.bin/mklocale/ldef.h +++ b/usr.bin/mklocale/ldef.h @@ -37,18 +37,20 @@ * $FreeBSD$ */ +#include + /* * This should look a LOT like a _RuneEntry */ typedef struct rune_list { - rune_t min; - rune_t max; - rune_t map; - unsigned long *types; + int32_t min; + int32_t max; + int32_t map; + uint32_t *types; struct rune_list *next; } rune_list; typedef struct rune_map { - unsigned long map[_CACHED_RUNES]; + uint32_t map[_CACHED_RUNES]; rune_list *root; } rune_map; diff --git a/usr.bin/mklocale/lex.l b/usr.bin/mklocale/lex.l index 2b3c81fce152..eeed535db2c6 100644 --- a/usr.bin/mklocale/lex.l +++ b/usr.bin/mklocale/lex.l @@ -45,7 +45,6 @@ static char sccsid[] = "@(#)lex.l 8.1 (Berkeley) 6/6/93"; __FBSDID("$FreeBSD$"); #include -#include #include #include diff --git a/usr.bin/mklocale/yacc.y b/usr.bin/mklocale/yacc.y index 5b0270206a80..fc2df7e1ef5d 100644 --- a/usr.bin/mklocale/yacc.y +++ b/usr.bin/mklocale/yacc.y @@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include #include #include @@ -59,9 +59,9 @@ __FBSDID("$FreeBSD$"); #include "extern.h" static void *xmalloc(unsigned int sz); -static unsigned long *xlalloc(unsigned int sz); +static uint32_t *xlalloc(unsigned int sz); void yyerror(const char *s); -static unsigned long *xrelalloc(unsigned long *old, unsigned int sz); +static uint32_t *xrelalloc(uint32_t *old, unsigned int sz); static void dump_tables(void); static void cleanout(void); @@ -71,17 +71,17 @@ rune_map maplower = { { 0 }, NULL }; rune_map mapupper = { { 0 }, NULL }; rune_map types = { { 0 }, NULL }; -_RuneLocale new_locale = { "", "", NULL, NULL, 0, {}, {}, {}, - {0, NULL}, {0, NULL}, {0, NULL}, NULL, 0 }; +_FileRuneLocale new_locale = { "", "", {}, {}, {}, 0, 0, 0, 0 }; +char *variable = NULL; -void set_map(rune_map *, rune_list *, unsigned long); +void set_map(rune_map *, rune_list *, uint32_t); void set_digitmap(rune_map *, rune_list *); -void add_map(rune_map *, rune_list *, unsigned long); +void add_map(rune_map *, rune_list *, uint32_t); static void usage(void); %} %union { - rune_t rune; + int32_t rune; int i; char *str; @@ -126,17 +126,15 @@ entry : ENCODING STRING strcmp($2, "BIG5") && strcmp($2, "MSKanji")) warnx("ENCODING %s is not supported by libc", $2); - strncpy(new_locale.__encoding, $2, - sizeof(new_locale.__encoding)); } + strncpy(new_locale.encoding, $2, + sizeof(new_locale.encoding)); } | VARIABLE - { new_locale.__variable_len = strlen($1) + 1; - new_locale.__variable = xmalloc(new_locale.__variable_len); - strcpy((char *)new_locale.__variable, $1); + { new_locale.variable_len = strlen($1) + 1; + variable = xmalloc(new_locale.variable_len); + strcpy(variable, $1); } | INVALID RUNE - { warnx("the INVALID keyword is deprecated"); - new_locale.__invalid_rune = $2; - } + { warnx("the INVALID keyword is deprecated"); } | LIST list { set_map(&types, $2, $1); } | MAPLOWER map @@ -259,8 +257,7 @@ main(int ac, char *av[]) mapupper.map[x] = x; maplower.map[x] = x; } - new_locale.__invalid_rune = _CurrentRuneLocale->__invalid_rune; - memcpy(new_locale.__magic, _RUNE_MAGIC_1, sizeof(new_locale.__magic)); + memcpy(new_locale.magic, _FILE_RUNE_MAGIC_1, sizeof(new_locale.magic)); yyparse(); @@ -291,23 +288,23 @@ xmalloc(sz) return(r); } -static unsigned long * +static uint32_t * xlalloc(sz) unsigned int sz; { - unsigned long *r = (unsigned long *)malloc(sz * sizeof(unsigned long)); + uint32_t *r = (uint32_t *)malloc(sz * sizeof(uint32_t)); if (!r) errx(1, "xlalloc"); return(r); } -static unsigned long * +static uint32_t * xrelalloc(old, sz) - unsigned long *old; + uint32_t *old; unsigned int sz; { - unsigned long *r = (unsigned long *)realloc((char *)old, - sz * sizeof(unsigned long)); + uint32_t *r = (uint32_t *)realloc((char *)old, + sz * sizeof(uint32_t)); if (!r) errx(1, "xrelalloc"); return(r); @@ -317,7 +314,7 @@ void set_map(map, list, flag) rune_map *map; rune_list *list; - unsigned long flag; + uint32_t flag; { while (list) { rune_list *nlist = list->next; @@ -331,7 +328,7 @@ set_digitmap(map, list) rune_map *map; rune_list *list; { - rune_t i; + int32_t i; while (list) { rune_list *nlist = list->next; @@ -352,12 +349,12 @@ void add_map(map, list, flag) rune_map *map; rune_list *list; - unsigned long flag; + uint32_t flag; { - rune_t i; + int32_t i; rune_list *lr = 0; rune_list *r; - rune_t run; + int32_t run; while (list->min < _CACHED_RUNES && list->min <= list->max) { if (flag) @@ -568,7 +565,7 @@ dump_tables() for(list = types.root; list; list = list->next) { list->map = list->types[0]; for (x = 1; x < list->max - list->min + 1; ++x) { - if ((rune_t)list->types[x] != list->map) { + if ((int32_t)list->types[x] != list->map) { list->map = 0; break; } @@ -577,7 +574,7 @@ dump_tables() first_d = curr_d = -1; for (x = 0; x < _CACHED_RUNES; ++x) { - unsigned long r = types.map[x]; + uint32_t r = types.map[x]; if (r & _CTYPE_D) { if (first_d < 0) @@ -598,8 +595,6 @@ dump_tables() else if (curr_d - first_d < 9) errx(1, "error: DIGIT range is too small in the single byte area"); - new_locale.__invalid_rune = htonl(new_locale.__invalid_rune); - /* * Fill in our tables. Do this in network order so that * diverse machines have a chance of sharing data. @@ -607,9 +602,9 @@ dump_tables() * word size. Sigh. We tried.) */ for (x = 0; x < _CACHED_RUNES; ++x) { - new_locale.__runetype[x] = htonl(types.map[x]); - new_locale.__maplower[x] = htonl(maplower.map[x]); - new_locale.__mapupper[x] = htonl(mapupper.map[x]); + new_locale.runetype[x] = htonl(types.map[x]); + new_locale.maplower[x] = htonl(maplower.map[x]); + new_locale.mapupper[x] = htonl(mapupper.map[x]); } /* @@ -618,38 +613,38 @@ dump_tables() list = types.root; while (list) { - new_locale.__runetype_ext.__nranges++; + new_locale.runetype_ext_nranges++; list = list->next; } - new_locale.__runetype_ext.__nranges = - htonl(new_locale.__runetype_ext.__nranges); + new_locale.runetype_ext_nranges = + htonl(new_locale.runetype_ext_nranges); list = maplower.root; while (list) { - new_locale.__maplower_ext.__nranges++; + new_locale.maplower_ext_nranges++; list = list->next; } - new_locale.__maplower_ext.__nranges = - htonl(new_locale.__maplower_ext.__nranges); + new_locale.maplower_ext_nranges = + htonl(new_locale.maplower_ext_nranges); list = mapupper.root; while (list) { - new_locale.__mapupper_ext.__nranges++; + new_locale.mapupper_ext_nranges++; list = list->next; } - new_locale.__mapupper_ext.__nranges = - htonl(new_locale.__mapupper_ext.__nranges); + new_locale.mapupper_ext_nranges = + htonl(new_locale.mapupper_ext_nranges); - new_locale.__variable_len = htonl(new_locale.__variable_len); + new_locale.variable_len = htonl(new_locale.variable_len); /* * Okay, we are now ready to write the new locale file. */ /* - * PART 1: The _RuneLocale structure + * PART 1: The _FileRuneLocale structure */ if (fwrite((char *)&new_locale, sizeof(new_locale), 1, fp) != 1) { perror(locale_file); @@ -661,11 +656,11 @@ dump_tables() list = types.root; while (list) { - _RuneEntry re; + _FileRuneEntry re; - re.__min = htonl(list->min); - re.__max = htonl(list->max); - re.__map = htonl(list->map); + re.min = htonl(list->min); + re.max = htonl(list->max); + re.map = htonl(list->map); if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) { perror(locale_file); @@ -680,11 +675,11 @@ dump_tables() list = maplower.root; while (list) { - _RuneEntry re; + _FileRuneEntry re; - re.__min = htonl(list->min); - re.__max = htonl(list->max); - re.__map = htonl(list->map); + re.min = htonl(list->min); + re.max = htonl(list->max); + re.map = htonl(list->map); if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) { perror(locale_file); @@ -699,11 +694,11 @@ dump_tables() list = mapupper.root; while (list) { - _RuneEntry re; + _FileRuneEntry re; - re.__min = htonl(list->min); - re.__max = htonl(list->max); - re.__map = htonl(list->map); + re.min = htonl(list->min); + re.max = htonl(list->max); + re.map = htonl(list->map); if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) { perror(locale_file); @@ -723,7 +718,7 @@ dump_tables() if (!list->map) { if (fwrite((char *)list->types, - (list->max - list->min + 1) * sizeof(unsigned long), + (list->max - list->min + 1) * sizeof(uint32_t), 1, fp) != 1) { perror(locale_file); exit(1); @@ -732,10 +727,10 @@ dump_tables() list = list->next; } /* - * PART 5: And finally the variable data + * PART 6: And finally the variable data */ - if (fwrite((char *)new_locale.__variable, - ntohl(new_locale.__variable_len), 1, fp) != 1) { + if (fwrite(variable, + ntohl(new_locale.variable_len), 1, fp) != 1) { perror(locale_file); exit(1); } @@ -748,10 +743,10 @@ dump_tables() if (!debug) return; - if (new_locale.__encoding[0]) - fprintf(stderr, "ENCODING %s\n", new_locale.__encoding); - if (new_locale.__variable) - fprintf(stderr, "VARIABLE %s\n", (char *)new_locale.__variable); + if (new_locale.encoding[0]) + fprintf(stderr, "ENCODING %s\n", new_locale.encoding); + if (variable) + fprintf(stderr, "VARIABLE %s\n", variable); fprintf(stderr, "\nMAPLOWER:\n\n"); @@ -759,7 +754,7 @@ dump_tables() if (isprint(maplower.map[x])) fprintf(stderr, " '%c'", (int)maplower.map[x]); else if (maplower.map[x]) - fprintf(stderr, "%04lx", maplower.map[x]); + fprintf(stderr, "%04x", maplower.map[x]); else fprintf(stderr, "%4x", 0); if ((x & 0xf) == 0xf) @@ -778,7 +773,7 @@ dump_tables() if (isprint(mapupper.map[x])) fprintf(stderr, " '%c'", (int)mapupper.map[x]); else if (mapupper.map[x]) - fprintf(stderr, "%04lx", mapupper.map[x]); + fprintf(stderr, "%04x", mapupper.map[x]); else fprintf(stderr, "%4x", 0); if ((x & 0xf) == 0xf) @@ -795,7 +790,7 @@ dump_tables() fprintf(stderr, "\nTYPES:\n\n"); for (x = 0; x < _CACHED_RUNES; ++x) { - unsigned long r = types.map[x]; + uint32_t r = types.map[x]; if (r) { if (isprint(x)) @@ -823,10 +818,10 @@ dump_tables() for (list = types.root; list; list = list->next) { if (list->map && list->min + 3 < list->max) { - unsigned long r = list->map; + uint32_t r = list->map; - fprintf(stderr, "%04lx: %2d", - (unsigned long)list->min, (int)(r & 0xff)); + fprintf(stderr, "%04x: %2d", + (uint32_t)list->min, (int)(r & 0xff)); fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : ""); fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : ""); @@ -844,8 +839,8 @@ dump_tables() fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : ""); fprintf(stderr, "\n...\n"); - fprintf(stderr, "%04lx: %2d", - (unsigned long)list->max, (int)(r & 0xff)); + fprintf(stderr, "%04x: %2d", + (uint32_t)list->max, (int)(r & 0xff)); fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : ""); fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : ""); @@ -864,7 +859,7 @@ dump_tables() fprintf(stderr, "\n"); } else for (x = list->min; x <= list->max; ++x) { - unsigned long r = ntohl(list->types[x - list->min]); + uint32_t r = ntohl(list->types[x - list->min]); if (r) { fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff));