write to location
This commit is contained in:
parent
fe34c61b12
commit
d273544702
3 changed files with 19 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue