cleanup file.h
This commit is contained in:
parent
73f2578648
commit
d3b188e44d
|
@ -35,6 +35,18 @@ int xfclose(pic_state *pic, xFILE *fp) {
|
||||||
return fp->vtable.close(pic, fp->vtable.cookie);
|
return fp->vtable.close(pic, fp->vtable.cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xclearerr(pic_state PIC_UNUSED(*pic), xFILE *fp) {
|
||||||
|
fp->flag &= ~(X_EOF | X_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
int xfeof(pic_state PIC_UNUSED(*pic), xFILE *fp) {
|
||||||
|
return (fp->flag & X_EOF) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int xferror(pic_state PIC_UNUSED(*pic), xFILE *fp) {
|
||||||
|
return (fp->flag & X_ERR) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
int x_fillbuf(pic_state *pic, xFILE *fp) {
|
int x_fillbuf(pic_state *pic, xFILE *fp) {
|
||||||
int bufsize;
|
int bufsize;
|
||||||
|
|
||||||
|
@ -187,7 +199,7 @@ char *xfgets(pic_state *pic, char *s, int size, xFILE *stream) {
|
||||||
return (c == EOF && buf == s) ? NULL : s;
|
return (c == EOF && buf == s) ? NULL : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xungetc(int c, xFILE *fp) {
|
int xungetc(pic_state PIC_UNUSED(*pic), int c, xFILE *fp) {
|
||||||
unsigned char uc = c;
|
unsigned char uc = c;
|
||||||
|
|
||||||
if (c == EOF || fp->base == fp->ptr) {
|
if (c == EOF || fp->base == fp->ptr) {
|
||||||
|
@ -211,7 +223,7 @@ size_t xfread(pic_state *pic, void *ptr, size_t size, size_t count, xFILE *fp) {
|
||||||
if ((c = x_fillbuf(pic, fp)) == EOF) {
|
if ((c = x_fillbuf(pic, fp)) == EOF) {
|
||||||
return (size * count - nbytes) / size;
|
return (size * count - nbytes) / size;
|
||||||
} else {
|
} else {
|
||||||
xungetc(c, fp);
|
xungetc(pic, c, fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(bptr, fp->ptr, nbytes);
|
memcpy(bptr, fp->ptr, nbytes);
|
||||||
|
@ -240,6 +252,10 @@ size_t xfwrite(pic_state *pic, const void *ptr, size_t size, size_t count, xFILE
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define XSEEK_CUR 0
|
||||||
|
#define XSEEK_END 1
|
||||||
|
#define XSEEK_SET 2
|
||||||
|
|
||||||
long xfseek(pic_state *pic, xFILE *fp, long offset, int whence) {
|
long xfseek(pic_state *pic, xFILE *fp, long offset, int whence) {
|
||||||
long s;
|
long s;
|
||||||
|
|
||||||
|
@ -535,17 +551,3 @@ xFILE *xfopen_null(pic_state PIC_UNUSED(*pic), const char *mode) {
|
||||||
return xfunopen(pic, 0, 0, null_write, null_seek, null_close);
|
return xfunopen(pic, 0, 0, null_write, null_seek, null_close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
xgets(buf);
|
|
||||||
|
|
||||||
xprintf("%s\n", buf);
|
|
||||||
xprintf("hello\n");
|
|
||||||
xprintf("hello\n");
|
|
||||||
// xfflush(0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -25,10 +25,6 @@ typedef struct {
|
||||||
int flag; /* mode of the file access */
|
int flag; /* mode of the file access */
|
||||||
} xFILE;
|
} xFILE;
|
||||||
|
|
||||||
#define xstdin (&pic->files[0])
|
|
||||||
#define xstdout (&pic->files[1])
|
|
||||||
#define xstderr (&pic->files[2])
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
X_READ = 01,
|
X_READ = 01,
|
||||||
X_WRITE = 02,
|
X_WRITE = 02,
|
||||||
|
@ -38,31 +34,28 @@ enum {
|
||||||
X_LNBUF = 040
|
X_LNBUF = 040
|
||||||
};
|
};
|
||||||
|
|
||||||
#define xclearerr(p) ((p)->flag &= ~(X_EOF | X_ERR))
|
#define xstdin (&pic->files[0])
|
||||||
#define xfeof(p) (((p)->flag & X_EOF) != 0)
|
#define xstdout (&pic->files[1])
|
||||||
#define xferror(p) (((p)->flag & X_ERR) != 0)
|
#define xstderr (&pic->files[2])
|
||||||
|
|
||||||
xFILE *xfunopen(pic_state *, void *cookie, int (*read)(pic_state *, void *, char *, int), int (*write)(pic_state *, void *, const char *, int), long (*seek)(pic_state *, void *, long, int), int (*close)(pic_state *, void *));
|
xFILE *xfunopen(pic_state *, void *cookie, int (*read)(pic_state *, void *, char *, int), int (*write)(pic_state *, void *, const char *, int), long (*seek)(pic_state *, void *, long, int), int (*close)(pic_state *, void *));
|
||||||
|
size_t xfread(pic_state *, void *ptr, size_t size, size_t count, xFILE *fp);
|
||||||
|
size_t xfwrite(pic_state *, const void *ptr, size_t size, size_t count, xFILE *fp);
|
||||||
|
long xfseek(pic_state *, xFILE *fp, long offset, int whence); /* 0:cur, 1:end, 2:set */
|
||||||
|
int xfclose(pic_state *, xFILE *fp);
|
||||||
|
|
||||||
enum {
|
void xclearerr(pic_state *, xFILE *fp);
|
||||||
XSEEK_CUR,
|
int xfeof(pic_state *, xFILE *fp);
|
||||||
XSEEK_END,
|
int xferror(pic_state *, xFILE *fp);
|
||||||
XSEEK_SET
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t xfread(pic_state *, void *, size_t, size_t, xFILE *);
|
int xfputc(pic_state *, int c, xFILE *fp);
|
||||||
size_t xfwrite(pic_state *, const void *, size_t, size_t, xFILE *);
|
int xfgetc(pic_state *, xFILE *fp);
|
||||||
long xfseek(pic_state *, xFILE *, long, int);
|
int xfputs(pic_state *, const char *s, xFILE *fp);
|
||||||
int xfflush(pic_state *, xFILE *);
|
char *xfgets(pic_state *, char *s, int size, xFILE *fp);
|
||||||
int xfclose(pic_state *, xFILE *);
|
int xungetc(pic_state *, int c, xFILE *fp);
|
||||||
|
int xfflush(pic_state *, xFILE *fp);
|
||||||
int xfputc(pic_state *, int, xFILE *);
|
int xfprintf(pic_state *, xFILE *fp, const char *fmt, ...);
|
||||||
int xfgetc(pic_state *, xFILE *);
|
int xvfprintf(pic_state *, xFILE *fp, const char *fmt, va_list);
|
||||||
int xfputs(pic_state *, const char *, xFILE *);
|
|
||||||
char *xfgets(pic_state *, char *, int, xFILE *);
|
|
||||||
int xungetc(int, xFILE *);
|
|
||||||
int xfprintf(pic_state *, xFILE *, const char *, ...);
|
|
||||||
int xvfprintf(pic_state *, xFILE *, const char *, va_list);
|
|
||||||
|
|
||||||
#if PIC_ENABLE_STDIO
|
#if PIC_ENABLE_STDIO
|
||||||
xFILE *xfopen_file(pic_state *, FILE *, const char *mode);
|
xFILE *xfopen_file(pic_state *, FILE *, const char *mode);
|
||||||
|
|
|
@ -199,7 +199,7 @@ pic_port_peek_u8(pic_state *pic)
|
||||||
return pic_eof_object(pic);
|
return pic_eof_object(pic);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
xungetc(c, pic_fileno(pic, port));
|
xungetc(pic, c, pic_fileno(pic, port));
|
||||||
return pic_int_value(pic, c);
|
return pic_int_value(pic, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ peek(pic_state *pic, xFILE *file)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
xungetc((c = xfgetc(pic, file)), file);
|
xungetc(pic, (c = xfgetc(pic, file)), file);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue