From d273544702ac8e66da5c3226667cb3b8312a1fda Mon Sep 17 00:00:00 2001 From: Luka Jankovic Date: Sat, 26 Jul 2025 01:51:24 +0200 Subject: [PATCH] write to location --- kubo_command.c | 22 +++++++++++++++------- kubo_command.h | 3 ++- kubo_command_bar.c | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/kubo_command.c b/kubo_command.c index c37f0c6..2543163 100644 --- a/kubo_command.c +++ b/kubo_command.c @@ -18,8 +18,8 @@ #include "kubo_command.h" -static inline void kubo_command_exit(struct kubo_context *context); -static inline void kubo_command_write(struct kubo_context *context); +static inline void kubo_command_exit(struct kubo_context *context, char *rest); +static inline void kubo_command_write(struct kubo_context *context, char *rest); static const struct kubo_command_data kubo_commands[] = { {":q", kubo_command_exit}, {":w", kubo_command_write}}; @@ -42,23 +42,31 @@ void kubo_command_pop() { } void kubo_command_accept_cmd(struct kubo_context *context) { + char *cmd = kubo_command_get_str(); + cmd = strtok(cmd, " "); + char *rest = strtok(NULL, " "); for (size_t i = 0; i < kubo_commands_size; i++) { - if (strcmp(kubo_commands[i].input, kubo_char_arr_build_str(&command)) == - 0) { - kubo_commands[i].function(context); + if (strcmp(cmd, kubo_commands[i].input) == 0) { + kubo_commands[i].function(context, rest); return; } } + free(cmd); } char *kubo_command_get_str() { return kubo_char_arr_build_str(&command); } void kubo_command_clear() { kubo_char_arr_clear(&command); } -static inline void kubo_command_exit(struct kubo_context *context) { +static inline void kubo_command_exit(struct kubo_context *context, char *rest) { + (void)rest; context->exit_pending = true; } -static inline void kubo_command_write(struct kubo_context *context) { +static inline void kubo_command_write(struct kubo_context *context, char *rest) { + if (rest) { + context->file_name = rest; + } + kubo_file_write(context); } diff --git a/kubo_command.h b/kubo_command.h index 635756c..69149ce 100644 --- a/kubo_command.h +++ b/kubo_command.h @@ -26,7 +26,7 @@ #include "kubo_context.h" #include "kubo_file.h" -typedef void (*kubo_command_function)(struct kubo_context *context); +typedef void (*kubo_command_function)(struct kubo_context *context, char *rest); struct kubo_command_data { const char *input; @@ -40,6 +40,7 @@ void kubo_command_append_char(int c); void kubo_command_pop(); void kubo_command_accept_cmd(struct kubo_context *context); void kubo_command_clear(); + char *kubo_command_get_str(); #endif diff --git a/kubo_command_bar.c b/kubo_command_bar.c index bdbe317..78da65d 100644 --- a/kubo_command_bar.c +++ b/kubo_command_bar.c @@ -25,4 +25,6 @@ void kubo_command_bar_render(int x, int y, int font_size) { x += MeasureText(cmd, font_size); x += 2; DrawRectangle(x, y, MeasureText("x", font_size), font_size, WHITE); + + free(cmd); }