aboutsummaryrefslogtreecommitdiff
path: root/src/command/builtin.cc
blob: 4c5c1e2b4b8da29835bb1c9f1e51f2cf7622533d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include "command/builtin.h"

namespace ov4
{

using namespace std;

//array<string> builtin_cmd_list{"quit", "fg", "bg", "jobs"};

unordered_map<string, function<void(char**)>> cmd =
{
    { "quit", ov4::command::quit },
    { "exit", ov4::command::exit },
    { "jobs", ov4::command::jobs },
    { "bg", ov4::command::bg },
    { "fg", ov4::command::fg },
    { "cd", ov4::command::cd },
};

/* 
 * builtin_cmd - If the user has typed a built-in command then execute
 *    it immediately.  
 */
bool exe_bultin_command(char **argv) 
{
    if (argv == nullptr || argv[0] == nullptr) return false;
    string s = argv[0];
    if (cmd.find(s) != cmd.end())
    {
        cmd[s](argv);
        return true;
    }
    return false;
}



}