Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CCUtil::main_setup (fixes issue #4230) #4239

Merged
merged 2 commits into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/ccutil/ccutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CCUtil::~CCUtil() = default;
void CCUtil::main_setup(const std::string &argv0, const std::string &basename) {
imagebasename = basename; /**< name of image */

char *tessdata_prefix = getenv("TESSDATA_PREFIX");
const char *tessdata_prefix = getenv("TESSDATA_PREFIX");

if (!argv0.empty()) {
/* Use tessdata prefix from the command line. */
Expand Down Expand Up @@ -77,17 +77,20 @@ void CCUtil::main_setup(const std::string &argv0, const std::string &basename) {
if (datadir.empty()) {
#if defined(TESSDATA_PREFIX)
// Use tessdata prefix which was compiled in.
datadir = TESSDATA_PREFIX "/tessdata";
// Note that some software (for example conda) patches TESSDATA_PREFIX
// in the binary, so it should not be used directly with a std::string.
tessdata_prefix = TESSDATA_PREFIX;
datadir = tessdata_prefix;
datadir += "/tessdata/";
#else
datadir = "./";
#endif /* TESSDATA_PREFIX */
}

// check for missing directory separator
const char *lastchar = datadir.c_str();
lastchar += datadir.length() - 1;
if ((strcmp(lastchar, "/") != 0) && (strcmp(lastchar, "\\") != 0)) {
datadir += "/";
const char lastchar = datadir.back();
if (lastchar != '/' && lastchar != '\\') {
datadir += '/';
}
}

Expand Down
Loading