|
1 | 1 | /**********************************************************************
|
2 | 2 | * File: mainblk.c (Formerly main.c)
|
3 | 3 | * Description: Function to call from main() to setup.
|
4 |
| - * Author: Ray Smith |
5 |
| - * Created: Tue Oct 22 11:09:40 BST 1991 |
| 4 | + * Author: Ray Smith |
| 5 | + * Created: Tue Oct 22 11:09:40 BST 1991 |
6 | 6 | *
|
7 | 7 | * (C) Copyright 1991, Hewlett-Packard Ltd.
|
8 | 8 | ** Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -47,26 +47,40 @@ namespace tesseract {
|
47 | 47 | * @param argv0 - paths to the directory with language files and config files.
|
48 | 48 | * An actual value of argv0 is used if not NULL, otherwise TESSDATA_PREFIX is
|
49 | 49 | * used if not NULL, next try to use compiled in -DTESSDATA_PREFIX. If previous
|
50 |
| - * is not sucessul - use current directory. |
| 50 | + * is not successful - use current directory. |
51 | 51 | * @param basename - name of image
|
52 | 52 | */
|
53 | 53 | void CCUtil::main_setup(const char *argv0, const char *basename) {
|
54 | 54 | imagebasename = basename; /**< name of image */
|
55 | 55 |
|
| 56 | + char *tessdata_prefix = getenv("TESSDATA_PREFIX"); |
| 57 | + |
56 | 58 | if (argv0 != NULL) {
|
| 59 | + /* Use tessdata prefix from the command line. */ |
57 | 60 | datadir = argv0;
|
| 61 | + } else if (tessdata_prefix) { |
| 62 | + /* Use tessdata prefix from the environment. */ |
| 63 | + datadir = tessdata_prefix; |
| 64 | +#if defined(_WIN32) |
| 65 | + } else if (datadir == NULL || access(datadir.string(), 0) != 0) { |
| 66 | + /* Look for tessdata in directory of executable. */ |
| 67 | + static char dir[128]; |
| 68 | + static char exe[128]; |
| 69 | + DWORD length = GetModuleFileName(NULL, exe, sizeof(exe)); |
| 70 | + if (length > 0 && length < sizeof(exe)) { |
| 71 | + _splitpath(exe, NULL, dir, NULL, NULL); |
| 72 | + datadir = dir; |
| 73 | + } |
| 74 | +#endif /* _WIN32 */ |
| 75 | +#if defined(TESSDATA_PREFIX) |
58 | 76 | } else {
|
59 |
| - if (getenv("TESSDATA_PREFIX")) { |
60 |
| - datadir = getenv("TESSDATA_PREFIX"); |
61 |
| - } else { |
62 |
| -#ifdef TESSDATA_PREFIX |
| 77 | + /* Use tessdata prefix which was compiled in. */ |
63 | 78 | #define _STR(a) #a
|
64 | 79 | #define _XSTR(a) _STR(a)
|
65 | 80 | datadir = _XSTR(TESSDATA_PREFIX);
|
66 | 81 | #undef _XSTR
|
67 | 82 | #undef _STR
|
68 | 83 | #endif
|
69 |
| - } |
70 | 84 | }
|
71 | 85 |
|
72 | 86 | // datadir may still be empty:
|
|
0 commit comments