Fossil SCM

Merge in various complications needed to support CYGWIN.

drh 2013-03-04 16:12 trunk merge
Commit d95cbba2e69347f96bbf8563f20f6f498754c313
4 files changed +5 -3 +1 -1 +35 -18 +35 -18
+5 -3
--- src/blob.c
+++ src/blob.c
@@ -792,11 +792,11 @@
792792
}
793793
nName = file_simplify_name(zName, nName, 0);
794794
for(i=1; i<nName; i++){
795795
if( zName[i]=='/' ){
796796
zName[i] = 0;
797
-#if defined(_WIN32)
797
+#if defined(_WIN32) || defined(__CYGWIN__)
798798
/*
799799
** On Windows, local path looks like: C:/develop/project/file.txt
800800
** The if stops us from trying to create a directory of a drive letter
801801
** C: in this example.
802802
*/
@@ -804,11 +804,11 @@
804804
#endif
805805
if( file_mkdir(zName, 1) && file_isdir(zName)!=1 ){
806806
fossil_fatal_recursive("unable to create directory %s", zName);
807807
return 0;
808808
}
809
-#if defined(_WIN32)
809
+#if defined(_WIN32) || defined(__CYGWIN__)
810810
}
811811
#endif
812812
zName[i] = '/';
813813
}
814814
}
@@ -1104,11 +1104,11 @@
11041104
zUtf8 = blob_str(pBlob) + bomSize;
11051105
blob_zero(&temp);
11061106
blob_append(&temp, zUtf8, -1);
11071107
blob_swap(pBlob, &temp);
11081108
blob_reset(&temp);
1109
-#ifdef _WIN32
1109
+#if defined(_WIN32) || defined(__CYGWIN__)
11101110
}else if( starts_with_utf16_bom(pBlob, &bomSize, &bomReverse) ){
11111111
zUtf8 = blob_buffer(pBlob);
11121112
if( bomReverse ){
11131113
/* Found BOM, but with reversed bytes */
11141114
unsigned int i = blob_size(pBlob);
@@ -1124,13 +1124,15 @@
11241124
zUtf8 = blob_str(pBlob) + bomSize;
11251125
zUtf8 = fossil_unicode_to_utf8(zUtf8);
11261126
blob_zero(pBlob);
11271127
blob_append(pBlob, zUtf8, -1);
11281128
fossil_unicode_free(zUtf8);
1129
+#endif /* _WIN32 || __CYGWIN__ */
1130
+#if defined(_WIN32)
11291131
}else if( useMbcs ){
11301132
zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
11311133
blob_reset(pBlob);
11321134
blob_append(pBlob, zUtf8, -1);
11331135
fossil_mbcs_free(zUtf8);
11341136
#endif /* _WIN32 */
11351137
}
11361138
}
11371139
--- src/blob.c
+++ src/blob.c
@@ -792,11 +792,11 @@
792 }
793 nName = file_simplify_name(zName, nName, 0);
794 for(i=1; i<nName; i++){
795 if( zName[i]=='/' ){
796 zName[i] = 0;
797 #if defined(_WIN32)
798 /*
799 ** On Windows, local path looks like: C:/develop/project/file.txt
800 ** The if stops us from trying to create a directory of a drive letter
801 ** C: in this example.
802 */
@@ -804,11 +804,11 @@
804 #endif
805 if( file_mkdir(zName, 1) && file_isdir(zName)!=1 ){
806 fossil_fatal_recursive("unable to create directory %s", zName);
807 return 0;
808 }
809 #if defined(_WIN32)
810 }
811 #endif
812 zName[i] = '/';
813 }
814 }
@@ -1104,11 +1104,11 @@
1104 zUtf8 = blob_str(pBlob) + bomSize;
1105 blob_zero(&temp);
1106 blob_append(&temp, zUtf8, -1);
1107 blob_swap(pBlob, &temp);
1108 blob_reset(&temp);
1109 #ifdef _WIN32
1110 }else if( starts_with_utf16_bom(pBlob, &bomSize, &bomReverse) ){
1111 zUtf8 = blob_buffer(pBlob);
1112 if( bomReverse ){
1113 /* Found BOM, but with reversed bytes */
1114 unsigned int i = blob_size(pBlob);
@@ -1124,13 +1124,15 @@
1124 zUtf8 = blob_str(pBlob) + bomSize;
1125 zUtf8 = fossil_unicode_to_utf8(zUtf8);
1126 blob_zero(pBlob);
1127 blob_append(pBlob, zUtf8, -1);
1128 fossil_unicode_free(zUtf8);
 
 
1129 }else if( useMbcs ){
1130 zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
1131 blob_reset(pBlob);
1132 blob_append(pBlob, zUtf8, -1);
1133 fossil_mbcs_free(zUtf8);
1134 #endif /* _WIN32 */
1135 }
1136 }
1137
--- src/blob.c
+++ src/blob.c
@@ -792,11 +792,11 @@
792 }
793 nName = file_simplify_name(zName, nName, 0);
794 for(i=1; i<nName; i++){
795 if( zName[i]=='/' ){
796 zName[i] = 0;
797 #if defined(_WIN32) || defined(__CYGWIN__)
798 /*
799 ** On Windows, local path looks like: C:/develop/project/file.txt
800 ** The if stops us from trying to create a directory of a drive letter
801 ** C: in this example.
802 */
@@ -804,11 +804,11 @@
804 #endif
805 if( file_mkdir(zName, 1) && file_isdir(zName)!=1 ){
806 fossil_fatal_recursive("unable to create directory %s", zName);
807 return 0;
808 }
809 #if defined(_WIN32) || defined(__CYGWIN__)
810 }
811 #endif
812 zName[i] = '/';
813 }
814 }
@@ -1104,11 +1104,11 @@
1104 zUtf8 = blob_str(pBlob) + bomSize;
1105 blob_zero(&temp);
1106 blob_append(&temp, zUtf8, -1);
1107 blob_swap(pBlob, &temp);
1108 blob_reset(&temp);
1109 #if defined(_WIN32) || defined(__CYGWIN__)
1110 }else if( starts_with_utf16_bom(pBlob, &bomSize, &bomReverse) ){
1111 zUtf8 = blob_buffer(pBlob);
1112 if( bomReverse ){
1113 /* Found BOM, but with reversed bytes */
1114 unsigned int i = blob_size(pBlob);
@@ -1124,13 +1124,15 @@
1124 zUtf8 = blob_str(pBlob) + bomSize;
1125 zUtf8 = fossil_unicode_to_utf8(zUtf8);
1126 blob_zero(pBlob);
1127 blob_append(pBlob, zUtf8, -1);
1128 fossil_unicode_free(zUtf8);
1129 #endif /* _WIN32 || __CYGWIN__ */
1130 #if defined(_WIN32)
1131 }else if( useMbcs ){
1132 zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
1133 blob_reset(pBlob);
1134 blob_append(pBlob, zUtf8, -1);
1135 fossil_mbcs_free(zUtf8);
1136 #endif /* _WIN32 */
1137 }
1138 }
1139
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -966,11 +966,11 @@
966966
if ( encodingOk ){
967967
return 0; /* We don't want encoding warnings for this file. */
968968
}
969969
zWarning = "Unicode";
970970
zDisable = "\"encoding-glob\" setting";
971
-#ifndef _WIN32
971
+#if !defined(_WIN32) && !defined(__CYGWIN__)
972972
zConvert = ""; /* On Unix, we cannot easily convert Unicode files. */
973973
#endif
974974
}
975975
file_relative_name(zFilename, &fname, 0);
976976
blob_zero(&ans);
977977
--- src/checkin.c
+++ src/checkin.c
@@ -966,11 +966,11 @@
966 if ( encodingOk ){
967 return 0; /* We don't want encoding warnings for this file. */
968 }
969 zWarning = "Unicode";
970 zDisable = "\"encoding-glob\" setting";
971 #ifndef _WIN32
972 zConvert = ""; /* On Unix, we cannot easily convert Unicode files. */
973 #endif
974 }
975 file_relative_name(zFilename, &fname, 0);
976 blob_zero(&ans);
977
--- src/checkin.c
+++ src/checkin.c
@@ -966,11 +966,11 @@
966 if ( encodingOk ){
967 return 0; /* We don't want encoding warnings for this file. */
968 }
969 zWarning = "Unicode";
970 zDisable = "\"encoding-glob\" setting";
971 #if !defined(_WIN32) && !defined(__CYGWIN__)
972 zConvert = ""; /* On Unix, we cannot easily convert Unicode files. */
973 #endif
974 }
975 file_relative_name(zFilename, &fname, 0);
976 blob_zero(&ans);
977
+35 -18
--- src/utf8.c
+++ src/utf8.c
@@ -23,10 +23,18 @@
2323
#include "utf8.h"
2424
#include <sqlite3.h>
2525
#ifdef _WIN32
2626
# include <windows.h>
2727
#endif
28
+#ifdef __CYGWIN__
29
+# include <sys/cygwin.h>
30
+# define CP_UTF8 65001
31
+ __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int,
32
+ const char *, int, const char *, int, const char *, const char *);
33
+ __declspec(dllimport) extern __stdcall int MultiByteToWideChar(int, int,
34
+ const char *, int, wchar_t*, int);
35
+#endif
2836
2937
#ifdef _WIN32
3038
/*
3139
** Translate MBCS to UTF-8. Return a pointer to the translated text.
3240
** Call fossil_mbcs_free() to deallocate any memory used to store the
@@ -42,38 +50,39 @@
4250
** any memory used to hold the translation
4351
*/
4452
void fossil_mbcs_free(char *zOld){
4553
sqlite3_free(zOld);
4654
}
55
+#endif /* _WIN32 */
4756
4857
/*
4958
** Translate Unicode text into UTF-8.
5059
** Return a pointer to the translated text.
5160
** Call fossil_unicode_free() to deallocate any memory used to store the
5261
** returned pointer when done.
5362
*/
5463
char *fossil_unicode_to_utf8(const void *zUnicode){
55
-#ifdef _WIN32
64
+#if defined(_WIN32) || defined(__CYGWIN__)
5665
int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
5766
char *zUtf = sqlite3_malloc( nByte );
5867
if( zUtf==0 ){
5968
return 0;
6069
}
6170
WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
6271
return zUtf;
6372
#else
64
- return fossil_strdup(zUtf8); /* TODO: implement for unix */
73
+ return fossil_strdup(zUnicode); /* TODO: implement for unix */
6574
#endif
6675
}
6776
6877
/*
6978
** Translate UTF-8 to unicode for use in system calls. Return a pointer to the
7079
** translated text.. Call fossil_unicode_free() to deallocate any memory
7180
** used to store the returned pointer when done.
7281
*/
7382
void *fossil_utf8_to_unicode(const char *zUtf8){
74
-#ifdef _WIN32
83
+#if defined(_WIN32) || defined(__CYGWIN__)
7584
int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
7685
wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
7786
if( zUnicode==0 ){
7887
return 0;
7988
}
@@ -87,17 +96,16 @@
8796
/*
8897
** Deallocate any memory that was previously allocated by
8998
** fossil_unicode_to_utf8().
9099
*/
91100
void fossil_unicode_free(void *pOld){
92
-#ifdef _WIN32
101
+#if defined(_WIN32) || defined(__CYGWIN__)
93102
sqlite3_free(pOld);
94103
#else
95104
fossil_free(pOld);
96105
#endif
97106
}
98
-#endif /* _WIN32 */
99107
100108
#if defined(__APPLE__) && !defined(WITHOUT_ICONV)
101109
# include <iconv.h>
102110
#endif
103111
@@ -160,17 +168,17 @@
160168
** Call fossil_filename_free() to deallocate any memory used to store the
161169
** returned pointer when done.
162170
*/
163171
void *fossil_utf8_to_filename(const char *zUtf8){
164172
#ifdef _WIN32
165
- int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
166
- wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
173
+ int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
174
+ wchar_t *zUnicode = sqlite3_malloc( nChar * 2 );
167175
wchar_t *wUnicode = zUnicode;
168176
if( zUnicode==0 ){
169177
return 0;
170178
}
171
- MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
179
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nChar);
172180
while( *wUnicode != '\0' ){
173181
if( *wUnicode == '/' ){
174182
*wUnicode = '\\';
175183
}
176184
++wUnicode;
@@ -178,22 +186,31 @@
178186
return zUnicode;
179187
#elif defined(__CYGWIN__)
180188
char *zPath, *p;
181189
if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
182190
&& (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
183
- int n = strlen(zUtf8);
184
- zPath = fossil_malloc( n+10 );
185
- memcpy(zPath, "/cygdrive/", 10);
186
- zPath[10] = zUtf8[0];
187
- memcpy(zPath+11, zUtf8+2, n-1);
191
+ /* win32 absolute path starting with drive specifier. */
192
+ int nByte;
193
+ wchar_t zUnicode[2000];
194
+ wchar_t *wUnicode = zUnicode;
195
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, count(zUnicode));
196
+ while( *wUnicode != '\0' ){
197
+ if( *wUnicode == '/' ){
198
+ *wUnicode = '\\';
199
+ }
200
+ ++wUnicode;
201
+ }
202
+ nByte = cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, NULL, 0);
203
+ zPath = fossil_malloc(nByte);
204
+ cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, zPath, nByte);
188205
} else {
189206
zPath = fossil_strdup(zUtf8);
190
- }
191
- zUtf8 = p = zPath;
192
- while( (*p = *zUtf8++) != 0){
193
- if (*p++ == '\\' ) {
194
- p[-1] = '/';
207
+ zUtf8 = p = zPath;
208
+ while( (*p = *zUtf8++) != 0){
209
+ if (*p++ == '\\' ) {
210
+ p[-1] = '/';
211
+ }
195212
}
196213
}
197214
return zPath;
198215
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
199216
return fossil_strdup(zUtf8);
200217
--- src/utf8.c
+++ src/utf8.c
@@ -23,10 +23,18 @@
23 #include "utf8.h"
24 #include <sqlite3.h>
25 #ifdef _WIN32
26 # include <windows.h>
27 #endif
 
 
 
 
 
 
 
 
28
29 #ifdef _WIN32
30 /*
31 ** Translate MBCS to UTF-8. Return a pointer to the translated text.
32 ** Call fossil_mbcs_free() to deallocate any memory used to store the
@@ -42,38 +50,39 @@
42 ** any memory used to hold the translation
43 */
44 void fossil_mbcs_free(char *zOld){
45 sqlite3_free(zOld);
46 }
 
47
48 /*
49 ** Translate Unicode text into UTF-8.
50 ** Return a pointer to the translated text.
51 ** Call fossil_unicode_free() to deallocate any memory used to store the
52 ** returned pointer when done.
53 */
54 char *fossil_unicode_to_utf8(const void *zUnicode){
55 #ifdef _WIN32
56 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
57 char *zUtf = sqlite3_malloc( nByte );
58 if( zUtf==0 ){
59 return 0;
60 }
61 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
62 return zUtf;
63 #else
64 return fossil_strdup(zUtf8); /* TODO: implement for unix */
65 #endif
66 }
67
68 /*
69 ** Translate UTF-8 to unicode for use in system calls. Return a pointer to the
70 ** translated text.. Call fossil_unicode_free() to deallocate any memory
71 ** used to store the returned pointer when done.
72 */
73 void *fossil_utf8_to_unicode(const char *zUtf8){
74 #ifdef _WIN32
75 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
76 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
77 if( zUnicode==0 ){
78 return 0;
79 }
@@ -87,17 +96,16 @@
87 /*
88 ** Deallocate any memory that was previously allocated by
89 ** fossil_unicode_to_utf8().
90 */
91 void fossil_unicode_free(void *pOld){
92 #ifdef _WIN32
93 sqlite3_free(pOld);
94 #else
95 fossil_free(pOld);
96 #endif
97 }
98 #endif /* _WIN32 */
99
100 #if defined(__APPLE__) && !defined(WITHOUT_ICONV)
101 # include <iconv.h>
102 #endif
103
@@ -160,17 +168,17 @@
160 ** Call fossil_filename_free() to deallocate any memory used to store the
161 ** returned pointer when done.
162 */
163 void *fossil_utf8_to_filename(const char *zUtf8){
164 #ifdef _WIN32
165 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
166 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
167 wchar_t *wUnicode = zUnicode;
168 if( zUnicode==0 ){
169 return 0;
170 }
171 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
172 while( *wUnicode != '\0' ){
173 if( *wUnicode == '/' ){
174 *wUnicode = '\\';
175 }
176 ++wUnicode;
@@ -178,22 +186,31 @@
178 return zUnicode;
179 #elif defined(__CYGWIN__)
180 char *zPath, *p;
181 if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
182 && (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
183 int n = strlen(zUtf8);
184 zPath = fossil_malloc( n+10 );
185 memcpy(zPath, "/cygdrive/", 10);
186 zPath[10] = zUtf8[0];
187 memcpy(zPath+11, zUtf8+2, n-1);
 
 
 
 
 
 
 
 
 
188 } else {
189 zPath = fossil_strdup(zUtf8);
190 }
191 zUtf8 = p = zPath;
192 while( (*p = *zUtf8++) != 0){
193 if (*p++ == '\\' ) {
194 p[-1] = '/';
195 }
196 }
197 return zPath;
198 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
199 return fossil_strdup(zUtf8);
200
--- src/utf8.c
+++ src/utf8.c
@@ -23,10 +23,18 @@
23 #include "utf8.h"
24 #include <sqlite3.h>
25 #ifdef _WIN32
26 # include <windows.h>
27 #endif
28 #ifdef __CYGWIN__
29 # include <sys/cygwin.h>
30 # define CP_UTF8 65001
31 __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int,
32 const char *, int, const char *, int, const char *, const char *);
33 __declspec(dllimport) extern __stdcall int MultiByteToWideChar(int, int,
34 const char *, int, wchar_t*, int);
35 #endif
36
37 #ifdef _WIN32
38 /*
39 ** Translate MBCS to UTF-8. Return a pointer to the translated text.
40 ** Call fossil_mbcs_free() to deallocate any memory used to store the
@@ -42,38 +50,39 @@
50 ** any memory used to hold the translation
51 */
52 void fossil_mbcs_free(char *zOld){
53 sqlite3_free(zOld);
54 }
55 #endif /* _WIN32 */
56
57 /*
58 ** Translate Unicode text into UTF-8.
59 ** Return a pointer to the translated text.
60 ** Call fossil_unicode_free() to deallocate any memory used to store the
61 ** returned pointer when done.
62 */
63 char *fossil_unicode_to_utf8(const void *zUnicode){
64 #if defined(_WIN32) || defined(__CYGWIN__)
65 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
66 char *zUtf = sqlite3_malloc( nByte );
67 if( zUtf==0 ){
68 return 0;
69 }
70 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
71 return zUtf;
72 #else
73 return fossil_strdup(zUnicode); /* TODO: implement for unix */
74 #endif
75 }
76
77 /*
78 ** Translate UTF-8 to unicode for use in system calls. Return a pointer to the
79 ** translated text.. Call fossil_unicode_free() to deallocate any memory
80 ** used to store the returned pointer when done.
81 */
82 void *fossil_utf8_to_unicode(const char *zUtf8){
83 #if defined(_WIN32) || defined(__CYGWIN__)
84 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
85 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
86 if( zUnicode==0 ){
87 return 0;
88 }
@@ -87,17 +96,16 @@
96 /*
97 ** Deallocate any memory that was previously allocated by
98 ** fossil_unicode_to_utf8().
99 */
100 void fossil_unicode_free(void *pOld){
101 #if defined(_WIN32) || defined(__CYGWIN__)
102 sqlite3_free(pOld);
103 #else
104 fossil_free(pOld);
105 #endif
106 }
 
107
108 #if defined(__APPLE__) && !defined(WITHOUT_ICONV)
109 # include <iconv.h>
110 #endif
111
@@ -160,17 +168,17 @@
168 ** Call fossil_filename_free() to deallocate any memory used to store the
169 ** returned pointer when done.
170 */
171 void *fossil_utf8_to_filename(const char *zUtf8){
172 #ifdef _WIN32
173 int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
174 wchar_t *zUnicode = sqlite3_malloc( nChar * 2 );
175 wchar_t *wUnicode = zUnicode;
176 if( zUnicode==0 ){
177 return 0;
178 }
179 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nChar);
180 while( *wUnicode != '\0' ){
181 if( *wUnicode == '/' ){
182 *wUnicode = '\\';
183 }
184 ++wUnicode;
@@ -178,22 +186,31 @@
186 return zUnicode;
187 #elif defined(__CYGWIN__)
188 char *zPath, *p;
189 if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
190 && (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
191 /* win32 absolute path starting with drive specifier. */
192 int nByte;
193 wchar_t zUnicode[2000];
194 wchar_t *wUnicode = zUnicode;
195 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, count(zUnicode));
196 while( *wUnicode != '\0' ){
197 if( *wUnicode == '/' ){
198 *wUnicode = '\\';
199 }
200 ++wUnicode;
201 }
202 nByte = cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, NULL, 0);
203 zPath = fossil_malloc(nByte);
204 cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, zPath, nByte);
205 } else {
206 zPath = fossil_strdup(zUtf8);
207 zUtf8 = p = zPath;
208 while( (*p = *zUtf8++) != 0){
209 if (*p++ == '\\' ) {
210 p[-1] = '/';
211 }
212 }
213 }
214 return zPath;
215 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
216 return fossil_strdup(zUtf8);
217
+35 -18
--- src/utf8.c
+++ src/utf8.c
@@ -23,10 +23,18 @@
2323
#include "utf8.h"
2424
#include <sqlite3.h>
2525
#ifdef _WIN32
2626
# include <windows.h>
2727
#endif
28
+#ifdef __CYGWIN__
29
+# include <sys/cygwin.h>
30
+# define CP_UTF8 65001
31
+ __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int,
32
+ const char *, int, const char *, int, const char *, const char *);
33
+ __declspec(dllimport) extern __stdcall int MultiByteToWideChar(int, int,
34
+ const char *, int, wchar_t*, int);
35
+#endif
2836
2937
#ifdef _WIN32
3038
/*
3139
** Translate MBCS to UTF-8. Return a pointer to the translated text.
3240
** Call fossil_mbcs_free() to deallocate any memory used to store the
@@ -42,38 +50,39 @@
4250
** any memory used to hold the translation
4351
*/
4452
void fossil_mbcs_free(char *zOld){
4553
sqlite3_free(zOld);
4654
}
55
+#endif /* _WIN32 */
4756
4857
/*
4958
** Translate Unicode text into UTF-8.
5059
** Return a pointer to the translated text.
5160
** Call fossil_unicode_free() to deallocate any memory used to store the
5261
** returned pointer when done.
5362
*/
5463
char *fossil_unicode_to_utf8(const void *zUnicode){
55
-#ifdef _WIN32
64
+#if defined(_WIN32) || defined(__CYGWIN__)
5665
int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
5766
char *zUtf = sqlite3_malloc( nByte );
5867
if( zUtf==0 ){
5968
return 0;
6069
}
6170
WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
6271
return zUtf;
6372
#else
64
- return fossil_strdup(zUtf8); /* TODO: implement for unix */
73
+ return fossil_strdup(zUnicode); /* TODO: implement for unix */
6574
#endif
6675
}
6776
6877
/*
6978
** Translate UTF-8 to unicode for use in system calls. Return a pointer to the
7079
** translated text.. Call fossil_unicode_free() to deallocate any memory
7180
** used to store the returned pointer when done.
7281
*/
7382
void *fossil_utf8_to_unicode(const char *zUtf8){
74
-#ifdef _WIN32
83
+#if defined(_WIN32) || defined(__CYGWIN__)
7584
int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
7685
wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
7786
if( zUnicode==0 ){
7887
return 0;
7988
}
@@ -87,17 +96,16 @@
8796
/*
8897
** Deallocate any memory that was previously allocated by
8998
** fossil_unicode_to_utf8().
9099
*/
91100
void fossil_unicode_free(void *pOld){
92
-#ifdef _WIN32
101
+#if defined(_WIN32) || defined(__CYGWIN__)
93102
sqlite3_free(pOld);
94103
#else
95104
fossil_free(pOld);
96105
#endif
97106
}
98
-#endif /* _WIN32 */
99107
100108
#if defined(__APPLE__) && !defined(WITHOUT_ICONV)
101109
# include <iconv.h>
102110
#endif
103111
@@ -160,17 +168,17 @@
160168
** Call fossil_filename_free() to deallocate any memory used to store the
161169
** returned pointer when done.
162170
*/
163171
void *fossil_utf8_to_filename(const char *zUtf8){
164172
#ifdef _WIN32
165
- int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
166
- wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
173
+ int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
174
+ wchar_t *zUnicode = sqlite3_malloc( nChar * 2 );
167175
wchar_t *wUnicode = zUnicode;
168176
if( zUnicode==0 ){
169177
return 0;
170178
}
171
- MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
179
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nChar);
172180
while( *wUnicode != '\0' ){
173181
if( *wUnicode == '/' ){
174182
*wUnicode = '\\';
175183
}
176184
++wUnicode;
@@ -178,22 +186,31 @@
178186
return zUnicode;
179187
#elif defined(__CYGWIN__)
180188
char *zPath, *p;
181189
if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
182190
&& (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
183
- int n = strlen(zUtf8);
184
- zPath = fossil_malloc( n+10 );
185
- memcpy(zPath, "/cygdrive/", 10);
186
- zPath[10] = zUtf8[0];
187
- memcpy(zPath+11, zUtf8+2, n-1);
191
+ /* win32 absolute path starting with drive specifier. */
192
+ int nByte;
193
+ wchar_t zUnicode[2000];
194
+ wchar_t *wUnicode = zUnicode;
195
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, count(zUnicode));
196
+ while( *wUnicode != '\0' ){
197
+ if( *wUnicode == '/' ){
198
+ *wUnicode = '\\';
199
+ }
200
+ ++wUnicode;
201
+ }
202
+ nByte = cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, NULL, 0);
203
+ zPath = fossil_malloc(nByte);
204
+ cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, zPath, nByte);
188205
} else {
189206
zPath = fossil_strdup(zUtf8);
190
- }
191
- zUtf8 = p = zPath;
192
- while( (*p = *zUtf8++) != 0){
193
- if (*p++ == '\\' ) {
194
- p[-1] = '/';
207
+ zUtf8 = p = zPath;
208
+ while( (*p = *zUtf8++) != 0){
209
+ if (*p++ == '\\' ) {
210
+ p[-1] = '/';
211
+ }
195212
}
196213
}
197214
return zPath;
198215
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
199216
return fossil_strdup(zUtf8);
200217
--- src/utf8.c
+++ src/utf8.c
@@ -23,10 +23,18 @@
23 #include "utf8.h"
24 #include <sqlite3.h>
25 #ifdef _WIN32
26 # include <windows.h>
27 #endif
 
 
 
 
 
 
 
 
28
29 #ifdef _WIN32
30 /*
31 ** Translate MBCS to UTF-8. Return a pointer to the translated text.
32 ** Call fossil_mbcs_free() to deallocate any memory used to store the
@@ -42,38 +50,39 @@
42 ** any memory used to hold the translation
43 */
44 void fossil_mbcs_free(char *zOld){
45 sqlite3_free(zOld);
46 }
 
47
48 /*
49 ** Translate Unicode text into UTF-8.
50 ** Return a pointer to the translated text.
51 ** Call fossil_unicode_free() to deallocate any memory used to store the
52 ** returned pointer when done.
53 */
54 char *fossil_unicode_to_utf8(const void *zUnicode){
55 #ifdef _WIN32
56 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
57 char *zUtf = sqlite3_malloc( nByte );
58 if( zUtf==0 ){
59 return 0;
60 }
61 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
62 return zUtf;
63 #else
64 return fossil_strdup(zUtf8); /* TODO: implement for unix */
65 #endif
66 }
67
68 /*
69 ** Translate UTF-8 to unicode for use in system calls. Return a pointer to the
70 ** translated text.. Call fossil_unicode_free() to deallocate any memory
71 ** used to store the returned pointer when done.
72 */
73 void *fossil_utf8_to_unicode(const char *zUtf8){
74 #ifdef _WIN32
75 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
76 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
77 if( zUnicode==0 ){
78 return 0;
79 }
@@ -87,17 +96,16 @@
87 /*
88 ** Deallocate any memory that was previously allocated by
89 ** fossil_unicode_to_utf8().
90 */
91 void fossil_unicode_free(void *pOld){
92 #ifdef _WIN32
93 sqlite3_free(pOld);
94 #else
95 fossil_free(pOld);
96 #endif
97 }
98 #endif /* _WIN32 */
99
100 #if defined(__APPLE__) && !defined(WITHOUT_ICONV)
101 # include <iconv.h>
102 #endif
103
@@ -160,17 +168,17 @@
160 ** Call fossil_filename_free() to deallocate any memory used to store the
161 ** returned pointer when done.
162 */
163 void *fossil_utf8_to_filename(const char *zUtf8){
164 #ifdef _WIN32
165 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
166 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
167 wchar_t *wUnicode = zUnicode;
168 if( zUnicode==0 ){
169 return 0;
170 }
171 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
172 while( *wUnicode != '\0' ){
173 if( *wUnicode == '/' ){
174 *wUnicode = '\\';
175 }
176 ++wUnicode;
@@ -178,22 +186,31 @@
178 return zUnicode;
179 #elif defined(__CYGWIN__)
180 char *zPath, *p;
181 if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
182 && (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
183 int n = strlen(zUtf8);
184 zPath = fossil_malloc( n+10 );
185 memcpy(zPath, "/cygdrive/", 10);
186 zPath[10] = zUtf8[0];
187 memcpy(zPath+11, zUtf8+2, n-1);
 
 
 
 
 
 
 
 
 
188 } else {
189 zPath = fossil_strdup(zUtf8);
190 }
191 zUtf8 = p = zPath;
192 while( (*p = *zUtf8++) != 0){
193 if (*p++ == '\\' ) {
194 p[-1] = '/';
195 }
196 }
197 return zPath;
198 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
199 return fossil_strdup(zUtf8);
200
--- src/utf8.c
+++ src/utf8.c
@@ -23,10 +23,18 @@
23 #include "utf8.h"
24 #include <sqlite3.h>
25 #ifdef _WIN32
26 # include <windows.h>
27 #endif
28 #ifdef __CYGWIN__
29 # include <sys/cygwin.h>
30 # define CP_UTF8 65001
31 __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int,
32 const char *, int, const char *, int, const char *, const char *);
33 __declspec(dllimport) extern __stdcall int MultiByteToWideChar(int, int,
34 const char *, int, wchar_t*, int);
35 #endif
36
37 #ifdef _WIN32
38 /*
39 ** Translate MBCS to UTF-8. Return a pointer to the translated text.
40 ** Call fossil_mbcs_free() to deallocate any memory used to store the
@@ -42,38 +50,39 @@
50 ** any memory used to hold the translation
51 */
52 void fossil_mbcs_free(char *zOld){
53 sqlite3_free(zOld);
54 }
55 #endif /* _WIN32 */
56
57 /*
58 ** Translate Unicode text into UTF-8.
59 ** Return a pointer to the translated text.
60 ** Call fossil_unicode_free() to deallocate any memory used to store the
61 ** returned pointer when done.
62 */
63 char *fossil_unicode_to_utf8(const void *zUnicode){
64 #if defined(_WIN32) || defined(__CYGWIN__)
65 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
66 char *zUtf = sqlite3_malloc( nByte );
67 if( zUtf==0 ){
68 return 0;
69 }
70 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
71 return zUtf;
72 #else
73 return fossil_strdup(zUnicode); /* TODO: implement for unix */
74 #endif
75 }
76
77 /*
78 ** Translate UTF-8 to unicode for use in system calls. Return a pointer to the
79 ** translated text.. Call fossil_unicode_free() to deallocate any memory
80 ** used to store the returned pointer when done.
81 */
82 void *fossil_utf8_to_unicode(const char *zUtf8){
83 #if defined(_WIN32) || defined(__CYGWIN__)
84 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
85 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
86 if( zUnicode==0 ){
87 return 0;
88 }
@@ -87,17 +96,16 @@
96 /*
97 ** Deallocate any memory that was previously allocated by
98 ** fossil_unicode_to_utf8().
99 */
100 void fossil_unicode_free(void *pOld){
101 #if defined(_WIN32) || defined(__CYGWIN__)
102 sqlite3_free(pOld);
103 #else
104 fossil_free(pOld);
105 #endif
106 }
 
107
108 #if defined(__APPLE__) && !defined(WITHOUT_ICONV)
109 # include <iconv.h>
110 #endif
111
@@ -160,17 +168,17 @@
168 ** Call fossil_filename_free() to deallocate any memory used to store the
169 ** returned pointer when done.
170 */
171 void *fossil_utf8_to_filename(const char *zUtf8){
172 #ifdef _WIN32
173 int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
174 wchar_t *zUnicode = sqlite3_malloc( nChar * 2 );
175 wchar_t *wUnicode = zUnicode;
176 if( zUnicode==0 ){
177 return 0;
178 }
179 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nChar);
180 while( *wUnicode != '\0' ){
181 if( *wUnicode == '/' ){
182 *wUnicode = '\\';
183 }
184 ++wUnicode;
@@ -178,22 +186,31 @@
186 return zUnicode;
187 #elif defined(__CYGWIN__)
188 char *zPath, *p;
189 if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
190 && (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
191 /* win32 absolute path starting with drive specifier. */
192 int nByte;
193 wchar_t zUnicode[2000];
194 wchar_t *wUnicode = zUnicode;
195 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, count(zUnicode));
196 while( *wUnicode != '\0' ){
197 if( *wUnicode == '/' ){
198 *wUnicode = '\\';
199 }
200 ++wUnicode;
201 }
202 nByte = cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, NULL, 0);
203 zPath = fossil_malloc(nByte);
204 cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, zPath, nByte);
205 } else {
206 zPath = fossil_strdup(zUtf8);
207 zUtf8 = p = zPath;
208 while( (*p = *zUtf8++) != 0){
209 if (*p++ == '\\' ) {
210 p[-1] = '/';
211 }
212 }
213 }
214 return zPath;
215 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
216 return fossil_strdup(zUtf8);
217

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button