Skip to content

Commit

Permalink
Initial version of a standard string library added.
Browse files Browse the repository at this point in the history
Some regressions fixed.
  • Loading branch information
zik.saleeba committed Jun 13, 2010
1 parent f9a2843 commit cb6c231
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions cstdlib/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 4 additions & 0 deletions include.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct IncludeLibrary IncludeLibInfo[] =
&MathSetupFunc,
&MathFunctions,
NULL },
{ "string.h",
&StringSetupFunc,
&StringFunctions,
NULL },
{ NULL, NULL, NULL, NULL }
};

Expand Down
4 changes: 4 additions & 0 deletions picoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
8 changes: 2 additions & 6 deletions tests/28_strings.c
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/28_strings.expect
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gollo!
-1
ollo!
lo!
NULL
1
grrrr!
grgrr!
1
Expand Down
1 change: 1 addition & 0 deletions tests/29_array_address.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>

char a[10];
strcpy(a, "abcdef");
Expand Down

0 comments on commit cb6c231

Please sign in to comment.