diff --git a/include/cli/cprintf.h b/include/cli/cprintf.h index 9ad5926..cf47e4c 100644 --- a/include/cli/cprintf.h +++ b/include/cli/cprintf.h @@ -3,9 +3,9 @@ #include #include +#include extern bool io_no_color; - typedef struct program_t program_t; program_t *cprintf_compile(const char *fmt); diff --git a/include/runtime.h b/include/runtime.h index 67aac8f..f2e2fb4 100644 --- a/include/runtime.h +++ b/include/runtime.h @@ -2,7 +2,7 @@ #define RUNTIME_H #include "types.h" -#include +struct arg_file; #define ANT_RUNTIME_CRYPTO_INIT (1u << 0) #define CODE_ARENA_BLOCK_SIZE (64 * 1024) diff --git a/libant/scripts/header.sh b/libant/scripts/header.sh index f910d9a..93fb0bc 100755 --- a/libant/scripts/header.sh +++ b/libant/scripts/header.sh @@ -34,7 +34,6 @@ HEADERS=( "utils.h:$INCLUDE_DIR/utils.h" "runtime.h:$INCLUDE_DIR/runtime.h" "esm/remote.h:$INCLUDE_DIR/esm/remote.h" - "argtable3.h:$VENDOR_DIR/argtable-v3.3.0.116da6c/src/argtable3.h" ) for f in "$INCLUDE_DIR"/modules/*.h; do @@ -111,7 +110,7 @@ for entry in "${HEADERS[@]}"; do continue fi - if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|uv|argtable3|types|utarray|uthash|minicoro)\.h\> ]]; then + if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|uv|types|utarray|uthash|minicoro)\.h\> ]]; then continue fi diff --git a/src/cli/cprintf.c b/src/cli/cprintf.c index 13e1757..1a36af5 100644 --- a/src/cli/cprintf.c +++ b/src/cli/cprintf.c @@ -542,18 +542,23 @@ static size_t visible_len(const char *s, size_t n) { return vis; } -int cprintf_vm_exec(program_t *prog, FILE *stream, va_list ap) { +typedef struct { + char *data; + size_t len; +} vm_output_t; + +static vm_output_t cprintf_vm_run(program_t *prog, va_list ap) { vm_regs_t regs = {0}; size_t cap = 512, pos = 0; char *out = malloc(cap); - if (!out) return -1; + if (!out) return (vm_output_t){ NULL, 0 }; #define ENSURE(n) ({ \ - while (pos + (n) + 1 > cap) { \ - cap *= 2; out = realloc(out, cap); \ - if (!out) return -1; \ - }}) + while (pos + (n) + 1 > cap) { \ + cap *= 2; out = realloc(out, cap); \ + if (!out) return (vm_output_t){ NULL, 0 }; \ + }}) #define OUT_STR(s, l) ({ ENSURE(l); memcpy(out+pos, s, l); pos += (l); }) #define OUT_CSTR(s) ({ size_t _l = strlen(s); OUT_STR(s, _l); }) @@ -782,8 +787,7 @@ int cprintf_vm_exec(program_t *prog, FILE *stream, va_list ap) { op_halt: { out[pos] = '\0'; - int ret = (int)fwrite(out, 1, pos, stream); - free(out); return ret; + return (vm_output_t){ out, pos }; } #undef ENSURE @@ -793,19 +797,24 @@ int cprintf_vm_exec(program_t *prog, FILE *stream, va_list ap) { int cprintf_exec(program_t *prog, FILE *stream, ...) { va_list ap; va_start(ap, stream); - int ret = cprintf_vm_exec(prog, stream, ap); + vm_output_t o = cprintf_vm_run(prog, ap); + va_end(ap); if (!o.data) return -1; + + int ret = (int)fwrite(o.data, 1, o.len, stream); + free(o.data); - va_end(ap); return ret; } int csprintf_inner(program_t *prog, char *buf, size_t size, ...) { - FILE *f = fmemopen(buf, size, "w"); - if (!f) return -1; - va_list ap; va_start(ap, size); - int ret = cprintf_vm_exec(prog, f, ap); + vm_output_t o = cprintf_vm_run(prog, ap); + va_end(ap); if (!o.data) return -1; + + size_t copy = (o.len < size) ? o.len : size - 1; + memcpy(buf, o.data, copy); + buf[copy] = '\0'; + free(o.data); - va_end(ap); fclose(f); - return ret; + return (int)o.len; } \ No newline at end of file diff --git a/src/runtime.c b/src/runtime.c index 5ff6d50..4affd53 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -6,6 +6,7 @@ #include #include #include +#include typedef struct { const char *ptr; diff --git a/vendor/argtable3.wrap b/vendor/argtable3.wrap index 643d71a..ca644e9 100644 --- a/vendor/argtable3.wrap +++ b/vendor/argtable3.wrap @@ -1,13 +1,14 @@ [wrap-file] -directory = argtable-v3.3.0.116da6c -source_url = https://github.com/argtable/argtable3/releases/download/v3.3.0.116da6c/argtable-v3.3.0.116da6c.tar.gz -source_filename = argtable-v3.3.0.116da6c.tar.gz -source_hash = 21d653eaab4b9dede76ceb0cb4e8878cf5cadb48ef9180c6a4d1a5cef1549e65 -patch_filename = argtable3_3.3.0-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/argtable3_3.3.0-1/get_patch -patch_hash = d08570286bcb991ebf0616e171bce86038edc3b6d90bf0aad17bcf49880d2c98 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/argtable3_3.3.0-1/argtable-v3.3.0.116da6c.tar.gz -wrapdb_version = 3.3.0-1 +directory = argtable-v3.3.1 +source_url = https://github.com/argtable/argtable3/releases/download/v3.3.1/argtable-v3.3.1.tar.gz +source_filename = argtable-v3.3.1.tar.gz +source_hash = c08bca4b88ddb9234726b75455b3b1670d7c864d8daf198eaa7a3b4d41addf2c +source_fallback_url = https://wrapdb.mesonbuild.com/v2/argtable3_3.3.1-1/get_source/argtable-v3.3.1.tar.gz +patch_filename = argtable3_3.3.1-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/argtable3_3.3.1-1/get_patch +patch_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/argtable3_3.3.1-1/argtable3_3.3.1-1_patch.zip +patch_hash = 6bbe3bfd71536fd0dbf806eeaa8b20e721d3364d7d494e698c5a8f346bb778d2 +wrapdb_version = 3.3.1-1 [provide] -argtable3 = argtable3_dep +dependency_names = argtable3