fix(libhectic): arena allocators

This commit is contained in:
2025-03-21 02:54:47 +00:00
parent 4f2391e9b5
commit 9438280750
7 changed files with 78 additions and 99 deletions

View File

@@ -1,4 +1,4 @@
{ stdenv, gcc, lib, libhectic }:
{ stdenv, gcc, lib, libhectic, cjson }:
stdenv.mkDerivation {
pname = "hmpl";
@@ -6,13 +6,13 @@ stdenv.mkDerivation {
src = ./.;
doCheck = true;
buildInputs = [ libhectic ];
buildInputs = [ libhectic cjson ];
buildPhase = ''
mkdir -p target
${gcc}/bin/cc -Wall -Wextra -g \
-pedantic -fsanitize=address hmpl.c \
-l:libhectic.a -o target/hmpl
-l:libhectic.a -l:cjson -o target/hmpl
'';
checkPhase = '' '';

View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//#include "libhmpl.h"
#include "libhectic.h"
@@ -80,8 +81,25 @@ void render_template(char *text, char *context) {
render_template_placeholders(text, context, "");
}
int main(void) {
render_template(text, context);
int main(int argc, char *argv[]) {
char *text = NULL;
char *context = strdup(argc > 1 ? argv[1] : "{}");
return 0;
if (argc > 2) {
text = strdup(argv[2]);
} else if (!isatty(fileno(stdin))) {
size_t size = 0;
ssize_t len = getdelim(&text, &size, '\0', stdin);
if (len < 0) {
perror("read stdin");
free(context);
return 1;
}
}
render_template(text, context);
free(text);
free(context);
return 0;
}