Skip to content

Commit

Permalink
fix data-input from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
plc-user committed Jan 14, 2025
1 parent c3c9e86 commit 1514c81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 16 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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_)
Expand Down

0 comments on commit 1514c81

Please sign in to comment.