aboutsummaryrefslogtreecommitdiff
path: root/emcc.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-21 00:25:34 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-10-21 00:25:34 +0100
commit47905e954726ff95ce5e4493def91b9107668c94 (patch)
treef0f7d0e8b649af74896fd12a8d5ecc466fdbac9c /emcc.c
parent12491021d0541ded9f8f160a15b886a36e5aa8ac (diff)
downloadpuzzles-47905e954726ff95ce5e4493def91b9107668c94.zip
puzzles-47905e954726ff95ce5e4493def91b9107668c94.tar.gz
puzzles-47905e954726ff95ce5e4493def91b9107668c94.tar.bz2
puzzles-47905e954726ff95ce5e4493def91b9107668c94.tar.xz
Revert "WASM: move save file encoding from JS into C."
Now that save files are (even more) officially ASCII, it's perfectly safe to pass them to JavaScript as UTF-8 strings. This means that the form in which save files are shipped from C to JavaScript is the same is the form in which they're shipped from JavaScript to C. That allows for doing new things with them, like writing them to local storage. This reverts commit f729f51e475ff98d0caf529f0723ef810b1c88ef.
Diffstat (limited to 'emcc.c')
-rw-r--r--emcc.c49
1 files changed, 4 insertions, 45 deletions
diff --git a/emcc.c b/emcc.c
index 5f21476..9f46c33 100644
--- a/emcc.c
+++ b/emcc.c
@@ -773,53 +773,12 @@ struct savefile_write_ctx {
size_t pos;
};
-static void savefile_write(void *vctx, const void *vbuf, int len)
+static void savefile_write(void *vctx, const void *buf, int len)
{
- static const unsigned char length[256] = {
- /*
- * Assign a length of 1 to any printable ASCII character that
- * can be written literally in URI-encoding, i.e.
- *
- * A-Z a-z 0-9 - _ . ! ~ * ' ( )
- *
- * Assign length 3 (for % and two hex digits) to all other
- * byte values.
- */
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 3,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
- 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1,
- 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- };
- static const char hexdigits[] = "0123456789ABCDEF";
-
struct savefile_write_ctx *ctx = (struct savefile_write_ctx *)vctx;
- const unsigned char *buf = (const unsigned char *)vbuf;
- for (int i = 0; i < len; i++) {
- unsigned char c = buf[i];
- int clen = length[c];
- if (ctx->buffer) {
- if (clen == 1) {
- ctx->buffer[ctx->pos] = c;
- } else {
- ctx->buffer[ctx->pos] = '%';
- ctx->buffer[ctx->pos+1] = hexdigits[c >> 4];
- ctx->buffer[ctx->pos+2] = hexdigits[c & 0xF];
- }
- }
- ctx->pos += clen;
- }
+ if (ctx->buffer)
+ memcpy(ctx->buffer + ctx->pos, buf, len);
+ ctx->pos += len;
}
char *get_save_file(void)