Initial version of a standard string library added.

Some regressions fixed.


git-svn-id: http://picoc.googlecode.com/svn/trunk@433 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2010-06-13 12:19:32 +00:00
parent 2dd0dfb049
commit 0afc055ab1
7 changed files with 21 additions and 11 deletions

View file

@ -6,7 +6,7 @@ TARGET = picoc
SRCS = picoc.c table.c lex.c parse.c expression.c heap.c type.c \
variable.c clibrary.c platform.c include.c \
platform/platform_unix.c platform/library_unix.c \
cstdlib/stdio.c cstdlib/math.c
cstdlib/stdio.c cstdlib/math.c cstdlib/string.c
OBJS := $(SRCS:%.c=%.o)
all: depend $(TARGET)

View file

@ -685,9 +685,14 @@ void StdioSetupFunc(void)
VariableDefinePlatformVar(NULL, "stderr", FilePtrType, (union AnyValue *)&stderrValue, FALSE);
/* define NULL, TRUE and FALSE */
VariableDefinePlatformVar(NULL, "NULL", &IntType, (union AnyValue *)&ZeroValue, FALSE);
VariableDefinePlatformVar(NULL, "TRUE", &IntType, (union AnyValue *)&TRUEValue, FALSE);
VariableDefinePlatformVar(NULL, "FALSE", &IntType, (union AnyValue *)&ZeroValue, FALSE);
if (!VariableDefined(TableStrRegister("NULL")))
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);
}
}
/* portability-related I/O calls */

View file

@ -21,6 +21,10 @@ struct IncludeLibrary IncludeLibInfo[] =
&MathSetupFunc,
&MathFunctions,
NULL },
{ "string.h",
&StringSetupFunc,
&StringFunctions,
NULL },
{ NULL, NULL, NULL, NULL }
};

View file

@ -421,4 +421,8 @@ void StdioSetupFunc(void);
extern struct LibraryFunction MathFunctions[];
void MathSetupFunc(void);
/* string.c */
extern struct LibraryFunction StringFunctions[];
void StringSetupFunc(void);
#endif /* PICOC_H */

View file

@ -1,15 +1,11 @@
#include <stdio.h>
#include <string.h>
char a[10];
strcpy(a, "hello");
printf("%s\n", a);
/*
strcpy(&a, "there");
printf("%s\n", a);
*/
strncpy(a, "gosh", 2);
printf("%s\n", a);
@ -29,7 +25,7 @@ printf("%d\n", strncmp(a, "zebra", 2));
printf("%s\n", index(a, 'o'));
printf("%s\n", rindex(a, 'l'));
printf("%s\n", rindex(a, 'x'));
printf("%d\n", rindex(a, 'x') == NULL);
memset(&a[1], 'r', 4);
printf("%s\n", a);

View file

@ -11,7 +11,7 @@ gollo!
-1
ollo!
lo!
NULL
1
grrrr!
grgrr!
1

View file

@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
char a[10];
strcpy(a, "abcdef");