#pragma once #include #include #include #include #include #include class Execute; class Builtin { BAN_NON_COPYABLE(Builtin); BAN_NON_MOVABLE(Builtin); public: struct BuiltinCommand { using function_t = int (*)(Execute&, BAN::Span, FILE* fin, FILE* fout); function_t function { nullptr }; bool immediate { false }; BuiltinCommand(function_t function, bool immediate) : function(function) , immediate(immediate) { } BAN::ErrorOr execute(Execute&, BAN::Span arguments, int fd_in, int fd_out) const; }; public: Builtin() = default; static Builtin& get() { static Builtin s_instance; return s_instance; } void initialize(); void for_each_builtin(BAN::Function) const; // return nullptr if not found const BuiltinCommand* find_builtin(const BAN::String& name) const; private: BAN::HashMap m_builtin_commands; };