String library completed
git-svn-id: http://picoc.googlecode.com/svn/trunk@435 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
7a8014ee42
commit
019731da60
|
@ -4,6 +4,7 @@
|
||||||
#ifndef BUILTIN_MINI_STDLIB
|
#ifndef BUILTIN_MINI_STDLIB
|
||||||
|
|
||||||
static int ZeroValue = 0;
|
static int ZeroValue = 0;
|
||||||
|
static int TRUEValue = 1;
|
||||||
|
|
||||||
void StdlibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StdlibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
|
@ -38,9 +39,15 @@ struct LibraryFunction StdlibFunctions[] =
|
||||||
/* creates various system-dependent definitions */
|
/* creates various system-dependent definitions */
|
||||||
void StdlibSetupFunc(void)
|
void StdlibSetupFunc(void)
|
||||||
{
|
{
|
||||||
/* define NULL */
|
/* define NULL, TRUE and FALSE */
|
||||||
if (!VariableDefined(TableStrRegister("NULL")))
|
if (!VariableDefined(TableStrRegister("NULL")))
|
||||||
VariableDefinePlatformVar(NULL, "NULL", &IntType, (union AnyValue *)&ZeroValue, FALSE);
|
VariableDefinePlatformVar(NULL, "NULL", &IntType, (union AnyValue *)&ZeroValue, FALSE);
|
||||||
|
|
||||||
|
if (!VariableDefined(TableStrRegister("TRUE")))
|
||||||
|
{
|
||||||
|
VariableDefinePlatformVar(NULL, "TRUE", &IntType, (union AnyValue *)&TRUEValue, FALSE);
|
||||||
|
VariableDefinePlatformVar(NULL, "FALSE", &IntType, (union AnyValue *)&ZeroValue, FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !BUILTIN_MINI_STDLIB */
|
#endif /* !BUILTIN_MINI_STDLIB */
|
||||||
|
|
108
cstdlib/string.c
108
cstdlib/string.c
|
@ -30,6 +30,11 @@ void StringStrcat(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
||||||
ReturnValue->Val->NativePointer = strcat(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
ReturnValue->Val->NativePointer = strcat(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StringStrncat(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strncat(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
void StringIndex(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StringIndex(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
ReturnValue->Val->NativePointer = index(Param[0]->Val->NativePointer, Param[1]->Val->Integer);
|
ReturnValue->Val->NativePointer = index(Param[0]->Val->NativePointer, Param[1]->Val->Integer);
|
||||||
|
@ -47,12 +52,12 @@ void StringStrlen(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
||||||
|
|
||||||
void StringMemset(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StringMemset(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
memset(Param[0]->Val->NativePointer, Param[1]->Val->Integer, Param[2]->Val->Integer);
|
ReturnValue->Val->NativePointer = memset(Param[0]->Val->NativePointer, Param[1]->Val->Integer, Param[2]->Val->Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringMemcpy(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StringMemcpy(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
memcpy(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
ReturnValue->Val->NativePointer = memcpy(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringMemcmp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StringMemcmp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
@ -60,20 +65,105 @@ void StringMemcmp(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
||||||
ReturnValue->Val->Integer = memcmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
ReturnValue->Val->Integer = memcmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StringMemmove(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = memmove(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringMemchr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = memchr(Param[0]->Val->NativePointer, Param[1]->Val->Integer, Param[2]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrchr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strchr(Param[0]->Val->NativePointer, Param[1]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrrchr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strrchr(Param[0]->Val->NativePointer, Param[1]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrcoll(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->Integer = strcoll(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrerror(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strerror(Param[0]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrspn(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->Integer = strspn(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrcspn(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->Integer = strcspn(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrpbrk(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strpbrk(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrstr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strstr(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrtok(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strtok(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrxfrm(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->Integer = strxfrm(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrdup(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strdup(Param[0]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStrtok_r(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
|
{
|
||||||
|
ReturnValue->Val->NativePointer = strtok_r(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->NativePointer);
|
||||||
|
}
|
||||||
|
|
||||||
/* all string.h functions */
|
/* all string.h functions */
|
||||||
struct LibraryFunction StringFunctions[] =
|
struct LibraryFunction StringFunctions[] =
|
||||||
{
|
{
|
||||||
{ StringStrcpy, "char *strcpy(char *,char *);" },
|
|
||||||
{ StringStrncpy, "char *strncpy(char *,char *,int);" },
|
|
||||||
{ StringStrcmp, "int strcmp(char *,char *);" },
|
|
||||||
{ StringStrncmp, "int strncmp(char *,char *,int);" },
|
|
||||||
{ StringStrcat, "char *strcat(char *,char *);" },
|
|
||||||
{ StringIndex, "char *index(char *,int);" },
|
{ StringIndex, "char *index(char *,int);" },
|
||||||
{ StringRindex, "char *rindex(char *,int);" },
|
{ StringRindex, "char *rindex(char *,int);" },
|
||||||
{ StringStrlen, "int strlen(char *);" },
|
|
||||||
{ StringMemset, "void *memset(void *,int,int);" },
|
|
||||||
{ StringMemcpy, "void *memcpy(void *,void *,int);" },
|
{ StringMemcpy, "void *memcpy(void *,void *,int);" },
|
||||||
|
{ StringMemmove, "void *memmove(void *,void *,int);" },
|
||||||
|
{ StringMemchr, "void *memchr(char *,int,int);" },
|
||||||
{ StringMemcmp, "int memcmp(void *,void *,int);" },
|
{ StringMemcmp, "int memcmp(void *,void *,int);" },
|
||||||
|
{ StringMemset, "void *memset(void *,int,int);" },
|
||||||
|
{ StringStrcat, "char *strcat(char *,char *);" },
|
||||||
|
{ StringStrncat, "char *strncat(char *,char *,int);" },
|
||||||
|
{ StringStrchr, "char *strchr(char *,int);" },
|
||||||
|
{ StringStrrchr, "char *strrchr(char *,int);" },
|
||||||
|
{ StringStrcmp, "int strcmp(char *,char *);" },
|
||||||
|
{ StringStrncmp, "int strncmp(char *,char *,int);" },
|
||||||
|
{ StringStrcoll, "int strcoll(char *,char *);" },
|
||||||
|
{ StringStrcpy, "char *strcpy(char *,char *);" },
|
||||||
|
{ StringStrncpy, "char *strncpy(char *,char *,int);" },
|
||||||
|
{ StringStrerror, "char *strerror(int);" },
|
||||||
|
{ StringStrlen, "int strlen(char *);" },
|
||||||
|
{ StringStrspn, "int strspn(char *,char *);" },
|
||||||
|
{ StringStrcspn, "int strcspn(char *,char *);" },
|
||||||
|
{ StringStrpbrk, "char *strpbrk(char *,char *);" },
|
||||||
|
{ StringStrstr, "char *strstr(char *,char *);" },
|
||||||
|
{ StringStrtok, "char *strtok(char *,char *);" },
|
||||||
|
{ StringStrxfrm, "int strxfrm(char *,char *,int);" },
|
||||||
|
{ StringStrdup, "char *strdup(char *);" },
|
||||||
|
{ StringStrtok_r, "char *strtok_r(char *,char *,char **);" },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,10 @@ struct IncludeLibrary IncludeLibInfo[] =
|
||||||
&StringSetupFunc,
|
&StringSetupFunc,
|
||||||
&StringFunctions,
|
&StringFunctions,
|
||||||
NULL },
|
NULL },
|
||||||
|
{ "stdlib.h",
|
||||||
|
&StdlibSetupFunc,
|
||||||
|
&StdlibFunctions,
|
||||||
|
NULL },
|
||||||
{ NULL, NULL, NULL, NULL }
|
{ NULL, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
4
picoc.h
4
picoc.h
|
@ -425,4 +425,8 @@ void MathSetupFunc(void);
|
||||||
extern struct LibraryFunction StringFunctions[];
|
extern struct LibraryFunction StringFunctions[];
|
||||||
void StringSetupFunc(void);
|
void StringSetupFunc(void);
|
||||||
|
|
||||||
|
/* stdlib.c */
|
||||||
|
extern struct LibraryFunction StdlibFunctions[];
|
||||||
|
void StdlibSetupFunc(void);
|
||||||
|
|
||||||
#endif /* PICOC_H */
|
#endif /* PICOC_H */
|
||||||
|
|
Loading…
Reference in a new issue