mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Add io_reader.is_closed
This commit is contained in:
1 parent
27036043ae
commit
a8406927ef
4 files changed
+23
-13
No files matched your search
@@ -93,6 +93,9 @@ size_t indent;
|
||||
// ----
|
||||
|
||||
const char* read_src() {
|
||||
if (src.meta.closed) {
|
||||
return "main: read error: unexpected EOF";
|
||||
}
|
||||
src.compact();
|
||||
if (src.meta.wi >= src.data.len) {
|
||||
return "main: src buffer is full";
|
||||
@@ -100,12 +103,12 @@ const char* read_src() {
|
||||
size_t n = fread(src.data.ptr + src.meta.wi, sizeof(uint8_t),
|
||||
src.data.len - src.meta.wi, stdin);
|
||||
src.meta.wi += n;
|
||||
if (n == 0) {
|
||||
if (feof(stdin)) {
|
||||
return "main: read error: unexpected EOF";
|
||||
} else {
|
||||
return "main: read error";
|
||||
}
|
||||
if (n > 0) {
|
||||
// No-op.
|
||||
} else if (feof(stdin)) {
|
||||
src.meta.closed = true;
|
||||
} else {
|
||||
return "main: read error";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -160,6 +160,10 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
b.printf(", ((uint64_t)(%s%s - %s%s)))", iopPrefix, name, io0Prefix, name)
|
||||
return nil
|
||||
|
||||
case t.IDIsClosed:
|
||||
b.printf("(%s && %s->meta.closed)", name, name)
|
||||
return nil
|
||||
|
||||
case t.IDMark:
|
||||
b.printf("((uint64_t)(%s%s - %s%s))", iopPrefix, name, io0Prefix, name)
|
||||
return nil
|
||||
|
||||
@@ -249,6 +249,7 @@ var Funcs = []string{
|
||||
|
||||
"io_reader.available() u64",
|
||||
"io_reader.count_since(mark: u64) u64",
|
||||
"io_reader.is_closed() bool",
|
||||
"io_reader.mark() u64",
|
||||
"io_reader.position() u64",
|
||||
"io_reader.since(mark: u64) slice u8",
|
||||
|
||||
+9
-7
@@ -491,13 +491,14 @@ const (
|
||||
IDCanUndoByte = ID(0x160)
|
||||
IDCountSince = ID(0x161)
|
||||
IDHistoryAvailable = ID(0x162)
|
||||
IDMark = ID(0x163)
|
||||
IDPosition = ID(0x164)
|
||||
IDSince = ID(0x165)
|
||||
IDSkip = ID(0x166)
|
||||
IDSkip32 = ID(0x167)
|
||||
IDSkip32Fast = ID(0x168)
|
||||
IDTake = ID(0x169)
|
||||
IDIsClosed = ID(0x163)
|
||||
IDMark = ID(0x164)
|
||||
IDPosition = ID(0x165)
|
||||
IDSince = ID(0x166)
|
||||
IDSkip = ID(0x167)
|
||||
IDSkip32 = ID(0x168)
|
||||
IDSkip32Fast = ID(0x169)
|
||||
IDTake = ID(0x16A)
|
||||
|
||||
IDCopyFromSlice = ID(0x170)
|
||||
IDCopyN32FromHistory = ID(0x171)
|
||||
@@ -841,6 +842,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDCanUndoByte: "can_undo_byte",
|
||||
IDCountSince: "count_since",
|
||||
IDHistoryAvailable: "history_available",
|
||||
IDIsClosed: "is_closed",
|
||||
IDMark: "mark",
|
||||
IDPosition: "position",
|
||||
IDSince: "since",
|
||||
|
||||
Reference in new issue
Block a user