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:
parent
2dd0dfb049
commit
0afc055ab1
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ TARGET = picoc
|
||||||
SRCS = picoc.c table.c lex.c parse.c expression.c heap.c type.c \
|
SRCS = picoc.c table.c lex.c parse.c expression.c heap.c type.c \
|
||||||
variable.c clibrary.c platform.c include.c \
|
variable.c clibrary.c platform.c include.c \
|
||||||
platform/platform_unix.c platform/library_unix.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)
|
OBJS := $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
all: depend $(TARGET)
|
all: depend $(TARGET)
|
||||||
|
|
|
@ -685,9 +685,14 @@ void StdioSetupFunc(void)
|
||||||
VariableDefinePlatformVar(NULL, "stderr", FilePtrType, (union AnyValue *)&stderrValue, FALSE);
|
VariableDefinePlatformVar(NULL, "stderr", FilePtrType, (union AnyValue *)&stderrValue, FALSE);
|
||||||
|
|
||||||
/* define NULL, TRUE and FALSE */
|
/* define NULL, TRUE and FALSE */
|
||||||
VariableDefinePlatformVar(NULL, "NULL", &IntType, (union AnyValue *)&ZeroValue, FALSE);
|
if (!VariableDefined(TableStrRegister("NULL")))
|
||||||
VariableDefinePlatformVar(NULL, "TRUE", &IntType, (union AnyValue *)&TRUEValue, FALSE);
|
VariableDefinePlatformVar(NULL, "NULL", &IntType, (union AnyValue *)&ZeroValue, FALSE);
|
||||||
VariableDefinePlatformVar(NULL, "FALSE", &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 */
|
/* portability-related I/O calls */
|
||||||
|
|
|
@ -21,6 +21,10 @@ struct IncludeLibrary IncludeLibInfo[] =
|
||||||
&MathSetupFunc,
|
&MathSetupFunc,
|
||||||
&MathFunctions,
|
&MathFunctions,
|
||||||
NULL },
|
NULL },
|
||||||
|
{ "string.h",
|
||||||
|
&StringSetupFunc,
|
||||||
|
&StringFunctions,
|
||||||
|
NULL },
|
||||||
{ NULL, NULL, NULL, NULL }
|
{ NULL, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
4
picoc.h
4
picoc.h
|
@ -421,4 +421,8 @@ void StdioSetupFunc(void);
|
||||||
extern struct LibraryFunction MathFunctions[];
|
extern struct LibraryFunction MathFunctions[];
|
||||||
void MathSetupFunc(void);
|
void MathSetupFunc(void);
|
||||||
|
|
||||||
|
/* string.c */
|
||||||
|
extern struct LibraryFunction StringFunctions[];
|
||||||
|
void StringSetupFunc(void);
|
||||||
|
|
||||||
#endif /* PICOC_H */
|
#endif /* PICOC_H */
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
char a[10];
|
char a[10];
|
||||||
|
|
||||||
strcpy(a, "hello");
|
strcpy(a, "hello");
|
||||||
printf("%s\n", a);
|
printf("%s\n", a);
|
||||||
|
|
||||||
/*
|
|
||||||
strcpy(&a, "there");
|
|
||||||
printf("%s\n", a);
|
|
||||||
*/
|
|
||||||
|
|
||||||
strncpy(a, "gosh", 2);
|
strncpy(a, "gosh", 2);
|
||||||
printf("%s\n", a);
|
printf("%s\n", a);
|
||||||
|
|
||||||
|
@ -29,7 +25,7 @@ printf("%d\n", strncmp(a, "zebra", 2));
|
||||||
|
|
||||||
printf("%s\n", index(a, 'o'));
|
printf("%s\n", index(a, 'o'));
|
||||||
printf("%s\n", rindex(a, 'l'));
|
printf("%s\n", rindex(a, 'l'));
|
||||||
printf("%s\n", rindex(a, 'x'));
|
printf("%d\n", rindex(a, 'x') == NULL);
|
||||||
|
|
||||||
memset(&a[1], 'r', 4);
|
memset(&a[1], 'r', 4);
|
||||||
printf("%s\n", a);
|
printf("%s\n", a);
|
||||||
|
|
|
@ -11,7 +11,7 @@ gollo!
|
||||||
-1
|
-1
|
||||||
ollo!
|
ollo!
|
||||||
lo!
|
lo!
|
||||||
NULL
|
1
|
||||||
grrrr!
|
grrrr!
|
||||||
grgrr!
|
grgrr!
|
||||||
1
|
1
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
char a[10];
|
char a[10];
|
||||||
strcpy(a, "abcdef");
|
strcpy(a, "abcdef");
|
||||||
|
|
Loading…
Reference in a new issue