forked from KolibriOS/kolibrios
Added several functions (to ctype.h, stdlib.h)
"Optimised" some functions in string.h Added dynamic libraries support based on sysfunction 68.19 (experimental) git-svn-id: svn://kolibrios.org@215 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
21
programs/develop/metcc/trunk/libc/string/atoi.c
Normal file
21
programs/develop/metcc/trunk/libc/string/atoi.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "ctype.h"
|
||||
|
||||
|
||||
/*
|
||||
** atoi(s) - convert s to integer.
|
||||
*/
|
||||
int atoi(char *s)
|
||||
{
|
||||
int sign, n;
|
||||
while(isspace(*s)) ++s;
|
||||
sign = 1;
|
||||
switch(*s) {
|
||||
case '-': sign = -1;
|
||||
case '+': ++s;
|
||||
}
|
||||
n = 0;
|
||||
while(isdigit(*s)) n = 10 * n + *s++ - '0';
|
||||
return (sign * n);
|
||||
}
|
22
programs/develop/metcc/trunk/libc/string/atoib.cpp
Normal file
22
programs/develop/metcc/trunk/libc/string/atoib.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "ctype.h"
|
||||
|
||||
/*
|
||||
** atoib(s,b) - Convert s to "unsigned" integer in base b.
|
||||
** NOTE: This is a non-standard function.
|
||||
*/
|
||||
int atoib(char *s,int b)
|
||||
{
|
||||
int n, digit;
|
||||
n = 0;
|
||||
while(isspace(*s)) ++s;
|
||||
while((digit = (127 & *s++)) >= '0') {
|
||||
if(digit >= 'a') digit -= 87;
|
||||
else if(digit >= 'A') digit -= 55;
|
||||
else digit -= '0';
|
||||
if(digit >= b) break;
|
||||
n = b * n + digit;
|
||||
}
|
||||
return (n);
|
||||
}
|
19
programs/develop/metcc/trunk/libc/string/is.c
Normal file
19
programs/develop/metcc/trunk/libc/string/is.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "ctype.h"
|
||||
char __is[128] = {
|
||||
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
|
||||
0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004,
|
||||
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
|
||||
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
|
||||
0x140, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
|
||||
0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
|
||||
0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459,
|
||||
0x459, 0x459, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
|
||||
0x0D0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253,
|
||||
0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
|
||||
0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
|
||||
0x253, 0x253, 0x253, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
|
||||
0x0D0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073,
|
||||
0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
|
||||
0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
|
||||
0x073, 0x073, 0x073, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x004
|
||||
};
|
21
programs/develop/metcc/trunk/libc/string/itoa.c
Normal file
21
programs/develop/metcc/trunk/libc/string/itoa.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "ctype.h"
|
||||
|
||||
/*
|
||||
** itoa(n,s) - Convert n to characters in s
|
||||
*/
|
||||
void itoa(int n,char* s)
|
||||
{
|
||||
int sign;
|
||||
char *ptr;
|
||||
ptr = s;
|
||||
if ((sign = n) < 0) n = -n;
|
||||
do {
|
||||
*ptr++ = n % 10 + '0';
|
||||
} while ((n = n / 10) > 0);
|
||||
if (sign < 0) *ptr++ = '-';
|
||||
*ptr = '\0';
|
||||
reverse(s);
|
||||
}
|
||||
|
24
programs/develop/metcc/trunk/libc/string/itoab.c
Normal file
24
programs/develop/metcc/trunk/libc/string/itoab.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "ctype.h"
|
||||
|
||||
/*
|
||||
** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b.
|
||||
** NOTE: This is a non-standard function.
|
||||
*/
|
||||
void itoab(int n,char* s,int b)
|
||||
{
|
||||
char *ptr;
|
||||
int lowbit;
|
||||
ptr = s;
|
||||
b >>= 1;
|
||||
do {
|
||||
lowbit = n & 1;
|
||||
n = (n >> 1) & 32767;
|
||||
*ptr = ((n % b) << 1) + lowbit;
|
||||
if(*ptr < 10) *ptr += '0'; else *ptr += 55;
|
||||
++ptr;
|
||||
} while(n /= b);
|
||||
*ptr = 0;
|
||||
reverse (s);
|
||||
}
|
@@ -2,12 +2,7 @@ char* strcat(char* strDest, const char* strSource)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (*strDest!='\0') strDest++;
|
||||
while (*strSource!='\0')
|
||||
{
|
||||
*strDest=*strSource;
|
||||
strDest++;
|
||||
strSource++;
|
||||
}
|
||||
while (*strDest++) ;
|
||||
while (*strDest++ = *strSource++) ;
|
||||
return res;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
char* strchr(const char* string, int c)
|
||||
{
|
||||
while (*string!='\0')
|
||||
while (*string)
|
||||
{
|
||||
if (*string==c)
|
||||
return (char*)string;
|
||||
|
@@ -2,13 +2,6 @@ char* strcpy(char* strDest,char* strSource)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while(1)
|
||||
{
|
||||
*strDest=*strSource;
|
||||
if (*strSource=='\0')
|
||||
break;
|
||||
strDest++;
|
||||
strSource++;
|
||||
}
|
||||
while(*strDest++ == strSource++) ;
|
||||
return res;
|
||||
}
|
||||
}
|
@@ -2,10 +2,6 @@ int strlen(const char* string)
|
||||
{
|
||||
int i;
|
||||
i=0;
|
||||
while (*string!='\0')
|
||||
{
|
||||
i++;
|
||||
string++;
|
||||
}
|
||||
while (*string!++) i++;
|
||||
return i;
|
||||
}
|
||||
|
@@ -2,13 +2,12 @@ char* strncat(char* strDest,const char* strSource,int count)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (*strDest!='\0') strDest++;
|
||||
while (count>0 && *strSource!='\0')
|
||||
while (*strDest++) ;
|
||||
while(count-->0)
|
||||
{
|
||||
*strDest=*strSource;
|
||||
count--;
|
||||
strDest++;
|
||||
strSource++;
|
||||
if(*strDest++ = *strSource++) continue;
|
||||
return(res);
|
||||
}
|
||||
*strDest = 0;
|
||||
return res;
|
||||
}
|
||||
}
|
@@ -1,14 +1,12 @@
|
||||
int strncmp(const char* string1, const char* string2, int count)
|
||||
{
|
||||
while(count>0)
|
||||
while(count>0 && *string1==*string2)
|
||||
{
|
||||
if (*string1<*string2)
|
||||
return -1;
|
||||
if (*string1>*string2)
|
||||
return 1;
|
||||
if (*string1=='\0')
|
||||
return 0;
|
||||
count--;
|
||||
}
|
||||
if (*string1) return 0;
|
||||
++string1;
|
||||
++string2;
|
||||
--count;
|
||||
}
|
||||
if(count) return (*string1 - *string2);
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -11,4 +11,4 @@ char* strncpy(char* strDest,const char* strSource,int count)
|
||||
count--;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
8
programs/develop/metcc/trunk/libc/string/tolower.c
Normal file
8
programs/develop/metcc/trunk/libc/string/tolower.c
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
** return lower-case of c if upper-case, else c
|
||||
*/
|
||||
char tolower(char c)
|
||||
{
|
||||
if(c<='Z' && c>='A') return (c+32);
|
||||
return (c);
|
||||
}
|
8
programs/develop/metcc/trunk/libc/string/toupper.c
Normal file
8
programs/develop/metcc/trunk/libc/string/toupper.c
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
** return upper-case of c if it is lower-case, else c
|
||||
*/
|
||||
char toupper(char c)
|
||||
{
|
||||
if(c<='z' && c>='a') return (c-32);
|
||||
return (c);
|
||||
}
|
Reference in New Issue
Block a user