From f4481e6f58eda0c46ec7c767c0c56b592bf5aa09 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Mon, 16 Oct 2023 16:36:58 -0600 Subject: [PATCH] APREPRO: Better handling of string in save_history_string --- .../libraries/aprepro_lib/apr_scanner.cc | 18 ++++++++++++------ .../seacas/libraries/aprepro_lib/aprepro.ll | 11 ++++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/seacas/libraries/aprepro_lib/apr_scanner.cc b/packages/seacas/libraries/aprepro_lib/apr_scanner.cc index 83aa675cec..17c31a764d 100644 --- a/packages/seacas/libraries/aprepro_lib/apr_scanner.cc +++ b/packages/seacas/libraries/aprepro_lib/apr_scanner.cc @@ -3300,7 +3300,8 @@ namespace SEAMS { } if (!string_is_ascii(line, strlen(line))) { - aprepro.warning("input line contains non-ASCII (probably UTF-8) characters which might be parsed incorrectly."); + aprepro.warning("input line contains non-ASCII (probably UTF-8) characters which might be " + "parsed incorrectly."); } SEAMS::gl_histadd(line); @@ -3323,8 +3324,8 @@ namespace SEAMS { } else { if (!string_is_ascii(buf, yyin->gcount())) { - aprepro.warning( - "input file contains non-ASCII (probably UTF-8) characters which might be parsed incorrectly."); + aprepro.warning("input file contains non-ASCII (probably UTF-8) characters which might " + "be parsed incorrectly."); } return yyin->gcount(); } @@ -3654,9 +3655,10 @@ namespace SEAMS { return; // Clear any possible end-of-stream if e.g., reading from a istringstream. - if (aprepro.ap_file_list.top().name == "interactive_input") { - yyin->clear(); - } + std::ios::iostate state = yyin->rdstate(); + size_t loc = yyin->tellg(); + yyin->clear(); + // Go back in the stream to where we started keeping history. yyin->seekg(hist_start); if (!yyin->good()) { @@ -3676,6 +3678,10 @@ namespace SEAMS { history_string = tmp; delete[] tmp; hist_start = 0; + + // restore stream state + yyin->seekg(loc); + yyin->setstate(state); } } // namespace SEAMS diff --git a/packages/seacas/libraries/aprepro_lib/aprepro.ll b/packages/seacas/libraries/aprepro_lib/aprepro.ll index 4c901f4921..105e78f5e7 100644 --- a/packages/seacas/libraries/aprepro_lib/aprepro.ll +++ b/packages/seacas/libraries/aprepro_lib/aprepro.ll @@ -1204,9 +1204,10 @@ integer {D}+({E})? return; // Clear any possible end-of-stream if e.g., reading from a istringstream. - if (aprepro.ap_file_list.top().name == "interactive_input") { - yyin->clear(); - } + std::ios::iostate state = yyin->rdstate(); + size_t loc = yyin->tellg(); + yyin->clear(); + // Go back in the stream to where we started keeping history. yyin->seekg(hist_start); if (!yyin->good()) { @@ -1226,6 +1227,10 @@ integer {D}+({E})? history_string = tmp; delete[] tmp; hist_start = 0; + + // restore stream state + yyin->seekg(loc); + yyin->setstate(state); } }