From 21948246d07e540e6c8ec0aa6ee558d278da0a77 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 13 Feb 2023 10:57:10 +0800 Subject: [PATCH] write shit --- Unvirt/CmdHelper.cpp | 100 +++++++++++++++++++++++ Unvirt/CmdHelper.hpp | 146 ++++++++++++++++++++++++++++++++++ Unvirt/InteractiveCmd.cpp | 14 ---- Unvirt/InteractiveCmd.hpp | 32 -------- Unvirt/Unvirt.cpp | 8 +- Unvirt/Unvirt.vcxproj | 4 +- Unvirt/Unvirt.vcxproj.filters | 4 +- 7 files changed, 256 insertions(+), 52 deletions(-) create mode 100644 Unvirt/CmdHelper.cpp create mode 100644 Unvirt/CmdHelper.hpp delete mode 100644 Unvirt/InteractiveCmd.cpp delete mode 100644 Unvirt/InteractiveCmd.hpp diff --git a/Unvirt/CmdHelper.cpp b/Unvirt/CmdHelper.cpp new file mode 100644 index 0000000..3e6acb8 --- /dev/null +++ b/Unvirt/CmdHelper.cpp @@ -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 CmdSplitter::Convert(std::string& u8cmd) { + // set up variables + std::vector 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 + + + + } +} \ No newline at end of file diff --git a/Unvirt/CmdHelper.hpp b/Unvirt/CmdHelper.hpp new file mode 100644 index 0000000..3ef3927 --- /dev/null +++ b/Unvirt/CmdHelper.hpp @@ -0,0 +1,146 @@ +#pragma once + +#include +#include +#include +#include + +namespace Unvirt { + namespace CmdHelper { + + class CmdSplitter { + public: + CmdSplitter(); + CmdSplitter(const CmdSplitter&) = delete; + CmdSplitter& operator=(const CmdSplitter&) = delete; + ~CmdSplitter(); + + std::vector Convert(std::string& u8cmd); + private: + char mCmdChar; + std::string* mBuffer; + std::vector* 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 mCmdDispatcher; + + + }; + + } +} \ No newline at end of file diff --git a/Unvirt/InteractiveCmd.cpp b/Unvirt/InteractiveCmd.cpp deleted file mode 100644 index 319c193..0000000 --- a/Unvirt/InteractiveCmd.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "InteractiveCmd.hpp" - -namespace Unvirt { - - InteractiveCmd::InteractiveCmd() { - - } - - InteractiveCmd::~InteractiveCmd() { - - } - - -} diff --git a/Unvirt/InteractiveCmd.hpp b/Unvirt/InteractiveCmd.hpp deleted file mode 100644 index 5704f6a..0000000 --- a/Unvirt/InteractiveCmd.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include -#include -//#include -//#include -//#include -//#include - -namespace Unvirt { - - //struct CmdRegisteryEntry { - // boost::program_options::options_description mOptDesc; - // boost::program_options::positional_options_description mPosOptDesc; - // std::function mBindProc; - //}; - - class InteractiveCmd { - public: - InteractiveCmd(); - ~InteractiveCmd(); - - void Run(void) { ; } - - private: - //std::unordered_map mCmdDispatcher; - - - }; - -} diff --git a/Unvirt/Unvirt.cpp b/Unvirt/Unvirt.cpp index 7f46a9b..24e92de 100644 --- a/Unvirt/Unvirt.cpp +++ b/Unvirt/Unvirt.cpp @@ -1,5 +1,6 @@ #include "AccessibleValue.hpp" #include "TerminalHelper.hpp" +#include "CmdHelper.hpp" #include "VTStruct.hpp" #include #include @@ -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; } diff --git a/Unvirt/Unvirt.vcxproj b/Unvirt/Unvirt.vcxproj index e17fefa..91f3083 100644 --- a/Unvirt/Unvirt.vcxproj +++ b/Unvirt/Unvirt.vcxproj @@ -172,14 +172,14 @@ - + - + diff --git a/Unvirt/Unvirt.vcxproj.filters b/Unvirt/Unvirt.vcxproj.filters index 6f340fb..c92a160 100644 --- a/Unvirt/Unvirt.vcxproj.filters +++ b/Unvirt/Unvirt.vcxproj.filters @@ -27,7 +27,7 @@ Sources - + Sources @@ -41,7 +41,7 @@ Headers - + Headers