Commit 53e42eabf476fa612fb9dc99b1584f0a6f498757
1 parent
d054890e
Exists in
develop
Adding macos tools.
Showing
2 changed files
with
92 additions
and
0 deletions
Show diff stats
pw3270.cbp
@@ -61,6 +61,9 @@ | @@ -61,6 +61,9 @@ | ||
61 | <Unit filename="src/main/linux/tools.c"> | 61 | <Unit filename="src/main/linux/tools.c"> |
62 | <Option compilerVar="CC" /> | 62 | <Option compilerVar="CC" /> |
63 | </Unit> | 63 | </Unit> |
64 | + <Unit filename="src/main/macos/tools.c"> | ||
65 | + <Option compilerVar="CC" /> | ||
66 | + </Unit> | ||
64 | <Unit filename="src/main/main.c"> | 67 | <Unit filename="src/main/main.c"> |
65 | <Option compilerVar="CC" /> | 68 | <Option compilerVar="CC" /> |
66 | </Unit> | 69 | </Unit> |
@@ -0,0 +1,89 @@ | @@ -0,0 +1,89 @@ | ||
1 | +/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
2 | + | ||
3 | +/* | ||
4 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
5 | + * | ||
6 | + * This program is free software: you can redistribute it and/or modify | ||
7 | + * it under the terms of the GNU Lesser General Public License as published | ||
8 | + * by the Free Software Foundation, either version 3 of the License, or | ||
9 | + * (at your option) any later version. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License | ||
17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
18 | + */ | ||
19 | + | ||
20 | + #include <config.h> | ||
21 | + #include <pw3270.h> | ||
22 | + #include <sys/syslimits.h> | ||
23 | + #include <CoreFoundation/CFBundle.h> | ||
24 | + #include <CoreFoundation/CFURL.h> | ||
25 | + | ||
26 | + static gchar * get_path_from_bundle(const char *name) { | ||
27 | + | ||
28 | + size_t szBuffer = PATH_MAX; | ||
29 | + char buffer[PATH_MAX+1]; | ||
30 | + memset(buffer,0,PATH_MAX+1]); | ||
31 | + | ||
32 | + CFBundleRef mainBundle = CFBundleGetMainBundle(); | ||
33 | + | ||
34 | + if (mainBundle) { | ||
35 | + | ||
36 | + CFURLRef url = CFBundleCopyBundleURL(mainBundle); | ||
37 | + | ||
38 | + if (url) { | ||
39 | + | ||
40 | + CFURLGetFileSystemRepresentation(url, true, (UInt8 *) buffer, szBuffer); | ||
41 | + CFRelease(url); | ||
42 | + | ||
43 | + gchar * path = g_build_filename(buffer,name,NULL); | ||
44 | + | ||
45 | + if(access(path,R_OK) == 0) { | ||
46 | + return path; | ||
47 | + } | ||
48 | + | ||
49 | + g_free(path); | ||
50 | + | ||
51 | + } | ||
52 | + | ||
53 | + } | ||
54 | + | ||
55 | + return NUL; | ||
56 | + | ||
57 | + } | ||
58 | + | ||
59 | + gchar * pw3270_build_data_path(const char *name) { | ||
60 | + | ||
61 | + gchar * path = get_path_from_bundle(name); | ||
62 | + | ||
63 | + if(path) { | ||
64 | + if(g_file_test(path,G_FILE_TEST_IS_DIR)) { | ||
65 | + return path; | ||
66 | + } | ||
67 | + g_free(path); | ||
68 | + } | ||
69 | + | ||
70 | + g_message("Cant find path for '%s'",path); | ||
71 | + return NULL; | ||
72 | + | ||
73 | + } | ||
74 | + | ||
75 | + gchar * pw3270_build_data_filename(const char *filename) { | ||
76 | + | ||
77 | + gchar * path = get_path_from_bundle(name); | ||
78 | + | ||
79 | + if(path) { | ||
80 | + if(g_file_test(path,G_FILE_TEST_IS_REGULAR)) { | ||
81 | + return path; | ||
82 | + } | ||
83 | + g_free(path); | ||
84 | + } | ||
85 | + | ||
86 | + g_error("Cant find '%s'",filename); | ||
87 | + return NULL; | ||
88 | + } | ||
89 | + |