From 0c9ddaccf78c330c5ed4b524b7ba429997a2985c Mon Sep 17 00:00:00 2001 From: joevt Date: Sun, 23 Jul 2023 20:56:04 -0700 Subject: [PATCH] Fix dppc debugger printenv of multiline variables. If a nvram variable has CRLF or CR, replace them with LF so each line appears on a new line in the console output. Also, add indent to each line so that each line appears only in the value column and not in the name column. --- devices/common/ofnvram.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/devices/common/ofnvram.cpp b/devices/common/ofnvram.cpp index eaf1692..a43a850 100644 --- a/devices/common/ofnvram.cpp +++ b/devices/common/ofnvram.cpp @@ -541,6 +541,15 @@ bool OfConfigUtils::open_container() { return false; } +static std::string ReplaceAll(std::string& str, const std::string& from, const std::string& to) { + size_t start_pos = 0; + while((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); // Handles case where 'to' is a substring of 'from' + } + return str; +} + void OfConfigUtils::printenv() { OfConfigImpl::config_dict vars; @@ -550,7 +559,11 @@ void OfConfigUtils::printenv() { vars = this->cfg_impl->get_config_vars(); for (auto& var : vars) { - cout << setw(34) << left << var.first << var.second << endl; + std::string val = var.second; + ReplaceAll(val, "\r\n", "\n"); + ReplaceAll(val, "\r", "\n"); + ReplaceAll(val, "\n", "\n "); // 34 spaces + cout << setw(34) << left << var.first << val << endl; // name column has width 34 } }