Skip to content

Commit 51d2e41

Browse files
Add FILE wrapper around FILEIOC library (Fix #78)
1 parent 4285eee commit 51d2e41

File tree

21 files changed

+203
-11
lines changed

21 files changed

+203
-11
lines changed

makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ INSTALLBF := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/include/fasmg-ez80
7474
INSTALLINC := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/include)
7575
INSTALLLIB := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib)
7676
INSTALLLL := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib/libload)
77+
INSTALLIO := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib/fileio)
7778
INSTALLSH := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib/shared)
7879
INSTALLST := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib/static)
7980
INSTALLLI := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib/linked)
@@ -209,6 +210,7 @@ $(DIRS):
209210
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLINC)) $(MKDIR) $(INSTALLINC)
210211
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLBF)) $(MKDIR) $(INSTALLBF)
211212
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLLL)) $(MKDIR) $(INSTALLLL)
213+
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLIO)) $(MKDIR) $(INSTALLIO)
212214
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLSH)) $(MKDIR) $(INSTALLSH)
213215
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLST)) $(MKDIR) $(INSTALLST)
214216
$(WINNCHKDIR) $(call WINCHKPATH,$(INSTALLLI)) $(MKDIR) $(INSTALLLI)

src/core_makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ LINK_FILES += $(call TOLOWER,$(LINK_CSOURCES))
111111
LINK_FILES += $(call TOLOWER,$(LINK_CPPSOURCES))
112112
LINK_FILES += $(LINK_ASMSOURCES)
113113
LINK_FILES += $(call NATIVEPATH,$(wildcard $(CEDEV)/lib/shared/*.src))
114+
LINK_FILES += $(call NATIVEPATH,$(wildcard $(CEDEV)/lib/fileio/*.src))
114115
LINK_LIBLOAD := $(call NATIVEPATH,$(wildcard $(CEDEV)/lib/libload/*.asm))
115116

116117
# check if there is an icon present that we can convert; if so, generate a recipe to build it properly

src/std/fileio/fclose.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
int fclose(FILE *stream) {
5+
ti_var_t slot = stream->slot;
6+
__stdio_files[slot].slot = 0;
7+
return ti_Close(slot);
8+
}

src/std/fileio/feof.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
int feof(FILE *stream) {
5+
char a;
6+
int sz;
7+
8+
sz = fread(&a, 1, 1, stream);
9+
fseek(stream, -sz, SEEK_CUR);
10+
return !sz;
11+
}

src/std/fileio/fgetc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
int fgetc(FILE *stream) {
5+
return ti_GetC(stream->slot);
6+
}

src/std/fileio/fgets.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
char *fgets(char *str, int num, FILE *stream) {
5+
int c;
6+
char *p = str;
7+
8+
if (num == 1) {
9+
*p = 0;
10+
return str;
11+
}
12+
13+
for (; num > 1; num--) {
14+
if ((c = fgetc(stream)) == EOF) {
15+
break;
16+
}
17+
*p++ = c;
18+
if (c == '\n') {
19+
break;
20+
}
21+
}
22+
23+
if (p == str) {
24+
return NULL;
25+
}
26+
27+
*p = 0;
28+
29+
return str;
30+
}

src/std/fileio/files.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <stdio.h>
2+
3+
FILE __stdio_files[FOPEN_MAX];

src/std/fileio/fopen.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
FILE *fopen(const char *filename, const char *mode) {
5+
ti_var_t f = ti_Open(filename, mode);
6+
if (!f) {
7+
return NULL;
8+
}
9+
__stdio_files[(unsigned char)f].slot = f;
10+
11+
return &__stdio_files[f];
12+
}

src/std/fileio/fputc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
int fputc(int c, FILE *stream) {
5+
return ti_PutC((char)c, stream->slot);
6+
}

src/std/fileio/fputs.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
#include <fileioc.h>
3+
4+
int fputs(const char *str, FILE *stream) {
5+
unsigned char slot = stream->slot;
6+
unsigned int i = 0;
7+
char c;
8+
9+
while((c = str[i])) {
10+
if(ti_PutC(c, slot) == EOF) {
11+
return EOF;
12+
}
13+
i++;
14+
}
15+
if(ti_PutC('\n', slot) == EOF) {
16+
return EOF;
17+
}
18+
return 1;
19+
}

0 commit comments

Comments
 (0)