diff options
| author | eunhhu <[email protected]> | 2026-10-13 06:16:12 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-13 06:16:12 +0100 |
| commit | 8568c8732ca36673b073688bdf99cc25d6b8065a (patch) | |
| tree | 85929b84713004f5fd00d97e14cbefed7f8c6a90 /cli | |
| parent | 109ea31ef2ca06210e196c1b8fa7005cd9ef5ce9 (diff) | |
| download | pure-8568c8732ca36673b073688bdf99cc25d6b8065a.tar.gz pure-8568c8732ca36673b073688bdf99cc25d6b8065a.zip | |
Module format and executor: 027's stage 2a: BYTES_SLICE (bytes from a up to before c, whole positions inside, numbers or i64s), BYTE (one byte of an i64 0-255), BYTES_LOAD and BYTES_STORE (an event's 32 values held by name, 0-15 bytes and 16-31 texts so a text's hold UTF-8 alone, emptied as an event or a view's body begins, appended to in place, counted in the room: MEMORY past it), CONCAT of bytes, NUM_TEXT in a format (a width padded with spaces or with zeros after the sign, d x X b o of an i64 or a whole number, f with 0-30 digits; -0 as 0), a reply of a held value kept by value, LEN wherever a value is read (it had been for handlers alone); pure-run's message NAME @PATH (the file's bytes, of any size); unit tests (16 formats, 9 slices, held values set, appended, set to a part of themselves, emptied each event, a doubling stopped by the room, a reply kept, 7 refused)
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/pure-run.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/cli/pure-run.c b/cli/pure-run.c index e62bc98..97bd6d5 100644 --- a/cli/pure-run.c +++ b/cli/pure-run.c @@ -13,7 +13,8 @@ * every N commands (and at the end), so N events share one commit. * down NAME | up NAME | frame [N] | type NAME HEX|- | message NAME HEX|- | tick NAME | time MS | replace PATH | save | show * budget N (the work an event may do) | memory N (what the states may hold) | work (the last event's work) - * (type gives a text input its bytes, message a message input its payload, laid out as the module says.) + * (type gives a text input its bytes, message a message input its payload, laid out as the module says; + * message NAME @PATH gives it the bytes of the file at PATH, of any size.) * Text states and text views print as JSON strings; cursors as byte positions; * lists as arrays of objects; indices as positions; a table view as an array * with an object of its columns per row. A failed view or cell is null. */ @@ -173,10 +174,22 @@ int main(int argc, char **argv) { for (size_t i = 0; i < length && length * 2 == strlen(data); ++i) text[i] = (unsigned char)(hex(data[2 * i]) << 4 | hex(data[2 * i + 1])); PureSpan given = {text, length}; - if (input < 0) failure = "unknown input"; + unsigned char *read = NULL; /* message NAME @PATH: the file's bytes */ + if (data[0] == '@') { + FILE *file = fopen(data + 1, "rb"); + long size = file && !fseek(file, 0, SEEK_END) ? ftell(file) : -1; + if (size >= 0 && !fseek(file, 0, SEEK_SET) && (read = malloc(size ? (size_t)size : 1)) && + fread(read, 1, (size_t)size, file) == (size_t)size) + given = (PureSpan){read, (size_t)size}; + else failure = "cannot read the file"; + if (file) fclose(file); + } + if (failure) { + } else if (input < 0) failure = "unknown input"; else if ((command[0] == 't' ? pure_app_text(&app, (uint32_t)input, given) : pure_app_message(&app, (uint32_t)input, NULL, -1, given)) != PURE_OK) failure = "event failed"; + free(read); } else if (!strcmp(command, "tick")) { int input = pure_module_input(app.module, argument); if (input < 0) failure = "unknown input"; |
