michael@0: // Common/CommandLineParser.h michael@0: michael@0: #ifndef __COMMON_COMMANDLINEPARSER_H michael@0: #define __COMMON_COMMANDLINEPARSER_H michael@0: michael@0: #include "Common/String.h" michael@0: michael@0: namespace NCommandLineParser { michael@0: michael@0: void SplitCommandLine(const UString &src, UString &dest1, UString &dest2); michael@0: void SplitCommandLine(const UString &s, UStringVector &parts); michael@0: michael@0: namespace NSwitchType { michael@0: enum EEnum michael@0: { michael@0: kSimple, michael@0: kPostMinus, michael@0: kLimitedPostString, michael@0: kUnLimitedPostString, michael@0: kPostChar michael@0: }; michael@0: } michael@0: michael@0: struct CSwitchForm michael@0: { michael@0: const wchar_t *IDString; michael@0: NSwitchType::EEnum Type; michael@0: bool Multi; michael@0: int MinLen; michael@0: int MaxLen; michael@0: const wchar_t *PostCharSet; michael@0: }; michael@0: michael@0: struct CSwitchResult michael@0: { michael@0: bool ThereIs; michael@0: bool WithMinus; michael@0: UStringVector PostStrings; michael@0: int PostCharIndex; michael@0: CSwitchResult(): ThereIs(false) {}; michael@0: }; michael@0: michael@0: class CParser michael@0: { michael@0: int _numSwitches; michael@0: CSwitchResult *_switches; michael@0: bool ParseString(const UString &s, const CSwitchForm *switchForms); michael@0: public: michael@0: UStringVector NonSwitchStrings; michael@0: CParser(int numSwitches); michael@0: ~CParser(); michael@0: void ParseStrings(const CSwitchForm *switchForms, michael@0: const UStringVector &commandStrings); michael@0: const CSwitchResult& operator[](size_t index) const; michael@0: }; michael@0: michael@0: ///////////////////////////////// michael@0: // Command parsing procedures michael@0: michael@0: struct CCommandForm michael@0: { michael@0: wchar_t *IDString; michael@0: bool PostStringMode; michael@0: }; michael@0: michael@0: // Returns: Index of form and postString; -1, if there is no match michael@0: int ParseCommand(int numCommandForms, const CCommandForm *commandForms, michael@0: const UString &commandString, UString &postString); michael@0: michael@0: } michael@0: michael@0: #endif