Skip to content

Commit

Permalink
Added ctype.h module
Browse files Browse the repository at this point in the history
  • Loading branch information
zik.saleeba committed Jun 29, 2010
1 parent 110df67 commit a746cb8
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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/string.c cstdlib/stdlib.c \
cstdlib/time.c cstdlib/errno.c
cstdlib/time.c cstdlib/errno.c cstdlib/ctype.c
OBJS := $(SRCS:%.c=%.o)

all: depend $(TARGET)
Expand Down
109 changes: 109 additions & 0 deletions cstdlib/ctype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* string.h library for large systems - small embedded systems use clibrary.c instead */
#include <ctype.h>
#include "../picoc.h"

#ifndef BUILTIN_MINI_STDLIB

void StdIsalnum(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isalnum(Param[0]->Val->Integer);
}

void StdIsalpha(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isalpha(Param[0]->Val->Integer);
}

void StdIsblank(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isblank(Param[0]->Val->Integer);
}

void StdIscntrl(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = iscntrl(Param[0]->Val->Integer);
}

void StdIsdigit(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isdigit(Param[0]->Val->Integer);
}

void StdIsgraph(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isgraph(Param[0]->Val->Integer);
}

void StdIslower(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = islower(Param[0]->Val->Integer);
}

void StdIsprint(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isprint(Param[0]->Val->Integer);
}

void StdIspunct(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = ispunct(Param[0]->Val->Integer);
}

void StdIsspace(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isspace(Param[0]->Val->Integer);
}

void StdIsupper(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isupper(Param[0]->Val->Integer);
}

void StdIsxdigit(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isxdigit(Param[0]->Val->Integer);
}

void StdTolower(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = tolower(Param[0]->Val->Integer);
}

void StdToupper(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = toupper(Param[0]->Val->Integer);
}

void StdIsascii(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = isascii(Param[0]->Val->Integer);
}

void StdToascii(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = toascii(Param[0]->Val->Integer);
}

/* all string.h functions */
struct LibraryFunction StdCtypeFunctions[] =
{
{ StdIsalnum, "int isalnum(int);" },
{ StdIsalpha, "int isalpha(int);" },
{ StdIsblank, "int isblank(int);" },
{ StdIscntrl, "int iscntrl(int);" },
{ StdIsdigit, "int isdigit(int);" },
{ StdIsgraph, "int isgraph(int);" },
{ StdIslower, "int islower(int);" },
{ StdIsprint, "int isprint(int);" },
{ StdIspunct, "int ispunct(int);" },
{ StdIsspace, "int isspace(int);" },
{ StdIsupper, "int isupper(int);" },
{ StdIsxdigit, "int isxdigit(int);" },
{ StdTolower, "int tolower(int);" },
{ StdToupper, "int toupper(int);" },
{ StdIsascii, "int isascii(int);" },
{ StdToascii, "int toascii(int);" },
{ NULL, NULL }
};

#endif /* !BUILTIN_MINI_STDLIB */
1 change: 1 addition & 0 deletions include.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct IncludeLibrary *IncludeLibList = NULL;
/* initialise the built-in include libraries */
void IncludeInit()
{
IncludeRegister("ctype.h", NULL, &StdCtypeFunctions, NULL);
IncludeRegister("errno.h", &StdErrnoSetupFunc, NULL, NULL);
IncludeRegister("stdio.h", &StdioSetupFunc, &StdioFunctions, StdioDefs);
IncludeRegister("math.h", &MathSetupFunc, &MathFunctions, NULL);
Expand Down
3 changes: 3 additions & 0 deletions picoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,7 @@ void StdTimeSetupFunc(void);
/* errno.c */
void StdErrnoSetupFunc(void);

/* ctype.c */
extern struct LibraryFunction StdCtypeFunctions[];

#endif /* PICOC_H */

0 comments on commit a746cb8

Please sign in to comment.