script: Added strnlen function added stub for tokenizer
authorLukas Krickl <lukas@krickl.dev>
Wed, 11 Mar 2026 12:58:44 +0000 (13:58 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 11 Mar 2026 12:58:44 +0000 (13:58 +0100)
src/l_lsl.c
src/l_lsl.h
src/lrts_impl.h
src/p_pc/u_string.c
src/u_string.c [new file with mode: 0644]
src/u_string.h

index c148d312e809b14e2f0dc267989a9890d341e1cd..17eafe254033d779c730c2b3bc2317272702b013 100644 (file)
@@ -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;
 }
 
index 8b11448ba76e3e278c6c29ffab8aa212b135663f..17ed52b53b0e6927e326cffd5fa625abe1c65072 100644 (file)
@@ -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);
index d6a23113a7b87c93cdc272dcd67ac53241f7b530..033fd0d766e504e4473003e4b8da32cb31434dea 100644 (file)
@@ -55,6 +55,7 @@
 #include "l_lsl.c"
 #include "u_debug.c"
 #include "u_file.c"
+#include "u_string.c"
 
 #endif
 
index 8219e26a6ee5d1a7eb464a396398b2522593f34d..98bc4555741da73b6723742b57506e7d70823829 100644 (file)
@@ -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 (file)
index 0000000..eb52107
--- /dev/null
@@ -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;
+}
index 8431cd05eda1cc5e78995cc949f3e2bda3ff422c..28b48b3f8a1a48ae5b39a34a1cee1d2341c056bb 100644 (file)
@@ -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