Adiciona libraries toml/fs, metadados .toml e build por library
- tinyblocks-toml: lexer + parser TOML (include/lexeme.h, include/ast.h, src/lexer.c, src/parser.c) e bloco Toml.Get. - tinyblocks-fs: categoria "Arquivos" com FS.Open/Read/Write/Append/Tell/Close. - library.toml em cada library com metadados (categoria, cor, descricao) e receita de build, sem precisar embutir isso no .so. - Makefiles proprios por library com build/ local; Makefile raiz delega. - Palco (tb_stage) movido para o core; pen deixa de depender do editor, o que torna os .so arrastaveis. - Editor linka com -rdynamic para resolver simbolos do core em .so via dlopen. - Testes: test-toml (parser) e test-plugin (dlopen de .so standalone).
This commit is contained in:
1 parent
90d47bf8a0
commit
dc23b92d15
48 files changed
+2405
-744
No files matched your search
@@ -0,0 +1,30 @@
|
||||
# Makefile da library appearance (categoria "Aparência")
|
||||
# Constroi build/libtinyblocks-appearance.a e build/libtinyblocks-appearance.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_appearance.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-appearance.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-appearance.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_appearance.c include/tb_appearance.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library appearance. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-appearance"
|
||||
version = "1.0.0"
|
||||
category = "Aparencia"
|
||||
description = "Saida visivel (escreva)"
|
||||
color = [153, 102, 255, 255]
|
||||
dark = [119, 77, 203, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_appearance.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-appearance.so"
|
||||
static = "build/libtinyblocks-appearance.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library control (categoria "Controle")
|
||||
# Constroi build/libtinyblocks-control.a e build/libtinyblocks-control.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_control.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-control.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-control.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_control.c include/tb_control.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library control. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-control"
|
||||
version = "1.0.0"
|
||||
category = "Controle"
|
||||
description = "Repita, se, se-senao, repita ate que"
|
||||
color = [255, 171, 25, 255]
|
||||
dark = [207, 139, 23, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_control.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-control.so"
|
||||
static = "build/libtinyblocks-control.a"
|
||||
depends = []
|
||||
@@ -1,35 +1,33 @@
|
||||
# Makefile da library editor (editor visual estilo Scratch)
|
||||
# Constroi build/libtinyblocks-editor.a e build/libtinyblocks-editor.so
|
||||
# Inclui o widget Editor.Stage (tb_stage.c).
|
||||
CC := gcc
|
||||
BUILD := ../../build
|
||||
|
||||
SDL2_CFLAGS := $(shell sdl2-config --cflags)
|
||||
SDL2_LIBS := $(shell sdl2-config --libs)
|
||||
SDL2TTF_CFLAGS:= $(shell pkg-config --cflags SDL2_ttf 2>/dev/null)
|
||||
SDL2TTF_LIBS := $(shell pkg-config --libs SDL2_ttf 2>/dev/null)
|
||||
|
||||
ifeq ($(SDL2TTF_LIBS),)
|
||||
$(error SDL2_ttf não encontrado. Instale: sudo apt install libsdl2-ttf-dev)
|
||||
endif
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L \
|
||||
-I../../include \
|
||||
-Iinclude \
|
||||
$(SDL2_CFLAGS) $(SDL2TTF_CFLAGS)
|
||||
-D_POSIX_C_SOURCE=200809L \
|
||||
-I../../include -Iinclude -Isrc \
|
||||
-I../tinyblocks-graphics/include \
|
||||
-I../tinyblocks-variables/include
|
||||
|
||||
LDFLAGS := $(SDL2_LIBS) $(SDL2TTF_LIBS) -lm
|
||||
|
||||
OBJ := $(BUILD)/tb_editor.o
|
||||
OBJ := $(BUILD)/tb_editor.o $(BUILD)/tb_stage_widget.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-editor.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-editor.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
|
||||
all: static shared
|
||||
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_editor.c include/tb_editor.h
|
||||
$(BUILD)/tb_editor.o: src/tb_editor.c include/tb_editor.h src/tb_stage_widget.h \
|
||||
../tinyblocks-graphics/include/tb_graphics.h \
|
||||
../tinyblocks-variables/include/tb_variables.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/tb_stage_widget.o: src/tb_stage_widget.c src/tb_stage_widget.h \
|
||||
../tinyblocks-graphics/include/tb_graphics.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
@@ -37,7 +35,7 @@ $(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
$(CC) -shared -o $@ $^ -ldl
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) $(LIB_A) $(LIB_SO)
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library editor. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-editor"
|
||||
version = "1.0.0"
|
||||
category = "Meus Blocos"
|
||||
description = "Editor visual e blocos compostos"
|
||||
color = [255, 102, 128, 255]
|
||||
dark = [255, 51, 85, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_editor.c", "src/tb_stage_widget.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-editor.so"
|
||||
static = "build/libtinyblocks-editor.a"
|
||||
depends = []
|
||||
@@ -35,8 +35,9 @@
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
#include <tb_graphics.h>
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include <tb_variables.h>
|
||||
#include "tb_stage.h"
|
||||
#include "tb_stage_widget.h"
|
||||
#include "../include/tb_editor.h"
|
||||
|
||||
|
||||
@@ -2555,7 +2556,7 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_text_c(rb, bx + (bw - tw(msg, FS_UI))*0.5f, by + ph*0.5f, msg, COL_TEXT_DIM, FS_UI);
|
||||
} else {
|
||||
TinyBlocks_RenderableBlock* sub = NULL;
|
||||
tb_stage_set_view(ed->stage, bw-2, ph-2);
|
||||
tb_stage_set_view(bw-2, ph-2);
|
||||
clip_set(ed, rb, bx+1, by+1, bw-2, ph-2);
|
||||
if (ed->stage->type->on_draw(ed->stage, ed->rt, &sub) && sub) {
|
||||
tb_draw_merge_offset(rb, sub, bx+1, by+1);
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage.c
|
||||
* O Palco do editor: uma tela lógica de 480x360 (origem no centro, y para
|
||||
* cima, como no Scratch) onde os blocos Stage.* desenham. É um componente de
|
||||
* UI: o editor o embute no painel direito (chamando seu on_draw) ou o entrega
|
||||
* como cena de um Graphics.Window próprio ("destacar palco").
|
||||
*
|
||||
* Os desenhos ficam numa lista retida e são re-emitidos a cada on_draw,
|
||||
* escalados para o tamanho da área (letterbox mantendo 4:3).
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <tb_graphics.h>
|
||||
#include "tb_stage.h"
|
||||
|
||||
#define STAGE_W 480.f
|
||||
#define STAGE_H 360.f
|
||||
#define STAGE_MAX_CMDS 4000
|
||||
#define STAGE_TEXT_FS 14.f
|
||||
|
||||
typedef enum { SC_RECT, SC_CIRCLE, SC_LINE, SC_TEXT } StageCmdKind;
|
||||
|
||||
typedef struct {
|
||||
StageCmdKind kind;
|
||||
float a, b, c, d; /* geometria em coordenadas do palco */
|
||||
float size; /* espessura da caneta */
|
||||
float col[3];
|
||||
char text[96];
|
||||
} StageCmd;
|
||||
|
||||
typedef struct {
|
||||
StageCmd* cmds;
|
||||
int n, cap;
|
||||
float bg[3];
|
||||
float pen[3];
|
||||
float pen_size;
|
||||
float view_w, view_h;
|
||||
bool full_warned;
|
||||
} Stage;
|
||||
|
||||
static TinyBlocks_Block* s_current = NULL;
|
||||
static TinyBlocks* s_rt = NULL; /* para mensagens de erro */
|
||||
|
||||
static Stage* stage_of(TinyBlocks_Block* b) { return b ? *(Stage**)b->userdata : NULL; }
|
||||
|
||||
TinyBlocks_Block* tb_stage_current(void) { return s_current; }
|
||||
|
||||
void tb_stage_set_view(TinyBlocks_Block* stage, float w, float h) {
|
||||
Stage* s = stage_of(stage);
|
||||
if (s && w > 0 && h > 0) { s->view_w = w; s->view_h = h; }
|
||||
}
|
||||
|
||||
/* ===
|
||||
* Editor.Stage
|
||||
* === */
|
||||
static bool stage_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)rt;
|
||||
Stage* s = (Stage*)calloc(1, sizeof(Stage));
|
||||
if (!s) return false;
|
||||
s->bg[0] = s->bg[1] = s->bg[2] = 1.f;
|
||||
s->pen[0] = 76/255.f; s->pen[1] = 151/255.f; s->pen[2] = 1.f;
|
||||
s->pen_size = 2.f;
|
||||
s->view_w = STAGE_W; s->view_h = STAGE_H;
|
||||
*(Stage**)self->userdata = s;
|
||||
s_current = self;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void stage_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)rt;
|
||||
Stage* s = stage_of(self);
|
||||
if (s) { free(s->cmds); free(s); }
|
||||
*(Stage**)self->userdata = NULL;
|
||||
if (s_current == self) s_current = NULL;
|
||||
}
|
||||
|
||||
/* input 0 (opcional): Graphics.Input da janela que mostra o palco - dá o tamanho da vista */
|
||||
static void eval_stage(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Block* in = v.kind == TB_VALUE_BLOCK ? v.as.block : NULL;
|
||||
if (!in || in->output_count < GFX_IN_COUNT) return;
|
||||
TinyBlocks_Value w = in->outputs[GFX_IN_WIN_W], h = in->outputs[GFX_IN_WIN_H];
|
||||
if (w.kind == TB_VALUE_INTEGER && h.kind == TB_VALUE_INTEGER)
|
||||
tb_stage_set_view(self, (float)w.as.integer, (float)h.as.integer);
|
||||
}
|
||||
|
||||
static bool stage_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, TinyBlocks_RenderableBlock** dst) {
|
||||
(void)rt;
|
||||
Stage* s = stage_of(self);
|
||||
if (!s) return false;
|
||||
TinyBlocks_RenderableBlock* rb = tb_renderable_acquire();
|
||||
if (!rb) return false;
|
||||
|
||||
float sc = s->view_w / STAGE_W < s->view_h / STAGE_H ? s->view_w / STAGE_W : s->view_h / STAGE_H;
|
||||
float ox = (s->view_w - STAGE_W*sc) * 0.5f, oy = (s->view_h - STAGE_H*sc) * 0.5f;
|
||||
#define SX(x) (ox + ((x) + STAGE_W*0.5f) * sc)
|
||||
#define SY(y) (oy + (STAGE_H*0.5f - (y)) * sc)
|
||||
|
||||
if (ox > 0.5f || oy > 0.5f) tb_draw_fill_rect(rb, 0, 0, s->view_w, s->view_h, 0.12f, 0.12f, 0.14f, 1.f);
|
||||
tb_draw_fill_rect(rb, ox, oy, STAGE_W*sc, STAGE_H*sc, s->bg[0], s->bg[1], s->bg[2], 1.f);
|
||||
tb_draw_set_clip(rb, ox, oy, STAGE_W*sc, STAGE_H*sc);
|
||||
|
||||
for (int i = 0; i < s->n && rb->count < TB_DRAW_CMD_CAP - 2; i++) {
|
||||
const StageCmd* c = &s->cmds[i];
|
||||
float r = c->col[0], g = c->col[1], b = c->col[2];
|
||||
switch (c->kind) {
|
||||
case SC_RECT:
|
||||
tb_draw_fill_rect(rb, SX(c->a - c->c*0.5f), SY(c->b + c->d*0.5f), c->c*sc, c->d*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_CIRCLE:
|
||||
tb_draw_fill_circle(rb, SX(c->a), SY(c->b), c->c*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_LINE:
|
||||
tb_draw_stroke_line(rb, SX(c->a), SY(c->b), SX(c->c), SY(c->d), c->size*sc, r, g, b, 1.f);
|
||||
break;
|
||||
case SC_TEXT: {
|
||||
float fs = STAGE_TEXT_FS * sc;
|
||||
tb_draw_text(rb, SX(c->a), SY(c->b) + fs*0.36f, c->text, fs, r, g, b, 1.f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tb_draw_clear_clip(rb);
|
||||
#undef SX
|
||||
#undef SY
|
||||
*dst = rb;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ===
|
||||
* API de desenho - usada pela library tinyblocks-pen (categoria "Caneta")
|
||||
* === */
|
||||
static float chan(float v) { return v < 0 ? 0.f : v > 255 ? 1.f : v / 255.f; }
|
||||
|
||||
static StageCmd* push(TinyBlocks* rt, StageCmdKind kind) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (!s) { tinyblocks_set_error(rt, "nenhum palco (Editor.Stage) criado"); return NULL; }
|
||||
if (s->n >= STAGE_MAX_CMDS) {
|
||||
if (!s->full_warned) tinyblocks_set_error(rt, "palco cheio (%d desenhos) = use \"apague tudo\"", STAGE_MAX_CMDS);
|
||||
s->full_warned = true;
|
||||
return NULL;
|
||||
}
|
||||
if (s->n >= s->cap) {
|
||||
int nc = s->cap ? s->cap * 2 : 64;
|
||||
StageCmd* p = (StageCmd*)realloc(s->cmds, (size_t)nc * sizeof(StageCmd));
|
||||
if (!p) return NULL;
|
||||
s->cmds = p; s->cap = nc;
|
||||
}
|
||||
StageCmd* c = &s->cmds[s->n++];
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->kind = kind;
|
||||
memcpy(c->col, s->pen, sizeof(c->col));
|
||||
c->size = s->pen_size;
|
||||
return c;
|
||||
}
|
||||
|
||||
void tb_stage_clear(void) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) { s->n = 0; s->full_warned = false; }
|
||||
}
|
||||
|
||||
void tb_stage_set_background(float r, float g, float b) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) { s->bg[0] = chan(r); s->bg[1] = chan(g); s->bg[2] = chan(b); }
|
||||
}
|
||||
|
||||
void tb_stage_set_pen(float r, float g, float b) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) { s->pen[0] = chan(r); s->pen[1] = chan(g); s->pen[2] = chan(b); }
|
||||
}
|
||||
|
||||
void tb_stage_set_pen_size(float size) {
|
||||
Stage* s = stage_of(s_current);
|
||||
if (s) s->pen_size = size < 1.f ? 1.f : size;
|
||||
}
|
||||
|
||||
void tb_stage_line(float x1, float y1, float x2, float y2) {
|
||||
StageCmd* c = push(s_rt, SC_LINE);
|
||||
if (c) { c->a = x1; c->b = y1; c->c = x2; c->d = y2; }
|
||||
}
|
||||
|
||||
void tb_stage_rect(float x, float y, float w, float h) {
|
||||
StageCmd* c = push(s_rt, SC_RECT);
|
||||
if (c) { c->a = x; c->b = y; c->c = w; c->d = h; }
|
||||
}
|
||||
|
||||
void tb_stage_circle(float x, float y, float radius) {
|
||||
StageCmd* c = push(s_rt, SC_CIRCLE);
|
||||
if (c) { c->a = x; c->b = y; c->c = radius; }
|
||||
}
|
||||
|
||||
void tb_stage_text(const char* text, float x, float y) {
|
||||
StageCmd* c = push(s_rt, SC_TEXT);
|
||||
if (c) {
|
||||
snprintf(c->text, sizeof(c->text), "%s", text ? text : "");
|
||||
c->a = x; c->b = y;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===
|
||||
* Registro do widget Editor.Stage
|
||||
* === */
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
s_rt = rt;
|
||||
static const TinyBlocks_SlotDesc stage_in[] = {{"entrada", TB_VALUE_BLOCK}};
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, "Editor.Stage", stage_in, 1, NULL, 0, eval_stage);
|
||||
if (!t) return false;
|
||||
tb_type_block_set_instance_hooks(t, sizeof(Stage*), stage_instance_init, stage_instance_deinit);
|
||||
t->on_draw = stage_on_draw;
|
||||
return tb_library_add(lib, &t->base);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage.h
|
||||
* Palco do editor (Editor.Stage) e API de desenho usada pela library Caneta.
|
||||
*/
|
||||
#ifndef TINYBLOCKS_EDITOR_STAGE_H
|
||||
#define TINYBLOCKS_EDITOR_STAGE_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
/* Registra apenas o widget Editor.Stage na library do editor */
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib);
|
||||
|
||||
/* Tamanho da área onde o palco será desenhado (on_draw usa 0..w - 0..h) */
|
||||
void tb_stage_set_view(TinyBlocks_Block* stage, float w, float h);
|
||||
|
||||
/* Palco onde o desenho acontece (o último Editor.Stage criado) */
|
||||
TinyBlocks_Block* tb_stage_current(void);
|
||||
|
||||
/* == API de desenho (usada pela library tinyblocks-pen) === */
|
||||
void tb_stage_clear(void);
|
||||
void tb_stage_set_background(float r, float g, float b); /* canais 0..255 */
|
||||
void tb_stage_set_pen(float r, float g, float b); /* canais 0..255 */
|
||||
void tb_stage_set_pen_size(float size);
|
||||
void tb_stage_line(float x1, float y1, float x2, float y2);
|
||||
void tb_stage_rect(float x, float y, float w, float h);
|
||||
void tb_stage_circle(float x, float y, float radius);
|
||||
void tb_stage_text(const char* text, float x, float y);
|
||||
|
||||
#endif /* TINYBLOCKS_EDITOR_STAGE_H */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage_widget.c (editor)
|
||||
* Editor.Stage: widget que renderiza o palco logico do runtime. Toda a
|
||||
* logica de desenho/estado fica no core (tb_stage.h); aqui so adaptamos ao
|
||||
* loop de UI do editor.
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
#include <tb_graphics.h>
|
||||
#include "tb_stage_widget.h"
|
||||
|
||||
/* input 0 (opcional): Graphics.Input da janela que mostra o palco - da o tamanho da vista */
|
||||
static void eval_stage(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Block* in = v.kind == TB_VALUE_BLOCK ? v.as.block : NULL;
|
||||
if (!in || in->output_count < GFX_IN_COUNT) return;
|
||||
TinyBlocks_Value w = in->outputs[GFX_IN_WIN_W], h = in->outputs[GFX_IN_WIN_H];
|
||||
if (w.kind == TB_VALUE_INTEGER && h.kind == TB_VALUE_INTEGER)
|
||||
tb_stage_set_view((float)w.as.integer, (float)h.as.integer);
|
||||
}
|
||||
|
||||
static bool stage_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, TinyBlocks_RenderableBlock** dst) {
|
||||
(void)self; (void)rt;
|
||||
TinyBlocks_RenderableBlock* rb = tb_renderable_acquire();
|
||||
if (!rb) return false;
|
||||
tb_stage_render(rb);
|
||||
*dst = rb;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool stage_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)self; (void)rt;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void stage_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
(void)self; (void)rt;
|
||||
tb_stage_reset();
|
||||
}
|
||||
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_SlotDesc stage_in[] = {{"entrada", TB_VALUE_BLOCK}};
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, "Editor.Stage", stage_in, 1, NULL, 0, eval_stage);
|
||||
if (!t) return false;
|
||||
tb_type_block_set_instance_hooks(t, 1, stage_instance_init, stage_instance_deinit);
|
||||
t->on_draw = stage_on_draw;
|
||||
return tb_library_add(lib, &t->base);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* TinyBlocks - tb_stage_widget.h (editor)
|
||||
* Widget Editor.Stage: exibe o palco logico do runtime (tb_stage.h).
|
||||
*/
|
||||
#ifndef TINYBLOCKS_EDITOR_STAGE_WIDGET_H
|
||||
#define TINYBLOCKS_EDITOR_STAGE_WIDGET_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
/* Registra o TypeBlock Editor.Stage na library do editor */
|
||||
bool tb_stage_register(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib);
|
||||
|
||||
#endif /* TINYBLOCKS_EDITOR_STAGE_WIDGET_H */
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library events (categoria "Eventos")
|
||||
# Constroi build/libtinyblocks-events.a e build/libtinyblocks-events.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_events.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-events.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-events.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_events.c include/tb_events.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library events. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-events"
|
||||
version = "1.0.0"
|
||||
category = "Eventos"
|
||||
description = "Blocos que iniciam scripts"
|
||||
color = [255, 191, 0, 255]
|
||||
dark = [204, 153, 0, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_events.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-events.so"
|
||||
static = "build/libtinyblocks-events.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,29 @@
|
||||
# Makefile da library fs (categoria "Arquivos")
|
||||
# Constroi build/libtinyblocks-fs.a e build/libtinyblocks-fs.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_fs.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-fs.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-fs.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_fs.c include/tb_fs.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* TinyBlocks - tb_fs.h
|
||||
* Library tinyblocks-fs: blocos de arquivo (abrir, ler, escrever, anexar,
|
||||
* posicao). Independente do editor; registra a categoria "Arquivos".
|
||||
*/
|
||||
#ifndef TINYBLOCKS_FS_H
|
||||
#define TINYBLOCKS_FS_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
TB_API const TinyBlocks_LibraryDescriptor* tb_fs_get_library(void);
|
||||
|
||||
#endif /* TINYBLOCKS_FS_H */
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library fs. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-fs"
|
||||
version = "1.0.0"
|
||||
category = "Arquivos"
|
||||
description = "Abra, leia, escreva, anexe e posicao de arquivo"
|
||||
color = [0, 188, 212, 255]
|
||||
dark = [0, 151, 167, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_fs.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-fs.so"
|
||||
static = "build/libtinyblocks-fs.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* TinyBlocks - tb_fs.c
|
||||
* Categoria "Arquivos": abra / leia / escreva / anexe / posicao.
|
||||
* Mantem uma pequena tabela de arquivos abertos (handle inteiro >= 1).
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_fs.h"
|
||||
|
||||
#define FS_MAX_FILES 64
|
||||
|
||||
static FILE* s_files[FS_MAX_FILES];
|
||||
|
||||
static int fs_slot(void) {
|
||||
for (int i = 0; i < FS_MAX_FILES; i++) if (!s_files[i]) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static FILE* fs_get(int64_t handle) {
|
||||
int i = (int)handle - 1;
|
||||
if (i < 0 || i >= FS_MAX_FILES) return NULL;
|
||||
return s_files[i];
|
||||
}
|
||||
|
||||
static void fs_close_slot(int i) {
|
||||
if (i >= 0 && i < FS_MAX_FILES && s_files[i]) { fclose(s_files[i]); s_files[i] = NULL; }
|
||||
}
|
||||
|
||||
static const char* in_text(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
|
||||
}
|
||||
static int64_t in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
if (v.kind == TB_VALUE_INTEGER) return v.as.integer;
|
||||
if (v.kind == TB_VALUE_REAL) return (int64_t)v.as.real;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void eval_open(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = in_text(self, rt, 0);
|
||||
int slot = fs_slot();
|
||||
int64_t handle = 0;
|
||||
if (slot >= 0 && path[0]) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (f) { s_files[slot] = f; handle = slot + 1; }
|
||||
}
|
||||
tb_block_set_output(self, 0, tb_value_integer(handle));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_read(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
int64_t want = in_int(self, rt, 1);
|
||||
char* buf = NULL; size_t n = 0;
|
||||
if (f) {
|
||||
long start = ftell(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
long end = ftell(f);
|
||||
fseek(f, start, SEEK_SET);
|
||||
size_t avail = (end > start) ? (size_t)(end - start) : 0;
|
||||
if (want > 0 && (size_t)want < avail) avail = (size_t)want;
|
||||
buf = (char*)malloc(avail + 1);
|
||||
if (buf) {
|
||||
n = fread(buf, 1, avail, f);
|
||||
buf[n] = 0;
|
||||
}
|
||||
}
|
||||
TinyBlocks_Value v = tb_value_text(buf ? buf : "");
|
||||
free(buf);
|
||||
tb_block_set_output(self, 0, v);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_write(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
const char* text = in_text(self, rt, 1);
|
||||
if (f) fwrite(text, 1, strlen(text), f);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_append(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = in_text(self, rt, 0);
|
||||
const char* text = in_text(self, rt, 1);
|
||||
if (path[0]) {
|
||||
FILE* f = fopen(path, "ab");
|
||||
if (f) { fwrite(text, 1, strlen(text), f); fclose(f); }
|
||||
}
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_tell(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
long pos = f ? ftell(f) : -1;
|
||||
tb_block_set_output(self, 0, tb_value_integer(pos));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_close(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
int64_t h = in_int(self, rt, 0);
|
||||
fs_close_slot((int)h - 1);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
/* -- Registro ------------------------------------------------------------ */
|
||||
|
||||
static bool reg(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib, const char* name,
|
||||
const TinyBlocks_SlotDesc* in, uint32_t ni,
|
||||
const TinyBlocks_SlotDesc* out, uint32_t no,
|
||||
void (*fn)(TinyBlocks_Block*, TinyBlocks*)) {
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, name, in, ni, out, no, fn);
|
||||
return t && tb_library_add(lib, &t->base);
|
||||
}
|
||||
|
||||
static bool fs_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_Category cat = {
|
||||
"Arquivos",
|
||||
{ 0/255.f, 188/255.f, 212/255.f, 1.f},
|
||||
{ 0/255.f, 151/255.f, 167/255.f, 1.f},
|
||||
};
|
||||
tb_library_set_category(lib, &cat);
|
||||
|
||||
static const TinyBlocks_SlotDesc open_in[] = {{"nome", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc read_in[] = {{"arquivo", TB_VALUE_INTEGER}, {"bytes", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc write_in[] = {{"arquivo", TB_VALUE_INTEGER}, {"texto", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc append_in[] = {{"nome", TB_VALUE_TEXT}, {"texto", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc tell_in[] = {{"arquivo", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc close_in[] = {{"arquivo", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc handle_out[]= {{"handle", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc text_out[] = {{"texto", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc pos_out[] = {{"posicao",TB_VALUE_INTEGER}};
|
||||
|
||||
return reg(rt, lib, "FS.Open", open_in, 1, handle_out, 1, eval_open)
|
||||
&& reg(rt, lib, "FS.Read", read_in, 2, text_out, 1, eval_read)
|
||||
&& reg(rt, lib, "FS.Write", write_in, 2, NULL, 0, eval_write)
|
||||
&& reg(rt, lib, "FS.Append", append_in, 2, NULL, 0, eval_append)
|
||||
&& reg(rt, lib, "FS.Tell", tell_in, 1, pos_out, 1, eval_tell)
|
||||
&& reg(rt, lib, "FS.Close", close_in, 1, NULL, 0, eval_close);
|
||||
}
|
||||
|
||||
static void fs_deinit(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
(void)rt; (void)lib;
|
||||
for (int i = 0; i < FS_MAX_FILES; i++) fs_close_slot(i);
|
||||
}
|
||||
|
||||
TINYBLOCKS_DEFINE_LIBRARY(fs,
|
||||
"tinyblocks-fs",
|
||||
"1.0.0",
|
||||
fs_init,
|
||||
fs_deinit)
|
||||
|
||||
const TinyBlocks_LibraryDescriptor* tb_fs_get_library(void) {
|
||||
return &_tb_lib_desc_fs;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
# Makefile da library graphics (interface grafica; backend padrao SDL2)
|
||||
# Constroi build/libtinyblocks-graphics.a e build/libtinyblocks-graphics.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -DTB_GRAPHICS_DEFAULT_SDL2 \
|
||||
-I../../include -Iinclude -I../tinyblocks-sdl2/include
|
||||
|
||||
OBJ := $(BUILD)/tb_graphics.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-graphics.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-graphics.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_graphics.c include/tb_graphics.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ -ldl
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library graphics. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-graphics"
|
||||
version = "1.0.0"
|
||||
category = "Graficos"
|
||||
description = "Interface grafica (janelas, entrada)"
|
||||
color = [0, 150, 136, 255]
|
||||
dark = [0, 121, 107, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_graphics.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-graphics.so"
|
||||
static = "build/libtinyblocks-graphics.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,35 @@
|
||||
# Makefile da library mcp (cliente MCP; reusa tinyblocks-python)
|
||||
# Constroi build/libtinyblocks-mcp.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
PYDIR := ../tinyblocks-python
|
||||
PYBUILD:= $(PYDIR)/build
|
||||
|
||||
PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
|
||||
PYTHON_LIBS := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include -Iinclude -Isrc -I$(PYDIR)/include $(PYTHON_CFLAGS)
|
||||
|
||||
OBJ := $(BUILD)/tb_mcp_lib.o
|
||||
LIB_SO := $(BUILD)/libtinyblocks-mcp.so
|
||||
PY_HDR := src/tb_mcp_py.h
|
||||
|
||||
.PHONY: all shared clean
|
||||
all: shared
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(PY_HDR): src/tb_mcp.py
|
||||
xxd -i -n tb_mcp_py $< $@
|
||||
|
||||
$(OBJ): src/tb_mcp.c $(PY_HDR) $(PYDIR)/include/tinyblocks-python/tb_python.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_SO): $(OBJ) $(PYBUILD)/libtinyblocks-python.so
|
||||
$(CC) -shared -Wl,-soname,libtinyblocks-mcp.so -o $@ $(OBJ) \
|
||||
-L$(PYBUILD) -ltinyblocks-python $(PYTHON_LIBS) \
|
||||
'-Wl,-rpath,$$ORIGIN/../../tinyblocks-python/build'
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD) $(PY_HDR)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library mcp. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-mcp"
|
||||
version = "1.0.0"
|
||||
category = "MCP"
|
||||
description = "Cliente MCP (usa tinyblocks-python)"
|
||||
color = [233, 30, 99, 255]
|
||||
dark = [194, 24, 91, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_mcp.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-mcp.so"
|
||||
static = "build/libtinyblocks-mcp.a"
|
||||
depends = ["tinyblocks-python"]
|
||||
@@ -1,314 +0,0 @@
|
||||
unsigned char tb_mcp_py[] = {
|
||||
0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x0a,
|
||||
0x0a, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x6a,
|
||||
0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20,
|
||||
0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6d, 0x70,
|
||||
0x6f, 0x72, 0x74, 0x20, 0x75, 0x72, 0x6c, 0x6c, 0x69, 0x62, 0x2e, 0x72,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2c, 0x20, 0x75, 0x72, 0x6c, 0x6c,
|
||||
0x69, 0x62, 0x2e, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x3d, 0x20, 0x6a,
|
||||
0x73, 0x6f, 0x6e, 0x2e, 0x64, 0x75, 0x6d, 0x70, 0x73, 0x28, 0x7b, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6a, 0x73, 0x6f,
|
||||
0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x20, 0x22, 0x32, 0x2e, 0x30, 0x22,
|
||||
0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69,
|
||||
0x64, 0x22, 0x3a, 0x20, 0x31, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x22, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x3a,
|
||||
0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x22, 0x3a, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x7d, 0x29, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x28,
|
||||
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x71, 0x20, 0x3d, 0x20,
|
||||
0x75, 0x72, 0x6c, 0x6c, 0x69, 0x62, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x28, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x75, 0x72, 0x6c, 0x2c,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x61, 0x74,
|
||||
0x61, 0x3d, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2c, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65,
|
||||
0x72, 0x73, 0x3d, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
|
||||
0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x61, 0x70,
|
||||
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74,
|
||||
0x22, 0x3a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x61, 0x70,
|
||||
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x75, 0x72, 0x6c, 0x6c, 0x69,
|
||||
0x62, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x75, 0x72,
|
||||
0x6c, 0x6f, 0x70, 0x65, 0x6e, 0x28, 0x72, 0x65, 0x71, 0x2c, 0x20, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x3d, 0x31, 0x35, 0x29, 0x20, 0x61,
|
||||
0x73, 0x20, 0x72, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20,
|
||||
0x72, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x28, 0x29, 0x2e, 0x64, 0x65, 0x63,
|
||||
0x6f, 0x64, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78,
|
||||
0x63, 0x65, 0x70, 0x74, 0x20, 0x75, 0x72, 0x6c, 0x6c, 0x69, 0x62, 0x2e,
|
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x45, 0x72,
|
||||
0x72, 0x6f, 0x72, 0x20, 0x61, 0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
|
||||
0x20, 0x7b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20, 0x7b,
|
||||
0x22, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x20, 0x65, 0x2e, 0x63, 0x6f,
|
||||
0x64, 0x65, 0x2c, 0x20, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||
0x22, 0x3a, 0x20, 0x65, 0x2e, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x7d,
|
||||
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74,
|
||||
0x20, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61,
|
||||
0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72,
|
||||
0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20, 0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65,
|
||||
0x22, 0x3a, 0x20, 0x2d, 0x31, 0x2c, 0x20, 0x22, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x22, 0x3a, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65, 0x29,
|
||||
0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
|
||||
0x72, 0x6e, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x73, 0x28, 0x62, 0x6f, 0x64, 0x79, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x45, 0x78, 0x63, 0x65, 0x70,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20,
|
||||
0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x20, 0x2d, 0x32, 0x2c,
|
||||
0x20, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3a, 0x20,
|
||||
0x22, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x4a, 0x53, 0x4f,
|
||||
0x4e, 0x3a, 0x20, 0x22, 0x20, 0x2b, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65,
|
||||
0x29, 0x7d, 0x7d, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x73, 0x74,
|
||||
0x64, 0x69, 0x6f, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x28,
|
||||
0x63, 0x6d, 0x64, 0x2c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c,
|
||||
0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x29, 0x3a, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x73, 0x75, 0x62,
|
||||
0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x63, 0x6d, 0x64, 0x2e, 0x73,
|
||||
0x70, 0x6c, 0x69, 0x74, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x74,
|
||||
0x72, 0x79, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x70, 0x72, 0x6f, 0x63, 0x20, 0x3d, 0x20, 0x73, 0x75, 0x62, 0x70, 0x72,
|
||||
0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e, 0x50, 0x6f, 0x70, 0x65, 0x6e, 0x28,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x64, 0x69, 0x6e,
|
||||
0x3d, 0x73, 0x75, 0x62, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e,
|
||||
0x50, 0x49, 0x50, 0x45, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x64, 0x6f, 0x75, 0x74,
|
||||
0x3d, 0x73, 0x75, 0x62, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e,
|
||||
0x50, 0x49, 0x50, 0x45, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x64, 0x65, 0x72, 0x72,
|
||||
0x3d, 0x73, 0x75, 0x62, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x2e,
|
||||
0x44, 0x45, 0x56, 0x4e, 0x55, 0x4c, 0x4c, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78,
|
||||
0x63, 0x65, 0x70, 0x74, 0x20, 0x46, 0x69, 0x6c, 0x65, 0x4e, 0x6f, 0x74,
|
||||
0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x61,
|
||||
0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72,
|
||||
0x72, 0x6f, 0x72, 0x22, 0x3a, 0x20, 0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65,
|
||||
0x22, 0x3a, 0x20, 0x2d, 0x31, 0x2c, 0x20, 0x22, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x22, 0x3a, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65, 0x29,
|
||||
0x7d, 0x7d, 0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20,
|
||||
0x73, 0x65, 0x6e, 0x64, 0x28, 0x6f, 0x62, 0x6a, 0x29, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20,
|
||||
0x3d, 0x20, 0x28, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x64, 0x75, 0x6d, 0x70,
|
||||
0x73, 0x28, 0x6f, 0x62, 0x6a, 0x29, 0x20, 0x2b, 0x20, 0x22, 0x5c, 0x6e,
|
||||
0x22, 0x29, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x28, 0x29, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63,
|
||||
0x2e, 0x73, 0x74, 0x64, 0x69, 0x6e, 0x2e, 0x77, 0x72, 0x69, 0x74, 0x65,
|
||||
0x28, 0x6c, 0x69, 0x6e, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e, 0x73, 0x74, 0x64, 0x69,
|
||||
0x6e, 0x2e, 0x66, 0x6c, 0x75, 0x73, 0x68, 0x28, 0x29, 0x0a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20, 0x72, 0x65, 0x63, 0x76, 0x28,
|
||||
0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c,
|
||||
0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e, 0x73,
|
||||
0x74, 0x64, 0x6f, 0x75, 0x74, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x6c, 0x69,
|
||||
0x6e, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65,
|
||||
0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x7d, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
|
||||
0x72, 0x6e, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x73, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2e, 0x64, 0x65, 0x63, 0x6f, 0x64,
|
||||
0x65, 0x28, 0x29, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x70, 0x28, 0x29, 0x29,
|
||||
0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x28,
|
||||
0x7b, 0x22, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x22,
|
||||
0x32, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x31, 0x2c,
|
||||
0x22, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x3a, 0x22, 0x69, 0x6e,
|
||||
0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x22, 0x2c, 0x22, 0x70,
|
||||
0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x3a, 0x7b, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x22, 0x3a, 0x22, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x31, 0x31, 0x2d,
|
||||
0x30, 0x35, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69,
|
||||
0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x7d, 0x2c, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x22, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x22,
|
||||
0x3a, 0x7b, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x74, 0x69,
|
||||
0x6e, 0x79, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x2d, 0x6d, 0x63, 0x70,
|
||||
0x22, 0x2c, 0x22, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
|
||||
0x22, 0x31, 0x2e, 0x30, 0x22, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x7d, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x72, 0x65, 0x63, 0x76, 0x28, 0x29, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x28, 0x7b,
|
||||
0x22, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x22, 0x32,
|
||||
0x2e, 0x30, 0x22, 0x2c, 0x22, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22,
|
||||
0x3a, 0x22, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x73, 0x2f, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69,
|
||||
0x7a, 0x65, 0x64, 0x22, 0x2c, 0x22, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x22, 0x3a, 0x7b, 0x7d, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x28, 0x7b, 0x22, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x72, 0x70, 0x63, 0x22, 0x3a, 0x22, 0x32, 0x2e, 0x30, 0x22,
|
||||
0x2c, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x32, 0x2c, 0x22, 0x6d, 0x65, 0x74,
|
||||
0x68, 0x6f, 0x64, 0x22, 0x3a, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c,
|
||||
0x22, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x3a, 0x70, 0x61, 0x72,
|
||||
0x61, 0x6d, 0x73, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x63,
|
||||
0x76, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x70, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x20, 0x45,
|
||||
0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x73, 0x20,
|
||||
0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72,
|
||||
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x7b, 0x22, 0x65, 0x72, 0x72, 0x6f,
|
||||
0x72, 0x22, 0x3a, 0x7b, 0x22, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x2d,
|
||||
0x31, 0x2c, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3a,
|
||||
0x73, 0x74, 0x72, 0x28, 0x65, 0x29, 0x7d, 0x7d, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x6c, 0x79, 0x3a, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e, 0x74,
|
||||
0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x28, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x2e,
|
||||
0x77, 0x61, 0x69, 0x74, 0x28, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74,
|
||||
0x3d, 0x33, 0x29, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x64, 0x69,
|
||||
0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20,
|
||||
0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20,
|
||||
0x75, 0x72, 0x6c, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x73, 0x77, 0x69,
|
||||
0x74, 0x68, 0x28, 0x22, 0x73, 0x74, 0x64, 0x69, 0x6f, 0x3a, 0x2f, 0x2f,
|
||||
0x22, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x73, 0x74, 0x64, 0x69,
|
||||
0x6f, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x72, 0x70, 0x63, 0x28, 0x75, 0x72,
|
||||
0x6c, 0x5b, 0x6c, 0x65, 0x6e, 0x28, 0x22, 0x73, 0x74, 0x64, 0x69, 0x6f,
|
||||
0x3a, 0x2f, 0x2f, 0x22, 0x29, 0x3a, 0x5d, 0x2c, 0x20, 0x6d, 0x65, 0x74,
|
||||
0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x29,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x6a, 0x73, 0x6f, 0x6e,
|
||||
0x72, 0x70, 0x63, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x6d, 0x65, 0x74,
|
||||
0x68, 0x6f, 0x64, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x29,
|
||||
0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x6d, 0x63, 0x70, 0x5f, 0x70, 0x69,
|
||||
0x6e, 0x67, 0x28, 0x75, 0x72, 0x6c, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x64, 0x69, 0x73,
|
||||
0x70, 0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x22,
|
||||
0x70, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x20, 0x7b, 0x7d, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72,
|
||||
0x22, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x70, 0x3a, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x3a, 0x20, 0x22, 0x20, 0x2b,
|
||||
0x20, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72,
|
||||
0x22, 0x5d, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x22, 0x2c, 0x20, 0x73, 0x74, 0x72, 0x28, 0x72, 0x65,
|
||||
0x73, 0x70, 0x5b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x29,
|
||||
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
|
||||
0x20, 0x22, 0x6f, 0x6b, 0x22, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x20, 0x6d,
|
||||
0x63, 0x70, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x5f, 0x74, 0x6f, 0x6f, 0x6c,
|
||||
0x73, 0x28, 0x75, 0x72, 0x6c, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x64, 0x69, 0x73, 0x70,
|
||||
0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x22, 0x74,
|
||||
0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x2c, 0x20,
|
||||
0x7b, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x22,
|
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65,
|
||||
0x73, 0x70, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x65, 0x72, 0x72, 0x6f,
|
||||
0x3a, 0x20, 0x22, 0x20, 0x2b, 0x20, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22,
|
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x2e, 0x67, 0x65, 0x74, 0x28,
|
||||
0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2c, 0x20, 0x73,
|
||||
0x74, 0x72, 0x28, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22, 0x65, 0x72, 0x72,
|
||||
0x6f, 0x72, 0x22, 0x5d, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72,
|
||||
0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x70,
|
||||
0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
|
||||
0x22, 0x2c, 0x20, 0x72, 0x65, 0x73, 0x70, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73,
|
||||
0x75, 0x6c, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x74, 0x6f, 0x6f,
|
||||
0x6c, 0x73, 0x22, 0x2c, 0x20, 0x5b, 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5b, 0x5d, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x20, 0x69, 0x6e, 0x20, 0x74,
|
||||
0x6f, 0x6f, 0x6c, 0x73, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x67,
|
||||
0x65, 0x74, 0x28, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2c, 0x22, 0x3f,
|
||||
0x22, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64,
|
||||
0x65, 0x73, 0x63, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x28,
|
||||
0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64,
|
||||
0x28, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2b, 0x20, 0x22, 0x3a, 0x20, 0x22,
|
||||
0x20, 0x2b, 0x20, 0x64, 0x65, 0x73, 0x63, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x5c, 0x6e, 0x22,
|
||||
0x2e, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x6f, 0x75, 0x74, 0x29, 0x20, 0x69,
|
||||
0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x22,
|
||||
0x28, 0x6e, 0x65, 0x6e, 0x68, 0x75, 0x6d, 0x61, 0x20, 0x66, 0x65, 0x72,
|
||||
0x72, 0x61, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x29, 0x22, 0x0a, 0x0a, 0x64,
|
||||
0x65, 0x66, 0x20, 0x6d, 0x63, 0x70, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f,
|
||||
0x74, 0x6f, 0x6f, 0x6c, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x74, 0x6f,
|
||||
0x6f, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x61, 0x72, 0x67,
|
||||
0x73, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x74, 0x72, 0x79, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6a, 0x73, 0x6f,
|
||||
0x6e, 0x2e, 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x28, 0x61, 0x72, 0x67, 0x73,
|
||||
0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x29, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72,
|
||||
0x67, 0x73, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20,
|
||||
0x61, 0x72, 0x67, 0x73, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x73, 0x74,
|
||||
0x72, 0x69, 0x70, 0x28, 0x29, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x7b,
|
||||
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74,
|
||||
0x20, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61,
|
||||
0x73, 0x20, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x65, 0x72, 0x72,
|
||||
0x6f, 0x3a, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x4a, 0x53, 0x4f, 0x4e,
|
||||
0x20, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x6f, 0x3a, 0x20, 0x22,
|
||||
0x20, 0x2b, 0x20, 0x73, 0x74, 0x72, 0x28, 0x65, 0x29, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x73, 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x64, 0x69,
|
||||
0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20,
|
||||
0x22, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x22,
|
||||
0x2c, 0x20, 0x7b, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x20, 0x74,
|
||||
0x6f, 0x6f, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x61,
|
||||
0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 0x20, 0x61,
|
||||
0x72, 0x67, 0x73, 0x7d, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66,
|
||||
0x20, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x20, 0x69, 0x6e, 0x20,
|
||||
0x72, 0x65, 0x73, 0x70, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x65, 0x72,
|
||||
0x72, 0x6f, 0x3a, 0x20, 0x22, 0x20, 0x2b, 0x20, 0x72, 0x65, 0x73, 0x70,
|
||||
0x5b, 0x22, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x2e, 0x67, 0x65,
|
||||
0x74, 0x28, 0x22, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2c,
|
||||
0x20, 0x73, 0x74, 0x72, 0x28, 0x72, 0x65, 0x73, 0x70, 0x5b, 0x22, 0x65,
|
||||
0x72, 0x72, 0x6f, 0x72, 0x22, 0x5d, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65,
|
||||
0x73, 0x70, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x72, 0x65, 0x73, 0x75,
|
||||
0x6c, 0x74, 0x22, 0x2c, 0x20, 0x72, 0x65, 0x73, 0x70, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x3d,
|
||||
0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x28,
|
||||
0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x2c, 0x20, 0x72,
|
||||
0x65, 0x73, 0x75, 0x6c, 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69,
|
||||
0x66, 0x20, 0x69, 0x73, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
|
||||
0x28, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2c, 0x20, 0x6c, 0x69,
|
||||
0x73, 0x74, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x70, 0x61, 0x72, 0x74, 0x73, 0x20, 0x3d, 0x20, 0x5b, 0x5d, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x20,
|
||||
0x69, 0x74, 0x65, 0x6d, 0x20, 0x69, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x74, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x73, 0x69, 0x6e,
|
||||
0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x28, 0x69, 0x74, 0x65, 0x6d, 0x2c,
|
||||
0x20, 0x64, 0x69, 0x63, 0x74, 0x29, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x70, 0x61, 0x72, 0x74, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64,
|
||||
0x28, 0x69, 0x74, 0x65, 0x6d, 0x2e, 0x67, 0x65, 0x74, 0x28, 0x22, 0x74,
|
||||
0x65, 0x78, 0x74, 0x22, 0x2c, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x64,
|
||||
0x75, 0x6d, 0x70, 0x73, 0x28, 0x69, 0x74, 0x65, 0x6d, 0x29, 0x29, 0x29,
|
||||
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x65, 0x6c, 0x73, 0x65, 0x3a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70,
|
||||
0x61, 0x72, 0x74, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28,
|
||||
0x73, 0x74, 0x72, 0x28, 0x69, 0x74, 0x65, 0x6d, 0x29, 0x29, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x2e, 0x6a, 0x6f, 0x69, 0x6e, 0x28,
|
||||
0x70, 0x61, 0x72, 0x74, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72,
|
||||
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6a, 0x73, 0x6f, 0x6e, 0x2e, 0x64,
|
||||
0x75, 0x6d, 0x70, 0x73, 0x28, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
|
||||
0x2c, 0x20, 0x65, 0x6e, 0x73, 0x75, 0x72, 0x65, 0x5f, 0x61, 0x73, 0x63,
|
||||
0x69, 0x69, 0x3d, 0x46, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x20, 0x69, 0x6e,
|
||||
0x64, 0x65, 0x6e, 0x74, 0x3d, 0x32, 0x29, 0x0a
|
||||
};
|
||||
unsigned int tb_mcp_py_len = 3728;
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library operators (categoria "Operadores")
|
||||
# Constroi build/libtinyblocks-operators.a e build/libtinyblocks-operators.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_operators.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-operators.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-operators.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_operators.c include/tb_operators.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library operators. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-operators"
|
||||
version = "1.0.0"
|
||||
category = "Operadores"
|
||||
description = "Logica, comparacao, matematica, texto e literais"
|
||||
color = [89, 192, 89, 255]
|
||||
dark = [56, 148, 56, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_operators.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-operators.so"
|
||||
static = "build/libtinyblocks-operators.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library pen (categoria "Caneta")
|
||||
# Constroi build/libtinyblocks-pen.a e build/libtinyblocks-pen.so
|
||||
# Depende do palco do editor (tb_stage.h); o .so resolve tb_stage_* no host.
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_pen.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-pen.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-pen.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_pen.c include/tb_pen.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library pen. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-pen"
|
||||
version = "1.0.0"
|
||||
category = "Caneta"
|
||||
description = "Desenhe no palco"
|
||||
color = [15, 189, 140, 255]
|
||||
dark = [11, 142, 105, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_pen.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-pen.so"
|
||||
static = "build/libtinyblocks-pen.a"
|
||||
depends = ["tinyblocks-editor"]
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_stage.h"
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include "tb_pen.h"
|
||||
|
||||
static float num(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Makefile da library python (embedding CPython)
|
||||
# Constroi build/libtinyblocks-python.so (soname unico p/ um so interpretador)
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
|
||||
PYTHON_LIBS := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include -Iinclude $(PYTHON_CFLAGS)
|
||||
|
||||
OBJ := $(BUILD)/tb_python_lib.o
|
||||
LIB_SO := $(BUILD)/libtinyblocks-python.so
|
||||
|
||||
.PHONY: all shared clean
|
||||
all: shared
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_python.c include/tinyblocks-python/tb_python.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -Wl,-soname,libtinyblocks-python.so -o $@ $^ $(PYTHON_LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library python. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-python"
|
||||
version = "1.0.0"
|
||||
category = "Python"
|
||||
description = "Embedding de CPython"
|
||||
color = [255, 215, 0, 255]
|
||||
dark = [255, 193, 7, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_python.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-python.so"
|
||||
static = "build/libtinyblocks-python.a"
|
||||
depends = []
|
||||
@@ -1,30 +1,34 @@
|
||||
CC := gcc
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include \
|
||||
$(shell sdl2-config --cflags)
|
||||
LDFLAGS := $(shell sdl2-config --libs)
|
||||
# Makefile da library sdl2 (backend grafico SDL2)
|
||||
# Constroi build/libtinyblocks-sdl2.a e build/libtinyblocks-sdl2.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
BUILD := ../../build
|
||||
LIB_SO := $(BUILD)/libtinyblocks-sdl2.so
|
||||
LIB_A := $(BUILD)/libtinyblocks-sdl2.a
|
||||
OBJ := $(BUILD)/tb_sdl2.o
|
||||
SDL2_CFLAGS := $(shell sdl2-config --cflags)
|
||||
SDL2_LIBS := $(shell sdl2-config --libs)
|
||||
|
||||
.PHONY: all clean shared static
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../../include -I../tinyblocks-graphics/include -Iinclude \
|
||||
$(SDL2_CFLAGS)
|
||||
LDFLAGS := $(SDL2_LIBS) -lm
|
||||
|
||||
all: shared static
|
||||
OBJ := $(BUILD)/tb_sdl2.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-sdl2.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-sdl2.so
|
||||
|
||||
shared: $(LIB_SO)
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_sdl2.c include/tb_sdl2.h
|
||||
$(OBJ): src/tb_sdl2.c include/tb_sdl2.h ../tinyblocks-graphics/include/tb_graphics.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c src/tb_sdl2.c -o $@
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) $(LIB_SO) $(LIB_A)
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library sdl2. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-sdl2"
|
||||
version = "1.0.0"
|
||||
category = "SDL2"
|
||||
description = "Backend grafico SDL2"
|
||||
color = [96, 125, 139, 255]
|
||||
dark = [69, 90, 100, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_sdl2.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-sdl2.so"
|
||||
static = "build/libtinyblocks-sdl2.a"
|
||||
depends = ["tinyblocks-graphics"]
|
||||
@@ -0,0 +1,37 @@
|
||||
# Makefile da library toml (parser de TOML + metadados)
|
||||
# Constroi build/libtinyblocks-toml.a e build/libtinyblocks-toml.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJS := $(BUILD)/lexer.o $(BUILD)/parser.o $(BUILD)/tb_toml.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-toml.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-toml.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(BUILD)/lexer.o: src/lexer.c include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/parser.o: src/parser.c include/ast.h include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/tb_toml.o: src/tb_toml.c include/tb_toml.h include/ast.h include/lexeme.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJS)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJS)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-toml
|
||||
* ast.h: arvore sintatica e leitura de documentos TOML.
|
||||
*/
|
||||
#ifndef TB_TOML_AST_H
|
||||
#define TB_TOML_AST_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "lexeme.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TOML_STRING,
|
||||
TOML_INTEGER,
|
||||
TOML_FLOAT,
|
||||
TOML_BOOL,
|
||||
TOML_DATETIME,
|
||||
TOML_ARRAY,
|
||||
TOML_TABLE
|
||||
} TomlValueKind;
|
||||
|
||||
typedef struct TomlValue TomlValue;
|
||||
typedef struct TomlKeyVal TomlKeyVal;
|
||||
|
||||
struct TomlKeyVal {
|
||||
char* key;
|
||||
TomlValue* value;
|
||||
TomlKeyVal* next;
|
||||
};
|
||||
|
||||
struct TomlValue {
|
||||
TomlValueKind kind;
|
||||
int line, col;
|
||||
union {
|
||||
char* string;
|
||||
long long integer;
|
||||
double real;
|
||||
bool boolean;
|
||||
struct { TomlValue** items; size_t count, cap; } array;
|
||||
struct { TomlKeyVal* head, *tail; size_t count; } table;
|
||||
} as;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
TomlValue* root; /* tabela raiz */
|
||||
} TomlDoc;
|
||||
|
||||
/* Parser (texto em memoria / arquivo). Em erro preenche err. */
|
||||
TomlDoc* toml_parse(const char* src, TomlLexError* err);
|
||||
TomlDoc* toml_parse_file(const char* path, TomlLexError* err);
|
||||
void toml_free(TomlDoc* doc);
|
||||
|
||||
/* Navegacao */
|
||||
const TomlValue* toml_table_get(const TomlValue* table, const char* key);
|
||||
const TomlValue* toml_path_get(const TomlValue* root, const char* dotted);
|
||||
const TomlValue* toml_array_get(const TomlValue* arr, size_t i);
|
||||
size_t toml_array_count(const TomlValue* arr);
|
||||
size_t toml_table_count(const TomlValue* table);
|
||||
const TomlKeyVal* toml_table_head(const TomlValue* table);
|
||||
|
||||
/* Conversoes com valor padrao */
|
||||
const char* toml_as_string(const TomlValue* v, const char* def);
|
||||
long long toml_as_int(const TomlValue* v, long long def);
|
||||
double toml_as_float(const TomlValue* v, double def);
|
||||
bool toml_as_bool(const TomlValue* v, bool def);
|
||||
|
||||
/* Escreve a arvore em stdout (debug) */
|
||||
void toml_dump(const TomlValue* v, int indent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TB_TOML_AST_H */
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-toml
|
||||
* lexeme.h: tipos de token e lexer de TOML.
|
||||
*/
|
||||
#ifndef TB_TOML_LEXEME_H
|
||||
#define TB_TOML_LEXEME_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TL_EOF = 0,
|
||||
TL_ERROR,
|
||||
TL_NEWLINE,
|
||||
TL_LBRACKET, /* [ */
|
||||
TL_RBRACKET, /* ] */
|
||||
TL_LBRACE, /* { */
|
||||
TL_RBRACE, /* } */
|
||||
TL_EQUALS, /* = */
|
||||
TL_COMMA, /* , */
|
||||
TL_DOT, /* . */
|
||||
TL_BARE, /* chave simples */
|
||||
TL_STRING, /* string (basica/literal) */
|
||||
TL_INTEGER,
|
||||
TL_FLOAT,
|
||||
TL_BOOL,
|
||||
TL_DATETIME
|
||||
} TomlLexKind;
|
||||
|
||||
typedef struct {
|
||||
TomlLexKind kind;
|
||||
const char* start; /* inicio no fonte (nao NUL-terminado) */
|
||||
size_t len; /* tamanho no fonte */
|
||||
int line, col;
|
||||
char* text; /* string decodificada (TL_STRING), malloc */
|
||||
long long ival;
|
||||
double fval;
|
||||
bool bval;
|
||||
} Lexeme;
|
||||
|
||||
typedef struct {
|
||||
Lexeme* items;
|
||||
size_t count, cap;
|
||||
} LexemeList;
|
||||
|
||||
typedef struct {
|
||||
bool ok;
|
||||
char msg[256];
|
||||
int line, col;
|
||||
} TomlLexError;
|
||||
|
||||
/* Tokeniza o texto inteiro. Em erro retorna false e preenche *err. */
|
||||
bool toml_lex(const char* src, LexemeList* out, TomlLexError* err);
|
||||
|
||||
/* Libera a lista e os textos decodificados */
|
||||
void toml_lexemes_free(LexemeList* list);
|
||||
|
||||
const char* toml_lexeme_kind_name(TomlLexKind kind);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TB_TOML_LEXEME_H */
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* TinyBlocks - tb_toml.h
|
||||
* Library tinyblocks-toml: parser de TOML (lexer + AST) e metadados de
|
||||
* library. Tambem expoe o bloco Toml.Get para scripts.
|
||||
*/
|
||||
#ifndef TINYBLOCKS_TOML_H
|
||||
#define TINYBLOCKS_TOML_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "lexeme.h"
|
||||
#include "ast.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
TB_API const TinyBlocks_LibraryDescriptor* tb_toml_get_library(void);
|
||||
|
||||
/* Le um valor escalar de um arquivo .toml (ex.: "library.category").
|
||||
* Retorna o valor em 'out' ou o default. Util para metadados de library. */
|
||||
TB_API const char* tb_toml_file_get(const char* path, const char* dotted, const char* def);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TINYBLOCKS_TOML_H */
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library toml. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-toml"
|
||||
version = "1.0.0"
|
||||
category = "TOML"
|
||||
description = "Parser de TOML e metadados de library"
|
||||
color = [158, 112, 219, 255]
|
||||
dark = [125, 51, 178, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/lexer.c", "src/parser.c", "src/tb_toml.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-toml.so"
|
||||
static = "build/libtinyblocks-toml.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-toml
|
||||
* lexer.c: tokenizacao de TOML (subset: chaves, strings, numeros, datas,
|
||||
* arrays, tabelas e tabelas inline).
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "lexeme.h"
|
||||
|
||||
typedef struct {
|
||||
const char* p;
|
||||
int line, col;
|
||||
LexemeList* out;
|
||||
TomlLexError* err;
|
||||
} Lexer;
|
||||
|
||||
static bool is_bare_char(int c) {
|
||||
return isalnum((unsigned char)c) || c == '_' || c == '-';
|
||||
}
|
||||
|
||||
static void adv(Lexer* L) {
|
||||
if (*L->p == '\n') { L->line++; L->col = 1; }
|
||||
else L->col++;
|
||||
L->p++;
|
||||
}
|
||||
|
||||
static bool push(Lexer* L, TomlLexKind kind, const char* start, size_t len) {
|
||||
if (L->out->count >= L->out->cap) {
|
||||
size_t nc = L->out->cap ? L->out->cap * 2 : 64;
|
||||
Lexeme* p = (Lexeme*)realloc(L->out->items, nc * sizeof(Lexeme));
|
||||
if (!p) return false;
|
||||
L->out->items = p; L->out->cap = nc;
|
||||
}
|
||||
Lexeme* t = &L->out->items[L->out->count++];
|
||||
memset(t, 0, sizeof(*t));
|
||||
t->kind = kind;
|
||||
t->start = start;
|
||||
t->len = len;
|
||||
t->line = L->line;
|
||||
t->col = L->col;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fail(Lexer* L, const char* msg) {
|
||||
if (L->err) {
|
||||
L->err->ok = false;
|
||||
snprintf(L->err->msg, sizeof(L->err->msg), "%s", msg);
|
||||
L->err->line = L->line;
|
||||
L->err->col = L->col;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* buffer de texto decodificado */
|
||||
typedef struct { char* p; size_t n, cap; } Buf;
|
||||
|
||||
static bool buf_put(Buf* b, char c) {
|
||||
if (b->n + 1 >= b->cap) {
|
||||
size_t nc = b->cap ? b->cap * 2 : 32;
|
||||
char* p = (char*)realloc(b->p, nc);
|
||||
if (!p) return false;
|
||||
b->p = p; b->cap = nc;
|
||||
}
|
||||
b->p[b->n++] = c;
|
||||
b->p[b->n] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int hexval(int c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool utf8_put(Buf* b, unsigned cp) {
|
||||
if (cp <= 0x7F) return buf_put(b, (char)cp);
|
||||
if (cp <= 0x7FF) {
|
||||
return buf_put(b, (char)(0xC0 | (cp >> 6))) &&
|
||||
buf_put(b, (char)(0x80 | (cp & 0x3F)));
|
||||
}
|
||||
if (cp <= 0xFFFF) {
|
||||
return buf_put(b, (char)(0xE0 | (cp >> 12))) &&
|
||||
buf_put(b, (char)(0x80 | ((cp >> 6) & 0x3F))) &&
|
||||
buf_put(b, (char)(0x80 | (cp & 0x3F)));
|
||||
}
|
||||
return buf_put(b, (char)(0xF0 | (cp >> 18))) &&
|
||||
buf_put(b, (char)(0x80 | ((cp >> 12) & 0x3F))) &&
|
||||
buf_put(b, (char)(0x80 | ((cp >> 6) & 0x3F))) &&
|
||||
buf_put(b, (char)(0x80 | (cp & 0x3F)));
|
||||
}
|
||||
|
||||
/* Le a string basica/literal (single ou multiline). Assume p no delimitador. */
|
||||
static bool lex_string(Lexer* L) {
|
||||
const char* start = L->p;
|
||||
char q = *L->p;
|
||||
bool multi = (L->p[1] == q && L->p[2] == q);
|
||||
Buf b = {0};
|
||||
|
||||
adv(L);
|
||||
if (multi) { adv(L); adv(L); }
|
||||
if (multi && (*L->p == '\r' || *L->p == '\n')) {
|
||||
if (*L->p == '\r' && L->p[1] == '\n') adv(L);
|
||||
adv(L);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
char c = *L->p;
|
||||
if (!c) { free(b.p); return fail(L, "string nao terminada"); }
|
||||
if (multi) {
|
||||
if (c == q && L->p[1] == q && L->p[2] == q) { adv(L); adv(L); adv(L); break; }
|
||||
} else {
|
||||
if (c == q) { adv(L); break; }
|
||||
if (c == '\n') { free(b.p); return fail(L, "quebra de linha em string"); }
|
||||
}
|
||||
if (q == '\'' ) { /* literal: sem escapes */
|
||||
buf_put(&b, c); adv(L); continue;
|
||||
}
|
||||
if (c == '\\') {
|
||||
adv(L);
|
||||
char e = *L->p;
|
||||
if (!multi && (e == '\n' || e == 0)) { free(b.p); return fail(L, "escape invalido"); }
|
||||
switch (e) {
|
||||
case 'b': buf_put(&b, '\b'); adv(L); break;
|
||||
case 't': buf_put(&b, '\t'); adv(L); break;
|
||||
case 'n': buf_put(&b, '\n'); adv(L); break;
|
||||
case 'f': buf_put(&b, '\f'); adv(L); break;
|
||||
case 'r': buf_put(&b, '\r'); adv(L); break;
|
||||
case '"': buf_put(&b, '"'); adv(L); break;
|
||||
case '\\': buf_put(&b, '\\'); adv(L); break;
|
||||
case 'u': case 'U': {
|
||||
int n = (e == 'u') ? 4 : 8;
|
||||
adv(L);
|
||||
unsigned cp = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int h = hexval((unsigned char)*L->p);
|
||||
if (h < 0) { free(b.p); return fail(L, "escape unicode invalido"); }
|
||||
cp = cp * 16 + (unsigned)h; adv(L);
|
||||
}
|
||||
utf8_put(&b, cp);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (multi && (e == '\n' || e == '\r' || e == ' ' || e == '\t')) {
|
||||
/* continua a linha: come a barra e espacos em branco */
|
||||
while (*L->p == ' ' || *L->p == '\t' || *L->p == '\r') adv(L);
|
||||
if (*L->p == '\n') adv(L);
|
||||
while (*L->p == ' ' || *L->p == '\t' || *L->p == '\r' || *L->p == '\n') adv(L);
|
||||
break;
|
||||
}
|
||||
free(b.p); return fail(L, "escape invalido");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
buf_put(&b, c); adv(L);
|
||||
}
|
||||
|
||||
if (!push(L, TL_STRING, start, (size_t)(L->p - start))) { free(b.p); return false; }
|
||||
L->out->items[L->out->count - 1].text = b.p ? b.p : (char*)calloc(1, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Tenta casar uma data/hora a partir de p; retorna o tamanho casado. */
|
||||
static size_t scan_datetime(const char* p) {
|
||||
const char* s = p;
|
||||
int digits = 0;
|
||||
while (isdigit((unsigned char)*s)) { s++; digits++; }
|
||||
if (digits == 4 && *s == '-') {
|
||||
const char* d = s + 1; int m = 0;
|
||||
while (isdigit((unsigned char)*d)) { d++; m++; }
|
||||
if (m != 2 || *d != '-') return 0;
|
||||
d++; int dd = 0;
|
||||
while (isdigit((unsigned char)*d)) { d++; dd++; }
|
||||
if (dd != 2) return 0;
|
||||
s = d;
|
||||
if (*s == 'T' || *s == 't' || *s == ' ') {
|
||||
const char* t = s + 1;
|
||||
int h = 0; while (isdigit((unsigned char)*t)) { t++; h++; }
|
||||
if (h == 2 && *t == ':') {
|
||||
t++; int mi = 0; while (isdigit((unsigned char)*t)) { t++; mi++; }
|
||||
if (mi == 2 && *t == ':') {
|
||||
t++; int se = 0; while (isdigit((unsigned char)*t)) { t++; se++; }
|
||||
if (se == 2) {
|
||||
if (*t == '.') { t++; while (isdigit((unsigned char)*t)) t++; }
|
||||
if (*t == 'Z' || *t == 'z') t++;
|
||||
else if ((*t == '+' || *t == '-')) {
|
||||
t++; int hh = 0; while (isdigit((unsigned char)*t)) { t++; hh++; }
|
||||
if (hh == 2 && *t == ':') { t++; int mm = 0; while (isdigit((unsigned char)*t)) { t++; mm++; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
s = t;
|
||||
}
|
||||
return (size_t)(s - p);
|
||||
}
|
||||
if (digits == 2) {
|
||||
const char* t = s;
|
||||
if (*t == ':') {
|
||||
t++; int mi = 0; while (isdigit((unsigned char)*t)) { t++; mi++; }
|
||||
if (mi == 2 && *t == ':') {
|
||||
t++; int se = 0; while (isdigit((unsigned char)*t)) { t++; se++; }
|
||||
if (se == 2) {
|
||||
if (*t == '.') { t++; while (isdigit((unsigned char)*t)) t++; }
|
||||
return (size_t)(t - p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool lex_number(Lexer* L) {
|
||||
const char* start = L->p;
|
||||
size_t dt = scan_datetime(L->p);
|
||||
if (dt) {
|
||||
while ((size_t)(L->p - start) < dt) adv(L);
|
||||
return push(L, TL_DATETIME, start, dt);
|
||||
}
|
||||
|
||||
if (*L->p == '+' || *L->p == '-') adv(L);
|
||||
/* inf / nan */
|
||||
if (strncmp(L->p, "inf", 3) == 0 || strncmp(L->p, "nan", 3) == 0) {
|
||||
adv(L); adv(L); adv(L);
|
||||
Lexeme tok; bool ok = push(L, TL_FLOAT, start, (size_t)(L->p - start));
|
||||
if (!ok) return false;
|
||||
tok = L->out->items[L->out->count - 1];
|
||||
tok.fval = (start[0] == '-') ? -0.0 : 0.0; /* inf/nan: valor 0 */
|
||||
L->out->items[L->out->count - 1] = tok;
|
||||
return true;
|
||||
}
|
||||
bool ishex = (L->p[0] == '0' && (L->p[1] == 'x' || L->p[1] == 'o' || L->p[1] == 'b'));
|
||||
bool isfloat = false;
|
||||
if (ishex) {
|
||||
int base = L->p[1] == 'x' ? 16 : (L->p[1] == 'o' ? 8 : 2);
|
||||
adv(L); adv(L);
|
||||
while (is_bare_char((unsigned char)*L->p) && *L->p != '-') adv(L);
|
||||
char buf[128]; size_t n = (size_t)(L->p - start);
|
||||
if (n >= sizeof(buf)) n = sizeof(buf) - 1;
|
||||
memcpy(buf, start, n); buf[n] = 0;
|
||||
/* remove underscores e prefixo */
|
||||
char clean[128]; size_t cn = 0;
|
||||
for (size_t i = 0; buf[i] && cn < sizeof(clean) - 1; i++)
|
||||
if (buf[i] != '_') clean[cn++] = buf[i];
|
||||
clean[cn] = 0;
|
||||
if (!push(L, TL_INTEGER, start, (size_t)(L->p - start))) return false;
|
||||
L->out->items[L->out->count - 1].ival = strtoll(clean, NULL, base);
|
||||
return true;
|
||||
}
|
||||
while (isdigit((unsigned char)*L->p) || *L->p == '_') adv(L);
|
||||
if (*L->p == '.') { isfloat = true; adv(L); while (isdigit((unsigned char)*L->p) || *L->p == '_') adv(L); }
|
||||
if (*L->p == 'e' || *L->p == 'E') {
|
||||
isfloat = true; adv(L);
|
||||
if (*L->p == '+' || *L->p == '-') adv(L);
|
||||
while (isdigit((unsigned char)*L->p) || *L->p == '_') adv(L);
|
||||
}
|
||||
char buf[128]; size_t n = (size_t)(L->p - start);
|
||||
if (n >= sizeof(buf)) n = sizeof(buf) - 1;
|
||||
memcpy(buf, start, n); buf[n] = 0;
|
||||
char clean[128]; size_t cn = 0;
|
||||
for (size_t i = 0; buf[i] && cn < sizeof(clean) - 1; i++)
|
||||
if (buf[i] != '_') clean[cn++] = buf[i];
|
||||
clean[cn] = 0;
|
||||
if (!push(L, isfloat ? TL_FLOAT : TL_INTEGER, start, (size_t)(L->p - start))) return false;
|
||||
Lexeme* t = &L->out->items[L->out->count - 1];
|
||||
if (isfloat) t->fval = strtod(clean, NULL);
|
||||
else t->ival = strtoll(clean, NULL, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool toml_lex(const char* src, LexemeList* out, TomlLexError* err) {
|
||||
Lexer L = { src, 1, 1, out, err };
|
||||
if (err) { err->ok = true; err->msg[0] = 0; err->line = err->col = 0; }
|
||||
|
||||
for (;;) {
|
||||
char c = *L.p;
|
||||
if (c == 0) { if (!push(&L, TL_EOF, L.p, 0)) return false; break; }
|
||||
if (c == ' ' || c == '\t') { adv(&L); continue; }
|
||||
if (c == '\r') { adv(&L); if (*L.p == '\n') adv(&L); if (!push(&L, TL_NEWLINE, L.p, 0)) return false; continue; }
|
||||
if (c == '\n') { adv(&L); if (!push(&L, TL_NEWLINE, L.p, 0)) return false; continue; }
|
||||
if (c == '#') { while (*L.p && *L.p != '\n') adv(&L); continue; }
|
||||
if (c == '"' || c == '\'') { if (!lex_string(&L)) return false; continue; }
|
||||
switch (c) {
|
||||
case '[': adv(&L); if (!push(&L, TL_LBRACKET, L.p - 1, 1)) return false; continue;
|
||||
case ']': adv(&L); if (!push(&L, TL_RBRACKET, L.p - 1, 1)) return false; continue;
|
||||
case '{': adv(&L); if (!push(&L, TL_LBRACE, L.p - 1, 1)) return false; continue;
|
||||
case '}': adv(&L); if (!push(&L, TL_RBRACE, L.p - 1, 1)) return false; continue;
|
||||
case '=': adv(&L); if (!push(&L, TL_EQUALS, L.p - 1, 1)) return false; continue;
|
||||
case ',': adv(&L); if (!push(&L, TL_COMMA, L.p - 1, 1)) return false; continue;
|
||||
case '.': adv(&L); if (!push(&L, TL_DOT, L.p - 1, 1)) return false; continue;
|
||||
default: break;
|
||||
}
|
||||
if (c == '+' || c == '-' || isdigit((unsigned char)c)) { if (!lex_number(&L)) return false; continue; }
|
||||
if (is_bare_char((unsigned char)c)) {
|
||||
const char* start = L.p;
|
||||
while (is_bare_char((unsigned char)*L.p)) adv(&L);
|
||||
size_t n = (size_t)(L.p - start);
|
||||
TomlLexKind k = TL_BARE;
|
||||
if (n == 4 && strncmp(start, "true", 4) == 0) k = TL_BOOL;
|
||||
else if (n == 5 && strncmp(start, "false", 5) == 0) k = TL_BOOL;
|
||||
else if ((n == 3 && (strncmp(start, "inf", 3) == 0 || strncmp(start, "nan", 3) == 0))) k = TL_FLOAT;
|
||||
if (!push(&L, k, start, n)) return false;
|
||||
Lexeme* t = &L.out->items[L.out->count - 1];
|
||||
if (k == TL_BOOL) t->bval = (start[0] == 't');
|
||||
if (k == TL_FLOAT) t->fval = 0.0;
|
||||
continue;
|
||||
}
|
||||
return fail(&L, "caractere inesperado");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void toml_lexemes_free(LexemeList* list) {
|
||||
if (!list) return;
|
||||
for (size_t i = 0; i < list->count; i++) free(list->items[i].text);
|
||||
free(list->items);
|
||||
list->items = NULL; list->count = list->cap = 0;
|
||||
}
|
||||
|
||||
const char* toml_lexeme_kind_name(TomlLexKind kind) {
|
||||
switch (kind) {
|
||||
case TL_EOF: return "EOF";
|
||||
case TL_ERROR: return "ERROR";
|
||||
case TL_NEWLINE: return "NEWLINE";
|
||||
case TL_LBRACKET: return "[";
|
||||
case TL_RBRACKET: return "]";
|
||||
case TL_LBRACE: return "{";
|
||||
case TL_RBRACE: return "}";
|
||||
case TL_EQUALS: return "=";
|
||||
case TL_COMMA: return ",";
|
||||
case TL_DOT: return ".";
|
||||
case TL_BARE: return "BARE";
|
||||
case TL_STRING: return "STRING";
|
||||
case TL_INTEGER: return "INTEGER";
|
||||
case TL_FLOAT: return "FLOAT";
|
||||
case TL_BOOL: return "BOOL";
|
||||
case TL_DATETIME: return "DATETIME";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-toml
|
||||
* parser.c: parser descendente recursivo de TOML sobre a lista de lexemas.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "ast.h"
|
||||
|
||||
typedef struct {
|
||||
const Lexeme* toks;
|
||||
size_t n, i;
|
||||
TomlValue* root;
|
||||
TomlValue* cur; /* tabela corrente (headers) */
|
||||
TomlLexError* err;
|
||||
} Parser;
|
||||
|
||||
static const Lexeme* peek(Parser* P) { return &P->toks[P->i]; }
|
||||
static const Lexeme* advance(Parser* P) {
|
||||
const Lexeme* t = &P->toks[P->i];
|
||||
if (P->i + 1 < P->n) P->i++;
|
||||
return t;
|
||||
}
|
||||
static bool at(Parser* P, TomlLexKind k) { return peek(P)->kind == k; }
|
||||
static bool accept(Parser* P, TomlLexKind k) {
|
||||
if (!at(P, k)) return false;
|
||||
advance(P);
|
||||
return true;
|
||||
}
|
||||
|
||||
static TomlValue* vnew(TomlValueKind k, int line, int col) {
|
||||
TomlValue* v = (TomlValue*)calloc(1, sizeof(TomlValue));
|
||||
if (!v) return NULL;
|
||||
v->kind = k; v->line = line; v->col = col;
|
||||
return v;
|
||||
}
|
||||
|
||||
static TomlValue* vtable(int line, int col) { return vnew(TOML_TABLE, line, col); }
|
||||
|
||||
static char* dup_range(const char* s, size_t n) {
|
||||
char* p = (char*)malloc(n + 1);
|
||||
if (!p) return NULL;
|
||||
memcpy(p, s, n); p[n] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* chave de um token (bare/string/numero/bool/data) */
|
||||
static char* token_key(const Lexeme* t) {
|
||||
if (t->kind == TL_STRING && t->text) return dup_range(t->text, strlen(t->text));
|
||||
return dup_range(t->start, t->len);
|
||||
}
|
||||
|
||||
static void value_free(TomlValue* v) {
|
||||
if (!v) return;
|
||||
switch (v->kind) {
|
||||
case TOML_STRING: free(v->as.string); break;
|
||||
case TOML_DATETIME: free(v->as.string); break;
|
||||
case TOML_ARRAY:
|
||||
for (size_t i = 0; i < v->as.array.count; i++) value_free(v->as.array.items[i]);
|
||||
free(v->as.array.items);
|
||||
break;
|
||||
case TOML_TABLE: {
|
||||
TomlKeyVal* kv = v->as.table.head;
|
||||
while (kv) { TomlKeyVal* nx = kv->next; free(kv->key); value_free(kv->value); free(kv); kv = nx; }
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
free(v);
|
||||
}
|
||||
|
||||
static TomlKeyVal* table_find(const TomlValue* t, const char* key) {
|
||||
if (!t || t->kind != TOML_TABLE) return NULL;
|
||||
for (TomlKeyVal* kv = t->as.table.head; kv; kv = kv->next)
|
||||
if (strcmp(kv->key, key) == 0) return kv;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool table_set(TomlValue* t, char* key, TomlValue* val) {
|
||||
TomlKeyVal* kv = table_find(t, key);
|
||||
if (kv) {
|
||||
free(key);
|
||||
value_free(kv->value);
|
||||
kv->value = val;
|
||||
return true;
|
||||
}
|
||||
kv = (TomlKeyVal*)calloc(1, sizeof(TomlKeyVal));
|
||||
if (!kv) { free(key); value_free(val); return false; }
|
||||
kv->key = key; kv->value = val;
|
||||
if (t->as.table.tail) t->as.table.tail->next = kv;
|
||||
else t->as.table.head = kv;
|
||||
t->as.table.tail = kv;
|
||||
t->as.table.count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
static TomlValue* table_child(TomlValue* t, const char* key, bool create) {
|
||||
TomlKeyVal* kv = table_find(t, key);
|
||||
if (kv) {
|
||||
if (kv->value->kind == TOML_TABLE) return kv->value;
|
||||
return NULL;
|
||||
}
|
||||
if (!create) return NULL;
|
||||
TomlValue* child = vtable(t->line, t->col);
|
||||
if (!child) return NULL;
|
||||
if (!table_set(t, dup_range(key, strlen(key)), child)) return NULL;
|
||||
return child;
|
||||
}
|
||||
|
||||
/* [[a.b]]: obtem/cria o array em 't' com a chave, devolve o array */
|
||||
static TomlValue* table_array(TomlValue* t, const char* key) {
|
||||
TomlKeyVal* kv = table_find(t, key);
|
||||
if (kv && kv->value->kind == TOML_ARRAY) return kv->value;
|
||||
if (kv) return NULL;
|
||||
TomlValue* arr = vnew(TOML_ARRAY, t->line, t->col);
|
||||
if (!arr) return NULL;
|
||||
if (!table_set(t, dup_range(key, strlen(key)), arr)) return NULL;
|
||||
return arr;
|
||||
}
|
||||
|
||||
static bool array_push(TomlValue* arr, TomlValue* v) {
|
||||
if (arr->as.array.count >= arr->as.array.cap) {
|
||||
size_t nc = arr->as.array.cap ? arr->as.array.cap * 2 : 8;
|
||||
TomlValue** p = (TomlValue**)realloc(arr->as.array.items, nc * sizeof(TomlValue*));
|
||||
if (!p) return false;
|
||||
arr->as.array.items = p; arr->as.array.cap = nc;
|
||||
}
|
||||
arr->as.array.items[arr->as.array.count++] = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fail(Parser* P, const Lexeme* t, const char* msg) {
|
||||
if (P->err) {
|
||||
P->err->ok = false;
|
||||
snprintf(P->err->msg, sizeof(P->err->msg), "%s", msg);
|
||||
P->err->line = t->line;
|
||||
P->err->col = t->col;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void skip_newlines(Parser* P) { while (at(P, TL_NEWLINE)) advance(P); }
|
||||
|
||||
/* le uma sequencia de chaves separadas por ponto: a, b.c */
|
||||
#define MAX_KEYS 16
|
||||
static int parse_key_path(Parser* P, char* keys[MAX_KEYS]) {
|
||||
int n = 0;
|
||||
for (;;) {
|
||||
const Lexeme* t = peek(P);
|
||||
if (t->kind != TL_BARE && t->kind != TL_STRING &&
|
||||
t->kind != TL_INTEGER && t->kind != TL_FLOAT &&
|
||||
t->kind != TL_BOOL && t->kind != TL_DATETIME) {
|
||||
fail(P, t, "chave esperada"); return -1;
|
||||
}
|
||||
if (n >= MAX_KEYS) { fail(P, t, "chaves demais"); return -1; }
|
||||
keys[n++] = token_key(t);
|
||||
advance(P);
|
||||
if (!accept(P, TL_DOT)) break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void free_keys(char* keys[], int n) { for (int i = 0; i < n; i++) free(keys[i]); }
|
||||
|
||||
static TomlValue* parse_value(Parser* P);
|
||||
|
||||
static TomlValue* parse_array(Parser* P) {
|
||||
const Lexeme* open = advance(P); /* [ */
|
||||
TomlValue* arr = vnew(TOML_ARRAY, open->line, open->col);
|
||||
if (!arr) return NULL;
|
||||
for (;;) {
|
||||
skip_newlines(P);
|
||||
if (accept(P, TL_RBRACKET)) return arr;
|
||||
TomlValue* v = parse_value(P);
|
||||
if (!v) { value_free(arr); return NULL; }
|
||||
array_push(arr, v);
|
||||
skip_newlines(P);
|
||||
if (accept(P, TL_COMMA)) continue;
|
||||
if (at(P, TL_RBRACKET)) continue;
|
||||
fail(P, peek(P), "esperado , ou ]");
|
||||
value_free(arr); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static TomlValue* parse_inline_table(Parser* P) {
|
||||
const Lexeme* open = advance(P); /* { */
|
||||
TomlValue* t = vtable(open->line, open->col);
|
||||
if (!t) return NULL;
|
||||
for (;;) {
|
||||
if (accept(P, TL_RBRACE)) return t;
|
||||
char* keys[MAX_KEYS];
|
||||
int n = parse_key_path(P, keys);
|
||||
if (n < 0) { value_free(t); return NULL; }
|
||||
if (!accept(P, TL_EQUALS)) {
|
||||
fail(P, peek(P), "esperado =");
|
||||
free_keys(keys, n); value_free(t); return NULL;
|
||||
}
|
||||
TomlValue* v = parse_value(P);
|
||||
if (!v) { free_keys(keys, n); value_free(t); return NULL; }
|
||||
TomlValue* dst = t;
|
||||
for (int j = 0; j < n - 1 && dst; j++) dst = table_child(dst, keys[j], true);
|
||||
if (!dst) { free_keys(keys, n); value_free(v); value_free(t); return NULL; }
|
||||
table_set(dst, keys[n - 1], v); /* consome keys[n-1] */
|
||||
for (int j = 0; j < n - 1; j++) free(keys[j]);
|
||||
if (accept(P, TL_COMMA)) continue;
|
||||
if (at(P, TL_RBRACE)) continue;
|
||||
fail(P, peek(P), "esperado , ou }");
|
||||
value_free(t); return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static TomlValue* parse_value(Parser* P) {
|
||||
const Lexeme* t = peek(P);
|
||||
switch (t->kind) {
|
||||
case TL_STRING: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_STRING, t->line, t->col);
|
||||
if (!v) return NULL;
|
||||
v->as.string = dup_range(t->text ? t->text : "", t->text ? strlen(t->text) : 0);
|
||||
return v;
|
||||
}
|
||||
case TL_INTEGER: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_INTEGER, t->line, t->col);
|
||||
if (v) v->as.integer = t->ival;
|
||||
return v;
|
||||
}
|
||||
case TL_FLOAT: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_FLOAT, t->line, t->col);
|
||||
if (v) v->as.real = t->fval;
|
||||
return v;
|
||||
}
|
||||
case TL_BOOL: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_BOOL, t->line, t->col);
|
||||
if (v) v->as.boolean = t->bval;
|
||||
return v;
|
||||
}
|
||||
case TL_DATETIME: {
|
||||
advance(P);
|
||||
TomlValue* v = vnew(TOML_DATETIME, t->line, t->col);
|
||||
if (v) v->as.string = dup_range(t->start, t->len);
|
||||
return v;
|
||||
}
|
||||
case TL_LBRACKET:
|
||||
return parse_array(P);
|
||||
case TL_LBRACE:
|
||||
return parse_inline_table(P);
|
||||
default:
|
||||
fail(P, t, "valor esperado");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* [a.b] / [[a.b]] */
|
||||
static bool parse_table_header(Parser* P) {
|
||||
const Lexeme* open = advance(P); /* [ */
|
||||
bool array = accept(P, TL_LBRACKET);
|
||||
char* keys[MAX_KEYS];
|
||||
int n = parse_key_path(P, keys);
|
||||
if (n < 0) return false;
|
||||
if (!accept(P, TL_RBRACKET)) { fail(P, peek(P), "esperado ]"); free_keys(keys, n); return false; }
|
||||
if (array && !accept(P, TL_RBRACKET)) { fail(P, peek(P), "esperado ]]"); free_keys(keys, n); return false; }
|
||||
|
||||
TomlValue* t = P->root;
|
||||
for (int j = 0; j < n - 1 && t; j++) t = table_child(t, keys[j], true);
|
||||
if (!t) { free_keys(keys, n); return true; }
|
||||
|
||||
if (array) {
|
||||
TomlValue* arr = table_array(t, keys[n - 1]);
|
||||
if (!arr) { free_keys(keys, n); fail(P, open, "array de tabelas invalido"); return false; }
|
||||
TomlValue* elem = vtable(open->line, open->col);
|
||||
if (!elem) { free_keys(keys, n); return false; }
|
||||
array_push(arr, elem);
|
||||
P->cur = elem;
|
||||
} else {
|
||||
TomlValue* child = table_child(t, keys[n - 1], true);
|
||||
if (!child) { free_keys(keys, n); fail(P, open, "tabela invalida"); return false; }
|
||||
P->cur = child;
|
||||
}
|
||||
free_keys(keys, n);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_keyval(Parser* P) {
|
||||
char* keys[MAX_KEYS];
|
||||
int n = parse_key_path(P, keys);
|
||||
if (n < 0) return false;
|
||||
if (!accept(P, TL_EQUALS)) { fail(P, peek(P), "esperado ="); free_keys(keys, n); return false; }
|
||||
TomlValue* v = parse_value(P);
|
||||
if (!v) { free_keys(keys, n); return false; }
|
||||
TomlValue* dst = P->cur ? P->cur : P->root;
|
||||
for (int j = 0; j < n - 1 && dst; j++) dst = table_child(dst, keys[j], true);
|
||||
if (!dst) { free_keys(keys, n); value_free(v); return false; }
|
||||
table_set(dst, keys[n - 1], v); /* consome keys[n-1] */
|
||||
for (int j = 0; j < n - 1; j++) free(keys[j]);
|
||||
return true;
|
||||
}
|
||||
|
||||
TomlDoc* toml_parse(const char* src, TomlLexError* err) {
|
||||
LexemeList toks = {0};
|
||||
if (!toml_lex(src, &toks, err)) { toml_lexemes_free(&toks); return NULL; }
|
||||
|
||||
Parser P = { toks.items, toks.count, 0, NULL, NULL, err };
|
||||
P.root = vtable(1, 1);
|
||||
P.cur = P.root;
|
||||
if (!P.root) { toml_lexemes_free(&toks); return NULL; }
|
||||
|
||||
bool ok = true;
|
||||
for (;;) {
|
||||
skip_newlines(&P);
|
||||
if (at(&P, TL_EOF)) break;
|
||||
if (at(&P, TL_LBRACKET)) { if (!parse_table_header(&P)) { ok = false; break; } }
|
||||
else { if (!parse_keyval(&P)) { ok = false; break; } }
|
||||
if (!accept(&P, TL_NEWLINE) && !at(&P, TL_EOF)) {
|
||||
fail(&P, peek(&P), "esperado quebra de linha");
|
||||
ok = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
toml_lexemes_free(&toks);
|
||||
if (!ok) { value_free(P.root); return NULL; }
|
||||
TomlDoc* doc = (TomlDoc*)calloc(1, sizeof(TomlDoc));
|
||||
if (!doc) { value_free(P.root); return NULL; }
|
||||
doc->root = P.root;
|
||||
return doc;
|
||||
}
|
||||
|
||||
TomlDoc* toml_parse_file(const char* path, TomlLexError* err) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (!f) {
|
||||
if (err) { err->ok = false; snprintf(err->msg, sizeof(err->msg), "nao abriu %s", path); err->line = err->col = 0; }
|
||||
return NULL;
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
long sz = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (sz < 0 || sz > (long)(64 * 1024 * 1024)) { fclose(f); return NULL; }
|
||||
char* buf = (char*)malloc((size_t)sz + 1);
|
||||
if (!buf) { fclose(f); return NULL; }
|
||||
size_t rd = fread(buf, 1, (size_t)sz, f);
|
||||
buf[rd] = 0;
|
||||
fclose(f);
|
||||
TomlDoc* doc = toml_parse(buf, err);
|
||||
free(buf);
|
||||
return doc;
|
||||
}
|
||||
|
||||
void toml_free(TomlDoc* doc) {
|
||||
if (!doc) return;
|
||||
value_free(doc->root);
|
||||
free(doc);
|
||||
}
|
||||
|
||||
/* -- Navegacao ----------------------------------------------------------- */
|
||||
|
||||
const TomlValue* toml_table_get(const TomlValue* table, const char* key) {
|
||||
TomlKeyVal* kv = table_find(table, key);
|
||||
return kv ? kv->value : NULL;
|
||||
}
|
||||
|
||||
const TomlValue* toml_path_get(const TomlValue* root, const char* dotted) {
|
||||
if (!root || !dotted) return NULL;
|
||||
const TomlValue* t = root;
|
||||
const char* p = dotted;
|
||||
char part[128];
|
||||
while (*p) {
|
||||
size_t n = 0;
|
||||
while (*p && *p != '.' && n < sizeof(part) - 1) part[n++] = *p++;
|
||||
part[n] = 0;
|
||||
if (t && t->kind == TOML_ARRAY) {
|
||||
bool digits = part[0] != 0;
|
||||
for (const char* q = part; *q; q++) if (!isdigit((unsigned char)*q)) digits = false;
|
||||
t = digits ? toml_array_get(t, (size_t)strtoul(part, NULL, 10)) : NULL;
|
||||
} else {
|
||||
t = toml_table_get(t, part);
|
||||
}
|
||||
if (!t) return NULL;
|
||||
if (*p == '.') p++;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
const TomlValue* toml_array_get(const TomlValue* arr, size_t i) {
|
||||
if (!arr || arr->kind != TOML_ARRAY || i >= arr->as.array.count) return NULL;
|
||||
return arr->as.array.items[i];
|
||||
}
|
||||
|
||||
size_t toml_array_count(const TomlValue* arr) {
|
||||
return (arr && arr->kind == TOML_ARRAY) ? arr->as.array.count : 0;
|
||||
}
|
||||
|
||||
size_t toml_table_count(const TomlValue* table) {
|
||||
return (table && table->kind == TOML_TABLE) ? table->as.table.count : 0;
|
||||
}
|
||||
|
||||
const TomlKeyVal* toml_table_head(const TomlValue* table) {
|
||||
return (table && table->kind == TOML_TABLE) ? table->as.table.head : NULL;
|
||||
}
|
||||
|
||||
const char* toml_as_string(const TomlValue* v, const char* def) {
|
||||
if (!v) return def;
|
||||
if (v->kind == TOML_STRING || v->kind == TOML_DATETIME) return v->as.string;
|
||||
return def;
|
||||
}
|
||||
long long toml_as_int(const TomlValue* v, long long def) {
|
||||
if (v && v->kind == TOML_INTEGER) return v->as.integer;
|
||||
return def;
|
||||
}
|
||||
double toml_as_float(const TomlValue* v, double def) {
|
||||
if (!v) return def;
|
||||
if (v->kind == TOML_FLOAT) return v->as.real;
|
||||
if (v->kind == TOML_INTEGER) return (double)v->as.integer;
|
||||
return def;
|
||||
}
|
||||
bool toml_as_bool(const TomlValue* v, bool def) {
|
||||
if (v && v->kind == TOML_BOOL) return v->as.boolean;
|
||||
return def;
|
||||
}
|
||||
|
||||
static void indent(int n) { for (int i = 0; i < n; i++) fputs(" ", stdout); }
|
||||
|
||||
void toml_dump(const TomlValue* v, int depth) {
|
||||
if (!v) return;
|
||||
switch (v->kind) {
|
||||
case TOML_STRING: indent(depth); printf("\"%s\"\n", v->as.string); break;
|
||||
case TOML_DATETIME: indent(depth); printf("%s\n", v->as.string); break;
|
||||
case TOML_INTEGER: indent(depth); printf("%lld\n", v->as.integer); break;
|
||||
case TOML_FLOAT: indent(depth); printf("%g\n", v->as.real); break;
|
||||
case TOML_BOOL: indent(depth); printf("%s\n", v->as.boolean ? "true" : "false"); break;
|
||||
case TOML_ARRAY:
|
||||
indent(depth); printf("[\n");
|
||||
for (size_t i = 0; i < v->as.array.count; i++) toml_dump(v->as.array.items[i], depth + 1);
|
||||
indent(depth); printf("]\n");
|
||||
break;
|
||||
case TOML_TABLE:
|
||||
for (TomlKeyVal* kv = v->as.table.head; kv; kv = kv->next) {
|
||||
indent(depth); printf("%s = ", kv->key);
|
||||
if (kv->value->kind == TOML_TABLE || kv->value->kind == TOML_ARRAY) { printf("\n"); toml_dump(kv->value, depth + 1); }
|
||||
else toml_dump(kv->value, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* TinyBlocks - tb_toml.c
|
||||
* Library tinyblocks-toml: registra o bloco Toml.Get e helpers de metadados.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_toml.h"
|
||||
|
||||
#define CAT_COLOR 0.62f, 0.44f, 0.86f, 1.f
|
||||
#define CAT_DARK 0.49f, 0.33f, 0.70f, 1.f
|
||||
|
||||
static const char* value_to_text(const TomlValue* v, char* buf, size_t cap) {
|
||||
if (!v) { buf[0] = 0; return buf; }
|
||||
switch (v->kind) {
|
||||
case TOML_STRING:
|
||||
case TOML_DATETIME: snprintf(buf, cap, "%s", v->as.string ? v->as.string : ""); break;
|
||||
case TOML_INTEGER: snprintf(buf, cap, "%lld", v->as.integer); break;
|
||||
case TOML_FLOAT: snprintf(buf, cap, "%g", v->as.real); break;
|
||||
case TOML_BOOL: snprintf(buf, cap, "%s", v->as.boolean ? "true" : "false"); break;
|
||||
default: buf[0] = 0; break;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void eval_toml_get(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value text = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Value key = tb_block_get_input(self, rt, 1);
|
||||
const char* src = (text.kind == TB_VALUE_TEXT && text.as.text) ? text.as.text : "";
|
||||
const char* dotted = (key.kind == TB_VALUE_TEXT && key.as.text) ? key.as.text : "";
|
||||
|
||||
TomlLexError err;
|
||||
TomlDoc* doc = toml_parse(src, &err);
|
||||
char out[512] = "";
|
||||
if (doc) {
|
||||
const TomlValue* v = toml_path_get(doc->root, dotted);
|
||||
value_to_text(v, out, sizeof(out));
|
||||
toml_free(doc);
|
||||
}
|
||||
tb_block_set_output(self, 0, tb_value_text(out));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static bool toml_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_Category cat = { "TOML", {CAT_COLOR}, {CAT_DARK} };
|
||||
tb_library_set_category(lib, &cat);
|
||||
|
||||
static const TinyBlocks_SlotDesc in[] = {{"texto", TB_VALUE_TEXT}, {"chave", TB_VALUE_TEXT}};
|
||||
static const TinyBlocks_SlotDesc out[] = {{"valor", TB_VALUE_TEXT}};
|
||||
TinyBlocks_TypeBlock* t = tb_type_block_create(rt, "Toml.Get", in, 2, out, 1, eval_toml_get);
|
||||
return t && tb_library_add(lib, &t->base);
|
||||
}
|
||||
|
||||
static void toml_deinit(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) { (void)rt; (void)lib; }
|
||||
|
||||
TINYBLOCKS_DEFINE_LIBRARY(toml,
|
||||
"tinyblocks-toml",
|
||||
"1.0.0",
|
||||
toml_init,
|
||||
toml_deinit)
|
||||
|
||||
const TinyBlocks_LibraryDescriptor* tb_toml_get_library(void) {
|
||||
return &_tb_lib_desc_toml;
|
||||
}
|
||||
|
||||
const char* tb_toml_file_get(const char* path, const char* dotted, const char* def) {
|
||||
static char buf[256];
|
||||
TomlLexError err;
|
||||
TomlDoc* doc = toml_parse_file(path, &err);
|
||||
if (!doc) return def;
|
||||
const TomlValue* v = toml_path_get(doc->root, dotted);
|
||||
if (!v) { toml_free(doc); return def; }
|
||||
value_to_text(v, buf, sizeof(buf));
|
||||
toml_free(doc);
|
||||
return buf;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
# Makefile da library variables (categoria "Variáveis")
|
||||
# Constroi build/libtinyblocks-variables.a e build/libtinyblocks-variables.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
CORE := ../../build
|
||||
|
||||
CFLAGS := -std=c11 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-D_POSIX_C_SOURCE=200809L -I../../include -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_variables.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-variables.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-variables.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(OBJ): src/tb_variables.c include/tb_variables.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,15 @@
|
||||
# Metadados da library variables. Lido pela UI/build sem recompilar o .so.
|
||||
[library]
|
||||
name = "tinyblocks-variables"
|
||||
version = "1.0.0"
|
||||
category = "Variaveis"
|
||||
description = "Mude, adicione e valor de variavel"
|
||||
color = [255, 140, 26, 255]
|
||||
dark = [219, 110, 0, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_variables.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-variables.so"
|
||||
static = "build/libtinyblocks-variables.a"
|
||||
depends = []
|
||||
Reference in new issue
Block a user