CE edit command
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m11s

This commit is contained in:
2026-03-05 16:29:59 +01:00
parent a5f5dbf21f
commit 25b289ccfb
11 changed files with 316 additions and 30 deletions

View File

@@ -1,12 +1,14 @@
#include "interp.h"
#include "arena_alloc.h"
#include "context.h"
#include "edit.h"
#include "parser.h"
#include "self.h"
#include <desc.h>
#include <filereader.h>
#include <filewriter.h>
#include <kb.h>
#include <liballoc.h>
#include <path.h>
#include <process.h>
#include <stddef.h>
@@ -189,6 +191,48 @@ static void ls (struct context* context, const char* path_string) {
volume_close ();
}
static void edit (struct context* context, const char* path_string) {
struct desc desc;
char volume[VOLUME_MAX];
const char* path;
int ret;
if (!path_parse (path_string, volume, &path)) {
cprintf (context, "ERROR bad path '%s'\n", path_string);
return;
}
if ((ret = volume_open (volume)) < 0) {
cprintf (context, "ERROR could not open volume '%s': %s\n", volume, str_status[-ret]);
return;
}
if ((ret = describe (path, &desc)) < 0) {
cprintf (context, "ERROR could not describe '%s': %s\n", path, str_status[-ret]);
volume_close ();
return;
}
char* str = malloc (desc.size + 1);
if (str == NULL) {
volume_close ();
return;
}
memset (str, 0, desc.size);
if ((ret = read_file (path, 0, (uint8_t*)str, desc.size)) < 0) {
free (str);
volume_close ();
return;
}
edit_start (str);
volume_close ();
}
static void quit1 (struct context* context) {
cprintf (context, "Goodbye!\n");
interp_shutdown ();
@@ -203,6 +247,7 @@ static void help (struct context* context) {
cprintf (context, "mkfile <file path>\n");
cprintf (context, "mkdir <directory path>\n");
cprintf (context, "rm <path>\n");
cprintf (context, "edit <path>\n");
cprintf (context, "quit\n");
}
@@ -239,6 +284,8 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
mkdir (context, cmd->args, cmd->arg_count);
} else if (strcmp (cmd->name, "rm") == 0) {
rm (context, cmd->args, cmd->arg_count);
} else if (strcmp (cmd->name, "edit") == 0) {
edit (context, cmd->args[0]);
} else {
char volume[VOLUME_MAX];
const char* path;