shell/include/shellUtils.h

47 lines
1013 B
C++

#pragma once
#include <iostream>
#include <string>
#include <map>
#include <cstdlib>
#include <filesystem>
#include <vector>
namespace sh
{
enum class Command
{
exit,
echo,
type,
pwd,
cd,
unknown
};
inline const std::map<const std::string_view, const Command>commandMap
{
{"exit", Command::exit},
{"echo", Command::echo},
{"type", Command::type},
{"pwd" , Command::pwd },
{"cd" , Command::cd }
};
inline constexpr std::string_view doubleQuoteEscapeChars = "\"$`\n\\";
inline constexpr std::string_view tokenDelimiters = " \t";
void tokenize(std::vector<std::string>& tokens, const std::string& input);
Command getCommand(std::string_view input);
std::optional<std::filesystem::path> isExec(const std::string& input);
void printType(const std::string& input);
std::filesystem::path getWorkingDir();
void changeDir(const std::vector<std::string>& tokens);
}