Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FILE wrapper around FILEIOC library (Fix #78)
- Loading branch information
1 parent
4285eee
commit 51d2e41
Showing
21 changed files
with
203 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int fclose(FILE *stream) { | ||
ti_var_t slot = stream->slot; | ||
__stdio_files[slot].slot = 0; | ||
return ti_Close(slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int feof(FILE *stream) { | ||
char a; | ||
int sz; | ||
|
||
sz = fread(&a, 1, 1, stream); | ||
fseek(stream, -sz, SEEK_CUR); | ||
return !sz; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int fgetc(FILE *stream) { | ||
return ti_GetC(stream->slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
char *fgets(char *str, int num, FILE *stream) { | ||
int c; | ||
char *p = str; | ||
|
||
if (num == 1) { | ||
*p = 0; | ||
return str; | ||
} | ||
|
||
for (; num > 1; num--) { | ||
if ((c = fgetc(stream)) == EOF) { | ||
break; | ||
} | ||
*p++ = c; | ||
if (c == '\n') { | ||
break; | ||
} | ||
} | ||
|
||
if (p == str) { | ||
return NULL; | ||
} | ||
|
||
*p = 0; | ||
|
||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <stdio.h> | ||
|
||
FILE __stdio_files[FOPEN_MAX]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
FILE *fopen(const char *filename, const char *mode) { | ||
ti_var_t f = ti_Open(filename, mode); | ||
if (!f) { | ||
return NULL; | ||
} | ||
__stdio_files[(unsigned char)f].slot = f; | ||
|
||
return &__stdio_files[f]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int fputc(int c, FILE *stream) { | ||
return ti_PutC((char)c, stream->slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int fputs(const char *str, FILE *stream) { | ||
unsigned char slot = stream->slot; | ||
unsigned int i = 0; | ||
char c; | ||
|
||
while((c = str[i])) { | ||
if(ti_PutC(c, slot) == EOF) { | ||
return EOF; | ||
} | ||
i++; | ||
} | ||
if(ti_PutC('\n', slot) == EOF) { | ||
return EOF; | ||
} | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
size_t fread(void *ptr, size_t size, size_t count, FILE *stream) { | ||
return ti_Read(ptr, size, count, stream->slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int fseek(FILE *stream, long int offset, int origin) { | ||
return ti_Seek((int)offset, origin, stream->slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
long int ftell(FILE *stream) { | ||
return (long int)ti_Tell(stream->slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream) { | ||
return ti_Write(ptr, size, count, stream->slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#---------------------------- | ||
# Makefile | ||
#---------------------------- | ||
|
||
# common/os specific things | ||
ifeq ($(OS),Windows_NT) | ||
SHELL = cmd.exe | ||
NATIVEPATH = $(subst /,\,$(1)) | ||
WINPATH = $(NATIVEPATH) | ||
RM = del /f 2>nul | ||
CEDEV ?= C:\CEdev | ||
BIN ?= $(CEDEV)/bin | ||
CC = $(call NATIVEPATH,$(BIN)/ez80cc.exe) | ||
else | ||
NATIVEPATH = $(subst \,/,$(1)) | ||
WINPATH = $(subst \,\\,$(shell winepath --windows $(1))) | ||
RM = rm -f | ||
CEDEV ?= $(HOME)/CEdev | ||
BIN ?= $(CEDEV)/bin | ||
CC = $(call NATIVEPATH,wine $(BIN)/ez80cc.exe) | ||
endif | ||
|
||
CCFLGS := -noasm -nodebug -nogenprint -nokeeplst -keepasm -promote -quiet -fplib -optsize -cpu:EZ80F91 -stdinc:"..;..\\..\\fileioc;..\\..\\ce" -define:_EZ80F91 -define:_EZ80 | ||
|
||
EZC := $(wildcard *.c) | ||
EZSRC := $(EZC:%.c=%.src) | ||
|
||
all: $(EZSRC) | ||
|
||
%.src: %.c | ||
$(CC) $(CCFLGS) $(call WINPATH,$<) | ||
|
||
clean: | ||
$(RM) $(EZSRC) | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <fileioc.h> | ||
|
||
int remove(const char *filename) { | ||
return !ti_Delete(filename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters