Initial revision
This commit is contained in:
parent
0a7c058d01
commit
749c364816
22 changed files with 466 additions and 0 deletions
21
lang/cem/libcc.ansi/string/memchr.c
Normal file
21
lang/cem/libcc.ansi/string/memchr.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void *
|
||||||
|
memchr(const void *s, int c, register size_t n)
|
||||||
|
{
|
||||||
|
register unsigned char *s1 = (unsigned char *)s;
|
||||||
|
unsigned char c1 = (unsigned char) c;
|
||||||
|
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
if (*s1++ == c1)
|
||||||
|
return (void *) --s1;
|
||||||
|
}
|
||||||
|
return (void *) NULL;
|
||||||
|
}
|
18
lang/cem/libcc.ansi/string/memcmp.c
Normal file
18
lang/cem/libcc.ansi/string/memcmp.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
memcmp(register const void *s1, register const void *s2, size_t n)
|
||||||
|
{
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
if (*s1++ != *s2++)
|
||||||
|
return *--s1 - *--s2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
19
lang/cem/libcc.ansi/string/memcpy.c
Normal file
19
lang/cem/libcc.ansi/string/memcpy.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void *
|
||||||
|
memcpy(register void *s1, register const void *s2, register size_t n)
|
||||||
|
{
|
||||||
|
void *ret = s1;
|
||||||
|
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
*s1++ = *s2++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
28
lang/cem/libcc.ansi/string/memmove.c
Normal file
28
lang/cem/libcc.ansi/string/memmove.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void *
|
||||||
|
memmove(register void *s1, register const void *s2, register size_t n)
|
||||||
|
{
|
||||||
|
void *ret = s1;
|
||||||
|
|
||||||
|
if (s2 <= s1 && s2 + (n-1) >= s1) {
|
||||||
|
/* overlap, copy backwards */
|
||||||
|
s1 += n;
|
||||||
|
s2 += n;
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
*--s1 = *--s2;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
*s1++ = *s2++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
19
lang/cem/libcc.ansi/string/memset.c
Normal file
19
lang/cem/libcc.ansi/string/memset.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void *
|
||||||
|
memset(void *s, int c, register size_t n)
|
||||||
|
{
|
||||||
|
register void *s1 = s;
|
||||||
|
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
*s1++ = c;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
20
lang/cem/libcc.ansi/string/strcat.c
Normal file
20
lang/cem/libcc.ansi/string/strcat.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strcat(register char *s1, register const char *s2)
|
||||||
|
{
|
||||||
|
char *ret = s1;
|
||||||
|
|
||||||
|
while (*s1++ != '\0')
|
||||||
|
/* EMPTY */ ;
|
||||||
|
s1--;
|
||||||
|
while (*s1++ = *s2++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
return ret;
|
||||||
|
}
|
20
lang/cem/libcc.ansi/string/strchr.c
Normal file
20
lang/cem/libcc.ansi/string/strchr.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strchr(register const char *s, int c)
|
||||||
|
{
|
||||||
|
register char c1 = (char) c;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (*s == c1)
|
||||||
|
return s;
|
||||||
|
} while (*s++ != '\0');
|
||||||
|
|
||||||
|
return (char *)NULL;
|
||||||
|
}
|
19
lang/cem/libcc.ansi/string/strcmp.c
Normal file
19
lang/cem/libcc.ansi/string/strcmp.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
strcmp(register const char *s1, register const char *s2)
|
||||||
|
{
|
||||||
|
for(;;) {
|
||||||
|
if (*s1 != *s2)
|
||||||
|
return *s1 - *s2;
|
||||||
|
if (*s1++ == '\0')
|
||||||
|
return 0;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
}
|
20
lang/cem/libcc.ansi/string/strcoll.c
Normal file
20
lang/cem/libcc.ansi/string/strcoll.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
strcoll(register const char *s1, register const char *s2)
|
||||||
|
{
|
||||||
|
for(;;) {
|
||||||
|
if (*s1 != *s2)
|
||||||
|
return *s1 - *s2;
|
||||||
|
if (*s1++ == '\0')
|
||||||
|
return 0;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
}
|
18
lang/cem/libcc.ansi/string/strcpy.c
Normal file
18
lang/cem/libcc.ansi/string/strcpy.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strcpy(register char *s1, register const char *s2)
|
||||||
|
{
|
||||||
|
char *ret = s1;
|
||||||
|
|
||||||
|
while (*s1++ = *s2++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
21
lang/cem/libcc.ansi/string/strcspn.c
Normal file
21
lang/cem/libcc.ansi/string/strcspn.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
size_t
|
||||||
|
strcspn(const char *string, const char *notin)
|
||||||
|
{
|
||||||
|
register char *s1, *s2;
|
||||||
|
|
||||||
|
for (s1 = string; *s1; s1++) {
|
||||||
|
for(s2 = notin; *s2 != *s1 && *s2; s2++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
if (*s2)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return s1 - string;
|
||||||
|
}
|
18
lang/cem/libcc.ansi/string/strerror.c
Normal file
18
lang/cem/libcc.ansi/string/strerror.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strerror(register int errnum)
|
||||||
|
{
|
||||||
|
extern const char *_sys_errlist[];
|
||||||
|
extern const int _sys_nerr;
|
||||||
|
|
||||||
|
if (errnum < 0 || errnum >= _sys_nerr)
|
||||||
|
return "unknown error";
|
||||||
|
return _sys_errlist[errnum];
|
||||||
|
}
|
18
lang/cem/libcc.ansi/string/strlen.c
Normal file
18
lang/cem/libcc.ansi/string/strlen.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
size_t
|
||||||
|
strlen(register const char *s)
|
||||||
|
{
|
||||||
|
char *org = s;
|
||||||
|
|
||||||
|
while (*s++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
|
||||||
|
return (s - 1) - org;
|
||||||
|
}
|
26
lang/cem/libcc.ansi/string/strncat.c
Normal file
26
lang/cem/libcc.ansi/string/strncat.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strncat(register char *s1, register const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
char *ret = s1;
|
||||||
|
|
||||||
|
if (n <= 0)
|
||||||
|
return s1;
|
||||||
|
while (*s1++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
s1--;
|
||||||
|
while (*s1++ = *s2++) {
|
||||||
|
if (--n == 0) {
|
||||||
|
*s1 = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
21
lang/cem/libcc.ansi/string/strncmp.c
Normal file
21
lang/cem/libcc.ansi/string/strncmp.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
strncmp(register const char *s1, register const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
if (*s1 != *s2)
|
||||||
|
return *s1 - *s2;
|
||||||
|
if (*s1++ == '\0')
|
||||||
|
return 0;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
23
lang/cem/libcc.ansi/string/strncpy.c
Normal file
23
lang/cem/libcc.ansi/string/strncpy.c
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strncpy(register char *s1, register const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
char *ret = s1;
|
||||||
|
|
||||||
|
while (*s2 && n > 0) {
|
||||||
|
n--;
|
||||||
|
*s1++ = *s2++;
|
||||||
|
}
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
*s1++ = '\0';
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
22
lang/cem/libcc.ansi/string/strpbrk.c
Normal file
22
lang/cem/libcc.ansi/string/strpbrk.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strpbrk(register const char *string, register const char *brk)
|
||||||
|
{
|
||||||
|
register char *s1;
|
||||||
|
|
||||||
|
while (*string) {
|
||||||
|
for (s1 = brk; *s1 && *s1 != *string; s1++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
if (*s1)
|
||||||
|
return string;
|
||||||
|
string++;
|
||||||
|
}
|
||||||
|
return (char *)NULL;
|
||||||
|
}
|
22
lang/cem/libcc.ansi/string/strrchr.c
Normal file
22
lang/cem/libcc.ansi/string/strrchr.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strrchr(register const char *s, int c)
|
||||||
|
{
|
||||||
|
register char *result;
|
||||||
|
register char c1 = (char) c;
|
||||||
|
|
||||||
|
result = (char *)NULL;
|
||||||
|
do {
|
||||||
|
if (*s == c1)
|
||||||
|
result = s;
|
||||||
|
} while (*s++);
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
21
lang/cem/libcc.ansi/string/strspn.c
Normal file
21
lang/cem/libcc.ansi/string/strspn.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
size_t
|
||||||
|
strspn(const char *string, const char *in)
|
||||||
|
{
|
||||||
|
register const char *s1, *s2;
|
||||||
|
|
||||||
|
for (s1 = string; *s1; s1++) {
|
||||||
|
for (s2 = in; *s2 && *s2 != *s1; s2++)
|
||||||
|
/* EMPTY */ ;
|
||||||
|
if (*s2 == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return s1 - string;
|
||||||
|
}
|
18
lang/cem/libcc.ansi/string/strstr.c
Normal file
18
lang/cem/libcc.ansi/string/strstr.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strstr(register const char *s, register const char *wanted)
|
||||||
|
{
|
||||||
|
int len = strlen(wanted);
|
||||||
|
|
||||||
|
while (*s != *wanted || strncmp(s, wanted, len))
|
||||||
|
if (*s++ == '\0')
|
||||||
|
return (char *)NULL;
|
||||||
|
return s;
|
||||||
|
}
|
30
lang/cem/libcc.ansi/string/strtok.c
Normal file
30
lang/cem/libcc.ansi/string/strtok.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strtok(register char *string, const char *separators)
|
||||||
|
{
|
||||||
|
register char *s1, *s2;
|
||||||
|
static char *savestring;
|
||||||
|
|
||||||
|
if (!string)
|
||||||
|
string = savestring;
|
||||||
|
|
||||||
|
if (!string)
|
||||||
|
return (char *)NULL;
|
||||||
|
|
||||||
|
if (*(s1 = string + strspn(string, separators)) == '\0') {
|
||||||
|
savestring = NULL;
|
||||||
|
return (char *)NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s2 = strpbrk(s1, separators))
|
||||||
|
*s2++ = '\0';
|
||||||
|
savestring = s2;
|
||||||
|
return s1;
|
||||||
|
}
|
24
lang/cem/libcc.ansi/string/strxfrm.c
Normal file
24
lang/cem/libcc.ansi/string/strxfrm.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
size_t
|
||||||
|
strxfrm(register char *s1, register const char *s2, register size_t n)
|
||||||
|
{
|
||||||
|
char *save = s2;
|
||||||
|
|
||||||
|
while (*s2) {
|
||||||
|
if (n > 1) {
|
||||||
|
n--;
|
||||||
|
*s1++ = *s2++;
|
||||||
|
} else
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
if (n >= 1)
|
||||||
|
*s1++ = '\0';
|
||||||
|
return s2 - save;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue