This commit is contained in:
lzwdgc 2024-02-03 13:20:21 +03:00
parent 161cd9d95e
commit 55e95ba805

View file

@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
// write script // write script
{ {
filename += ".txt"; filename += ".txt";
if (std::ofstream ofile(filename); ofile) { if (std::ofstream ofile(filename, std::ios::binary); ofile) {
std::string indent, space = " "s; std::string indent, space = " "s;
auto inc = [&]() { auto inc = [&]() {
indent += space; indent += space;
@ -56,12 +56,19 @@ int main(int argc, char *argv[]) {
return false; return false;
}; };
int procs{}; int procs{};
bool prev_newline{};
for (auto &&l : lines) { for (auto &&l : lines) {
auto else_ = l == "ELSE"sv;
auto proc = l.starts_with("PROC"sv); auto proc = l.starts_with("PROC"sv);
auto end = l == "END"sv; auto end = l == "END"sv;
auto lbrace = l == "{"sv; auto lbrace = l == "{"sv;
auto rbrace = l == "}"sv; auto rbrace = l == "}"sv;
if (else_ && prev_newline) {
ofile.seekp(-1, std::ios::cur);
}
prev_newline = false;
if (rbrace) { if (rbrace) {
if (!dec()) { if (!dec()) {
ofile << "// script2txt2 comment: unbalanced!\n"; ofile << "// script2txt2 comment: unbalanced!\n";
@ -75,8 +82,9 @@ int main(int argc, char *argv[]) {
ofile << indent << l << "\n"; ofile << indent << l << "\n";
if (end && indent.empty()) { if ((end || rbrace) && indent.empty()) {
//ofile << "\n"; ofile << "\n";
prev_newline = true;
} }
if (end && procs) { if (end && procs) {
procs = 0; procs = 0;