Added EOF to stdio.
Tested stdio functions so far. git-svn-id: http://picoc.googlecode.com/svn/trunk@422 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
a21f1d8a70
commit
8ca43880c9
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#ifndef NO_HASH_INCLUDE
|
#ifndef NO_HASH_INCLUDE
|
||||||
|
|
||||||
|
static int EOFValue = EOF;
|
||||||
|
|
||||||
void StdioFopen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StdioFopen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
ReturnValue->Val->NativePointer = fopen(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
ReturnValue->Val->NativePointer = fopen(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
|
||||||
|
@ -53,6 +55,9 @@ void StdioSetupFunc(void)
|
||||||
{
|
{
|
||||||
/* make a "struct FILEStruct" which is the same size as a native FILE structure */
|
/* make a "struct FILEStruct" which is the same size as a native FILE structure */
|
||||||
TypeCreateOpaqueStruct(NULL, TableStrRegister("FILEStruct"), sizeof(FILE));
|
TypeCreateOpaqueStruct(NULL, TableStrRegister("FILEStruct"), sizeof(FILE));
|
||||||
|
|
||||||
|
/* define EOF equal to the system EOF */
|
||||||
|
VariableDefinePlatformVar(NULL, "EOF", &IntType, (union AnyValue *)&EOFValue, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* NO_HASH_INCLUDE */
|
#endif /* NO_HASH_INCLUDE */
|
||||||
|
|
45
tests/40_stdio.c
Normal file
45
tests/40_stdio.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
FILE *f = fopen("fred.txt", "w");
|
||||||
|
fwrite("hello\nhello\n", 1, 12, f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
char freddy[7];
|
||||||
|
f = fopen("fred.txt", "r");
|
||||||
|
if (fread(freddy, 1, 6, f) != 6)
|
||||||
|
printf("couldn't read fred.txt\n");
|
||||||
|
|
||||||
|
freddy[6] = '\0';
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
printf("%s", freddy);
|
||||||
|
|
||||||
|
char InChar;
|
||||||
|
char ShowChar;
|
||||||
|
f = fopen("fred.txt", "r");
|
||||||
|
while ( (InChar = fgetc(f)) != EOF)
|
||||||
|
{
|
||||||
|
ShowChar = InChar;
|
||||||
|
if (ShowChar < ' ')
|
||||||
|
ShowChar = '.';
|
||||||
|
|
||||||
|
printf("ch: %d '%c'\n", InChar, ShowChar);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
f = fopen("fred.txt", "r");
|
||||||
|
while ( (InChar = getc(f)) != EOF)
|
||||||
|
{
|
||||||
|
ShowChar = InChar;
|
||||||
|
if (ShowChar < ' ')
|
||||||
|
ShowChar = '.';
|
||||||
|
|
||||||
|
printf("ch: %d '%c'\n", InChar, ShowChar);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
f = fopen("fred.txt", "r");
|
||||||
|
while (fgets(freddy, sizeof(freddy), f) != NULL)
|
||||||
|
printf("x: %s", freddy);
|
||||||
|
|
||||||
|
fclose(f);
|
27
tests/40_stdio.expect
Normal file
27
tests/40_stdio.expect
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
hello
|
||||||
|
ch: 104 'h'
|
||||||
|
ch: 101 'e'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 111 'o'
|
||||||
|
ch: 10 '.'
|
||||||
|
ch: 104 'h'
|
||||||
|
ch: 101 'e'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 111 'o'
|
||||||
|
ch: 10 '.'
|
||||||
|
ch: 104 'h'
|
||||||
|
ch: 101 'e'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 111 'o'
|
||||||
|
ch: 10 '.'
|
||||||
|
ch: 104 'h'
|
||||||
|
ch: 101 'e'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 108 'l'
|
||||||
|
ch: 111 'o'
|
||||||
|
ch: 10 '.'
|
||||||
|
x: hello
|
||||||
|
x: hello
|
|
@ -32,7 +32,8 @@ TESTS= 00_assignment.test \
|
||||||
36_array_initialisers.test \
|
36_array_initialisers.test \
|
||||||
37_sprintf.test \
|
37_sprintf.test \
|
||||||
38_multiple_array_index.test \
|
38_multiple_array_index.test \
|
||||||
39_typedef.test
|
39_typedef.test \
|
||||||
|
40_stdio.test
|
||||||
|
|
||||||
%.test: %.expect %.c
|
%.test: %.expect %.c
|
||||||
@echo Test: $*...
|
@echo Test: $*...
|
||||||
|
|
Loading…
Reference in a new issue