forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathw32support.cpp
More file actions
121 lines (94 loc) · 2.29 KB
/
Copy pathw32support.cpp
File metadata and controls
121 lines (94 loc) · 2.29 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
#include <windows.h>
#include <cstring>
#include <revolution/support.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 char[strlen(one) + 1];
strcpy(two, one);
}
return two;
}
char *get_currrent_directory()
{
char *dptr = new 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;
}