Simplify external command script substitution

The command script is now stored in string form. Substitution is performed
using normal string methods instead of regular expressions, since all used
substitutions are simple string replacements. Tokenization is performed after
substitution.
This commit is contained in:
Esa Korhonen
2019-05-29 13:00:09 +03:00
parent 44d1b821c3
commit 4b69156875
3 changed files with 77 additions and 157 deletions

View File

@ -28,8 +28,6 @@ public:
*/
static ExternalCmd* create(const char* argstr, int timeout);
~ExternalCmd();
/**
* Execute a command
*
@ -44,10 +42,8 @@ public:
*
* @param match Match string
* @param replace Replacement string
*
* @return True if replacement was successful, false on error
*/
bool substitute_arg(const char* match, const char* replace);
void substitute_arg(const std::string& match, const std::string& replace);
/**
* Simple matching of string and command
@ -58,14 +54,18 @@ public:
*/
bool externcmd_matches(const char* match);
const char* substituted() const;
static const int MAX_ARGS {256};
char* argv[MAX_ARGS + 1] {}; /**< Arguments. First element is the command. */
private:
int m_timeout; /**< Command timeout in seconds */
std::string m_command; /**< Original command */
std::string m_command_substituted; /**< Command with substitutions */
ExternalCmd(int timeout);
int tokenize_arguments(const char* argstr);
int m_timeout; /**< Command timeout in seconds */
ExternalCmd(const std::string& script, int timeout);
int tokenize_args(char* dest[], int dest_size);
};