From 90b2323eb09d91aab6a6efda7acc42cece42e713 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Thu, 3 Oct 2024 20:37:24 +0800 Subject: [PATCH] slash --- ArgsParser/argsparser.cpp | 31 +++-- StoryPresent/StoryPresent.vcxproj | 13 +- StoryPresent/main.cpp | 33 +---- WsNovelManager/WsNovelManager.vcxproj | 119 ++++++++++++++++++ WsNovelManager/WsNovelManager.vcxproj.filters | 31 +++++ WsNovelManager/WsNovelManager.vcxproj.user | 12 ++ WsNovelManager/main.cpp | 51 ++++++++ WsNovelParser.sln | 9 ++ WsNovelParser/main.cpp | 10 +- 9 files changed, 254 insertions(+), 55 deletions(-) create mode 100644 WsNovelManager/WsNovelManager.vcxproj create mode 100644 WsNovelManager/WsNovelManager.vcxproj.filters create mode 100644 WsNovelManager/WsNovelManager.vcxproj.user create mode 100644 WsNovelManager/main.cpp diff --git a/ArgsParser/argsparser.cpp b/ArgsParser/argsparser.cpp index c760bc4..9d2dfc3 100644 --- a/ArgsParser/argsparser.cpp +++ b/ArgsParser/argsparser.cpp @@ -47,7 +47,7 @@ int FloatKeyValue::matchLenth() const { bool FloatKeyValue::parse(const QList args, int start) { auto args_t = args[start]; auto args_v = args[start + 1]; - if (args_t == u8"--" + bindKey()){ + if (args_t == u8"--" + bindKey()) { setValue(args_v); return true; } @@ -74,8 +74,7 @@ __FloatArgvImpls::__FloatArgvImpls(const QString& key, const QString& means, boo : __ArgvPackImpls(means, ParamType::FloatParam), key_name(key), optional_value(optional) { } FloatOption::FloatOption(const QString& key, const QString& means, bool opt) - : __FloatArgvImpls(key, means, opt) { -} + : __FloatArgvImpls(key, means, opt) { } QString args_parse::FloatOption::placeHolder(bool d) const { if (optional() && d) @@ -89,8 +88,9 @@ int FloatOption::matchLenth() const { bool FloatOption::parse(const QList args, int start) { auto args_t = args[start]; - setValue(args_t == bindKey()); - return args_t == u8"--" + bindKey(); + if (args_t == u8"--" + bindKey()) + setValue(true); + return false; } MatchMode::MatchMode(int mode_code, const QString& mode) @@ -124,8 +124,17 @@ QString args_parse::MatchMode::explanString() const { sections << QString(" Switch:"); for (auto& item : args_mode) { - sections << " " + item->placeHolder(false); - sections << " " + item->means(); + if (item->paramType() == ParamType::IndexParam) { + sections << " " + item->placeHolder(false); + sections << " " + item->means(); + } + } + + for (auto& item : args_mode) { + if (item->paramType() == ParamType::FloatParam) { + sections << " " + item->placeHolder(false); + sections << " " + item->means(); + } } return sections.join("\n"); @@ -136,9 +145,6 @@ QString args_parse::MatchMode::explanString() const { */ bool MatchMode::parse(const QList& args, int argv_index, int parse_index) { - if (argv_index >= args.size()) - return true; - // »ñȡģʽƥÅäµ¥Ôª auto parse_unit = args_mode[parse_index]; switch (parse_unit->paramType()) { @@ -151,18 +157,19 @@ bool MatchMode::parse(const QList& args, int argv_index, int parse_inde case ParamType::FloatParam:// ¸¡¶¯²ÎÊýÆ¥Åä { QList> float_parsers; - for (auto& unit : args_mode) { if (unit->paramType() == ParamType::FloatParam) float_parsers << dynamic_pointer_cast<__FloatArgvImpls>(unit); } for (auto& unit : float_parsers) { - if (unit->matchLenth() + argv_index > args.size()) + if (argv_index + unit->matchLenth() > args.size()) continue; auto result = unit->parse(args, argv_index); + // Æ¥Åä³É¹¦ if (result) + // ¼ÌÐøÏÂÒ»¸ö if (parse(args, argv_index + unit->matchLenth(), parse_index + 1)) return true; else if (!result && unit->optional()) diff --git a/StoryPresent/StoryPresent.vcxproj b/StoryPresent/StoryPresent.vcxproj index 67106eb..33cdec2 100644 --- a/StoryPresent/StoryPresent.vcxproj +++ b/StoryPresent/StoryPresent.vcxproj @@ -60,17 +60,16 @@ - storym + StoryPresent - StoryManage - $(SolutionDir)ArgsParser;$(IncludePath) - $(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath) + $(ProjectName) - - ArgsParser.lib;%(AdditionalDependencies) - + + + + diff --git a/StoryPresent/main.cpp b/StoryPresent/main.cpp index b707634..9f97a82 100644 --- a/StoryPresent/main.cpp +++ b/StoryPresent/main.cpp @@ -3,42 +3,13 @@ #include "xast_parse.h" #include "dag_present.h" #include "view_present.h" -#include #include +#include #include + int main(int argc, char* argv[]) { QApplication a(argc, argv); - args_parse::ArgsParser entry_parser; - QList> args_mode; - args_mode << std::make_shared(u8"³ÌÐòÃû³Æ"); - args_mode << std::make_shared(u8"--help", "°ïÖúÑ¡Ïî"); - entry_parser.loadMode(0x000au, args_mode); - args_mode.clear(); - - args_mode << std::make_shared(u8"³ÌÐòÃû³Æ"); - args_mode << std::make_shared(u8"--nsc", u8"µ÷ÓñàÒ빦ÄÜ"); - args_mode << std::make_shared(u8"--path", u8"Ô´ÂëĿ¼·¾¶", true); - args_mode << std::make_shared(u8"--dest", u8"Éú³ÉÄ¿±êĿ¼"); - entry_parser.loadMode(0x000bu, args_mode); - args_mode.clear(); - - args_mode << std::make_shared(u8"³ÌÐòÃû³Æ"); - args_mode << std::make_shared(u8"--make_anchor"); - entry_parser.loadMode(0x000cu, args_mode); - args_mode.clear(); - - args_mode << std::make_shared(u8"³ÌÐòÃû³Æ"); - args_mode << std::make_shared(u8"--cmp"); - entry_parser.loadMode(0x000du, args_mode); - args_mode.clear(); - - args_mode << std::make_shared(u8"³ÌÐòÃû³Æ"); - args_mode << std::make_shared(u8"--graph"); - entry_parser.loadMode(0x000eu, args_mode); - - - return a.exec(); } diff --git a/WsNovelManager/WsNovelManager.vcxproj b/WsNovelManager/WsNovelManager.vcxproj new file mode 100644 index 0000000..8a935ac --- /dev/null +++ b/WsNovelManager/WsNovelManager.vcxproj @@ -0,0 +1,119 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {DD802A96-BBB6-47CD-9B64-3582FD1805F3} + QtVS_v304 + 10.0 + 10.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + Application + v143 + true + Unicode + + + Application + v143 + false + true + Unicode + + + + + + + 5.12.11_msvc2017_64 + core + debug + + + 5.12.11_msvc2017_64 + core + release + + + + + + + + + + + + + + + + + $(SolutionDir)ArgsParser;$(IncludePath) + $(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath) + nsmt + + + nsmt + $(SolutionDir)ArgsParser;$(IncludePath) + $(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath) + + + + ArgsParser.lib;%(AdditionalDependencies) + + + + + ArgsParser.lib;%(AdditionalDependencies) + + + + + true + Level3 + true + true + + + Console + true + + + + + true + Level3 + true + true + true + true + + + Console + false + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/WsNovelManager/WsNovelManager.vcxproj.filters b/WsNovelManager/WsNovelManager.vcxproj.filters new file mode 100644 index 0000000..db47d74 --- /dev/null +++ b/WsNovelManager/WsNovelManager.vcxproj.filters @@ -0,0 +1,31 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + + + Source Files + + + + diff --git a/WsNovelManager/WsNovelManager.vcxproj.user b/WsNovelManager/WsNovelManager.vcxproj.user new file mode 100644 index 0000000..41a709a --- /dev/null +++ b/WsNovelManager/WsNovelManager.vcxproj.user @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/WsNovelManager/main.cpp b/WsNovelManager/main.cpp new file mode 100644 index 0000000..b41b76e --- /dev/null +++ b/WsNovelManager/main.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +using namespace args_parse; +using namespace std; + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + ArgsParser entry_parser; + auto help_mode = make_shared(0x000au, u8"´òÓ¡°ïÖúÐÅÏ¢£¡"); + entry_parser << help_mode; + (*help_mode) << make_shared(u8"nsmt", u8"³ÌÐòÃû³Æ") + << make_shared(u8"help", u8"°ïÖúÑ¡Ïî"); + + auto build_mode = make_shared(0x000bu, u8"µ÷Óù¹½¨³ÌÐò£¬±àÒë¹ÊÊÂÏߣ¡"); + entry_parser << build_mode; + (*build_mode) << make_shared(u8"nsmt", u8"³ÌÐòÃû³Æ") + << make_shared(u8"nsc", u8"µ÷ÓñàÒ빦ÄÜ") + << make_shared(u8"path", u8"Ô´ÂëĿ¼·¾¶", true) + << make_shared(u8"dest", u8"Éú³ÉÄ¿±êĿ¼"); + + auto anchor_mode = make_shared(0x000cu, u8"ÉèÖÃÀï³Ì±®"); + entry_parser << anchor_mode; + (*anchor_mode) << make_shared(u8"nsmt", u8"³ÌÐòÃû³Æ") + << make_shared(u8"mk_anchor", u8"ÉèÖÃÀï³Ì±®"); + + auto cmp_mode = make_shared(0x000du, u8"±È½Ïµ±Ç°¹ÊÊÂÏߺÍÀï³Ì±®¹ÊÊÂÏß"); + entry_parser << cmp_mode; + (*cmp_mode) << make_shared(u8"nsmt", u8"³ÌÐòÃû³Æ") + << make_shared(u8"cmp", u8"±È½Ïµ±Ç°¹ÊÊÂÏßÄÚÈÝ"); + + auto graph_mode = make_shared(0x000eu, u8"ͼÐλ¯ÏÔʾµ±Ç°ÄÚÈÝ"); + entry_parser << graph_mode; + (*graph_mode) << make_shared(u8"nsmt", u8"³ÌÐòÃû³Æ") + << make_shared(u8"gmode", u8"ÉèÖÃͼÐλ¯ÏÔʾµÄģʽ"); + + auto rst = entry_parser.parse(argc, argv); + std::cout << rst << std::endl; + if (!rst) { + qDebug().noquote() << u8"ÃüÁîÐвÎÊý´íÎó"; + qDebug().noquote() << entry_parser.helpDoc(); + return 0; + } + + + return 0; +} diff --git a/WsNovelParser.sln b/WsNovelParser.sln index df2ff76..06b75ea 100644 --- a/WsNovelParser.sln +++ b/WsNovelParser.sln @@ -33,6 +33,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArgsParser", "ArgsParser\Ar EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StoryPresent", "StoryPresent\StoryPresent.vcxproj", "{48DA8516-26EA-4D59-8913-7EF28E3F87C3}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WsNovelManager", "WsNovelManager\WsNovelManager.vcxproj", "{DD802A96-BBB6-47CD-9B64-3582FD1805F3}" + ProjectSection(ProjectDependencies) = postProject + {1FF80476-26C9-42FB-BFF6-D587C4941964} = {1FF80476-26C9-42FB-BFF6-D587C4941964} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -63,6 +68,10 @@ Global {48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x64.Build.0 = Debug|x64 {48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.ActiveCfg = Release|x64 {48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.Build.0 = Release|x64 + {DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.ActiveCfg = Debug|x64 + {DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.Build.0 = Debug|x64 + {DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.ActiveCfg = Release|x64 + {DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WsNovelParser/main.cpp b/WsNovelParser/main.cpp index 069a8cf..6f13083 100644 --- a/WsNovelParser/main.cpp +++ b/WsNovelParser/main.cpp @@ -40,15 +40,11 @@ int main(int argc, char* argv[]) { auto p_result = args_parser.parse(argc, argv); if (!p_result) { + qDebug().noquote() << u8"ÃüÁîÐвÎÊý´íÎó£¡"; qDebug().noquote() << args_parser.helpDoc(); } else { switch (p_result->modeCode()) { - case 0xAu: - default: - qDebug().noquote() << u8"ÃüÁîÐвÎÊý´íÎó£¡"; - qDebug().noquote() << args_parser.helpDoc(); - break; case 0xBu: { auto src_dir = dynamic_pointer_cast(p_result->getUnitViaKey(u8"path")); @@ -119,6 +115,10 @@ int main(int argc, char* argv[]) { qDebug().noquote() << QString(u8"%±àÒë³É¹¦£º%1¡£").arg(QFileInfo(file).absoluteFilePath()); } }break; + case 0xAu: + default: + qDebug().noquote() << args_parser.helpDoc(); + break; } } //return a.exec();