From 66d91b8828470c9ea89af11cbfe5060993155f83 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 14 Jan 2012 13:50:45 +0000 Subject: [PATCH] support '\' as a line continuation marker when executing commands in file --- src/main.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.cc b/src/main.cc index 0ec4b97c..2e81cc81 100644 --- a/src/main.cc +++ b/src/main.cc @@ -553,12 +553,33 @@ void exec_commands_in_file(const CommandParameters& params, CommandManager& cmd_manager = CommandManager::instance(); size_t pos = 0; + bool cat_with_previous = false; + std::string command_line; while (true) { + if (not cat_with_previous) + command_line.clear(); + size_t end_pos = file_content.find_first_of('\n', pos); - cmd_manager.execute(file_content.substr(pos, end_pos - pos), context); + if (end_pos != pos and end_pos != std::string::npos and + file_content[end_pos - 1] == '\\') + { + command_line += file_content.substr(pos, end_pos - pos - 1); + cat_with_previous = true; + } + else + { + command_line += file_content.substr(pos, end_pos - pos); + cmd_manager.execute(command_line, context); + cat_with_previous = false; + } if (end_pos == std::string::npos) + { + if (cat_with_previous) + print_status("while executing commands in \"" + params[0] + + "\": last command not complete"); break; + } pos = end_pos + 1; } }