write shit

This commit is contained in:
yyc12345 2023-02-13 10:57:10 +08:00
parent 1fb1b81253
commit 21948246d0
7 changed files with 256 additions and 52 deletions

100
Unvirt/CmdHelper.cpp Normal file
View File

@ -0,0 +1,100 @@
#include "CmdHelper.hpp"
namespace Unvirt {
namespace CmdHelper {
#pragma region cmd splitter
CmdSplitter::CmdSplitter() :
mCmdChar(0), mBuffer(nullptr), mResult(nullptr),
mState(StateType::NORMAL), mPreState(StateType::NORMAL) {
;
}
CmdSplitter::~CmdSplitter() {
;
}
std::vector<std::string> CmdSplitter::Convert(std::string& u8cmd) {
// set up variables
std::vector<std::string> result;
std::string buffer;
mBuffer = &buffer;
mResult = &result;
mState = mPreState = StateType::SPACE;
// split
for (auto it = u8cmd.begin(); it != u8cmd.end(); ++it) {
mCmdChar = (*it);
switch (mState) {
case StateType::SPACE:
ProcSpace();
break;
case StateType::SINGLE:
ProcSingle();
break;
case StateType::DOUBLE:
ProcDouble();
break;
case StateType::ESCAPE:
ProcEscape();
break;
case StateType::NORMAL:
ProcNormal();
break;
}
}
// final proc
switch (mState) {
case StateType::SPACE:
break;
case StateType::NORMAL:
// push the last one
mResult->push_back(*mBuffer);
break;
case StateType::SINGLE:
case StateType::DOUBLE:
case StateType::ESCAPE:
// error
result.clear();
break;
}
// return value
return result;
}
#pragma endregion
#pragma region interactive cmd helper classes
SubCmd::SubCmd() {
}
SubCmd::~SubCmd() {
}
#pragma endregion
#pragma region interactive cmd
InteractiveCmd::InteractiveCmd() {
}
InteractiveCmd::~InteractiveCmd() {
}
void InteractiveCmd::Run(void) {
}
#pragma endregion
}
}

146
Unvirt/CmdHelper.hpp Normal file
View File

@ -0,0 +1,146 @@
#pragma once
#include <unordered_map>
#include <string>
#include <functional>
#include <vector>
namespace Unvirt {
namespace CmdHelper {
class CmdSplitter {
public:
CmdSplitter();
CmdSplitter(const CmdSplitter&) = delete;
CmdSplitter& operator=(const CmdSplitter&) = delete;
~CmdSplitter();
std::vector<std::string> Convert(std::string& u8cmd);
private:
char mCmdChar;
std::string* mBuffer;
std::vector<std::string>* mResult;
enum class StateType : int {
SPACE,
SINGLE,
DOUBLE,
ESCAPE,
NORMAL
};
StateType mState, mPreState;
inline void ProcSpace(void) {
switch (mCmdChar) {
case '\'':
mState = StateType::SINGLE;
break;
case '"':
mState = StateType::DOUBLE;
break;
case '\\':
mState = StateType::ESCAPE;
mPreState = StateType::NORMAL;
break;
case ' ':
break; // skip blank
default:
mBuffer->push_back(mCmdChar);
mState = StateType::NORMAL;
break;
}
}
inline void ProcSingle(void) {
switch (mCmdChar) {
case '\'':
mState = StateType::NORMAL;
break;
case '"':
mBuffer->push_back('"');
break;
case '\\':
mState = StateType::ESCAPE;
mPreState = StateType::SINGLE;
break;
case ' ':
mBuffer->push_back(' ');
break;
default:
mBuffer->push_back(mCmdChar);
break;
}
}
inline void ProcDouble(void) {
switch (mCmdChar) {
case '\'':
mBuffer->push_back('\'');
break;
case '"':
mState = StateType::NORMAL;
break;
case '\\':
mState = StateType::ESCAPE;
mPreState = StateType::DOUBLE;
break;
case ' ':
mBuffer->push_back(' ');
break;
default:
mBuffer->push_back(mCmdChar);
break;
}
}
inline void ProcEscape(void) {
// add itself
mBuffer->push_back(mCmdChar);
// restore state
mState = mPreState;
}
inline void ProcNormal(void) {
switch (mCmdChar) {
case '\'':
mBuffer->push_back('\'');
break;
case '"':
mBuffer->push_back('"');
break;
case '\\':
mState = StateType::ESCAPE;
mPreState = StateType::NORMAL;
break;
case ' ':
mResult->push_back(*mBuffer);
mBuffer->clear();
mState = StateType::SPACE;
break;
default:
mBuffer->push_back(mCmdChar);
break;
}
}
};
class SubCmd {
public:
SubCmd();
~SubCmd();
private:
};
class InteractiveCmd {
public:
InteractiveCmd();
~InteractiveCmd();
void Run(void);
private:
//std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
};
}
}

View File

@ -1,14 +0,0 @@
#include "InteractiveCmd.hpp"
namespace Unvirt {
InteractiveCmd::InteractiveCmd() {
}
InteractiveCmd::~InteractiveCmd() {
}
}

View File

@ -1,32 +0,0 @@
#pragma once
#include <unordered_map>
#include <string>
#include <functional>
//#include <boost/program_options/options_description.hpp>
//#include <boost/program_options/positional_options.hpp>
//#include <boost/program_options/parsers.hpp>
//#include <boost/program_options/variables_map.hpp>
namespace Unvirt {
//struct CmdRegisteryEntry {
// boost::program_options::options_description mOptDesc;
// boost::program_options::positional_options_description mPosOptDesc;
// std::function<void(boost::program_options::options_description&, boost::program_options::variables_map&)> mBindProc;
//};
class InteractiveCmd {
public:
InteractiveCmd();
~InteractiveCmd();
void Run(void) { ; }
private:
//std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
};
}

View File

@ -1,5 +1,6 @@
#include "AccessibleValue.hpp"
#include "TerminalHelper.hpp"
#include "CmdHelper.hpp"
#include "VTStruct.hpp"
#include <cstdio>
#include <iostream>
@ -12,9 +13,12 @@ int main(int argc, char* argv[]) {
LibCmo::CKFile vtfile(vtctx);
vtfile.Load("Language.old.nmo", LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
printf(UNVIRT_TERMCOL_LIGHT_YELLOW(("Hello, %s\n")), u8"㴮!");
//printf(UNVIRT_TERMCOL_LIGHT_YELLOW(("Hello, %s\n")), u8"㴮!");
//std::string bbb("load \"Language. 㴮!old.nmo\" utf8 ");
//Unvirt::CmdHelper::CmdSplitter sp;
//auto a = sp.Convert(bbb);
//printf(UNVIRT_TERMCOL_LIGHT_YELLOW(("%s\n")), a[1].c_str());
return 0;
}

View File

@ -172,14 +172,14 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AccessibleValue.cpp" />
<ClCompile Include="InteractiveCmd.cpp" />
<ClCompile Include="CmdHelper.cpp" />
<ClCompile Include="TerminalHelper.cpp" />
<ClCompile Include="StringHelper.cpp" />
<ClCompile Include="Unvirt.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AccessibleValue.hpp" />
<ClInclude Include="InteractiveCmd.hpp" />
<ClInclude Include="CmdHelper.hpp" />
<ClInclude Include="TerminalHelper.hpp" />
<ClInclude Include="StringHelper.hpp" />
</ItemGroup>

View File

@ -27,7 +27,7 @@
<ClCompile Include="TerminalHelper.cpp">
<Filter>Sources</Filter>
</ClCompile>
<ClCompile Include="InteractiveCmd.cpp">
<ClCompile Include="CmdHelper.cpp">
<Filter>Sources</Filter>
</ClCompile>
</ItemGroup>
@ -41,7 +41,7 @@
<ClInclude Include="TerminalHelper.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="InteractiveCmd.hpp">
<ClInclude Include="CmdHelper.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup>