[6s] Break out builtin commands into a list of structs

The 6s builtin commands are now in a separate file, with a list of name,
description, and function pointers.
This commit is contained in:
Justin C. Miller
2024-04-29 01:11:15 -07:00
parent 7322df98f5
commit 172eb70551
4 changed files with 78 additions and 9 deletions

31
src/user/6s/commands.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include <stddef.h>
namespace edit {
class source;
}
class builtin
{
public:
using runf = void (*)(edit::source &);
builtin(const char *name, const char *desc, runf func) :
m_name {name}, m_desc {desc}, m_func {func} {}
const char * name() const { return m_name; }
const char * description() const { return m_desc; }
void run(edit::source &s) { m_func(s); }
private:
const char *m_name;
const char *m_desc;
runf m_func;
};
extern builtin g_builtins[];
extern size_t g_builtins_count;