Arquivos: bloco "leia o arquivo %1" (FS.ReadText)

Le o arquivo inteiro de uma vez e devolve o texto (vazio se nao abrir).
Com isso da para ler .obj/.json direto nos blocos, sem abrir/ler/fechar
na mao; e o que faltava para um leitor de Wavefront .obj em project.json.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5 committed 2026-10-29 00:48:48 -03:00
1 parent 67ba86601c
commit bf298ccefa
4 files changed
+41 -4

No files matched your search

+13 -2
View File
@@ -1,7 +1,7 @@
/*
* os_fs_test.c - testa tinyblocks-os (informacoes do sistema) e os blocos
* de pasta do tinyblocks-fs (FS.ListDir / ListCount / ListItem / IsFile /
* IsDir / Exists).
* de pasta do tinyblocks-fs (FS.ListDir / ListCount / ListItem / ReadText /
* IsFile / IsDir / Exists).
*/
#include <stdio.h>
#include <stdlib.h>
@@ -124,6 +124,17 @@ int main(void) {
CHECK(!strcmp(out_text(b), ""), "FS.ListItem fora da faixa = vazio");
tb_block_destroy(b, rt);
/* FS.ReadText: o arquivo inteiro de uma vez */
snprintf(p, sizeof(p), "%s/b.txt", dir);
FILE* wf = fopen(p, "wb");
if (wf) { fputs("v 1 2 3\nf 1 2 3\n", wf); fclose(wf); }
b = run("FS.ReadText", p, -1);
CHECK(b != NULL && !strcmp(out_text(b), "v 1 2 3\nf 1 2 3\n"), "FS.ReadText le o arquivo inteiro");
tb_block_destroy(b, rt);
b = run("FS.ReadText", "/tmp/tb_nao_existe_xyz.txt", -1);
CHECK(b != NULL && !strcmp(out_text(b), ""), "FS.ReadText de arquivo inexistente = vazio");
tb_block_destroy(b, rt);
snprintf(p, sizeof(p), "%s/b.txt", dir);
b = run("FS.IsFile", p, -1); CHECK(out_int(b) == 1, "FS.IsFile(arquivo) verdadeiro"); tb_block_destroy(b, rt);
b = run("FS.IsDir", p, -1); CHECK(out_int(b) == 0, "FS.IsDir(arquivo) falso"); tb_block_destroy(b, rt);