1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-05 09:14:03 +00:00

Migrate from XPG4 to XPG3 (libxpg4 will be added soon)

Remove big part of my startup_setlocale hack.
Add missing manpage links.
This commit is contained in:
Andrey A. Chernov 1995-10-23 01:34:17 +00:00
parent b596ee8d4e
commit 350a3d3e48
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=11695
9 changed files with 451 additions and 63 deletions

View File

@ -4,8 +4,7 @@
.PATH: ${.CURDIR}/${MACHINE}/locale ${.CURDIR}/locale
SRCS+= ansi.c ctype.c euc.c frune.c isctype.c lconv.c localeconv.c \
mbrune.c none.c rune.c common_setlocale.c \
startup_setlocale.c read_runemagi.c setlocale.c table.c utf2.c \
mbrune.c none.c rune.c setlocale.c table.c utf2.c setrunelocale.c \
runetype.c tolower.c toupper.c nomacros.c collate.c
MAN3+= locale/ctype.3 locale/isalnum.3 locale/isalpha.3 locale/isascii.3 \
@ -15,3 +14,8 @@ MAN3+= locale/ctype.3 locale/isalnum.3 locale/isalpha.3 locale/isascii.3 \
locale/rune.3 locale/setlocale.3 locale/toascii.3 locale/tolower.3 \
locale/toupper.3
MAN4+= locale/euc.4 locale/utf2.4
MLINKS+= rune.3 setrunelocale.3 rune.3 setinvalidrune.3 rune.3 sgetrune.3 \
rune.3 sputrune.3 rune.3 fgetrune.3 rune.3 fungetrune.3 \
rune.3 fputrune.3 mbrune.3 mbrrune.3 mbrune.3 mbmb.3 \
multibyte.3 mblen.3 multibyte.3 mbstowcs.3 multibyte.3 mbtowc.3 \
multibyte.3 wcstombs.3 multibyte.3 wctomb.3 setlocale.3 localeconv.3

View File

@ -34,6 +34,7 @@
* SUCH DAMAGE.
*/
#ifdef XPG4
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)euc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
@ -218,3 +219,4 @@ _EUC_sputrune(c, string, n, result)
}
return (len);
}
#endif /* XPG4 */

View File

@ -38,65 +38,12 @@
static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <rune.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "common_rune.h"
char *_PathLocale;
extern int _none_init __P((_RuneLocale *));
extern int _UTF2_init __P((_RuneLocale *));
extern int _EUC_init __P((_RuneLocale *));
int
setrunelocale(encoding)
char *encoding;
{
FILE *fp;
char name[PATH_MAX];
_RuneLocale *rl;
if (!encoding)
return(EFAULT);
/*
* The "C" and "POSIX" locale are always here.
*/
if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) {
_CurrentRuneLocale = &_DefaultRuneLocale;
return(0);
}
if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
PathLocale = _PATH_LOCALE;
(void) strcpy(name, PathLocale);
(void) strcat(name, "/");
(void) strcat(name, encoding);
(void) strcat(name, "/LC_CTYPE");
if ((fp = fopen(name, "r")) == NULL)
return(ENOENT);
if ((rl = _Read_RuneMagi(fp)) == 0) {
fclose(fp);
return(EFTYPE);
}
fclose(fp);
if (!rl->encoding[0] || !strcmp(rl->encoding, "UTF2")) {
return(_UTF2_init(rl));
} else if (!strcmp(rl->encoding, "NONE")) {
return(_none_init(rl));
} else if (!strcmp(rl->encoding, "EUC")) {
return(_EUC_init(rl));
} else
return(EINVAL);
}
#include <sys/types.h>
#include <sys/stat.h>
void
setinvalidrune(ir)
@ -105,3 +52,129 @@ setinvalidrune(ir)
_INVALID_RUNE = ir;
}
_RuneLocale *
_Read_RuneMagi(fp)
FILE *fp;
{
char *data;
void *lastp;
_RuneLocale *rl;
_RuneEntry *rr;
struct stat sb;
int x;
if (fstat(fileno(fp), &sb) < 0)
return(0);
if (sb.st_size < sizeof(_RuneLocale))
return(0);
if ((data = malloc(sb.st_size)) == NULL)
return(0);
rewind(fp); /* Someone might have read the magic number once already */
if (fread(data, sb.st_size, 1, fp) != 1) {
free(data);
return(0);
}
rl = (_RuneLocale *)data;
lastp = data + sb.st_size;
rl->variable = rl + 1;
if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) {
free(data);
return(0);
}
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_ext.ranges = (_RuneEntry *)rl->variable;
rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges;
if (rl->variable > lastp) {
free(data);
return(0);
}
rl->maplower_ext.ranges = (_RuneEntry *)rl->variable;
rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges;
if (rl->variable > lastp) {
free(data);
return(0);
}
rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable;
rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges;
if (rl->variable > lastp) {
free(data);
return(0);
}
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) {
free(data);
return(0);
}
while (len-- > 0)
rr[x].types[len] = ntohl(rr[x].types[len]);
} else
rr[x].types = 0;
}
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);
}
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);
}
if (((char *)rl->variable) + rl->variable_len > (char *)lastp) {
free(data);
return(0);
}
/*
* Go out and zero pointers that should be zero.
*/
if (!rl->variable_len)
rl->variable = 0;
if (!rl->runetype_ext.nranges)
rl->runetype_ext.ranges = 0;
if (!rl->maplower_ext.nranges)
rl->maplower_ext.ranges = 0;
if (!rl->mapupper_ext.nranges)
rl->mapupper_ext.ranges = 0;
return(rl);
}

View File

@ -1,3 +1,39 @@
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#include <stdio.h>
#include <rune.h>

View File

@ -43,13 +43,49 @@ static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
#include <rune.h>
#include <stdlib.h>
#include <string.h>
#include "common_setlocale.h"
#include "common_rune.h"
#include "collate.h"
/*
* Category names for getenv()
*/
static char *categories[_LC_LAST] = {
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
};
/*
* Current locales for each category
*/
static char current_categories[_LC_LAST][32] = {
"C",
"C",
"C",
"C",
"C",
"C",
};
/*
* The locales we are going to try and load
*/
static char new_categories[_LC_LAST][32];
static char current_locale_string[_LC_LAST * 33];
char *_PathLocale;
static char *currentlocale __P((void));
static char *loadlocale __P((int));
extern int __time_load_locale __P((const char *)); /* strftime.c */
#ifdef XPG4
extern int _xpg4_setrunelocale __P((char *));
#endif
char *
setlocale(category, locale)
int category;
@ -58,8 +94,8 @@ setlocale(category, locale)
int found, i, len;
char *env, *r;
if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
PathLocale = _PATH_LOCALE;
if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE")))
_PathLocale = _PATH_LOCALE;
if (category < 0 || category >= _LC_LAST)
return (NULL);
@ -139,6 +175,47 @@ setlocale(category, locale)
return (NULL);
}
#ifndef XPG4
/* To be compatible with old binaries */
void
_startup_setlocale(category, locale)
int category;
const char *locale;
{
(void) setlocale(category, locale);
}
#endif
static char *
currentlocale()
{
int i, len;
(void)strcpy(current_locale_string, current_categories[1]);
for (i = 2; i < _LC_LAST; ++i)
if (strcmp(current_categories[1], current_categories[i])) {
len = strlen(current_categories[1]) + 1 +
strlen(current_categories[2]) + 1 +
strlen(current_categories[3]) + 1 +
strlen(current_categories[4]) + 1 +
strlen(current_categories[5]) + 1;
if (len > sizeof(current_locale_string))
return NULL;
(void) strcpy(current_locale_string, current_categories[1]);
(void) strcat(current_locale_string, "/");
(void) strcat(current_locale_string, current_categories[2]);
(void) strcat(current_locale_string, "/");
(void) strcat(current_locale_string, current_categories[3]);
(void) strcat(current_locale_string, "/");
(void) strcat(current_locale_string, current_categories[4]);
(void) strcat(current_locale_string, "/");
(void) strcat(current_locale_string, current_categories[5]);
break;
}
return (current_locale_string);
}
static char *
loadlocale(category)
int category;
@ -151,7 +228,11 @@ loadlocale(category)
return (current_categories[category]);
if (category == LC_CTYPE) {
#ifdef XPG4
if (_xpg4_setrunelocale(new_categories[LC_CTYPE]))
#else
if (setrunelocale(new_categories[LC_CTYPE]))
#endif
return (NULL);
(void)strcpy(current_categories[LC_CTYPE],
new_categories[LC_CTYPE]);
@ -191,7 +272,7 @@ loadlocale(category)
* Some day we will actually look at this file.
*/
(void)snprintf(name, sizeof(name), "%s/%s/%s",
PathLocale, new_categories[category], categories[category]);
_PathLocale, new_categories[category], categories[category]);
#endif
switch (category) {
case LC_MONETARY:

View File

@ -0,0 +1,118 @@
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#include <rune.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char *_PathLocale;
extern int _none_init __P((_RuneLocale *));
#ifdef XPG4
extern int _UTF2_init __P((_RuneLocale *));
extern int _EUC_init __P((_RuneLocale *));
#endif
extern _RuneLocale *_Read_RuneMagi __P((FILE *));
#ifdef XPG4
int
setrunelocale(encoding)
char *encoding;
{
return _xpg4_setrunelocale(encoding);
}
#endif
int
#ifndef XPG4
setrunelocale(encoding)
#else
_xpg4_setrunelocale(encoding)
#endif
char *encoding;
{
FILE *fp;
char name[PATH_MAX];
_RuneLocale *rl;
if (!encoding)
return(EFAULT);
/*
* The "C" and "POSIX" locale are always here.
*/
if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) {
_CurrentRuneLocale = &_DefaultRuneLocale;
return(0);
}
if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE")))
_PathLocale = _PATH_LOCALE;
(void) strcpy(name, _PathLocale);
(void) strcat(name, "/");
(void) strcat(name, encoding);
(void) strcat(name, "/LC_CTYPE");
if ((fp = fopen(name, "r")) == NULL)
return(ENOENT);
if ((rl = _Read_RuneMagi(fp)) == 0) {
fclose(fp);
return(EFTYPE);
}
fclose(fp);
#ifdef XPG4
if (!rl->encoding[0] || !strcmp(rl->encoding, "UTF2")) {
return(_UTF2_init(rl));
#else
if (!rl->encoding[0]) {
return(EINVAL);
#endif
} else if (!strcmp(rl->encoding, "NONE")) {
return(_none_init(rl));
#ifdef XPG4
} else if (!strcmp(rl->encoding, "EUC")) {
return(_EUC_init(rl));
#endif
} else
return(EINVAL);
}

View File

@ -1,3 +1,39 @@
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#include <stdio.h>
#include <rune.h>

View File

@ -1,3 +1,39 @@
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#include <stdio.h>
#include <rune.h>

View File

@ -34,6 +34,7 @@
* SUCH DAMAGE.
*/
#ifdef XPG4
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)utf2.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
@ -146,3 +147,4 @@ _UTF2_sputrune(c, string, n, result)
return (1);
}
}
#endif /* XPG4 */