Linha de comando: pasta é ignorada com aviso, projeto é aberto

Todo argumento ia para o dlopen como library: abrir o editor com uma pasta
(./TinyBlocks.AppDir) dava "dlopen: ... Is a directory". Agora .so é
library, pasta é ignorada com um aviso claro e qualquer outro arquivo é
aberto como projeto (.json, ou .txt em scratchblocks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-23 15:55:37 -03:00
1 parent 2a2d22a64a
commit bfa17eecea
15 files changed
+9784 -124

No files matched your search

+75
View File
@@ -103,6 +103,81 @@ int main(void) {
free(csv);
tb_blueprint_free(bp);
char err2[160] = "";
/* -- aba grande: muito mais que o limite antigo (256 blocos) -- */
{
const int N = 5000;
TbBlueprint* big = tb_blueprint_new();
TbBpTab* T = tb_blueprint_tab(big, tb_blueprint_add_tab(big, "Grande", false));
int prev = -1;
for (int i = 0; i < N; i++) {
int bi = tb_blueprint_alloc_block(T);
if (i == 0) tb_blueprint_top_add(T, bi);
snprintf(T->blocks[bi].type, sizeof(T->blocks[bi].type), "Variables.Change");
snprintf(T->blocks[bi].in_text[0], 64, "cont");
if (prev >= 0) tb_blueprint_link(T, prev, TB_BP_REL_NEXT, bi);
prev = bi;
}
CHECK(prev == N - 1 && T->blocks_n == N, "aba grande: 5000 blocos em sequencia");
char* j = tb_blueprint_serialize(big, TB_BP_FMT_JSON, false);
TbBlueprint* back = j ? tb_blueprint_parse(j, TB_BP_FMT_JSON, err2, sizeof(err2)) : NULL;
CHECK(back != NULL, "aba grande: ida e volta em JSON");
if (back) {
TbBpTab* B = &back->tabs[0];
int n = 0;
for (int i = 0; i < B->blocks_n; i++) if (B->blocks[i].used) n++;
CHECK(n == N, "aba grande: os 5000 blocos voltam inteiros");
CHECK(B->blocks[N-1].used && B->blocks[N-2].next == N - 1, "aba grande: vinculos do fim preservados");
CHECK(B->top_n == 1 && B->top[0] == 0, "aba grande: topo preservado");
tb_blueprint_free(back);
}
free(j);
tb_blueprint_free(big);
}
/* -- indices esparsos e o teto por aba -- */
{
TbBlueprint* sp = tb_blueprint_new();
TbBpTab* T = tb_blueprint_tab(sp, tb_blueprint_add_tab(sp, "Esparso", false));
TbBpBlock* far = tb_blueprint_tab_slot(T, 3000);
CHECK(far != NULL && T->blocks_n == 3001, "indice esparso (3000) cresce o vetor ate ele");
if (far) { far->used = true; snprintf(far->type, sizeof(far->type), "Events.WhenRun"); tb_blueprint_top_add(T, 3000); }
char* j = tb_blueprint_serialize(sp, TB_BP_FMT_JSON, false);
TbBlueprint* back = j ? tb_blueprint_parse(j, TB_BP_FMT_JSON, err2, sizeof(err2)) : NULL;
CHECK(back && back->tabs[0].blocks_n == 3001 && back->tabs[0].blocks[3000].used,
"indice esparso sobrevive ao arquivo");
if (back) tb_blueprint_free(back);
free(j);
CHECK(tb_blueprint_tab_slot(T, TB_BP_MAX_WS) == NULL, "indice no teto (65536) e recusado");
CHECK(tb_blueprint_tab_slot(T, -1) == NULL, "indice negativo e recusado");
tb_blueprint_free(sp);
/* arquivo com indice fora do teto: ignora, sem estourar */
const char* js = "{\"format\":\"tinyblocks-project\",\"version\":2,\"cur_tab\":0,\"tabs\":[{"
"\"name\":\"Fim\",\"composite\":false,\"comp_id\":-1,\"color\":0,\"blocks\":["
"{\"i\":99999,\"type\":\"Events.WhenRun\"}],\"top\":[0]}],"
"\"user_blocks\":[],\"variables\":[]}";
TbBlueprint* ob = tb_blueprint_parse(js, TB_BP_FMT_JSON, err2, sizeof(err2));
CHECK(ob && ob->tab_count == 1, "bloco com indice fora do teto nao quebra a leitura");
if (ob) tb_blueprint_free(ob);
}
/* -- variaveis: o limite era 64 -- */
{
TbBlueprint* vp = tb_blueprint_new();
tb_blueprint_add_tab(vp, "Vars", false);
char nm[32];
for (int i = 0; i < 300; i++) { snprintf(nm, sizeof(nm), "v%d", i); tb_blueprint_var_set_text(vp, nm, "1"); }
char* vj = tb_blueprint_serialize(vp, TB_BP_FMT_JSON, false);
TbBlueprint* vb = vj ? tb_blueprint_parse(vj, TB_BP_FMT_JSON, err2, sizeof(err2)) : NULL;
CHECK(vb && vb->var_n == 300, "300 variaveis sobrevivem ao arquivo (o limite era 64)");
CHECK(vb && strcmp(vb->vars[299].name, "v299") == 0, "ultima variavel preservada");
if (vb) tb_blueprint_free(vb);
free(vj);
tb_blueprint_free(vp);
}
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
return fails != 0;
}
+72
View File
@@ -1317,6 +1317,78 @@ int main(void) {
t = mcp("ui_type", "{\"key\":\"escape\"}", &err, NULL);
CHECK(!err && ax_in(0, TB_A11Y_DIALOG, "Configurações") < 0, "mcp: ui_type aperta Esc e fecha");
free(t);
/* colar de uma vez mais blocos que o limite antigo por aba (256) */
{
size_t cap = 400 * 40 + 64;
char* big = (char*)malloc(cap);
size_t p = 0;
p += snprintf(big + p, cap - p, "{\"code\":\"when flag clicked\\n");
for (int i = 0; i < 300; i++) p += snprintf(big + p, cap - p, "change [colados v] by (1)\\n");
p += snprintf(big + p, cap - p, "\",\"x\":40,\"y\":600}");
t = mcp("add_scratchblocks", big, &err, NULL);
free(big);
CHECK(!err && ws_count("adicione (1) a (colados)") >= 300,
"mcp: cola 300 blocos numa aba (o limite antigo era 256)");
free(t);
}
}
/* 14. Aba grande: mais blocos que o limite antigo (256): carrega, roda e salva */
{
const int N = 600;
const char* bigp = "/tmp/tb_harness_big.json";
remove(bigp);
FILE* bf = fopen(bigp, "wb");
CHECK(bf != NULL, "aba grande: projeto de teste escrito");
if (bf) {
fputs("{\"format\":\"tinyblocks-project\",\"version\":2,\"cur_tab\":0,"
"\"tabs\":[{\"name\":\"Grande\",\"composite\":false,\"comp_id\":-1,\"color\":0,\"blocks\":[", bf);
fprintf(bf, "{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1}");
for (int i = 1; i <= N; i++)
fprintf(bf, ",{\"i\":%d,\"type\":\"Variables.Change\",\"parent\":%d,\"prel\":0,\"next\":%d,"
"\"in_text\":[\"cont\",\"1\"]}", i, i - 1, i + 1);
fprintf(bf, ",{\"i\":%d,\"type\":\"IO.Print\",\"parent\":%d,\"prel\":0,"
"\"in_text\":[\"cont\",\"\"],"
"\"args\":[-1,%d,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]}", N + 1, N, N + 2);
fprintf(bf, ",{\"i\":%d,\"type\":\"Variables.Get\",\"parent\":%d,\"prel\":5,"
"\"in_text\":[\"cont\"]}", N + 2, N + 1);
fputs("],\"top\":[0]}],\"user_blocks\":[],"
"\"variables\":[{\"name\":\"cont\",\"kind\":0,\"num\":0,\"text\":\"\"}]}", bf);
fclose(bf);
}
ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE);
type_path(bigp);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_TAB, "Grande") >= 0,
"aba grande: abre o projeto de 602 blocos");
CHECK(ws_count("adicione (1) a (cont)") >= N,
"aba grande: os 600 blocos entram na área de scripts");
{
/* a area de scripts e desenhada antes do palco: sem culling os
* blocos fora da vista comem o teto de comandos e o palco some */
int stage = ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco");
CHECK(stage >= 0 && drawn_count(TB_DRAW_FILL_RECT, stage) > 0,
"aba grande: o palco continua desenhado (culling dos blocos fora da vista)");
CHECK(pane("Saída") >= 0 && ncmd < TB_DRAW_CMD_CAP,
"aba grande: os comandos de desenho não estouram o teto");
}
flag();
for (int i = 0; i < 4; i++) frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(console_has("cont = 600"), "aba grande: o script roda inteiro (a VM passa do bloco 256)");
stop();
const char* bigp2 = "/tmp/tb_harness_big2.json";
remove(bigp2);
ax_do(menu_btn("Salvar"), TB_A11Y_ACT_ACTIVATE);
type_path(bigp2);
CHECK(toast_has("Projeto salvo"), "aba grande: salva o projeto");
ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE);
type_path(bigp2);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(ws_count("adicione (1) a (cont)") >= N, "aba grande: volta inteira do arquivo salvo");
remove(bigp);
remove(bigp2);
}
tinyblocks_deinit(&rt);
+7 -4
View File
@@ -35,6 +35,9 @@ static const TbSbContext CX = { s_labels, 2, shape, slot_kind, category, NULL };
static TbBpTab* fresh(void) { return calloc(1, sizeof(TbBpTab)); }
/* a aba tem pool dinamico desde o limite de 65536 blocos */
static void drop(TbBpTab* t) { if (!t) return; tb_blueprint_tab_free(t); free(t); }
static const char* SCRIPT =
"[scratchblocks]\n"
"when flag clicked\n"
@@ -116,7 +119,7 @@ int main(void) {
tb_scratchblocks_import(txt ? txt : "", t2, &CX, warn, sizeof(warn));
char* txt2 = tb_scratchblocks_export(t2, &CX);
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); drop(t2); drop(t);
/* -- blocos só do TinyBlocks: rótulo em português + ::categoria --- */
t = fresh();
@@ -139,14 +142,14 @@ int main(void) {
CHECK(txt && strstr(txt, "if <[/tmp] é pasta? :: extension> then\n"), "booleano do TinyBlocks dentro do if");
if (txt && !strstr(txt, "if <[/tmp] é pasta? :: extension> then\n")) printf("---- obtido:\n%s----\n", txt);
CHECK(txt && strstr(txt, "forever\n set pen size to (4)\nend\n"), "sempre (tampa) com corpo");
free(txt); free(t);
free(txt); drop(t);
/* -- linha desconhecida: avisa e segue --- */
t = fresh();
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(!strcmp(ty(t, t->blocks[t->top[0]].next), "Stage.Clear"), "e o resto continua sendo importado");
free(t);
drop(t);
/* -- texto com colchetes é escapado --- */
t = fresh();
@@ -154,7 +157,7 @@ int main(void) {
CHECK(!strcmp(t->blocks[t->top[0]].in_text[0], "a ] b"), "\\] dentro de [ ] é texto");
txt = tb_scratchblocks_export(t, &CX);
CHECK(txt && !strcmp(txt, "say [a \\] b]\n"), "exporta escapando o ]");
free(txt); free(t);
free(txt); drop(t);
if (fails) printf("\n%d FALHA(S)\n", fails);
else printf("\nTUDO OK\n");