This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathw32support.cpp
More file actions
138 lines (106 loc) · 2.93 KB
/
w32support.cpp
File metadata and controls
138 lines (106 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include <windows.h>
#include <cstring>
#include <revolution/support.h>
#include <core.h>
char *string_from_utf16(const unsigned short *p_utf16_string, int p_utf16_length)
{
char *t_string;
t_string = (char *)malloc(p_utf16_length + 1);
if (t_string == NULL)
return NULL;
WideCharToMultiByte(1252, 0, (LPCWSTR)p_utf16_string, p_utf16_length, t_string, p_utf16_length, NULL, NULL);
t_string[p_utf16_length] = '\0';
return t_string;
}
char *string_to_utf8(const char *p_native_path)
{
int t_length;
t_length = strlen(p_native_path) + 1;
WCHAR *t_utf16_path;
t_utf16_path = (WCHAR *)malloc(sizeof(WCHAR) * t_length);
MultiByteToWideChar(1252, MB_PRECOMPOSED, p_native_path, t_length, t_utf16_path, t_length);
int t_utf8_length;
t_utf8_length = WideCharToMultiByte(CP_UTF8, 0, t_utf16_path, t_length, NULL, 0, NULL, NULL);
char *t_utf8_path;
t_utf8_path = (char *)malloc(t_utf8_length);
WideCharToMultiByte(CP_UTF8, 0, t_utf16_path, t_length, t_utf8_path, t_utf8_length, NULL, NULL);
free(t_utf16_path);
return t_utf8_path;
}
char *os_path_to_native_utf8(const char *p_path)
{
char *t_native_path;
t_native_path = os_path_to_native(p_path);
char *t_native_utf8_path;
t_native_utf8_path = string_to_utf8(t_native_path);
free(t_native_path);
return t_native_utf8_path;
}
char *os_path_to_native(const char *p_path)
{
char *t_path;
t_path = strdup(p_path);
char *dptr;
dptr = t_path;
if (!*dptr)
return dptr;
do {
if (*dptr == '/')
*dptr = '\\';
} while (*++dptr);
return t_path;
}
char *os_path_from_native(const char *p_native_path)
{
char *t_path;
t_path = strdup(p_native_path);
char *dptr;
dptr = t_path;
if (!*dptr)
return dptr;
do {
if (*dptr == '\\')
*dptr = '/';
} while (*++dptr);
return t_path;
}
char *strclone(const char *one)
{
char *two = NULL;
if (one != NULL)
{
two = new (nothrow) char[strlen(one) + 1];
strcpy(two, one);
}
return two;
}
char *get_currrent_directory()
{
char *dptr = new (nothrow) char[PATH_MAX + 2];
GetCurrentDirectoryA(PATH_MAX +1, (LPSTR)dptr);
dptr = os_path_to_native(dptr);
return dptr;
}
char *os_path_resolve(const char *p_native_path)
{
if (p_native_path == NULL)
{
char *tpath = get_currrent_directory();
tpath = os_path_to_native(tpath);
return tpath;
}
char *cstr = strclone(p_native_path);
cstr = os_path_to_native(cstr);
return cstr;
}