| | @@ -34,10 +34,11 @@ |
| 34 | 34 | ** On Windows, include the Platform SDK header file. |
| 35 | 35 | */ |
| 36 | 36 | #ifdef _WIN32 |
| 37 | 37 | # include <direct.h> |
| 38 | 38 | # include <windows.h> |
| 39 | +# include <tchar.h> |
| 39 | 40 | #endif |
| 40 | 41 | |
| 41 | 42 | /* |
| 42 | 43 | ** The file status information from the most recent stat() call. |
| 43 | 44 | ** |
| | @@ -69,12 +70,12 @@ |
| 69 | 70 | }else{ |
| 70 | 71 | return stat(zFilename, buf); |
| 71 | 72 | } |
| 72 | 73 | #else |
| 73 | 74 | int rc = 0; |
| 74 | | - wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename); |
| 75 | | - rc = _wstati64(zMbcs, buf); |
| 75 | + TCHAR *zMbcs = fossil_utf8_to_mbcs(zFilename); |
| 76 | + rc = _tstati64(zMbcs, buf); |
| 76 | 77 | fossil_mbcs_free(zMbcs); |
| 77 | 78 | return rc; |
| 78 | 79 | #endif |
| 79 | 80 | } |
| 80 | 81 | |
| | @@ -300,12 +301,12 @@ |
| 300 | 301 | /* |
| 301 | 302 | ** Wrapper around the access() system call. |
| 302 | 303 | */ |
| 303 | 304 | int file_access(const char *zFilename, int flags){ |
| 304 | 305 | #ifdef _WIN32 |
| 305 | | - wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename); |
| 306 | | - int rc = _waccess(zMbcs, flags); |
| 306 | + TCHAR *zMbcs = fossil_utf8_to_mbcs(zFilename); |
| 307 | + int rc = _taccess(zMbcs, flags); |
| 307 | 308 | fossil_mbcs_free(zMbcs); |
| 308 | 309 | #else |
| 309 | 310 | int rc = access(zFilename, flags); |
| 310 | 311 | #endif |
| 311 | 312 | return rc; |
| | @@ -395,12 +396,12 @@ |
| 395 | 396 | /* |
| 396 | 397 | ** Delete a file. |
| 397 | 398 | */ |
| 398 | 399 | void file_delete(const char *zFilename){ |
| 399 | 400 | #ifdef _WIN32 |
| 400 | | - wchar_t *z = fossil_utf8_to_unicode(zFilename); |
| 401 | | - _wunlink(z); |
| 401 | + TCHAR *z = fossil_utf8_to_mbcs(zFilename); |
| 402 | + _tunlink(z); |
| 402 | 403 | fossil_mbcs_free(z); |
| 403 | 404 | #else |
| 404 | 405 | unlink(zFilename); |
| 405 | 406 | #endif |
| 406 | 407 | } |
| | @@ -419,12 +420,12 @@ |
| 419 | 420 | file_delete(zName); |
| 420 | 421 | } |
| 421 | 422 | if( rc!=1 ){ |
| 422 | 423 | #if defined(_WIN32) |
| 423 | 424 | int rc; |
| 424 | | - wchar_t *zMbcs = fossil_utf8_to_unicode(zName); |
| 425 | | - rc = _wmkdir(zMbcs); |
| 425 | + TCHAR *zMbcs = fossil_utf8_to_mbcs(zName); |
| 426 | + rc = _tmkdir(zMbcs); |
| 426 | 427 | fossil_mbcs_free(zMbcs); |
| 427 | 428 | return rc; |
| 428 | 429 | #else |
| 429 | 430 | return mkdir(zName, 0755); |
| 430 | 431 | #endif |
| | @@ -579,15 +580,15 @@ |
| 579 | 580 | void file_getcwd(char *zBuf, int nBuf){ |
| 580 | 581 | #ifdef _WIN32 |
| 581 | 582 | char *zPwdUtf8; |
| 582 | 583 | int nPwd; |
| 583 | 584 | int i; |
| 584 | | - wchar_t zPwd[2000]; |
| 585 | | - if( _wgetcwd(zPwd, sizeof(zPwd)/sizeof(zPwd[0])-1)==0 ){ |
| 585 | + TCHAR zPwd[2000]; |
| 586 | + if( _tgetcwd(zPwd, sizeof(zPwd)/sizeof(zPwd[0])-1)==0 ){ |
| 586 | 587 | fossil_fatal("cannot find the current working directory."); |
| 587 | 588 | } |
| 588 | | - zPwdUtf8 = fossil_unicode_to_utf8(zPwd); |
| 589 | + zPwdUtf8 = fossil_mbcs_to_utf8(zPwd); |
| 589 | 590 | nPwd = strlen(zPwdUtf8); |
| 590 | 591 | if( nPwd > nBuf-1 ){ |
| 591 | 592 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| 592 | 593 | } |
| 593 | 594 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| | @@ -937,14 +938,14 @@ |
| 937 | 938 | unsigned int i, j; |
| 938 | 939 | const char *zDir = "."; |
| 939 | 940 | int cnt = 0; |
| 940 | 941 | |
| 941 | 942 | #if defined(_WIN32) |
| 942 | | - wchar_t zTmpPath[MAX_PATH]; |
| 943 | + TCHAR zTmpPath[MAX_PATH]; |
| 943 | 944 | |
| 944 | | - if( GetTempPathW(MAX_PATH, zTmpPath) ){ |
| 945 | | - azDirs[0] = fossil_unicode_to_utf8(zTmpPath); |
| 945 | + if( GetTempPath(MAX_PATH, zTmpPath) ){ |
| 946 | + azDirs[0] = fossil_mbcs_to_utf8(zTmpPath); |
| 946 | 947 | } |
| 947 | 948 | |
| 948 | 949 | azDirs[1] = fossil_getenv("TEMP"); |
| 949 | 950 | azDirs[2] = fossil_getenv("TMP"); |
| 950 | 951 | #endif |
| | @@ -1008,11 +1009,11 @@ |
| 1008 | 1009 | /* |
| 1009 | 1010 | ** Portable unicode implementation of opendir() |
| 1010 | 1011 | */ |
| 1011 | 1012 | #if INTERFACE |
| 1012 | 1013 | |
| 1013 | | -#if defined(_WIN32) |
| 1014 | +#if defined(_WIN32) && defined(UNICODE) |
| 1014 | 1015 | # include <dirent.h> |
| 1015 | 1016 | # define FOSSIL_DIR _WDIR |
| 1016 | 1017 | # define fossil_dirent _wdirent |
| 1017 | 1018 | # define fossil_opendir _wopendir |
| 1018 | 1019 | # define fossil_readdir _wreaddir |
| | @@ -1035,84 +1036,80 @@ |
| 1035 | 1036 | ** Since everything is always UTF8 on unix, these routines are no-ops |
| 1036 | 1037 | ** there. |
| 1037 | 1038 | */ |
| 1038 | 1039 | |
| 1039 | 1040 | /* |
| 1040 | | -** Translate MBCS to UTF8. Return a pointer to the translated text. |
| 1041 | | -** Call fossil_mbcs_free() to deallocate any memory used to store the |
| 1042 | | -** returned pointer when done. |
| 1041 | +** Translate unicode/mbcs to UTF8. Return a pointer to the translated |
| 1042 | +** text. Call fossil_mbcs_free() to deallocate any memory used to store |
| 1043 | +** the returned pointer when done. |
| 1044 | +*/ |
| 1045 | +char *fossil_mbcs_to_utf8(const void *zMbcs){ |
| 1046 | +#ifdef _WIN32 |
| 1047 | +#ifdef UNICODE |
| 1048 | + int nByte = WideCharToMultiByte(CP_UTF8, 0, zMbcs, -1, 0, 0, 0, 0); |
| 1049 | + char *zUtf = sqlite3_malloc( nByte ); |
| 1050 | + if( zUtf==0 ){ |
| 1051 | + return 0; |
| 1052 | + } |
| 1053 | + WideCharToMultiByte(CP_UTF8, 0, zMbcs, -1, zUtf, nByte, 0, 0); |
| 1054 | + return zUtf; |
| 1055 | +#else |
| 1056 | + extern char *sqlite3_win32_mbcs_to_utf8(const char*); |
| 1057 | + return sqlite3_win32_mbcs_to_utf8(zMbcs); |
| 1058 | +#endif |
| 1059 | +#else |
| 1060 | + return (char*)zMbcs; /* No-op on unix */ |
| 1061 | +#endif |
| 1062 | +} |
| 1063 | + |
| 1064 | +/* |
| 1065 | +** Translate mbcs to UTF8. Return a pointer to the translated text. |
| 1066 | +** Call fossil_mbcs_free() to deallocate any memory used to store |
| 1067 | +** the returned pointer when done. |
| 1043 | 1068 | */ |
| 1044 | | -char *fossil_mbcs_to_utf8(const char *zMbcs){ |
| 1069 | +char *fossil_console_to_utf8(const void *zMbcs){ |
| 1045 | 1070 | #ifdef _WIN32 |
| 1046 | 1071 | extern char *sqlite3_win32_mbcs_to_utf8(const char*); |
| 1047 | 1072 | return sqlite3_win32_mbcs_to_utf8(zMbcs); |
| 1048 | 1073 | #else |
| 1049 | 1074 | return (char*)zMbcs; /* No-op on unix */ |
| 1050 | 1075 | #endif |
| 1051 | 1076 | } |
| 1052 | 1077 | |
| 1053 | 1078 | /* |
| 1054 | | -** Translate Unicode to UTF8. Return a pointer to the translated text. |
| 1055 | | -** Call fossil_mbcs_free() to deallocate any memory used to store the |
| 1056 | | -** returned pointer when done. |
| 1057 | | -*/ |
| 1058 | | -char *fossil_unicode_to_utf8(const void *zUnicode){ |
| 1059 | | -#ifdef _WIN32 |
| 1060 | | - int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0); |
| 1061 | | - char *zUtf = sqlite3_malloc( nByte ); |
| 1062 | | - if( zUtf==0 ){ |
| 1063 | | - return 0; |
| 1064 | | - } |
| 1065 | | - WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0); |
| 1066 | | - return zUtf; |
| 1067 | | -#else |
| 1068 | | - return (char *)zUnicode; /* No-op on unix */ |
| 1069 | | -#endif |
| 1070 | | -} |
| 1071 | | - |
| 1072 | | -/* |
| 1073 | | -** Translate UTF8 to MBCS for use in system calls. Return a pointer to the |
| 1074 | | -** translated text.. Call fossil_mbcs_free() to deallocate any memory |
| 1075 | | -** used to store the returned pointer when done. |
| 1076 | | -*/ |
| 1077 | | -char *fossil_utf8_to_mbcs(const char *zUtf8){ |
| 1078 | | -#ifdef _WIN32 |
| 1079 | | - extern char *sqlite3_win32_utf8_to_mbcs(const char*); |
| 1080 | | - return sqlite3_win32_utf8_to_mbcs(zUtf8); |
| 1081 | | -#else |
| 1082 | | - return (char*)zUtf8; /* No-op on unix */ |
| 1083 | | -#endif |
| 1084 | | -} |
| 1085 | | - |
| 1086 | | -/* |
| 1087 | | -** Translate UTF8 to unicode for use in system calls. Return a pointer to the |
| 1088 | | -** translated text.. Call fossil_mbcs_free() to deallocate any memory |
| 1089 | | -** used to store the returned pointer when done. |
| 1090 | | -*/ |
| 1091 | | -void *fossil_utf8_to_unicode(const char *zUtf8){ |
| 1092 | | -#ifdef _WIN32 |
| 1079 | +** Translate UTF8 to unicode/mbcs for use in system calls. Return a |
| 1080 | +** pointer to the translated text.. Call fossil_mbcs_free() to |
| 1081 | +** deallocate any memory used to store the returned pointer when done. |
| 1082 | +*/ |
| 1083 | +void *fossil_utf8_to_mbcs(const char *zUtf8){ |
| 1084 | +#ifdef _WIN32 |
| 1085 | +#ifdef UNICODE |
| 1093 | 1086 | int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0); |
| 1094 | 1087 | wchar_t *zUnicode = sqlite3_malloc( nByte * 2 ); |
| 1095 | 1088 | if( zUnicode==0 ){ |
| 1096 | 1089 | return 0; |
| 1097 | 1090 | } |
| 1098 | 1091 | MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte); |
| 1099 | 1092 | return zUnicode; |
| 1100 | 1093 | #else |
| 1101 | | - return (void *)zUtf8; /* No-op on unix */ |
| 1094 | + extern char *sqlite3_win32_utf8_to_mbcs(const char*); |
| 1095 | + return sqlite3_win32_utf8_to_mbcs(zUtf8); |
| 1096 | +#endif |
| 1097 | +#else |
| 1098 | + return (char*)zUtf8; /* No-op on unix */ |
| 1102 | 1099 | #endif |
| 1103 | 1100 | } |
| 1104 | 1101 | |
| 1105 | 1102 | /* |
| 1106 | 1103 | ** Return the value of an environment variable as UTF8. |
| 1107 | 1104 | */ |
| 1108 | 1105 | char *fossil_getenv(const char *zName){ |
| 1109 | 1106 | #ifdef _WIN32 |
| 1110 | | - wchar_t *uName = fossil_utf8_to_unicode(zName); |
| 1111 | | - void *zValue = _wgetenv(uName); |
| 1107 | + TCHAR *uName = fossil_utf8_to_mbcs(zName); |
| 1108 | + void *zValue = _tgetenv(uName); |
| 1112 | 1109 | fossil_mbcs_free(uName); |
| 1113 | | - if( zValue ) zValue = fossil_unicode_to_utf8(zValue); |
| 1110 | + if( zValue ) zValue = fossil_mbcs_to_utf8(zValue); |
| 1114 | 1111 | #else |
| 1115 | 1112 | char *zValue = getenv(zName); |
| 1116 | 1113 | #endif |
| 1117 | 1114 | return zValue; |
| 1118 | 1115 | } |
| | @@ -1197,15 +1194,15 @@ |
| 1197 | 1194 | /* |
| 1198 | 1195 | ** Like fopen() but always takes a UTF8 argument. |
| 1199 | 1196 | */ |
| 1200 | 1197 | FILE *fossil_fopen(const char *zName, const char *zMode){ |
| 1201 | 1198 | #ifdef _WIN32 |
| 1202 | | - wchar_t *uMode = fossil_utf8_to_unicode(zMode); |
| 1203 | | - wchar_t *uName = fossil_utf8_to_unicode(zName); |
| 1204 | | - FILE *f = _wfopen(uName, uMode); |
| 1199 | + TCHAR *uMode = fossil_utf8_to_mbcs(zMode); |
| 1200 | + TCHAR *uName = fossil_utf8_to_mbcs(zName); |
| 1201 | + FILE *f = _tfopen(uName, uMode); |
| 1205 | 1202 | fossil_mbcs_free(uName); |
| 1206 | 1203 | fossil_mbcs_free(uMode); |
| 1207 | 1204 | #else |
| 1208 | 1205 | FILE *f = fopen(zName, zMode); |
| 1209 | 1206 | #endif |
| 1210 | 1207 | return f; |
| 1211 | 1208 | } |
| 1212 | 1209 | |