From c7a0e5f0e18e0a38e0bf074cbd6bdeaafee436cf Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 24 Aug 2023 21:23:35 -0400 Subject: [PATCH] use line splitting method that keeps empty lines and set line numbers --- src/library.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index ba7021cfb7..2859195e90 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -18,6 +18,7 @@ #define LAMMPS_LIB_MPI 1 #include "library.h" #include +#include #include "accelerator_kokkos.h" #include "atom.h" @@ -627,10 +628,13 @@ executing. void lammps_commands_string(void *handle, const char *str) { + if (!handle) return; + auto lmp = (LAMMPS *) handle; - std::string cmd; + std::string cmd, line, buffer; bool append = false; bool triple = false; + if (str) buffer = str; BEGIN_CAPTURE { @@ -638,8 +642,24 @@ void lammps_commands_string(void *handle, const char *str) lmp->error->all(FLERR,"Library error: issuing LAMMPS command during run"); } - // process continuation characters and here docs - for (const auto &line : utils::split_lines(str)) { + std::size_t cursor = 0; + int nline = -1; + + // split buffer into lines, set line number, process continuation characters, and here docs + + while (cursor < buffer.size()) { + ++ nline; + std::size_t start = cursor; + cursor = buffer.find('\n', start); + if (cursor != std::string::npos) { + line = buffer.substr(start, cursor-start); + std::replace(line.begin(), line.end(), '\r', ' '); + ++cursor; + lmp->output->thermo->set_line(nline); + } else { + line = buffer; + } + if (append || triple) cmd += line; else