From 1514c81e18467a536b43a07d99954579f2100e17 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:07:51 +0100 Subject: [PATCH] fix data-input from stdin --- main.cpp | 21 ++++++++++++++++----- main.h | 3 ++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 8a75dc9..987cc87 100644 --- a/main.cpp +++ b/main.cpp @@ -82,13 +82,18 @@ int main(int argc, char **argv) } // check the result of "doc.load"-Function if (!result){ - std::cerr << "File \"" << ElementFile << "\" could not be loaded: " << result.description() << std::endl; - std::cerr << "Check file up to byte-offset: " << result.offset << " -- content partly shown here:\n"; // try to read the corrupt part and output to stderr - std::cerr << "(...)" << ReadPieceOfFile(ElementFile, result.offset, (get_terminal_width()-10)) << "(...)\n\n"; + if (xPrintToStdOut == true) { + std::cerr << "Data could not be loaded: " << result.description() << std::endl; + std::cerr << "Check data up to byte-offset: " << result.offset << "\n"; + } else { + std::cerr << "File \"" << ElementFile << "\" could not be loaded: " << result.description() << std::endl; + std::cerr << "Check file up to byte-offset: " << result.offset << " -- content partly shown here:\n"; + std::cerr << "(...)" << ReadPieceOfFile(ElementFile, result.offset, (get_terminal_width()-10)) << "(...)\n\n"; + } return -1; } else { - if (_DEBUG_) std::cerr << "Element-File loaded successfully.\n"; + if (_DEBUG_) std::cerr << "Element-Data loaded successfully.\n"; } // xml-file was successfully loaded, let's check, what kind of data we have... @@ -109,7 +114,13 @@ int main(int argc, char **argv) if (xOverwriteOriginal == true){ std::cerr << "will overwrite original file!" << std::endl; } else { - (xIsElmtFile ? ElementFileScaled.insert(ElementFileScaled.length()-5, ".SCALED") : ElementFileScaled += ".SCALED" ); + if (xPrintToStdOut == false) { + if (xIsElmtFile == true) { + ElementFileScaled.insert(ElementFileScaled.length()-5, ".SCALED"); + } else { + ElementFileScaled += ".SCALED"; + } + } } if (_DEBUG_) std::cerr << ElementFileScaled << std::endl; diff --git a/main.h b/main.h index 627c44f..cbb004f 100644 --- a/main.h +++ b/main.h @@ -43,7 +43,7 @@ // global variables // ============================================================================= -const std::string sVersion = "v0.5.2"; +const std::string sVersion = "v0.5.2.1"; // the element-file to process: static std::string ElementFile = ""; @@ -198,6 +198,7 @@ int parseCommandline(int argc, char *argv[]) { if (_DEBUG_) std::cerr << "Read from STDIN\n"; xReadFromStdIn = true; + xPrintToStdOut = true; break; case 'o': if (_DEBUG_)