Substitui barras de caixa (─ ═ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴), travessões (—), setas (→ ←), reticências (…), bullets (•), multiplicação (×) e guillemets (› ‹) por equivalentes ASCII. Acentos portugueses são preservados.
69 lines
2.0 KiB
C
69 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include "tinyblocks/tinyblocks.h"
|
|
|
|
/* -- Vtable --- */
|
|
static void integer_eval(TinyBlocks_Block* self, TinyBlocks* rt)
|
|
{
|
|
(void)rt;
|
|
TinyBlocks_IntegerBlock* ib = (TinyBlocks_IntegerBlock*)self;
|
|
tb_block_set_output(self, 0, tb_value_integer(ib->value));
|
|
self->dirty = false;
|
|
}
|
|
|
|
static void integer_destroy(TinyBlocks_Block* self, TinyBlocks* rt)
|
|
{
|
|
(void)self; (void)rt; /* nada a liberar além do base */
|
|
}
|
|
|
|
static size_t integer_to_string(TinyBlocks_Block* self, TinyBlocks* rt,
|
|
char* buf, size_t sz)
|
|
{
|
|
(void)rt;
|
|
TinyBlocks_IntegerBlock* ib = (TinyBlocks_IntegerBlock*)self;
|
|
return (size_t)snprintf(buf, sz, "%lld", (long long)ib->value);
|
|
}
|
|
|
|
static TinyBlocks_Block* integer_clone(const TinyBlocks_Block* self, TinyBlocks* rt)
|
|
{
|
|
const TinyBlocks_IntegerBlock* ib = (const TinyBlocks_IntegerBlock*)self;
|
|
TinyBlocks_IntegerBlock* clone = tb_integer_block_create(rt, ib->value);
|
|
if (clone && self->name) clone->base.name = tb_strdup(rt, self->name);
|
|
return (TinyBlocks_Block*)clone;
|
|
}
|
|
|
|
static const TinyBlocks_BlockVTable s_integer_vtable = {
|
|
.eval = integer_eval,
|
|
.destroy = integer_destroy,
|
|
.to_string = integer_to_string,
|
|
.clone = integer_clone,
|
|
};
|
|
|
|
/* -- Ciclo de vida --- */
|
|
TinyBlocks_IntegerBlock* tb_integer_block_create(TinyBlocks* rt, int64_t value)
|
|
{
|
|
TinyBlocks_IntegerBlock* ib = (TinyBlocks_IntegerBlock*)tb_block_alloc_base(
|
|
rt, TB_KIND_INTEGER, sizeof(TinyBlocks_IntegerBlock),
|
|
0, 1, &s_integer_vtable);
|
|
if (!ib) return NULL;
|
|
ib->value = value;
|
|
return ib;
|
|
}
|
|
|
|
void tb_integer_block_destroy(TinyBlocks_IntegerBlock* ib, TinyBlocks* rt)
|
|
{
|
|
tb_block_destroy(&ib->base, rt);
|
|
}
|
|
|
|
/* -- Acesso --- */
|
|
int64_t tb_integer_block_get(const TinyBlocks_IntegerBlock* ib)
|
|
{
|
|
return ib ? ib->value : 0;
|
|
}
|
|
|
|
void tb_integer_block_set(TinyBlocks_IntegerBlock* ib, int64_t value)
|
|
{
|
|
if (!ib) return;
|
|
ib->value = value;
|
|
ib->base.dirty = true;
|
|
}
|