Skip to content

Commit

Permalink
Rework check for readable input file
Browse files Browse the repository at this point in the history
This reverts commit 1a09644 and
implements an alternate check which allows input from stdin.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Oct 6, 2018
1 parent 140bfa4 commit 67bf906
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,15 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
buf.assign((std::istreambuf_iterator<char>(std::cin)),
(std::istreambuf_iterator<char>()));
data = reinterpret_cast<const l_uint8 *>(buf.data());
} else {
// Check whether the input file can be read.
if (FILE* file = fopen(filename, "rb")) {
fclose(file);
} else {
fprintf(stderr, "Error, cannot read input file %s: %s\n",
filename, strerror(errno));
return false;
}
}

// Here is our autodetection
Expand Down
7 changes: 0 additions & 7 deletions src/api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,6 @@ int main(int argc, char** argv) {
return EXIT_SUCCESS;
}

if (FILE* file = fopen(image, "r")) {
fclose(file);
} else {
fprintf(stderr, "Cannot open input file: %s\n", image);
return EXIT_FAILURE;
}

FixPageSegMode(&api, pagesegmode);

if (dpi) {
Expand Down

0 comments on commit 67bf906

Please sign in to comment.