From c1936b23b7712996273374dd5982dbbc03bb811a Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 11 Mar 2026 13:58:44 +0100 Subject: [PATCH] script: Added strnlen function added stub for tokenizer --- src/l_lsl.c | 18 +++++++++++++++++- src/l_lsl.h | 5 ++++- src/lrts_impl.h | 1 + src/p_pc/u_string.c | 1 + src/u_string.c | 9 +++++++++ src/u_string.h | 2 ++ 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/u_string.c diff --git a/src/l_lsl.c b/src/l_lsl.c index c148d31..17eafe2 100644 --- a/src/l_lsl.c +++ b/src/l_lsl.c @@ -23,9 +23,21 @@ struct l_lsl_value l_lsl_value_init(void) { return val; } +char *tokbuf[L_LSL_TOK_MAX]; +const char* l_lsl_next_token(const char *code, u32 len, u32 *token_len) { + LRTS_UNUSED(code); + LRTS_UNUSED(len); + + *token_len = 0; + + return LRTS_NULL; +} + struct l_lsl_value l_lsl_compile_file(struct l_lsl_vm *v, const char *path) { struct l_lsl_value val = l_lsl_value_init(); const char *src = u_file_read(path); + u32 token_len; + u32 src_len = 0; if (src == LRTS_NULL) { u_log(U_LOG_CRIT, "%s: No such file or directory\n", path); @@ -33,11 +45,15 @@ struct l_lsl_value l_lsl_compile_file(struct l_lsl_vm *v, const char *path) { return val; } + src_len = u_strnlen(src, L_LSL_SOURCE_MAX); + u_printf("%s\n", src); - u_free((void*)src); + l_lsl_next_token(src, src_len, &token_len); + + u_free((void*)src); return val; } diff --git a/src/l_lsl.h b/src/l_lsl.h index 8b11448..17ed52b 100644 --- a/src/l_lsl.h +++ b/src/l_lsl.h @@ -7,6 +7,9 @@ * in-game scripting interpreter */ +#define L_LSL_TOK_MAX 256 +#define L_LSL_SOURCE_MAX 0xFFFFFFFF + /* special tokens */ #define L_LWL_TOK_STR_LPAREN "(" #define L_LWL_TOK_STR_RPAREN ")" @@ -89,7 +92,7 @@ void l_lsl_value_free(struct l_lsl_value *v); /* * gets the next token returns tone's length in token_len - * the result token is placed into an interla string buffer and should not be modified + * the result token is placed into an internal string buffer and should not be modified * or saved. */ const char* l_lsl_next_token(const char *code, u32 len, u32 *token_len); diff --git a/src/lrts_impl.h b/src/lrts_impl.h index d6a2311..033fd0d 100644 --- a/src/lrts_impl.h +++ b/src/lrts_impl.h @@ -55,6 +55,7 @@ #include "l_lsl.c" #include "u_debug.c" #include "u_file.c" +#include "u_string.c" #endif diff --git a/src/p_pc/u_string.c b/src/p_pc/u_string.c index 8219e26..98bc455 100644 --- a/src/p_pc/u_string.c +++ b/src/p_pc/u_string.c @@ -20,3 +20,4 @@ int u_sprintf(char *buffer, const char *fmt, ...) { int u_strncmp(const char *s1, const char *s2, u32 n) { return strncmp(s1, s2, n); } + diff --git a/src/u_string.c b/src/u_string.c new file mode 100644 index 0000000..eb52107 --- /dev/null +++ b/src/u_string.c @@ -0,0 +1,9 @@ +#include "u_string.h" + +int u_strnlen(const char *s, u32 n) { + u32 i = 0; + while (s[i++] && i < n) { + i++; + } + return i; +} diff --git a/src/u_string.h b/src/u_string.h index 8431cd0..28b48b3 100644 --- a/src/u_string.h +++ b/src/u_string.h @@ -8,4 +8,6 @@ int u_sprintf(char *buffer, const char *fmt, ...); int u_strncmp(const char *s1, const char *s2, u32 n); +int u_strnlen(const char *s, u32 n); + #endif -- 2.30.2