Add 8bit collate stuff

Submitted by: alex@elvisti.kiev.ua
This commit is contained in:
Andrey A. Chernov 1995-02-16 17:01:11 +00:00
parent 96658fee5a
commit a4d5d0cbde
5 changed files with 153 additions and 113 deletions

View File

@ -2,6 +2,7 @@
.PATH: ${.CURDIR}/${MACHINE}/string ${.CURDIR}/string
CFLAGS += -I${.CURDIR}/locale
# machine-independent string sources
SRCS+= memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \
strmode.c strtok.c strxfrm.c swab.c

View File

@ -1,9 +1,6 @@
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek and the American National Standards Committee X3,
.\" on Information Processing Systems.
.\" Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
.\" at Electronni Visti IA, Kiev, Ukraine.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -13,18 +10,11 @@
.\" 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
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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)
@ -33,9 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)strcoll.3 8.1 (Berkeley) 6/4/93
.\"
.Dd June 4, 1993
.Dd January 27, 1995
.Dt STRCOLL 3
.Os
.Sh NAME
@ -53,17 +41,15 @@ lexicographically compares the null-terminated strings
.Fa s1
and
.Fa s2
according to the current locale collation
according to the current locale collation if any, otherwith call
.Fa strcmp ,
and returns an integer greater than, equal to, or less than 0,
according as
.Fa s1
is greater than, equal to, or less than
.Fa s2 .
.Sh SEE ALSO
.Xr bcmp 3 ,
.Xr memcmp 3 ,
.Xr setlocale 3 ,
.Xr strcasecmp 3 ,
.Xr strcmp 3 ,
.Xr strxfrm 3
.Sh STANDARDS

View File

@ -1,9 +1,7 @@
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
* at Electronni Visti IA, Kiev, Ukraine.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -13,18 +11,11 @@
* 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
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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)
@ -32,22 +23,58 @@
* 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.
*
* $Id: strcoll.c,v 1.4 1995/01/27 12:51:06 alex Exp alex $
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
#include <stdlib.h>
#include <string.h>
#include "collate.h"
/* Compare strings according to LC_COLLATE category of current locale */
/*
* Compare strings according to LC_COLLATE category of current locale.
*/
int
strcoll(s1, s2)
const char *s1, *s2;
strcoll(s, s2)
const char *s, *s2;
{
/* LC_COLLATE is unimplemented, hence always "C" */
return (strcmp(s1, s2));
int len, len2, prim, prim2, sec, sec2, ret, ret2;
char *tt, *t, *tt2, *t2;
if (__collate_load_error)
return strcmp(s, s2);
len = len2 = 1;
ret = ret2 = 0;
tt = t = __collate_substitute(s);
tt2 = t2 = __collate_substitute(s2);
while(*t && *t2) {
prim = prim2 = 0;
while(*t && !prim) {
__collate_lookup(t, &len, &prim, &sec);
t += len;
}
while(*t2 && !prim2) {
__collate_lookup(t2, &len2, &prim2, &sec2);
t2 += len2;
}
if(!prim || !prim2)
break;
if(prim != prim2) {
ret = prim - prim2;
goto end;
}
if(!ret2)
ret2 = sec - sec2;
}
if(!*t && *t2)
ret = -(int)((u_char)*t2);
else if(*t && !*t2)
ret = (u_char)*t;
else if(!*t && !*t2)
ret = ret2;
end:
free(tt);
free(tt2);
return ret;
}

View File

@ -1,9 +1,6 @@
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek and the American National Standards Committee X3,
.\" on Information Processing Systems.
.\" Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
.\" at Electronni Visti IA, Kiev, Ukraine.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -13,18 +10,11 @@
.\" 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
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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)
@ -33,9 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)strxfrm.3 8.1 (Berkeley) 6/4/93
.\"
.Dd June 4, 1993
.Dd January 27, 1995
.Dt STRXFRM 3
.Os
.Sh NAME
@ -48,16 +36,25 @@
.Sh DESCRIPTION
The
.Fn strxfrm
function
does something horrible (see
.Tn ANSI
standard).
In this implementation it just copies.
function transform null-terminating string pointed by
.Fa src
according to the current locale collation if any,
then copied not more than
.Fa n-1
characters of the result string into
.Fa dst ,
ending it whith null character and return result length.
Comparing two strings using
.Fn strcmp
after
.Fn strxfrm
is equal to comparing
two original strings with
.Fn strcoll .
.Sh BUGS
Sometimes biheviour of this function is unpredicatable.
.Sh SEE ALSO
.Xr bcmp 3 ,
.Xr memcmp 3 ,
.\" .Xr setlocale 3 ,
.Xr strcasecmp 3 ,
.Xr setlocale 3 ,
.Xr strcmp 3 ,
.Xr strcoll 3
.Sh STANDARDS

View File

@ -1,9 +1,7 @@
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
* at Electronni Visti IA, Kiev, Ukraine.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -13,18 +11,11 @@
* 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
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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)
@ -32,36 +23,74 @@
* 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.
*
* $Id: strxfrm.c,v 1.5 1995/01/27 12:51:06 alex Exp alex $
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
#include <stdlib.h>
#include <string.h>
#include "collate.h"
/*
* Transform src, storing the result in dst, such that
* strcmp() on transformed strings returns what strcoll()
* on the original untransformed strings would return.
* Transform src, storing the result in dest, such that strcmp()
* on transformed strings returns what strcoll() on the original
* untransformed strings would return.
*/
size_t
strxfrm(dst, src, n)
register char *dst;
const char *src;
size_t n;
{
register size_t srclen, copysize;
/*
* Since locales are unimplemented, this is just a copy.
*/
srclen = strlen(src);
if (n != 0) {
copysize = srclen < n ? srclen : n - 1;
(void)memcpy(dst, src, copysize);
dst[copysize] = 0;
size_t
strxfrm(dest, src, len)
char *dest;
const char *src;
size_t len;
{
int prim, sec, l;
char *d = dest, *s, *ss;
if (len < 1)
return 0;
if (!*src) {
*d = '\0';
return 0;
}
return (srclen);
if (__collate_load_error) {
size_t slen, ncopy;
slen = strlen(src);
ncopy = slen < len ? slen : len - 1;
(void)memcpy(d, src, ncopy);
d[ncopy] = '\0';
return ncopy;
}
ss = s = __collate_substitute(src);
prim = sec = 0;
while (*s && len > 1) {
while (*s && !prim) {
__collate_lookup(s, &l, &prim, &sec);
s += l;
}
if (prim) {
*d++ = (char)prim;
len--;
}
}
#if 0
s = ss;
while (*s && len > 1) {
while (*s && !prim) {
lookup(s, &l, &prim, &sec);
s += l;
}
if (prim && sec) {
*d++ = (char)sec;
len--;
}
}
#endif /* 0 */
*d = '\0';
free(ss);
return d - dest;
}