Comentários: separadores com no máximo "---"

Trechos com quatro ou mais hífens dentro de comentários viram "---"
(strings não mudam).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-23 07:24:19 -03:00
1 parent 374b445a8f
commit 80bd330766
40 files changed
+137 -137

No files matched your search

+1 -1
View File
@@ -45,7 +45,7 @@ TB_API int tb_image_format_count(void);
TB_API TinyBlocks_Image* tb_image_load(const char* path); TB_API TinyBlocks_Image* tb_image_load(const char* path);
TB_API bool tb_image_save(const TinyBlocks_Image* img, const char* path); TB_API bool tb_image_save(const TinyBlocks_Image* img, const char* path);
/* -- Armazem de imagens nomeadas (usado pelos blocos "desenhe imagem") ---- /* -- Armazem de imagens nomeadas (usado pelos blocos "desenhe imagem") ---
* Uma imagem carregada ganha um NOME (ex: "c0bot" e "c0bot.png") e um NUMERO * Uma imagem carregada ganha um NOME (ex: "c0bot" e "c0bot.png") e um NUMERO
* (1, 2, 3... na ordem em que entrou). O armazem mantem uma referencia, entao * (1, 2, 3... na ordem em que entrou). O armazem mantem uma referencia, entao
* o palco pode desenhar a imagem depois sem se preocupar com a memoria. */ * o palco pode desenhar a imagem depois sem se preocupar com a memoria. */
+2 -2
View File
@@ -43,7 +43,7 @@ static const char* path_basename(const char* p) {
return s ? s + 1 : p; return s ? s + 1 : p;
} }
/* -- Modulos de codigo (bundle) e watcher de arquivos ------------------- */ /* -- Modulos de codigo (bundle) e watcher de arquivos --- */
typedef struct { typedef struct {
char name[64]; char name[64];
@@ -416,7 +416,7 @@ bool tb_api_reload(int idx) {
return tb_api_load(path) >= 0; return tb_api_load(path) >= 0;
} }
/* -- Descoberta de libraries no disco ---------------------------------- */ /* -- Descoberta de libraries no disco --- */
static bool try_path(const char* dir, const char* file, char* out, size_t cap) { static bool try_path(const char* dir, const char* file, char* out, size_t cap) {
if (!dir || !dir[0]) return false; if (!dir || !dir[0]) return false;
+2 -2
View File
@@ -88,7 +88,7 @@ char* tb_base64_decode_str(const char* s, size_t* out_len) {
return (char*)tb_base64_decode(s, out_len); return (char*)tb_base64_decode(s, out_len);
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_encode(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_encode(TinyBlocks_Block* self, TinyBlocks* rt) {
@@ -105,7 +105,7 @@ static void eval_decode(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------ */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
@@ -545,7 +545,7 @@ static TinyBlocks_JsonValue* blueprint_csv_tree(const TbBlueprint* bp) {
return arr; return arr;
} }
/* -- Formatos (TbBpFormat) ------------------------------------------------ */ /* -- Formatos (TbBpFormat) --- */
static char* buf_take(Buf* b) { static char* buf_take(Buf* b) {
if (!b->p) { b->p = (char*)malloc(1); if (b->p) b->p[0] = 0; } if (!b->p) { b->p = (char*)malloc(1); if (b->p) b->p[0] = 0; }
+1 -1
View File
@@ -121,7 +121,7 @@ bool tb_bmp_save(const TinyBlocks_Image* img, const char* path) {
return ok; return ok;
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
TinyBlocks_Value v = tb_block_get_input(self, rt, i); TinyBlocks_Value v = tb_block_get_input(self, rt, i);
@@ -12,7 +12,7 @@ static void eval_noop(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Fluxos ------------------------------------------------------------------ /* -- Fluxos ---
* step: 0 = entrando, 1 = vai testar/entrar na volta, 2 = a volta acabou * step: 0 = entrando, 1 = vai testar/entrar na volta, 2 = a volta acabou
* (pausa um quadro, como no Scratch, e testa de novo). */ * (pausa um quadro, como no Scratch, e testa de novo). */
@@ -53,7 +53,7 @@ static const TinyBlocks_FlowClass s_forever = { 1, { NULL }, true, forever_n
static const TinyBlocks_FlowClass s_if = { 1, { NULL }, false, if_next, NULL }; static const TinyBlocks_FlowClass s_if = { 1, { NULL }, false, if_next, NULL };
static const TinyBlocks_FlowClass s_if_else = { 2, { "senão" }, false, if_else_next, NULL }; static const TinyBlocks_FlowClass s_if_else = { 2, { "senão" }, false, if_else_next, NULL };
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+5 -5
View File
@@ -40,7 +40,7 @@ static void push_point(TinyBlocks_JsonValue* arr, double x, double y) {
tb_json_release(pt); tb_json_release(pt);
} }
/* -- Curvas -------------------------------------------------------------- */ /* -- Curvas --- */
TinyBlocks_JsonValue* tb_curves_line(double x0, double y0, double x1, double y1, TinyBlocks_JsonValue* tb_curves_line(double x0, double y0, double x1, double y1,
int steps) { int steps) {
@@ -104,7 +104,7 @@ TinyBlocks_JsonValue* tb_curves_circle(double cx, double cy, double r, int steps
return tb_curves_arc(cx, cy, r, 0.0, 360.0, steps); return tb_curves_arc(cx, cy, r, 0.0, 360.0, steps);
} }
/* -- Leitura ------------------------------------------------------------- */ /* -- Leitura --- */
int tb_curves_count(const TinyBlocks_JsonValue* pts) { int tb_curves_count(const TinyBlocks_JsonValue* pts) {
if (!pts || tb_json_kind(pts) != TB_JSON_ARRAY) return 0; if (!pts || tb_json_kind(pts) != TB_JSON_ARRAY) return 0;
@@ -128,7 +128,7 @@ bool tb_curves_point(const TinyBlocks_JsonValue* pts, int i, double* x, double*
return ok; return ok;
} }
/* -- Helpers de entrada -------------------------------------------------- */ /* -- Helpers de entrada --- */
static int64_t in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static int64_t in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
@@ -149,7 +149,7 @@ static void out_pts(TinyBlocks_Block* self, TinyBlocks_JsonValue* pts) {
self->dirty = false; self->dirty = false;
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_line(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_line(TinyBlocks_Block* self, TinyBlocks* rt) {
out_pts(self, tb_curves_line(tb_block_input_number(self,rt,0, 0), tb_block_input_number(self,rt,1, 0), out_pts(self, tb_curves_line(tb_block_input_number(self,rt,0, 0), tb_block_input_number(self,rt,1, 0),
@@ -195,7 +195,7 @@ static void eval_pointy(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------ */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
@@ -19,7 +19,7 @@
#include <tb_editor_internal.h> #include <tb_editor_internal.h>
#include "tb_editor_files.h" #include "tb_editor_files.h"
/* -- Geometria ------------------------------------------------------------ */ /* -- Geometria --- */
#define FD_HEAD_H 46 #define FD_HEAD_H 46
#define FD_BAR_H 44 #define FD_BAR_H 44
#define FD_SIDE_W 196 #define FD_SIDE_W 196
@@ -87,7 +87,7 @@ static void fd_layout(Ed* ed, FdL* L) {
L->cancel_x = L->ok_x - 10.f - FD_BTN_W; L->cancel_x = L->ok_x - 10.f - FD_BTN_W;
} }
/* -- Utilidades ----------------------------------------------------------- */ /* -- Utilidades --- */
static unsigned fd_now_ms(void) { static unsigned fd_now_ms(void) {
struct timespec ts; struct timespec ts;
@@ -213,7 +213,7 @@ static void fd_time_str(char* out, size_t cap, long long t) {
strftime(out, cap, "%d/%m/%Y %H:%M", &tmv); strftime(out, cap, "%d/%m/%Y %H:%M", &tmv);
} }
/* -- Listagem ------------------------------------------------------------- */ /* -- Listagem --- */
static int fd_cmp(const void* a, const void* b) { static int fd_cmp(const void* a, const void* b) {
const FileEnt* x = a; const FileEnt* x = a;
@@ -346,7 +346,7 @@ static void fd_places(Ed* ed) {
fd_add_place(F, "Raiz do sistema", "/"); fd_add_place(F, "Raiz do sistema", "/");
} }
/* -- Trilha da pasta atual (segmentos clicaveis) ------------------------- */ /* -- Trilha da pasta atual (segmentos clicaveis) --- */
#define FD_MAX_CRUMBS 48 #define FD_MAX_CRUMBS 48
typedef struct { typedef struct {
int n, first; /* segmentos; primeiro visivel */ int n, first; /* segmentos; primeiro visivel */
@@ -400,7 +400,7 @@ static void fd_crumbs(Ed* ed, const FdL* L, FdCrumbs* K) {
} }
} }
/* -- Acoes ---------------------------------------------------------------- */ /* -- Acoes --- */
static void fd_ensure_visible(Ed* ed) { static void fd_ensure_visible(Ed* ed) {
FileDlg* F = &ed->fdlg; FileDlg* F = &ed->fdlg;
@@ -549,7 +549,7 @@ void tb_editor_files_open(Ed* ed, int mode, const char* def) {
fd_ensure_visible(ed); fd_ensure_visible(ed);
} }
/* -- Desenho -------------------------------------------------------------- */ /* -- Desenho --- */
static void fd_icon_folder(TinyBlocks_RenderableBlock* rb, float x, float y, bool dim) { static void fd_icon_folder(TinyBlocks_RenderableBlock* rb, float x, float y, bool dim) {
Col c = COL_FD_FOLDER, d = COL_FD_FOLDER_DARK; Col c = COL_FD_FOLDER, d = COL_FD_FOLDER_DARK;
@@ -797,7 +797,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
} }
} }
/* -- Entrada -------------------------------------------------------------- */ /* -- Entrada --- */
static void fd_rescan_keep(Ed* ed) { static void fd_rescan_keep(Ed* ed) {
FileDlg* F = &ed->fdlg; FileDlg* F = &ed->fdlg;
@@ -53,7 +53,7 @@ static const Col IMG_PALETTE[12] = {
{0.55f,0.38f,0.24f,1.f}, {0.60f,0.60f,0.60f,1.f} {0.55f,0.38f,0.24f,1.f}, {0.60f,0.60f,0.60f,1.f}
}; };
/* Cor: HSV (roda de matiz + quadrado saturacao/valor) ------------------- */ /* Cor: HSV (roda de matiz + quadrado saturacao/valor) --- */
static Col img_hsv_col(float h, float sat, float v) { static Col img_hsv_col(float h, float sat, float v) {
float c = v * sat; float c = v * sat;
float hp = h / 60.f; float hp = h / 60.f;
@@ -95,7 +95,7 @@ static void img_hsv_apply(Tab* T) {
T->img_swatch = -1; T->img_swatch = -1;
} }
/* Geometria ------------------------------------------------------------- /* Geometria ---
* Layout (como no Krita): ferramentas na coluna da esquerda, tela no meio e * Layout (como no Krita): ferramentas na coluna da esquerda, tela no meio e
* na direita uma coluna com a roda de cores em cima e as camadas embaixo. */ * na direita uma coluna com a roda de cores em cima e as camadas embaixo. */
#define IMG_TOOL_W 54 /* coluna de ferramentas (esquerda) */ #define IMG_TOOL_W 54 /* coluna de ferramentas (esquerda) */
@@ -248,7 +248,7 @@ static void img_side_btn(Ed* ed, int which, float* x, float* y, float* w, float*
(void)ed; (void)ed;
} }
/* Camadas --------------------------------------------------------------- */ /* Camadas --- */
#define IMG_THUMB_W 40 #define IMG_THUMB_W 40
#define IMG_THUMB_H 30 #define IMG_THUMB_H 30
/* Miniatura da camada (cacheada por revisao) - como no painel do Scratch */ /* Miniatura da camada (cacheada por revisao) - como no painel do Scratch */
@@ -383,7 +383,7 @@ static bool img_layer_add(Ed* ed, Tab* T, int kind, const char* src, const char*
return true; return true;
} }
/* Desenho --------------------------------------------------------------- */ /* Desenho --- */
static bool img_pixel_at(Ed* ed, Tab* T, float mx, float my, int* px, int* py) { static bool img_pixel_at(Ed* ed, Tab* T, float mx, float my, int* px, int* py) {
float dx, dy, dw, dh; float dx, dy, dw, dh;
img_view(ed, T, &dx, &dy, &dw, &dh); img_view(ed, T, &dx, &dy, &dw, &dh);
@@ -514,9 +514,9 @@ static void img_flatten(Tab* T, TinyBlocks_Image* dst) {
} }
} }
/* Miniatura do documento (cache; reconstruida so quando algo muda) -------- */ /* Miniatura do documento (cache; reconstruida so quando algo muda) --- */
/* Selecao: mover / redimensionar pixels ---------------------------------- */ /* Selecao: mover / redimensionar pixels --- */
void tb_editor_image_sel_reset(Tab* T) { void tb_editor_image_sel_reset(Tab* T) {
if (T->img_sel.buf) { tb_image_release(T->img_sel.buf); T->img_sel.buf = NULL; } if (T->img_sel.buf) { tb_image_release(T->img_sel.buf); T->img_sel.buf = NULL; }
memset(&T->img_sel, 0, sizeof(T->img_sel)); memset(&T->img_sel, 0, sizeof(T->img_sel));
@@ -606,7 +606,7 @@ static void img_sel_resize(Tab* T, int hnd, int px, int py) {
if (S->h < 1) S->h = 1; if (S->h < 1) S->h = 1;
} }
/* Undo ------------------------------------------------------------------ */ /* Undo --- */
static void img_undo_push(Tab* T) { static void img_undo_push(Tab* T) {
ImgLayer* L = img_active(T); ImgLayer* L = img_active(T);
if (!L || !L->img) return; if (!L || !L->img) return;
@@ -636,7 +636,7 @@ static void img_undo_do(Tab* T) {
T->img_rev++; T->img_rev++;
} }
/* Icones das ferramentas ------------------------------------------------ */ /* Icones das ferramentas --- */
static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c) { static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c) {
switch (tool) { switch (tool) {
case IT_SEL: case IT_SEL:
@@ -672,7 +672,7 @@ static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, fl
} }
} }
/* Render ---------------------------------------------------------------- */ /* Render --- */
void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
Tab* T = &CT; Tab* T = &CT;
img_ensure(ed, T); img_ensure(ed, T);
@@ -805,7 +805,7 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
labels[i], enabled ? COL_TEXT : COL_TEXT_DIM, FS_UI - 1); labels[i], enabled ? COL_TEXT : COL_TEXT_DIM, FS_UI - 1);
} }
/* ---- widget novo: slider de zoom ---- */ /* --- widget novo: slider de zoom --- */
{ {
float sx, sy, sw, sh; float sx, sy, sw, sh;
img_zoom_slider(ed, &sx, &sy, &sw, &sh); img_zoom_slider(ed, &sx, &sy, &sw, &sh);
@@ -907,7 +907,7 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_text_c(rb, px + IMG_PAD, img_pal_y(ed) + 4 * 30 + 6, inf, COL_TEXT, FS_UI); rb_text_c(rb, px + IMG_PAD, img_pal_y(ed) + 4 * 30 + 6, inf, COL_TEXT, FS_UI);
} }
/* ---- camadas: embaixo da roda de cores (como no Krita) ---- */ /* --- camadas: embaixo da roda de cores (como no Krita) --- */
rb_line(rb, px + IMG_PAD, img_layers_title_y(ed) - 14, rb_line(rb, px + IMG_PAD, img_layers_title_y(ed) - 14,
px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, COL_PAINT_LINE); px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, COL_PAINT_LINE);
rb_text_c(rb, px + IMG_PAD, img_layers_title_y(ed), "Camadas", COL_TEXT_DIM, 11.f); rb_text_c(rb, px + IMG_PAD, img_layers_title_y(ed), "Camadas", COL_TEXT_DIM, 11.f);
@@ -957,7 +957,7 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
} }
} }
/* Entrada --------------------------------------------------------------- */ /* Entrada --- */
static void img_clear_layer(Tab* T) { static void img_clear_layer(Tab* T) {
ImgLayer* L = img_active(T); ImgLayer* L = img_active(T);
if (!L || !L->img) return; if (!L || !L->img) return;
@@ -51,7 +51,7 @@ static char s_dir[512] = "";
const char* tb_ed_modules_dir(void) { return s_dir; } const char* tb_ed_modules_dir(void) { return s_dir; }
/* -- utilidades ---------------------------------------------------------- */ /* -- utilidades --- */
static bool file_exists(const char* p) { static bool file_exists(const char* p) {
struct stat st; struct stat st;
@@ -157,7 +157,7 @@ static bool resolve_files(void) {
return ok; return ok;
} }
/* -- carga --------------------------------------------------------------- */ /* -- carga --- */
bool tb_ed_modules_load(Ed* ed) { bool tb_ed_modules_load(Ed* ed) {
if (!tb_api_runtime()) tb_api_init(ed->rt); if (!tb_api_runtime()) tb_api_init(ed->rt);
@@ -26,7 +26,7 @@ static EnvPair s_env[ENV_MAX];
static int s_env_n = 0; static int s_env_n = 0;
static char s_err[256] = ""; static char s_err[256] = "";
/* -- Store --------------------------------------------------------------- */ /* -- Store --- */
static char* dup_str(const char* s) { static char* dup_str(const char* s) {
if (!s) s = ""; if (!s) s = "";
@@ -200,7 +200,7 @@ const char* tb_environ_env_path(void) {
return (e && e[0]) ? e : ""; return (e && e[0]) ? e : "";
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_get(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_get(TinyBlocks_Block* self, TinyBlocks* rt) {
@@ -223,7 +223,7 @@ static void eval_unset(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------ */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+5 -5
View File
@@ -11,7 +11,7 @@
#include <tinyblocks/tinyblocks.h> #include <tinyblocks/tinyblocks.h>
#include "tb_errors.h" #include "tb_errors.h"
/* -- Saidas --------------------------------------------------------------- */ /* -- Saidas --- */
/* Toma a referencia de r */ /* Toma a referencia de r */
static void out_result(TinyBlocks_Block* self, TinyBlocks_Result* r) { static void out_result(TinyBlocks_Block* self, TinyBlocks_Result* r) {
@@ -25,7 +25,7 @@ static void out_bool(TinyBlocks_Block* self, bool b) {
self->dirty = false; self->dirty = false;
} }
/* -- Blocos: resultados --------------------------------------------------- */ /* -- Blocos: resultados --- */
/* "tente obter (x)": avalia x (o tipo tem lazy_inputs); erro vira Erro(msg), /* "tente obter (x)": avalia x (o tipo tem lazy_inputs); erro vira Erro(msg),
valor vira Ok(valor) */ valor vira Ok(valor) */
@@ -102,7 +102,7 @@ static void eval_message(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Blocos: tratamento --------------------------------------------------- */ /* -- Blocos: tratamento --- */
/* "lance o erro [msg]" (raise / panic!) */ /* "lance o erro [msg]" (raise / panic!) */
static void eval_raise(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_raise(TinyBlocks_Block* self, TinyBlocks* rt) {
@@ -124,7 +124,7 @@ static void eval_nop(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Fluxos: tente / se der erro / finalmente ------------------------------- /* -- Fluxos: tente / se der erro / finalmente ---
* step: 0 entrando, 1 no "tente", 2 no "se der erro", 3 no "finalmente". */ * step: 0 entrando, 1 no "tente", 2 no "se der erro", 3 no "finalmente". */
static void catch_enter(TinyBlocks_Flow* f, const char* msg) { static void catch_enter(TinyBlocks_Flow* f, const char* msg) {
@@ -182,7 +182,7 @@ static const TinyBlocks_FlowClass s_try_catch = {
static const TinyBlocks_FlowClass s_try = { static const TinyBlocks_FlowClass s_try = {
3, { "se der erro", "finalmente" }, false, try_next, try_error }; 3, { "se der erro", "finalmente" }, false, try_next, try_error };
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+2 -2
View File
@@ -108,7 +108,7 @@ static void eval_close(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Pastas --------------------------------------------------------------- */ /* -- Pastas --- */
static int cmp_name(const void* a, const void* b) { static int cmp_name(const void* a, const void* b) {
return strcasecmp(*(char* const*)a, *(char* const*)b); return strcasecmp(*(char* const*)a, *(char* const*)b);
@@ -206,7 +206,7 @@ static void eval_exists(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------ */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+4 -4
View File
@@ -77,7 +77,7 @@ TinyBlocks_Image* tb_imglib_scale(const TinyBlocks_Image* img,
return out; return out;
} }
/* -- Helpers de entrada -------------------------------------------------- */ /* -- Helpers de entrada --- */
static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
TinyBlocks_Value v = tb_block_get_input(self, rt, i); TinyBlocks_Value v = tb_block_get_input(self, rt, i);
@@ -92,7 +92,7 @@ static void out_img(TinyBlocks_Block* self, TinyBlocks_Image* img) {
self->dirty = false; self->dirty = false;
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_new(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_new(TinyBlocks_Block* self, TinyBlocks* rt) {
int w = (int)tb_block_input_number(self, rt, 0, 0), h = (int)tb_block_input_number(self, rt, 1, 0); int w = (int)tb_block_input_number(self, rt, 0, 0), h = (int)tb_block_input_number(self, rt, 1, 0);
@@ -155,7 +155,7 @@ static void eval_save(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Conversoes ---------------------------------------------------------- */ /* -- Conversoes --- */
#define IMG_MAX_PIXELS (4096 * 4096) #define IMG_MAX_PIXELS (4096 * 4096)
@@ -304,7 +304,7 @@ static void eval_to_text(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------ */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+4 -4
View File
@@ -22,7 +22,7 @@
#include <tb_graphics.h> #include <tb_graphics.h>
#include "tb_input_lib.h" #include "tb_input_lib.h"
/* -- Nomes de tecla ------------------------------------------------------- */ /* -- Nomes de tecla --- */
typedef struct { const char* name; int key; } KeyName; typedef struct { const char* name; int key; } KeyName;
@@ -89,7 +89,7 @@ TB_API const char* tb_input_key_name(int key) {
return ""; return "";
} }
/* -- Entradas/saidas ------------------------------------------------------ */ /* -- Entradas/saidas --- */
@@ -117,7 +117,7 @@ static void out_bool(TinyBlocks_Block* self, bool b) {
self->dirty = false; self->dirty = false;
} }
/* -- Blocos --------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_mouse_x(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; out_num(self, roundf(tb_input_mouse_x())); } static void eval_mouse_x(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; out_num(self, roundf(tb_input_mouse_x())); }
static void eval_mouse_y(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; out_num(self, roundf(tb_input_mouse_y())); } static void eval_mouse_y(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; out_num(self, roundf(tb_input_mouse_y())); }
@@ -172,7 +172,7 @@ static void eval_reset_timer(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+1 -1
View File
@@ -129,7 +129,7 @@ bool tb_jpg_save(const TinyBlocks_Image* img, const char* path, int quality) {
return ok; return ok;
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
TinyBlocks_Value v = tb_block_get_input(self, rt, i); TinyBlocks_Value v = tb_block_get_input(self, rt, i);
@@ -10,7 +10,7 @@
TB_API const TinyBlocks_LibraryDescriptor* tb_markdown_get_library(void); TB_API const TinyBlocks_LibraryDescriptor* tb_markdown_get_library(void);
/* -- API C (resultados com malloc; libere com free) ---------------------- */ /* -- API C (resultados com malloc; libere com free) --- */
TB_API char* tb_markdown_to_html(const char* md); TB_API char* tb_markdown_to_html(const char* md);
TB_API char* tb_markdown_to_xml(const char* md); TB_API char* tb_markdown_to_xml(const char* md);
TB_API char* tb_markdown_to_svg(const char* md); TB_API char* tb_markdown_to_svg(const char* md);
@@ -18,7 +18,7 @@
static char s_err[160] = ""; static char s_err[160] = "";
const char* tb_markdown_last_error(void) { return s_err; } const char* tb_markdown_last_error(void) { return s_err; }
/* ---------------------------------------------------------------- Buffer */ /* --- Buffer */
typedef struct { char* p; size_t n, cap; } Buf; typedef struct { char* p; size_t n, cap; } Buf;
static bool b_res(Buf* b, size_t extra) { static bool b_res(Buf* b, size_t extra) {
if (b->n + extra + 1 <= b->cap) return true; if (b->n + extra + 1 <= b->cap) return true;
@@ -49,7 +49,7 @@ static void b_esc(Buf* b, const char* s, size_t n) {
} }
} }
/* ----------------------------------------------------------------- Blocos */ /* --- Blocos */
typedef enum { BLK_H, BLK_P, BLK_LI, BLK_CODE, BLK_QUOTE, BLK_HR } BlkKind; typedef enum { BLK_H, BLK_P, BLK_LI, BLK_CODE, BLK_QUOTE, BLK_HR } BlkKind;
typedef struct { typedef struct {
BlkKind kind; BlkKind kind;
@@ -208,7 +208,7 @@ static Doc* parse(const char* md) {
return d; return d;
} }
/* ---------------------------------------------------------------- Inline */ /* --- Inline */
/* Serializa inline markdown para HTML (xml=false) ou XML (xml=true). */ /* Serializa inline markdown para HTML (xml=false) ou XML (xml=true). */
static void inline_out(Buf* b, const char* s, bool xml) { static void inline_out(Buf* b, const char* s, bool xml) {
const char* bold0 = xml ? "<bold>" : "<strong>"; const char* bold0 = xml ? "<bold>" : "<strong>";
@@ -276,7 +276,7 @@ static void inline_out(Buf* b, const char* s, bool xml) {
} }
} }
/* ------------------------------------------------------------------ HTML */ /* --- HTML */
char* tb_markdown_to_html(const char* md) { char* tb_markdown_to_html(const char* md) {
s_err[0] = 0; s_err[0] = 0;
Doc* d = parse(md); Doc* d = parse(md);
@@ -320,7 +320,7 @@ char* tb_markdown_to_html(const char* md) {
return b.p; return b.p;
} }
/* ------------------------------------------------------------------- XML */ /* --- XML */
char* tb_markdown_to_xml(const char* md) { char* tb_markdown_to_xml(const char* md) {
s_err[0] = 0; s_err[0] = 0;
Doc* d = parse(md); Doc* d = parse(md);
@@ -367,7 +367,7 @@ char* tb_markdown_to_xml(const char* md) {
return b.p; return b.p;
} }
/* ------------------------------------------------------------------- SVG */ /* --- SVG */
char* tb_markdown_to_svg_opts(const char* md, int width, int font_size) { char* tb_markdown_to_svg_opts(const char* md, int width, int font_size) {
s_err[0] = 0; s_err[0] = 0;
if (width < 80) width = 640; if (width < 80) width = 640;
@@ -470,7 +470,7 @@ char* tb_markdown_to_svg_opts(const char* md, int width, int font_size) {
char* tb_markdown_to_svg(const char* md) { return tb_markdown_to_svg_opts(md, 640, 16); } char* tb_markdown_to_svg(const char* md) { return tb_markdown_to_svg_opts(md, 640, 16); }
/* ---------------------------------------------------------------- Blocos */ /* --- Blocos */
static void eval_html(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_html(TinyBlocks_Block* self, TinyBlocks* rt) {
char* s = tb_markdown_to_html(tb_block_input_text(self, rt, 0)); char* s = tb_markdown_to_html(tb_block_input_text(self, rt, 0));
tb_block_set_output(self, 0, tb_value_text(s ? s : "")); free(s); self->dirty = false; tb_block_set_output(self, 0, tb_value_text(s ? s : "")); free(s); self->dirty = false;
+5 -5
View File
@@ -26,7 +26,7 @@
#endif #endif
#define DEG (M_PI / 180.0) #define DEG (M_PI / 180.0)
/* -- API ------------------------------------------------------------------ */ /* -- API --- */
TB_API double tb_number_round_to(double x, int places) { TB_API double tb_number_round_to(double x, int places) {
if (places < 0) places = 0; if (places < 0) places = 0;
@@ -60,7 +60,7 @@ TB_API void tb_number_format(double x, int places, char* out, size_t cap) {
} }
} }
/* -- Entradas/saidas ------------------------------------------------------ */ /* -- Entradas/saidas --- */
/* Inteiro quando o resultado for exato (e couber), senao real */ /* Inteiro quando o resultado for exato (e couber), senao real */
@@ -80,7 +80,7 @@ static void out_bool(TinyBlocks_Block* self, bool b) {
/* trigonometria: corta o ruido de ponto flutuante (sen 180 = 0, nao 1e-16) */ /* trigonometria: corta o ruido de ponto flutuante (sen 180 = 0, nao 1e-16) */
static double trig(double x) { return tb_number_round_to(x, 10); } static double trig(double x) { return tb_number_round_to(x, 10); }
/* -- Blocos --------------------------------------------------------------- */ /* -- Blocos --- */
#define N(i) tb_block_input_number(self, rt, (i), 0) #define N(i) tb_block_input_number(self, rt, (i), 0)
@@ -147,7 +147,7 @@ static void eval_is_int(TinyBlocks_Block* self, TinyBlocks* rt) {
out_bool(self, isfinite(x) && x == floor(x)); out_bool(self, isfinite(x) && x == floor(x));
} }
/* -- Conversoes ----------------------------------------------------------- */ /* -- Conversoes --- */
/* Texto -> numero: o mesmo do core (espacos nas pontas, virgula decimal) */ /* Texto -> numero: o mesmo do core (espacos nas pontas, virgula decimal) */
TB_API bool tb_number_parse(const char* s, double* out) { TB_API bool tb_number_parse(const char* s, double* out) {
@@ -201,7 +201,7 @@ static void eval_from_base(TinyBlocks_Block* self, TinyBlocks* rt) {
out_num(self, (double)r); out_num(self, (double)r);
} }
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
@@ -16,7 +16,7 @@
TB_API const TinyBlocks_LibraryDescriptor* tb_opentype_get_library(void); TB_API const TinyBlocks_LibraryDescriptor* tb_opentype_get_library(void);
/* -- API C --------------------------------------------------------------- */ /* -- API C --- */
/* Carrega uma fonte; devolve um handle (>0) ou 0 em erro. */ /* Carrega uma fonte; devolve um handle (>0) ou 0 em erro. */
TB_API int tb_opentype_load(const char* path); TB_API int tb_opentype_load(const char* path);
@@ -294,7 +294,7 @@ const char* tb_opentype_default_font(void) {
return NULL; return NULL;
} }
/* ---------------------------------------------------------------- Blocos */ /* --- Blocos */
static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) {
int h = tb_opentype_load(tb_block_input_text(self, rt, 0)); int h = tb_opentype_load(tb_block_input_text(self, rt, 0));
+3 -3
View File
@@ -22,7 +22,7 @@ static void copy(char* out, size_t cap, const char* s) {
snprintf(out, cap, "%s", s ? s : ""); snprintf(out, cap, "%s", s ? s : "");
} }
/* -- Consultas ------------------------------------------------------------ */ /* -- Consultas --- */
TB_API void tb_os_name(char* out, size_t cap) { TB_API void tb_os_name(char* out, size_t cap) {
#if defined(__APPLE__) #if defined(__APPLE__)
@@ -104,7 +104,7 @@ TB_API long long tb_os_uptime_s(void) {
return (long long)up; return (long long)up;
} }
/* -- Blocos --------------------------------------------------------------- */ /* -- Blocos --- */
static void out_text(TinyBlocks_Block* self, void (*fn)(char*, size_t)) { static void out_text(TinyBlocks_Block* self, void (*fn)(char*, size_t)) {
char buf[512]; char buf[512];
@@ -170,7 +170,7 @@ static void eval_is(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+1 -1
View File
@@ -72,7 +72,7 @@ bool tb_png_save(const TinyBlocks_Image* img, const char* path) {
return ok; return ok;
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
TinyBlocks_Value v = tb_block_get_input(self, rt, i); TinyBlocks_Value v = tb_block_get_input(self, rt, i);
+3 -3
View File
@@ -110,7 +110,7 @@ bool tb_ppm_save(const TinyBlocks_Image* img, const char* path) {
return ok; return ok;
} }
/* -- Helpers de entrada -------------------------------------------------- */ /* -- Helpers de entrada --- */
static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
TinyBlocks_Value v = tb_block_get_input(self, rt, i); TinyBlocks_Value v = tb_block_get_input(self, rt, i);
@@ -123,7 +123,7 @@ static uint8_t clamp8(double v) {
return (uint8_t)(v + 0.5); return (uint8_t)(v + 0.5);
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) {
TinyBlocks_Image* img = tb_ppm_load(tb_block_input_text(self, rt, 0)); TinyBlocks_Image* img = tb_ppm_load(tb_block_input_text(self, rt, 0));
@@ -186,7 +186,7 @@ static void eval_getpixel(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Registro ------------------------------------------------------------ */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
@@ -10,7 +10,7 @@
TB_API const TinyBlocks_LibraryDescriptor* tb_regex_get_library(void); TB_API const TinyBlocks_LibraryDescriptor* tb_regex_get_library(void);
/* -- API C --------------------------------------------------------------- */ /* -- API C --- */
/* Verdadeiro se o padrao casa em algum ponto do texto. */ /* Verdadeiro se o padrao casa em algum ponto do texto. */
TB_API bool tb_regex_test(const char* text, const char* pattern); TB_API bool tb_regex_test(const char* text, const char* pattern);
+2 -2
View File
@@ -107,7 +107,7 @@ int tb_regex_count(const char* text, const char* pattern) {
return count; return count;
} }
/* --- Expansao do substituto -------------------------------------------- */ /* --- Expansao do substituto --- */
typedef struct { char* p; size_t n, cap; } Buf; typedef struct { char* p; size_t n, cap; } Buf;
static bool b_res(Buf* b, size_t extra) { static bool b_res(Buf* b, size_t extra) {
if (b->n + extra + 1 <= b->cap) return true; if (b->n + extra + 1 <= b->cap) return true;
@@ -210,7 +210,7 @@ void tb_regex_free_list(char** list) {
free(list); free(list);
} }
/* ---------------------------------------------------------------- Blocos */ /* --- Blocos */
static void eval_test(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_test(TinyBlocks_Block* self, TinyBlocks* rt) {
bool ok = tb_regex_test(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1)); bool ok = tb_regex_test(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1));
@@ -21,7 +21,7 @@
#include "tb_scratchblocks.h" #include "tb_scratchblocks.h"
/* -- Modelos internos (ingles do Scratch 3) ------------------------------- */ /* -- Modelos internos (ingles do Scratch 3) --- */
/* forma: h chapeu, s comando, c C, C se/senao, e sempre, r repórter, b booleano */ /* forma: h chapeu, s comando, c C, C se/senao, e sempre, r repórter, b booleano */
typedef struct { const char* type; const char* text; char shape; bool import_only; } Tpl; typedef struct { const char* type; const char* text; char shape; bool import_only; } Tpl;
@@ -88,7 +88,7 @@ static const Tpl s_builtin[] = {
}; };
#define BUILTIN_N ((int)(sizeof(s_builtin) / sizeof(s_builtin[0]))) #define BUILTIN_N ((int)(sizeof(s_builtin) / sizeof(s_builtin[0])))
/* -- Texto dinamico -------------------------------------------------------- */ /* -- Texto dinamico --- */
typedef struct { char* p; size_t n, cap; } Sb; typedef struct { char* p; size_t n, cap; } Sb;
static void sb_add(Sb* b, const char* s, size_t n) { static void sb_add(Sb* b, const char* s, size_t n) {
@@ -114,7 +114,7 @@ static void sb_esc(Sb* b, const char* s) {
} }
} }
/* -- Tokens ---------------------------------------------------------------- */ /* -- Tokens --- */
enum { T_WORD, T_ROUND, T_SQUARE, T_ANGLE }; /* palavra, ( ), [ ], < > */ enum { T_WORD, T_ROUND, T_SQUARE, T_ANGLE }; /* palavra, ( ), [ ], < > */
#define TOK_MAX 40 #define TOK_MAX 40
#define TOK_TEXT 256 #define TOK_TEXT 256
@@ -228,7 +228,7 @@ static void strip_category(char* s) {
} }
} }
/* -- Modelos (internos + rotulos do chamador) ------------------------------ */ /* -- Modelos (internos + rotulos do chamador) --- */
typedef struct { typedef struct {
const char* type; const char* type;
char shape; char shape;
@@ -347,7 +347,7 @@ static bool model_match(const Model* m, const Tok* t, int n) {
static bool shape_is_stmt(char s) { return s == 's' || s == 'h' || s == 'c' || s == 'C' || s == 'e'; } static bool shape_is_stmt(char s) { return s == 's' || s == 'h' || s == 'c' || s == 'C' || s == 'e'; }
/* -- Exportar -------------------------------------------------------------- */ /* -- Exportar --- */
static bool is_literal(const char* type) { return strncmp(type, "Literal.", 8) == 0; } static bool is_literal(const char* type) { return strncmp(type, "Literal.", 8) == 0; }
static int block_shape(const Models* M, const char* type) { static int block_shape(const Models* M, const char* type) {
@@ -530,7 +530,7 @@ char* tb_scratchblocks_export(const TbBpTab* tab, const TbSbContext* cx) {
return out.p; return out.p;
} }
/* -- Importar -------------------------------------------------------------- */ /* -- Importar --- */
typedef struct { typedef struct {
const Models* M; const Models* M;
TbBpTab* tab; TbBpTab* tab;
+6 -6
View File
@@ -22,7 +22,7 @@
#define STR_MAX_OUT (1u << 20) /* teto de 1 MB para "repita" */ #define STR_MAX_OUT (1u << 20) /* teto de 1 MB para "repita" */
/* -- UTF-8 ---------------------------------------------------------------- */ /* -- UTF-8 --- */
static size_t u8_len(unsigned char c) { static size_t u8_len(unsigned char c) {
if (c < 0x80) return 1; if (c < 0x80) return 1;
@@ -77,7 +77,7 @@ static size_t u8_count(const char* s, size_t nbytes) {
return n; return n;
} }
/* -- API ------------------------------------------------------------------ */ /* -- API --- */
TB_API size_t tb_string_length(const char* s) { TB_API size_t tb_string_length(const char* s) {
return u8_count(s, strlen(s)); return u8_count(s, strlen(s));
@@ -156,7 +156,7 @@ TB_API bool tb_string_is_number(const char* s) {
return *e == 0; return *e == 0;
} }
/* -- Entradas ------------------------------------------------------------- */ /* -- Entradas --- */
/* Texto da entrada i (numeros viram texto). Fica valido ate o proximo uso. */ /* Texto da entrada i (numeros viram texto). Fica valido ate o proximo uso. */
@@ -174,7 +174,7 @@ static void out_bool(TinyBlocks_Block* self, bool b) {
#define TXT(i) tb_block_input_text(self, rt, (i)) #define TXT(i) tb_block_input_text(self, rt, (i))
/* -- Blocos --------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_upper(TinyBlocks_Block* self, TinyBlocks* rt) { out_owned(self, tb_string_upper(TXT(0))); } static void eval_upper(TinyBlocks_Block* self, TinyBlocks* rt) { out_owned(self, tb_string_upper(TXT(0))); }
static void eval_lower(TinyBlocks_Block* self, TinyBlocks* rt) { out_owned(self, tb_string_lower(TXT(0))); } static void eval_lower(TinyBlocks_Block* self, TinyBlocks* rt) { out_owned(self, tb_string_lower(TXT(0))); }
@@ -285,7 +285,7 @@ static void eval_isempty(TinyBlocks_Block* self, TinyBlocks* rt) {
free(t); free(t);
} }
/* -- Conversoes ----------------------------------------------------------- */ /* -- Conversoes --- */
/* "texto de (x)": cada tipo de valor sabe virar texto (classe do valor) */ /* "texto de (x)": cada tipo de valor sabe virar texto (classe do valor) */
static void eval_from(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_from(TinyBlocks_Block* self, TinyBlocks* rt) {
@@ -330,7 +330,7 @@ static void eval_from_code(TinyBlocks_Block* self, TinyBlocks* rt) {
out_owned(self, dup_n(buf, n)); out_owned(self, dup_n(buf, n));
} }
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+5 -5
View File
@@ -23,7 +23,7 @@
static char s_err[200] = ""; static char s_err[200] = "";
const char* tb_svg_last_error(void) { return s_err; } const char* tb_svg_last_error(void) { return s_err; }
/* -- Utilitarios de parsing ---------------------------------------------- */ /* -- Utilitarios de parsing --- */
static void skip_ws(const char** p) { static void skip_ws(const char** p) {
while (**p && (isspace((unsigned char)**p) || **p == ',')) (*p)++; while (**p && (isspace((unsigned char)**p) || **p == ',')) (*p)++;
@@ -109,7 +109,7 @@ static bool parse_color(const char* s, float* r, float* g, float* b, float* a) {
return false; return false;
} }
/* -- Cotas de imagens embutidas ------------------------------------------ */ /* -- Cotas de imagens embutidas --- */
typedef struct { double x, y, w, h; TinyBlocks_Image* img; } SvgImg; typedef struct { double x, y, w, h; TinyBlocks_Image* img; } SvgImg;
#define SVG_MAX_IMGS 16 #define SVG_MAX_IMGS 16
@@ -157,7 +157,7 @@ static TinyBlocks_Image* decode_data_uri(const char* uri) {
return img; return img;
} }
/* -- Parsing de shapes ---------------------------------------------------- */ /* -- Parsing de shapes --- */
typedef struct { double* xy; int n, cap; } Pts; typedef struct { double* xy; int n, cap; } Pts;
@@ -288,7 +288,7 @@ static void parse_path(TinyBlocks_VectorData* v, const char* d, bool do_fill, bo
pts_free(&poly); pts_free(&poly);
} }
/* -- Parse principal ------------------------------------------------------ */ /* -- Parse principal --- */
static TinyBlocks_VectorData* svg_parse_internal(const char* svg, int* out_w, int* out_h, static TinyBlocks_VectorData* svg_parse_internal(const char* svg, int* out_w, int* out_h,
SvgImg* imgs, int* img_n) { SvgImg* imgs, int* img_n) {
@@ -451,7 +451,7 @@ TinyBlocks_Image* tb_svg_render(const char* svg, int w, int h) {
return im; return im;
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_parse(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_parse(TinyBlocks_Block* self, TinyBlocks* rt) {
@@ -19,7 +19,7 @@
TB_API const TinyBlocks_LibraryDescriptor* tb_syntax_get_library(void); TB_API const TinyBlocks_LibraryDescriptor* tb_syntax_get_library(void);
/* -- API C --------------------------------------------------------------- */ /* -- API C --- */
/* Realca `text` como `lang` e devolve XML (malloc; libere com free). */ /* Realca `text` como `lang` e devolve XML (malloc; libere com free). */
TB_API char* tb_syntax_highlight(const char* text, const char* lang); TB_API char* tb_syntax_highlight(const char* text, const char* lang);
+7 -7
View File
@@ -17,7 +17,7 @@
static char s_err[160] = ""; static char s_err[160] = "";
const char* tb_syntax_last_error(void) { return s_err; } const char* tb_syntax_last_error(void) { return s_err; }
/* ---------------------------------------------------------------- Buffer */ /* --- Buffer */
typedef struct { char* p; size_t n, cap; } Buf; typedef struct { char* p; size_t n, cap; } Buf;
static bool b_reserve(Buf* b, size_t extra) { static bool b_reserve(Buf* b, size_t extra) {
@@ -46,7 +46,7 @@ static void b_esc(Buf* b, const char* s, size_t n) {
} }
} }
/* ------------------------------------------------------------- Token tip */ /* --- Token tip */
typedef enum { T_PLAIN, T_KW, T_TYPE, T_STR, T_NUM, T_CMT, T_PRE, typedef enum { T_PLAIN, T_KW, T_TYPE, T_STR, T_NUM, T_CMT, T_PRE,
T_FN, T_OP, T_PUNC, T_ID } TK; T_FN, T_OP, T_PUNC, T_ID } TK;
@@ -96,7 +96,7 @@ const char* tb_syntax_type_color(const char* type) {
return tk_color(T_PLAIN); return tk_color(T_PLAIN);
} }
/* ------------------------------------------------------------ Linguagens */ /* --- Linguagens */
typedef struct { typedef struct {
const char* name; const char* name;
const char* aliases; /* separados por espaco */ const char* aliases; /* separados por espaco */
@@ -218,7 +218,7 @@ static bool word_in(const char* list, const char* w, size_t n) {
return false; return false;
} }
/* -------------------------------------------------------------- Emissao */ /* --- Emissao */
static bool emit(Buf* b, TK k, const char* s, size_t n, bool inline_mode) { static bool emit(Buf* b, TK k, const char* s, size_t n, bool inline_mode) {
(void)inline_mode; (void)inline_mode;
if (n == 0) return true; if (n == 0) return true;
@@ -232,7 +232,7 @@ static bool emit(Buf* b, TK k, const char* s, size_t n, bool inline_mode) {
return true; return true;
} }
/* --------------------------------------------------------- Tokenizadores */ /* --- Tokenizadores */
static bool is_id_start(int c) { return isalpha(c) || c == '_'; } static bool is_id_start(int c) { return isalpha(c) || c == '_'; }
static bool is_id_char(int c) { return isalnum(c) || c == '_'; } static bool is_id_char(int c) { return isalnum(c) || c == '_'; }
static bool is_op(int c) { static bool is_op(int c) {
@@ -386,7 +386,7 @@ static void tok_md(Buf* b, const char* s, bool inline_mode) {
} }
} }
/* ---------------------------------------------------------------- Render */ /* --- Render */
char* tb_syntax_highlight_inline(const char* text, const char* lang) { char* tb_syntax_highlight_inline(const char* text, const char* lang) {
s_err[0] = 0; s_err[0] = 0;
if (!text) text = ""; if (!text) text = "";
@@ -435,7 +435,7 @@ char* tb_syntax_highlight(const char* text, const char* lang) {
return b.p; return b.p;
} }
/* ---------------------------------------------------------------- Blocos */ /* --- Blocos */
static void eval_highlight(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_highlight(TinyBlocks_Block* self, TinyBlocks* rt) {
char* x = tb_syntax_highlight(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1)); char* x = tb_syntax_highlight(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1));
+1 -1
View File
@@ -355,7 +355,7 @@ void toml_free(TomlDoc* doc) {
free(doc); free(doc);
} }
/* -- Navegacao ----------------------------------------------------------- */ /* -- Navegacao --- */
const TomlValue* toml_table_get(const TomlValue* table, const char* key) { const TomlValue* toml_table_get(const TomlValue* table, const char* key) {
TomlKeyVal* kv = table_find(table, key); TomlKeyVal* kv = table_find(table, key);
+6 -6
View File
@@ -26,7 +26,7 @@
#define LIST_MAX_RANGE 100000 #define LIST_MAX_RANGE 100000
/* -- Itens ---------------------------------------------------------------- */ /* -- Itens --- */
static bool text_number(const char* s, double* out) { static bool text_number(const char* s, double* out) {
while (isspace((unsigned char)*s)) s++; while (isspace((unsigned char)*s)) s++;
@@ -101,7 +101,7 @@ static bool item_equal(const TinyBlocks_JsonValue* a, const TinyBlocks_JsonValue
return strcasecmp(sa, sb) == 0; return strcasecmp(sa, sb) == 0;
} }
/* -- Listas --------------------------------------------------------------- */ /* -- Listas --- */
static void push_owned(TinyBlocks_JsonValue* arr, TinyBlocks_JsonValue* item) { static void push_owned(TinyBlocks_JsonValue* arr, TinyBlocks_JsonValue* item) {
if (!item) return; if (!item) return;
@@ -163,7 +163,7 @@ static TinyBlocks_JsonValue* list_copy(const TinyBlocks_JsonValue* src, uint32_t
return arr; return arr;
} }
/* -- Entradas/saidas ------------------------------------------------------ */ /* -- Entradas/saidas --- */
static TinyBlocks_JsonValue* in_list(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_JsonValue* in_list(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
return tb_vector_from_value(tb_block_get_input(self, rt, i)); return tb_vector_from_value(tb_block_get_input(self, rt, i));
@@ -188,7 +188,7 @@ static void out_int(TinyBlocks_Block* self, long long n) {
self->dirty = false; self->dirty = false;
} }
/* -- Blocos --------------------------------------------------------------- */ /* -- Blocos --- */
static void eval_empty(TinyBlocks_Block* self, TinyBlocks* rt) { static void eval_empty(TinyBlocks_Block* self, TinyBlocks* rt) {
(void)rt; (void)rt;
@@ -409,7 +409,7 @@ static void eval_sum(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false; self->dirty = false;
} }
/* -- Listas com nome (comandos que mudam a lista, como no Scratch) -------- */ /* -- Listas com nome (comandos que mudam a lista, como no Scratch) --- */
#define NAMED_MAX 64 #define NAMED_MAX 64
typedef struct { char name[64]; TinyBlocks_JsonValue* arr; } NamedList; typedef struct { char name[64]; TinyBlocks_JsonValue* arr; } NamedList;
@@ -554,7 +554,7 @@ static void eval_from(TinyBlocks_Block* self, TinyBlocks* rt) {
out_list(self, tb_vector_from_value(v)); out_list(self, tb_vector_from_value(v));
} }
/* -- Registro ------------------------------------------------------------- */ /* -- Registro --- */
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name, static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
const TinyBlocks_SlotDesc* in, uint32_t ni, const TinyBlocks_SlotDesc* in, uint32_t ni,
+2 -2
View File
@@ -156,7 +156,7 @@ TinyBlocks_Image* tb_vg_render(const TinyBlocks_VectorData* v, int w, int h, flo
return im; return im;
} }
/* -- Helpers de construcao ------------------------------------------------ */ /* -- Helpers de construcao --- */
TinyBlocks_VectorData* tb_vg_new(void) { return tb_vector_data_create(); } TinyBlocks_VectorData* tb_vg_new(void) { return tb_vector_data_create(); }
@@ -196,7 +196,7 @@ bool tb_vg_polygon(TinyBlocks_VectorData* v, const double* xy, int n, bool close
return tb_vector_fill(v, r, g, b, a); return tb_vector_fill(v, r, g, b, a);
} }
/* -- Blocos -------------------------------------------------------------- */ /* -- Blocos --- */
static TinyBlocks_VectorData* in_vec(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { static TinyBlocks_VectorData* in_vec(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
TinyBlocks_Value v = tb_block_get_input(self, rt, i); TinyBlocks_Value v = tb_block_get_input(self, rt, i);
+1 -1
View File
@@ -95,7 +95,7 @@ bool tb_image_get_pixel(const TinyBlocks_Image* img, int x, int y,
return true; return true;
} }
/* -- Registro de formatos ------------------------------------------------- */ /* -- Registro de formatos --- */
#define TB_IMAGE_MAX_FORMATS 24 #define TB_IMAGE_MAX_FORMATS 24
+12 -12
View File
@@ -13,7 +13,7 @@
#include <strings.h> #include <strings.h>
#include "tinyblocks/tinyblocks.h" #include "tinyblocks/tinyblocks.h"
/* -- Construtores ---------------------------------------------------------- */ /* -- Construtores --- */
TinyBlocks_Value tb_value_none(void) TinyBlocks_Value tb_value_none(void)
{ {
@@ -63,7 +63,7 @@ TinyBlocks_Value tb_value_block(TinyBlocks_Block* block)
return v; return v;
} }
/* -- Auxiliares ------------------------------------------------------------ */ /* -- Auxiliares --- */
bool tb_text_to_number(const char* s, double* out) bool tb_text_to_number(const char* s, double* out)
{ {
@@ -95,7 +95,7 @@ static size_t put(char* out, size_t cap, const char* s)
static TinyBlocks_Value obj_copy(TinyBlocks_Value v) { tb_object_retain(v.as.object); return v; } static TinyBlocks_Value obj_copy(TinyBlocks_Value v) { tb_object_retain(v.as.object); return v; }
static void obj_release(TinyBlocks_Value* v) { tb_object_release(v->as.object); v->as.object = NULL; } static void obj_release(TinyBlocks_Value* v) { tb_object_release(v->as.object); v->as.object = NULL; }
/* -- Classe: nada ---------------------------------------------------------- */ /* -- Classe: nada --- */
static size_t none_text(TinyBlocks_Value v, char* out, size_t cap) { (void)v; return put(out, cap, ""); } static size_t none_text(TinyBlocks_Value v, char* out, size_t cap) { (void)v; return put(out, cap, ""); }
static bool never(TinyBlocks_Value v) { (void)v; return false; } static bool never(TinyBlocks_Value v) { (void)v; return false; }
@@ -104,7 +104,7 @@ static const TinyBlocks_ValueClass s_none = {
TB_VALUE_NONE, "nada", NULL, NULL, none_text, NULL, never, NULL, NULL, TB_VALUE_NONE, "nada", NULL, NULL, none_text, NULL, never, NULL, NULL,
}; };
/* -- Classe: inteiro ------------------------------------------------------- */ /* -- Classe: inteiro --- */
static size_t int_text(TinyBlocks_Value v, char* out, size_t cap) static size_t int_text(TinyBlocks_Value v, char* out, size_t cap)
{ return (size_t)snprintf(out, cap, "%lld", (long long)v.as.integer); } { return (size_t)snprintf(out, cap, "%lld", (long long)v.as.integer); }
@@ -116,7 +116,7 @@ static const TinyBlocks_ValueClass s_integer = {
TB_VALUE_INTEGER, "número inteiro", NULL, NULL, int_text, int_num, int_truthy, int_eq, NULL, TB_VALUE_INTEGER, "número inteiro", NULL, NULL, int_text, int_num, int_truthy, int_eq, NULL,
}; };
/* -- Classe: real ---------------------------------------------------------- */ /* -- Classe: real --- */
static size_t real_text(TinyBlocks_Value v, char* out, size_t cap) static size_t real_text(TinyBlocks_Value v, char* out, size_t cap)
{ return (size_t)snprintf(out, cap, "%.15g", v.as.real); } { return (size_t)snprintf(out, cap, "%.15g", v.as.real); }
@@ -128,7 +128,7 @@ static const TinyBlocks_ValueClass s_real = {
TB_VALUE_REAL, "número real", NULL, NULL, real_text, real_num, real_truthy, real_eq, NULL, TB_VALUE_REAL, "número real", NULL, NULL, real_text, real_num, real_truthy, real_eq, NULL,
}; };
/* -- Classe: texto --------------------------------------------------------- */ /* -- Classe: texto --- */
static TinyBlocks_Value text_copy(TinyBlocks_Value v) { return tb_value_text(v.as.text); } static TinyBlocks_Value text_copy(TinyBlocks_Value v) { return tb_value_text(v.as.text); }
static void text_release(TinyBlocks_Value* v) { free(v->as.text); v->as.text = NULL; } static void text_release(TinyBlocks_Value* v) { free(v->as.text); v->as.text = NULL; }
@@ -149,7 +149,7 @@ static const TinyBlocks_ValueClass s_text = {
TB_VALUE_TEXT, "texto", text_copy, text_release, text_text, text_num, text_truthy, text_eq, NULL, TB_VALUE_TEXT, "texto", text_copy, text_release, text_text, text_num, text_truthy, text_eq, NULL,
}; };
/* -- Classe: referencia a bloco -------------------------------------------- */ /* -- Classe: referencia a bloco --- */
static size_t block_text(TinyBlocks_Value v, char* out, size_t cap) static size_t block_text(TinyBlocks_Value v, char* out, size_t cap)
{ {
@@ -163,7 +163,7 @@ static const TinyBlocks_ValueClass s_block = {
TB_VALUE_BLOCK, "bloco", NULL, NULL, block_text, NULL, block_truthy, block_eq, NULL, TB_VALUE_BLOCK, "bloco", NULL, NULL, block_text, NULL, block_truthy, block_eq, NULL,
}; };
/* -- Classe: desenho vetorial ---------------------------------------------- */ /* -- Classe: desenho vetorial --- */
static size_t vec_text(TinyBlocks_Value v, char* out, size_t cap) static size_t vec_text(TinyBlocks_Value v, char* out, size_t cap)
{ return (size_t)snprintf(out, cap, "[desenho com %u comandos]", v.as.vector ? v.as.vector->count : 0u); } { return (size_t)snprintf(out, cap, "[desenho com %u comandos]", v.as.vector ? v.as.vector->count : 0u); }
@@ -174,7 +174,7 @@ static const TinyBlocks_ValueClass s_vector = {
TB_VALUE_VECTOR, "desenho vetorial", obj_copy, obj_release, vec_text, NULL, vec_truthy, vec_eq, NULL, TB_VALUE_VECTOR, "desenho vetorial", obj_copy, obj_release, vec_text, NULL, vec_truthy, vec_eq, NULL,
}; };
/* -- Classe: JSON (listas e objetos) --------------------------------------- */ /* -- Classe: JSON (listas e objetos) --- */
/* texto JSON sai sem aspas; o resto, como JSON */ /* texto JSON sai sem aspas; o resto, como JSON */
@@ -238,7 +238,7 @@ static const TinyBlocks_ValueClass s_json = {
TB_VALUE_JSON, "JSON", obj_copy, obj_release, json_text, json_num, json_truthy, json_eq, json_type_name, TB_VALUE_JSON, "JSON", obj_copy, obj_release, json_text, json_num, json_truthy, json_eq, json_type_name,
}; };
/* -- Classe: imagem -------------------------------------------------------- */ /* -- Classe: imagem --- */
static size_t img_text(TinyBlocks_Value v, char* out, size_t cap) static size_t img_text(TinyBlocks_Value v, char* out, size_t cap)
{ return (size_t)snprintf(out, cap, "[imagem %dx%d]", tb_image_width(v.as.image), tb_image_height(v.as.image)); } { return (size_t)snprintf(out, cap, "[imagem %dx%d]", tb_image_width(v.as.image), tb_image_height(v.as.image)); }
@@ -249,7 +249,7 @@ static const TinyBlocks_ValueClass s_image = {
TB_VALUE_IMAGE, "imagem", obj_copy, obj_release, img_text, NULL, img_truthy, img_eq, NULL, TB_VALUE_IMAGE, "imagem", obj_copy, obj_release, img_text, NULL, img_truthy, img_eq, NULL,
}; };
/* -- Classe: resultado (Ok | Erro) ----------------------------------------- */ /* -- Classe: resultado (Ok | Erro) --- */
static size_t res_text(TinyBlocks_Value v, char* out, size_t cap) static size_t res_text(TinyBlocks_Value v, char* out, size_t cap)
@@ -279,7 +279,7 @@ static const TinyBlocks_ValueClass s_result = {
TB_VALUE_RESULT, "resultado", obj_copy, obj_release, res_text, NULL, res_truthy, res_eq, res_type_name, TB_VALUE_RESULT, "resultado", obj_copy, obj_release, res_text, NULL, res_truthy, res_eq, res_type_name,
}; };
/* -- Tabela e despacho ----------------------------------------------------- */ /* -- Tabela e despacho --- */
static const TinyBlocks_ValueClass* const s_classes[TB_VALUE_KIND_COUNT] = { static const TinyBlocks_ValueClass* const s_classes[TB_VALUE_KIND_COUNT] = {
[TB_VALUE_NONE] = &s_none, [TB_VALUE_NONE] = &s_none,
+4 -4
View File
@@ -24,7 +24,7 @@ static VarTable s_global;
static TbVarScope* s_cur = NULL; static TbVarScope* s_cur = NULL;
static TbVarScope* s_live = NULL; static TbVarScope* s_live = NULL;
/* -- Tabela ---------------------------------------------------------------- */ /* -- Tabela --- */
static int table_find(const VarTable* t, const char* name) { static int table_find(const VarTable* t, const char* name) {
for (int i = 0; i < t->n; i++) if (!strcmp(t->v[i].name, name)) return i; for (int i = 0; i < t->n; i++) if (!strcmp(t->v[i].name, name)) return i;
@@ -78,7 +78,7 @@ static VarTable* where(const char* name, int* idx) {
return NULL; return NULL;
} }
/* -- Escopos --------------------------------------------------------------- */ /* -- Escopos --- */
TbVarScope* tb_vars_scope_new(TbVarScope* parent) { TbVarScope* tb_vars_scope_new(TbVarScope* parent) {
TbVarScope* s = calloc(1, sizeof(TbVarScope)); TbVarScope* s = calloc(1, sizeof(TbVarScope));
@@ -103,7 +103,7 @@ void tb_vars_scope_free(TbVarScope* s) {
TbVarScope* tb_vars_scope_current(void) { return s_cur; } TbVarScope* tb_vars_scope_current(void) { return s_cur; }
void tb_vars_scope_set(TbVarScope* s) { s_cur = s; } void tb_vars_scope_set(TbVarScope* s) { s_cur = s; }
/* -- Valores --------------------------------------------------------------- */ /* -- Valores --- */
const TinyBlocks_Value* tb_vars_get(const char* name) { const TinyBlocks_Value* tb_vars_get(const char* name) {
if (!name || !name[0]) return NULL; if (!name || !name[0]) return NULL;
@@ -140,7 +140,7 @@ bool tb_vars_delete(const char* name) {
return true; return true;
} }
/* -- Globais --------------------------------------------------------------- */ /* -- Globais --- */
int tb_vars_global_count(void) { return s_global.n; } int tb_vars_global_count(void) { return s_global.n; }
const char* tb_vars_global_name(int i) { return (i >= 0 && i < s_global.n) ? s_global.v[i].name : ""; } const char* tb_vars_global_name(int i) { return (i >= 0 && i < s_global.n) ? s_global.v[i].name : ""; }
+1 -1
View File
@@ -28,7 +28,7 @@ static void set_pts(TinyBlocks_Block* b, uint32_t i, TinyBlocks_JsonValue* pts)
static bool near(double a, double b) { return fabs(a - b) < 1e-6; } static bool near(double a, double b) { return fabs(a - b) < 1e-6; }
int main(void) { int main(void) {
/* -- API C: reta ---- */ /* -- API C: reta --- */
TinyBlocks_JsonValue* ln = tb_curves_line(0, 0, 10, 20, 4); TinyBlocks_JsonValue* ln = tb_curves_line(0, 0, 10, 20, 4);
CHECK(tb_curves_count(ln) == 5, "reta com 4 passos -> 5 pontos"); CHECK(tb_curves_count(ln) == 5, "reta com 4 passos -> 5 pontos");
double x, y; double x, y;
+5 -5
View File
@@ -73,7 +73,7 @@ static const char* ty(const TbBpTab* t, int bi) { return bi >= 0 ? t->blocks[bi]
int main(void) { int main(void) {
char warn[256]; char warn[256];
/* -- importar ---------------------------------------------------------- */ /* -- importar --- */
TbBpTab* t = fresh(); TbBpTab* t = fresh();
int n = tb_scratchblocks_import(SCRIPT, t, &CX, warn, sizeof(warn)); int n = tb_scratchblocks_import(SCRIPT, t, &CX, warn, sizeof(warn));
CHECK(n == 1 && !warn[0], "importa um script (uma pilha, sem avisos)"); CHECK(n == 1 && !warn[0], "importa um script (uma pilha, sem avisos)");
@@ -106,7 +106,7 @@ int main(void) {
!strcmp(t->blocks[child(t, item, 0)].in_text[0], "frutas"), !strcmp(t->blocks[child(t, item, 0)].in_text[0], "frutas"),
"item (1) of [frutas v] usa a lista com nome"); "item (1) of [frutas v] usa a lista com nome");
/* -- exportar ---------------------------------------------------------- */ /* -- exportar --- */
char* txt = tb_scratchblocks_export(t, &CX); char* txt = tb_scratchblocks_export(t, &CX);
CHECK(txt && !strcmp(txt, EXPECTED), "exporta igual ao texto do fórum"); CHECK(txt && !strcmp(txt, EXPECTED), "exporta igual ao texto do fórum");
if (txt && strcmp(txt, EXPECTED)) printf("---- obtido:\n%s----\n", txt); if (txt && strcmp(txt, EXPECTED)) printf("---- obtido:\n%s----\n", txt);
@@ -118,7 +118,7 @@ int main(void) {
CHECK(txt2 && txt && !strcmp(txt, txt2), "ida e volta (exportar(importar(texto))) é estável"); CHECK(txt2 && txt && !strcmp(txt, txt2), "ida e volta (exportar(importar(texto))) é estável");
free(txt); free(txt2); free(t2); free(t); free(txt); free(txt2); free(t2); free(t);
/* -- blocos só do TinyBlocks: rótulo em português + ::categoria ------- */ /* -- blocos só do TinyBlocks: rótulo em português + ::categoria --- */
t = fresh(); t = fresh();
n = tb_scratchblocks_import( n = tb_scratchblocks_import(
"when flag clicked\n" "when flag clicked\n"
@@ -141,14 +141,14 @@ int main(void) {
CHECK(txt && strstr(txt, "forever\n set pen size to (4)\nend\n"), "sempre (tampa) com corpo"); CHECK(txt && strstr(txt, "forever\n set pen size to (4)\nend\n"), "sempre (tampa) com corpo");
free(txt); free(t); free(txt); free(t);
/* -- linha desconhecida: avisa e segue -------------------------------- */ /* -- linha desconhecida: avisa e segue --- */
t = fresh(); t = fresh();
n = tb_scratchblocks_import("when flag clicked\nvoe para a lua\nerase all\n", t, &CX, warn, sizeof(warn)); n = tb_scratchblocks_import("when flag clicked\nvoe para a lua\nerase all\n", t, &CX, warn, sizeof(warn));
CHECK(n == 1 && strstr(warn, "linha 2"), "linha desconhecida gera aviso com o número da linha"); CHECK(n == 1 && strstr(warn, "linha 2"), "linha desconhecida gera aviso com o número da linha");
CHECK(!strcmp(ty(t, t->blocks[t->top[0]].next), "Stage.Clear"), "e o resto continua sendo importado"); CHECK(!strcmp(ty(t, t->blocks[t->top[0]].next), "Stage.Clear"), "e o resto continua sendo importado");
free(t); free(t);
/* -- texto com colchetes é escapado ----------------------------------- */ /* -- texto com colchetes é escapado --- */
t = fresh(); t = fresh();
tb_scratchblocks_import("say [a \\] b]\n", t, &CX, warn, sizeof(warn)); tb_scratchblocks_import("say [a \\] b]\n", t, &CX, warn, sizeof(warn));
CHECK(!strcmp(t->blocks[t->top[0]].in_text[0], "a ] b"), "\\] dentro de [ ] é texto"); CHECK(!strcmp(t->blocks[t->top[0]].in_text[0], "a ] b"), "\\] dentro de [ ] é texto");
+1 -1
View File
@@ -198,7 +198,7 @@ int main(void) {
tb_block_destroy(bs, rt); tb_block_destroy(bs, rt);
} }
/* -- Conversoes de tipo ------------------------------------------------ */ /* -- Conversoes de tipo --- */
CHECK(is_real(run("Number.From", " 3,5 ", NULL, NULL), 3.5), "número de \" 3,5 \" (vírgula decimal)"); CHECK(is_real(run("Number.From", " 3,5 ", NULL, NULL), 3.5), "número de \" 3,5 \" (vírgula decimal)");
CHECK(is_int(run("Number.From", "42", NULL, NULL), 42) && is_int(run("Number.From", "abc", NULL, NULL), 0), CHECK(is_int(run("Number.From", "42", NULL, NULL), 42) && is_int(run("Number.From", "abc", NULL, NULL), 0),
"número de texto: inteiro sai inteiro, não-número vira 0"); "número de texto: inteiro sai inteiro, não-número vira 0");