Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
basedir.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 * File: basedir.c (Formerly getpath.c)
3 * Description: Find the directory location of the current executable using PATH.
4 * Author: Ray Smith
5 * Created: Mon Jul 09 09:06:39 BST 1990
6 *
7 * (C) Copyright 1990, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #include "basedir.h"
21
22 #include <stdlib.h>
23
24 #include "mfcpch.h" // Precompiled headers
25
26 // Assuming that code_path is the name of some file in a desired directory,
27 // returns the given code_path stripped back to the last slash, leaving
28 // the last slash in place. If there is no slash, returns ./ assuming that
29 // the input was the name of something in the current directory.
30 // Useful for getting to the directory of argv[0], but does not search
31 // any paths.
32 TESS_API void truncate_path(const char *code_path, STRING* trunc_path) {
33 int trunc_index = -1;
34 if (code_path != NULL) {
35 const char* last_slash = strrchr(code_path, '/');
36 if (last_slash != NULL && last_slash + 1 - code_path > trunc_index)
37 trunc_index = last_slash + 1 - code_path;
38 last_slash = strrchr(code_path, '\\');
39 if (last_slash != NULL && last_slash + 1 - code_path > trunc_index)
40 trunc_index = last_slash + 1 - code_path;
41 }
42 *trunc_path = code_path;
43 if (trunc_index >= 0)
44 trunc_path->truncate_at(trunc_index);
45 else
46 *trunc_path = "./";
47 }