Skip to content

Commit

Permalink
APREPRO: Better handling of string in save_history_string
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed Oct 16, 2023
1 parent c7094dd commit f4481e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 12 additions & 6 deletions packages/seacas/libraries/aprepro_lib/apr_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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

Expand Down
11 changes: 8 additions & 3 deletions packages/seacas/libraries/aprepro_lib/aprepro.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -1226,6 +1227,10 @@ integer {D}+({E})?
history_string = tmp;
delete[] tmp;
hist_start = 0;

// restore stream state
yyin->seekg(loc);
yyin->setstate(state);
}
}

Expand Down

0 comments on commit f4481e6

Please sign in to comment.