static void write_indent(Context* ctx) { static char s_indent[] = " " " "; static size_t s_indent_len = sizeof(s_indent) - 1; size_t indent = ctx->indent; while (indent > s_indent_len) { wasm_write_data(&ctx->stream, s_indent, s_indent_len, NULL); indent -= s_indent_len; } if (indent > 0) { wasm_write_data(&ctx->stream, s_indent, indent, NULL); } }
static void write_next_char(Context* ctx) { switch (ctx->next_char) { case NEXT_CHAR_SPACE: wasm_write_data(&ctx->stream, " ", 1, NULL); break; case NEXT_CHAR_NEWLINE: case NEXT_CHAR_FORCE_NEWLINE: wasm_write_data(&ctx->stream, "\n", 1, NULL); write_indent(ctx); break; default: case NEXT_CHAR_NONE: break; } ctx->next_char = NEXT_CHAR_NONE; }
static void write_data_with_next_char(Context* ctx, const void* src, size_t size) { write_next_char(ctx); wasm_write_data(&ctx->stream, src, size, NULL); }
static void write_putc(Context* ctx, char c) { wasm_write_data(&ctx->stream, &c, 1, NULL); }
void wasm_writef(WasmStream* stream, const char* format, ...) { WASM_SNPRINTF_ALLOCA(buffer, length, format); wasm_write_data(stream, buffer, length, NULL); }