diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-02-13 21:39:41 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-02-13 21:39:41 +0000 |
| commit | 5f86941b8f928e75cea58068bb3df1aef0ca7da6 (patch) | |
| tree | 34a0b0d71eae74950f2d809e1705f189de189875 /src | |
| parent | 2c8a6ca56a7cf331229acbc20472781bda97639e (diff) | |
support multiline strings when executing file commands
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/main.cc b/src/main.cc index 40c9a764..9062da2b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -710,6 +710,7 @@ void exec_commands_in_file(const CommandParameters& params, CommandManager& cmd_manager = CommandManager::instance(); size_t pos = 0; + size_t length = file_content.length(); bool cat_with_previous = false; std::string command_line; while (true) @@ -717,8 +718,31 @@ void exec_commands_in_file(const CommandParameters& params, if (not cat_with_previous) command_line.clear(); - size_t end_pos = file_content.find_first_of('\n', pos); - if (end_pos != pos and end_pos != std::string::npos and + size_t end_pos = pos; + + while (file_content[end_pos] != '\n' and end_pos != length) + { + if (file_content[end_pos] == '"' or file_content[end_pos] == '\'' or + file_content[end_pos] == '`') + { + char delimiter = file_content[end_pos]; + ++end_pos; + while (file_content[end_pos] != delimiter or + file_content[end_pos-1] == '\\' and end_pos != length) + ++end_pos; + + if (end_pos == length) + { + print_status(std::string("unterminated '") + delimiter + "' string"); + return; + } + + ++end_pos; + } + + ++end_pos; + } + if (end_pos != pos and end_pos != length and file_content[end_pos - 1] == '\\') { command_line += file_content.substr(pos, end_pos - pos - 1); @@ -730,7 +754,7 @@ void exec_commands_in_file(const CommandParameters& params, cmd_manager.execute(command_line, context); cat_with_previous = false; } - if (end_pos == std::string::npos) + if (end_pos == length) { if (cat_with_previous) print_status("while executing commands in \"" + params[0] + |
