Configuracoes: caminho do arquivo de config + toggle da variavel de ambiente
- tb_environ_config_path: caminho padrao ($XDG_CONFIG_HOME/tinyblocks/ settings.csv ou $HOME/.config/tinyblocks/settings.csv). - tb_environ_env_path: le TINYBLOCKS_SETTINGS. - tb_environ_export_csv_meta: escreve uma linha de metadados "# arquivo_config,<caminho>" antes da tabela; export_csv agora tambem cria as pastas do caminho (mkdir -p). - Editor: o CSV de settings passa a ser salvo no caminho do arquivo de configuracao (mostrado no campo) e inclui esse caminho no proprio CSV. - Nova linha de opcoes com o toggle "Detectar caminho de TINYBLOCKS_SETTINGS" (checkbox): ligado usa a variavel de ambiente, desligado usa o caminho padrao; mostra o valor atual (ou "nao definida"). - Testes: test-environ cobre config_path/env_path/export_csv_meta e a criacao de pastas; harness passa a ligar o toggle com TINYBLOCKS_SETTINGS e confere a linha de metadados no CSV.
This commit is contained in:
1 parent
7fc3a18234
commit
a14c7f9937
7 files changed
+139
-1088
No files matched your search
@@ -12,6 +12,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_environ.h"
|
||||
@@ -107,11 +109,29 @@ static void csv_field(FILE* f, const char* s) {
|
||||
fputc('"', f);
|
||||
}
|
||||
|
||||
bool tb_environ_export_csv(const char* path) {
|
||||
/* Cria as pastas do caminho (como mkdir -p do diretorio pai). */
|
||||
static void mkparents(const char* path) {
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof(tmp), "%s", path);
|
||||
for (char* p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') { *p = 0; mkdir(tmp, 0755); *p = '/'; }
|
||||
}
|
||||
}
|
||||
|
||||
bool tb_environ_export_csv_meta(const char* path, const char* meta_key,
|
||||
const char* meta_value) {
|
||||
s_err[0] = 0;
|
||||
if (!path || !path[0]) { snprintf(s_err, sizeof(s_err), "caminho vazio"); return false; }
|
||||
mkparents(path);
|
||||
FILE* f = fopen(path, "wb");
|
||||
if (!f) { snprintf(s_err, sizeof(s_err), "nao foi possivel abrir %s", path); return false; }
|
||||
if (meta_key && meta_key[0]) {
|
||||
fputs("# ", f);
|
||||
csv_field(f, meta_key);
|
||||
fputc(',', f);
|
||||
csv_field(f, meta_value ? meta_value : "");
|
||||
fputc('\n', f);
|
||||
}
|
||||
fputs("chave,valor\n", f);
|
||||
for (int i = 0; i < s_env_n; i++) {
|
||||
csv_field(f, s_env[i].key);
|
||||
@@ -123,6 +143,24 @@ bool tb_environ_export_csv(const char* path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tb_environ_export_csv(const char* path) {
|
||||
return tb_environ_export_csv_meta(path, NULL, NULL);
|
||||
}
|
||||
|
||||
void tb_environ_config_path(char* buf, size_t cap) {
|
||||
if (!buf || cap == 0) return;
|
||||
const char* xdg = getenv("XDG_CONFIG_HOME");
|
||||
const char* home = getenv("HOME");
|
||||
if (xdg && xdg[0]) snprintf(buf, cap, "%s/tinyblocks/settings.csv", xdg);
|
||||
else if (home && home[0]) snprintf(buf, cap, "%s/.config/tinyblocks/settings.csv", home);
|
||||
else snprintf(buf, cap, "%s", "tinyblocks-settings.csv");
|
||||
}
|
||||
|
||||
const char* tb_environ_env_path(void) {
|
||||
const char* e = getenv("TINYBLOCKS_SETTINGS");
|
||||
return (e && e[0]) ? e : "";
|
||||
}
|
||||
|
||||
/* -- Blocos -------------------------------------------------------------- */
|
||||
|
||||
static const char* in_text(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
|
||||
Reference in new issue
Block a user