Prefix the names of members of _RuneLocale and its sub-structures

with ``__'' to avoid polluting the namespace. This doesn't change the
documented rune interface at all, but breaks applications that accessed
_RuneLocale directly.
This commit is contained in:
Tim J. Robbins 2004-06-23 07:01:44 +00:00
parent 587a4462c9
commit ddc1eded85
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130961
11 changed files with 158 additions and 153 deletions

View file

@ -190,7 +190,7 @@ static __inline int
__maskrune(__ct_rune_t _c, unsigned long _f)
{
return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
_CurrentRuneLocale->runetype[_c]) & _f;
_CurrentRuneLocale->__runetype[_c]) & _f;
}
static __inline int
@ -203,21 +203,21 @@ static __inline int
__isctype(__ct_rune_t _c, unsigned long _f)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
!!(_DefaultRuneLocale.runetype[_c] & _f);
!!(_DefaultRuneLocale.__runetype[_c] & _f);
}
static __inline __ct_rune_t
__toupper(__ct_rune_t _c)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
_CurrentRuneLocale->mapupper[_c];
_CurrentRuneLocale->__mapupper[_c];
}
static __inline __ct_rune_t
__tolower(__ct_rune_t _c)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
_CurrentRuneLocale->maplower[_c];
_CurrentRuneLocale->__maplower[_c];
}
#else /* not using inlines */

View file

@ -190,7 +190,7 @@ static __inline int
__maskrune(__ct_rune_t _c, unsigned long _f)
{
return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
_CurrentRuneLocale->runetype[_c]) & _f;
_CurrentRuneLocale->__runetype[_c]) & _f;
}
static __inline int
@ -203,21 +203,21 @@ static __inline int
__isctype(__ct_rune_t _c, unsigned long _f)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
!!(_DefaultRuneLocale.runetype[_c] & _f);
!!(_DefaultRuneLocale.__runetype[_c] & _f);
}
static __inline __ct_rune_t
__toupper(__ct_rune_t _c)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
_CurrentRuneLocale->mapupper[_c];
_CurrentRuneLocale->__mapupper[_c];
}
static __inline __ct_rune_t
__tolower(__ct_rune_t _c)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
_CurrentRuneLocale->maplower[_c];
_CurrentRuneLocale->__maplower[_c];
}
#else /* not using inlines */

View file

@ -48,13 +48,11 @@
typedef __rune_t rune_t;
#endif
#define _INVALID_RUNE _CurrentRuneLocale->invalid_rune
#define _INVALID_RUNE _CurrentRuneLocale->__invalid_rune
#define __sgetrune _CurrentRuneLocale->sgetrune
#define __sputrune _CurrentRuneLocale->sputrune
#define sgetrune(s, n, r) (*__sgetrune)((s), (n), (r))
#define sputrune(c, s, n, r) (*__sputrune)((c), (s), (n), (r))
#define sgetrune(s, n, r) (_CurrentRuneLocale->__sgetrune)((s), (n), (r))
#define sputrune(c, s, n, r) (_CurrentRuneLocale->__sputrune)((c), (s), \
(n), (r))
__BEGIN_DECLS
char *mbrune(const char *, rune_t);

View file

@ -50,40 +50,40 @@
* The lower 8 bits of runetype[] contain the digit value of the rune.
*/
typedef struct {
__rune_t min; /* First rune of the range */
__rune_t max; /* Last rune (inclusive) of the range */
__rune_t map; /* What first maps to in maps */
unsigned long *types; /* Array of types in range */
__rune_t __min; /* First rune of the range */
__rune_t __max; /* Last rune (inclusive) of the range */
__rune_t __map; /* What first maps to in maps */
unsigned long *__types; /* Array of types in range */
} _RuneEntry;
typedef struct {
int nranges; /* Number of ranges stored */
_RuneEntry *ranges; /* Pointer to the ranges */
int __nranges; /* Number of ranges stored */
_RuneEntry *__ranges; /* Pointer to the ranges */
} _RuneRange;
typedef struct {
char magic[8]; /* Magic saying what version we are */
char encoding[32]; /* ASCII name of this encoding */
char __magic[8]; /* Magic saying what version we are */
char __encoding[32]; /* ASCII name of this encoding */
__rune_t (*sgetrune)(const char *, __size_t, char const **);
int (*sputrune)(__rune_t, char *, __size_t, char **);
__rune_t invalid_rune;
__rune_t (*__sgetrune)(const char *, __size_t, char const **);
int (*__sputrune)(__rune_t, char *, __size_t, char **);
__rune_t __invalid_rune;
unsigned long runetype[_CACHED_RUNES];
__rune_t maplower[_CACHED_RUNES];
__rune_t mapupper[_CACHED_RUNES];
unsigned long __runetype[_CACHED_RUNES];
__rune_t __maplower[_CACHED_RUNES];
__rune_t __mapupper[_CACHED_RUNES];
/*
* The following are to deal with Runes larger than _CACHED_RUNES - 1.
* Their data is actually contiguous with this structure so as to make
* it easier to read/write from/to disk.
*/
_RuneRange runetype_ext;
_RuneRange maplower_ext;
_RuneRange mapupper_ext;
_RuneRange __runetype_ext;
_RuneRange __maplower_ext;
_RuneRange __mapupper_ext;
void *variable; /* Data which depends on the encoding */
int variable_len; /* how long that data is */
void *__variable; /* Data which depends on the encoding */
int __variable_len; /* how long that data is */
} _RuneLocale;
#define _RUNE_MAGIC_1 "RuneMagi" /* Indicates version 0 of RuneLocale */

View file

@ -74,10 +74,10 @@ _EUC_init(_RuneLocale *rl)
int x, new__mb_cur_max;
char *v, *e;
if (rl->variable == NULL)
if (rl->__variable == NULL)
return (EFTYPE);
v = (char *)rl->variable;
v = (char *)rl->__variable;
while (*v == ' ' || *v == '\t')
++v;
@ -109,8 +109,8 @@ _EUC_init(_RuneLocale *rl)
free(ei);
return (EFTYPE);
}
rl->variable = ei;
rl->variable_len = sizeof(_EucInfo);
rl->__variable = ei;
rl->__variable_len = sizeof(_EucInfo);
_CurrentRuneLocale = rl;
__mb_cur_max = new__mb_cur_max;
__mbrtowc = _EUC_mbrtowc;
@ -126,7 +126,7 @@ _EUC_mbsinit(const mbstate_t *ps)
return (ps == NULL || ((const _EucState *)ps)->want == 0);
}
#define CEI ((_EucInfo *)(_CurrentRuneLocale->variable))
#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
#define _SS2 0x008e
#define _SS3 0x008f

View file

@ -92,86 +92,89 @@ _Read_RuneMagi(fp)
rl = (_RuneLocale *)data;
lastp = data + sb.st_size;
rl->variable = rl + 1;
rl->__variable = rl + 1;
if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) {
if (memcmp(rl->__magic, _RUNE_MAGIC_1, sizeof(rl->__magic))) {
free(data);
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);
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);
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]);
rl->__runetype[x] = ntohl(rl->__runetype[x]);
rl->__maplower[x] = ntohl(rl->__maplower[x]);
rl->__mapupper[x] = ntohl(rl->__mapupper[x]);
}
rl->runetype_ext.ranges = (_RuneEntry *)rl->variable;
rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges;
if (rl->variable > lastp) {
rl->__runetype_ext.__ranges = (_RuneEntry *)rl->__variable;
rl->__variable = rl->__runetype_ext.__ranges +
rl->__runetype_ext.__nranges;
if (rl->__variable > lastp) {
free(data);
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) {
rl->__maplower_ext.__ranges = (_RuneEntry *)rl->__variable;
rl->__variable = rl->__maplower_ext.__ranges +
rl->__maplower_ext.__nranges;
if (rl->__variable > lastp) {
free(data);
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) {
rl->__mapupper_ext.__ranges = (_RuneEntry *)rl->__variable;
rl->__variable = rl->__mapupper_ext.__ranges +
rl->__mapupper_ext.__nranges;
if (rl->__variable > lastp) {
free(data);
errno = EFTYPE;
return (NULL);
}
for (x = 0; x < rl->runetype_ext.nranges; ++x) {
rr = rl->runetype_ext.ranges;
for (x = 0; x < rl->__runetype_ext.__nranges; ++x) {
rr = rl->__runetype_ext.__ranges;
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) {
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);
errno = EFTYPE;
return (NULL);
}
while (len-- > 0)
rr[x].types[len] = ntohl(rr[x].types[len]);
rr[x].__types[len] = ntohl(rr[x].__types[len]);
} else
rr[x].types = 0;
rr[x].__types = 0;
}
for (x = 0; x < rl->maplower_ext.nranges; ++x) {
rr = rl->maplower_ext.ranges;
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);
rr[x].__min = ntohl(rr[x].__min);
rr[x].__max = ntohl(rr[x].__max);
rr[x].__map = ntohl(rr[x].__map);
}
for (x = 0; x < rl->mapupper_ext.nranges; ++x) {
rr = rl->mapupper_ext.ranges;
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);
rr[x].__min = ntohl(rr[x].__min);
rr[x].__max = ntohl(rr[x].__max);
rr[x].__map = ntohl(rr[x].__map);
}
if (((char *)rl->variable) + rl->variable_len > (char *)lastp) {
if (((char *)rl->__variable) + rl->__variable_len > (char *)lastp) {
free(data);
errno = EFTYPE;
return (NULL);
@ -180,17 +183,17 @@ _Read_RuneMagi(fp)
/*
* Go out and zero pointers that should be zero.
*/
if (!rl->variable_len)
rl->variable = 0;
if (!rl->__variable_len)
rl->__variable = 0;
if (!rl->runetype_ext.nranges)
rl->runetype_ext.ranges = 0;
if (!rl->__runetype_ext.__nranges)
rl->__runetype_ext.__ranges = 0;
if (!rl->maplower_ext.nranges)
rl->maplower_ext.ranges = 0;
if (!rl->__maplower_ext.__nranges)
rl->__maplower_ext.__ranges = 0;
if (!rl->mapupper_ext.nranges)
rl->mapupper_ext.ranges = 0;
if (!rl->__mapupper_ext.__nranges)
rl->__mapupper_ext.__ranges = 0;
return (rl);
}

View file

@ -45,22 +45,22 @@ ___runetype(c)
__ct_rune_t c;
{
size_t lim;
_RuneRange *rr = &_CurrentRuneLocale->runetype_ext;
_RuneRange *rr = &_CurrentRuneLocale->__runetype_ext;
_RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(0L);
/* Binary search -- see bsearch.c for explanation. */
base = rr->ranges;
for (lim = rr->nranges; lim != 0; lim >>= 1) {
base = rr->__ranges;
for (lim = rr->__nranges; lim != 0; lim >>= 1) {
re = base + (lim >> 1);
if (re->min <= c && c <= re->max) {
if (re->types)
return(re->types[c - re->min]);
if (re->__min <= c && c <= re->__max) {
if (re->__types)
return(re->__types[c - re->__min]);
else
return(re->map);
} else if (c > re->max) {
return(re->__map);
} else if (c > re->__max) {
base = re + 1;
lim--;
}

View file

@ -159,33 +159,33 @@ __setrunelocale(const char *encoding)
__mbsrtowcs = __mbsrtowcs_std;
__wcrtomb = NULL;
__wcsrtombs = __wcsrtombs_std;
rl->sputrune = __emulated_sputrune;
rl->sgetrune = __emulated_sgetrune;
if (strcmp(rl->encoding, "NONE") == 0)
rl->__sputrune = __emulated_sputrune;
rl->__sgetrune = __emulated_sgetrune;
if (strcmp(rl->__encoding, "NONE") == 0)
ret = _none_init(rl);
else if (strcmp(rl->encoding, "UTF2") == 0)
else if (strcmp(rl->__encoding, "UTF2") == 0)
ret = _UTF2_init(rl);
else if (strcmp(rl->encoding, "UTF-8") == 0)
else if (strcmp(rl->__encoding, "UTF-8") == 0)
ret = _UTF8_init(rl);
else if (strcmp(rl->encoding, "EUC") == 0)
else if (strcmp(rl->__encoding, "EUC") == 0)
ret = _EUC_init(rl);
else if (strcmp(rl->encoding, "GB18030") == 0)
else if (strcmp(rl->__encoding, "GB18030") == 0)
ret = _GB18030_init(rl);
else if (strcmp(rl->encoding, "GB2312") == 0)
else if (strcmp(rl->__encoding, "GB2312") == 0)
ret = _GB2312_init(rl);
else if (strcmp(rl->encoding, "GBK") == 0)
else if (strcmp(rl->__encoding, "GBK") == 0)
ret = _GBK_init(rl);
else if (strcmp(rl->encoding, "BIG5") == 0)
else if (strcmp(rl->__encoding, "BIG5") == 0)
ret = _BIG5_init(rl);
else if (strcmp(rl->encoding, "MSKanji") == 0)
else if (strcmp(rl->__encoding, "MSKanji") == 0)
ret = _MSKanji_init(rl);
else
ret = EFTYPE;
if (ret == 0) {
if (CachedRuneLocale != NULL) {
/* See euc.c */
if (strcmp(CachedRuneLocale->encoding, "EUC") == 0)
free(CachedRuneLocale->variable);
if (strcmp(CachedRuneLocale->__encoding, "EUC") == 0)
free(CachedRuneLocale->__variable);
free(CachedRuneLocale);
}
CachedRuneLocale = _CurrentRuneLocale;

View file

@ -45,19 +45,19 @@ ___tolower(c)
__ct_rune_t c;
{
size_t lim;
_RuneRange *rr = &_CurrentRuneLocale->maplower_ext;
_RuneRange *rr = &_CurrentRuneLocale->__maplower_ext;
_RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
/* Binary search -- see bsearch.c for explanation. */
base = rr->ranges;
for (lim = rr->nranges; lim != 0; lim >>= 1) {
base = rr->__ranges;
for (lim = rr->__nranges; lim != 0; lim >>= 1) {
re = base + (lim >> 1);
if (re->min <= c && c <= re->max)
return (re->map + c - re->min);
else if (c > re->max) {
if (re->__min <= c && c <= re->__max)
return (re->__map + c - re->__min);
else if (c > re->__max) {
base = re + 1;
lim--;
}

View file

@ -45,19 +45,19 @@ ___toupper(c)
__ct_rune_t c;
{
size_t lim;
_RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
_RuneRange *rr = &_CurrentRuneLocale->__mapupper_ext;
_RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
/* Binary search -- see bsearch.c for explanation. */
base = rr->ranges;
for (lim = rr->nranges; lim != 0; lim >>= 1) {
base = rr->__ranges;
for (lim = rr->__nranges; lim != 0; lim >>= 1) {
re = base + (lim >> 1);
if (re->min <= c && c <= re->max)
return (re->map + c - re->min);
else if (c > re->max) {
if (re->__min <= c && c <= re->__max)
return (re->__map + c - re->__min);
else if (c > re->__max) {
base = re + 1;
lim--;
}

View file

@ -127,15 +127,16 @@ 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;
new_locale.__variable = xmalloc(new_locale.__variable_len);
strcpy((char *)new_locale.__variable, $1);
}
| INVALID RUNE
{ warnx("the INVALID keyword is deprecated");
new_locale.invalid_rune = $2;
new_locale.__invalid_rune = $2;
}
| LIST list
{ set_map(&types, $2, $1); }
@ -259,8 +260,8 @@ main(int ac, char *av[])
mapupper.map[x] = x;
maplower.map[x] = x;
}
new_locale.invalid_rune = _INVALID_RUNE;
memcpy(new_locale.magic, _RUNE_MAGIC_1, sizeof(new_locale.magic));
new_locale.__invalid_rune = _INVALID_RUNE;
memcpy(new_locale.__magic, _RUNE_MAGIC_1, sizeof(new_locale.__magic));
yyparse();
@ -598,7 +599,7 @@ 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);
new_locale.__invalid_rune = htonl(new_locale.__invalid_rune);
/*
* Fill in our tables. Do this in network order so that
@ -607,9 +608,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,28 +619,31 @@ 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.
@ -660,9 +664,9 @@ dump_tables()
while (list) {
_RuneEntry 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);
@ -679,9 +683,9 @@ dump_tables()
while (list) {
_RuneEntry 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);
@ -698,9 +702,9 @@ dump_tables()
while (list) {
_RuneEntry 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);
@ -731,8 +735,8 @@ dump_tables()
/*
* PART 5: And finally the variable data
*/
if (fwrite((char *)new_locale.variable,
ntohl(new_locale.variable_len), 1, fp) != 1) {
if (fwrite((char *)new_locale.__variable,
ntohl(new_locale.__variable_len), 1, fp) != 1) {
perror(locale_file);
exit(1);
}
@ -745,10 +749,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 (new_locale.__variable)
fprintf(stderr, "VARIABLE %s\n", (char *)new_locale.__variable);
fprintf(stderr, "\nMAPLOWER:\n\n");