Fossil SCM

Translate decomposed-UTF8 filenames on MacOS into precomposed-UTF8. Fix for ticket [e399bc1edfe45b]

drh 2012-11-29 13:12 UTC ticket-e399bc
Commit 1002e7238c5b94e60babfa87f2bc0605f8b35f45
3 files changed +1 -1 +20 -3 +11 -7
+1 -1
--- auto.def
+++ auto.def
@@ -79,11 +79,10 @@
7979
if {[opt-bool static]} {
8080
# XXX: This will not work on all systems.
8181
define-append EXTRA_LDFLAGS -static
8282
}
8383
84
-
8584
# Check for zlib, using the given location if specified
8685
set zlibpath [opt-val with-zlib]
8786
if {$zlibpath ne ""} {
8887
cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
8988
define-append EXTRA_CFLAGS -I$zlibpath
@@ -221,14 +220,15 @@
221220
# Last resort, may be Windows
222221
if {[string match *mingw* [get-define host]]} {
223222
define-append LIBS -lwsock32
224223
}
225224
}
225
+cc-check-function-in-lib iconv iconv
226226
227227
# Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
228228
if {![cc-check-functions getpassphrase]} {
229229
# Haiku needs this
230230
cc-check-function-in-lib getpass bsd
231231
}
232232
233233
make-template Makefile.in
234234
make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
235235
--- auto.def
+++ auto.def
@@ -79,11 +79,10 @@
79 if {[opt-bool static]} {
80 # XXX: This will not work on all systems.
81 define-append EXTRA_LDFLAGS -static
82 }
83
84
85 # Check for zlib, using the given location if specified
86 set zlibpath [opt-val with-zlib]
87 if {$zlibpath ne ""} {
88 cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
89 define-append EXTRA_CFLAGS -I$zlibpath
@@ -221,14 +220,15 @@
221 # Last resort, may be Windows
222 if {[string match *mingw* [get-define host]]} {
223 define-append LIBS -lwsock32
224 }
225 }
 
226
227 # Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
228 if {![cc-check-functions getpassphrase]} {
229 # Haiku needs this
230 cc-check-function-in-lib getpass bsd
231 }
232
233 make-template Makefile.in
234 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
235
--- auto.def
+++ auto.def
@@ -79,11 +79,10 @@
79 if {[opt-bool static]} {
80 # XXX: This will not work on all systems.
81 define-append EXTRA_LDFLAGS -static
82 }
83
 
84 # Check for zlib, using the given location if specified
85 set zlibpath [opt-val with-zlib]
86 if {$zlibpath ne ""} {
87 cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
88 define-append EXTRA_CFLAGS -I$zlibpath
@@ -221,14 +220,15 @@
220 # Last resort, may be Windows
221 if {[string match *mingw* [get-define host]]} {
222 define-append LIBS -lwsock32
223 }
224 }
225 cc-check-function-in-lib iconv iconv
226
227 # Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
228 if {![cc-check-functions getpassphrase]} {
229 # Haiku needs this
230 cc-check-function-in-lib getpass bsd
231 }
232
233 make-template Makefile.in
234 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
235
+20 -3
--- src/main.c
+++ src/main.c
@@ -2022,15 +2022,32 @@
20222022
#endif
20232023
}
20242024
20252025
/*
20262026
** COMMAND: test-echo
2027
+**
2028
+** Usage: %fossil test-echo [--hex] ARGS...
20272029
**
20282030
** Echo all command-line arguments (enclosed in [...]) to the screen so that
20292031
** wildcard expansion behavior of the host shell can be investigated.
2032
+**
2033
+** With the --hex option, show the output as hexadecimal. This can be used
2034
+** to verify the fossil_filename_to_utf8() routine on Windows and Mac.
20302035
*/
20312036
void test_echo_cmd(void){
2032
- int i;
2033
- for(i=0; i<g.argc; i++){
2034
- fossil_print("argv[%d] = [%s]\n", i, g.argv[i]);
2037
+ int i, j;
2038
+ if( find_option("hex",0,0)==0 ){
2039
+ for(i=0; i<g.argc; i++){
2040
+ fossil_print("argv[%d] = [%s]\n", i, g.argv[i]);
2041
+ }
2042
+ }else{
2043
+ unsigned char *z, c;
2044
+ for(i=0; i<g.argc; i++){
2045
+ fossil_print("argv[%d] = [", i);
2046
+ z = (unsigned char*)g.argv[i];
2047
+ for(j=0; (c = z[j])!=0; j++){
2048
+ fossil_print("%02x", c);
2049
+ }
2050
+ fossil_print("]\n");
2051
+ }
20352052
}
20362053
}
20372054
--- src/main.c
+++ src/main.c
@@ -2022,15 +2022,32 @@
2022 #endif
2023 }
2024
2025 /*
2026 ** COMMAND: test-echo
 
 
2027 **
2028 ** Echo all command-line arguments (enclosed in [...]) to the screen so that
2029 ** wildcard expansion behavior of the host shell can be investigated.
 
 
 
2030 */
2031 void test_echo_cmd(void){
2032 int i;
2033 for(i=0; i<g.argc; i++){
2034 fossil_print("argv[%d] = [%s]\n", i, g.argv[i]);
 
 
 
 
 
 
 
 
 
 
 
 
2035 }
2036 }
2037
--- src/main.c
+++ src/main.c
@@ -2022,15 +2022,32 @@
2022 #endif
2023 }
2024
2025 /*
2026 ** COMMAND: test-echo
2027 **
2028 ** Usage: %fossil test-echo [--hex] ARGS...
2029 **
2030 ** Echo all command-line arguments (enclosed in [...]) to the screen so that
2031 ** wildcard expansion behavior of the host shell can be investigated.
2032 **
2033 ** With the --hex option, show the output as hexadecimal. This can be used
2034 ** to verify the fossil_filename_to_utf8() routine on Windows and Mac.
2035 */
2036 void test_echo_cmd(void){
2037 int i, j;
2038 if( find_option("hex",0,0)==0 ){
2039 for(i=0; i<g.argc; i++){
2040 fossil_print("argv[%d] = [%s]\n", i, g.argv[i]);
2041 }
2042 }else{
2043 unsigned char *z, c;
2044 for(i=0; i<g.argc; i++){
2045 fossil_print("argv[%d] = [", i);
2046 z = (unsigned char*)g.argv[i];
2047 for(j=0; (c = z[j])!=0; j++){
2048 fossil_print("%02x", c);
2049 }
2050 fossil_print("]\n");
2051 }
2052 }
2053 }
2054
+11 -7
--- src/utf8.c
+++ src/utf8.c
@@ -42,11 +42,11 @@
4242
4343
/*
4444
** After translating from UTF8 to MBCS, invoke this routine to deallocate
4545
** any memory used to hold the translation
4646
*/
47
-void fossil_mbcs_free(void *zOld){
47
+void fossil_mbcs_free(char *zOld){
4848
#ifdef _WIN32
4949
sqlite3_free(zOld);
5050
#else
5151
/* No-op on unix */
5252
#endif
@@ -56,11 +56,11 @@
5656
** Translate Unicode text into UTF8.
5757
** Return a pointer to the translated text.
5858
** Call fossil_unicode_free() to deallocate any memory used to store the
5959
** returned pointer when done.
6060
*/
61
-char *fossil_unicode_to_utf8(const void *zUnicode){
61
+char *fossil_unicode_to_utf8(const char *zUnicode){
6262
#ifdef _WIN32
6363
int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
6464
char *zUtf = sqlite3_malloc( nByte );
6565
if( zUtf==0 ){
6666
return 0;
@@ -111,11 +111,11 @@
111111
** Translate text from the filename character set into
112112
** to precomposed UTF8. Return a pointer to the translated text.
113113
** Call fossil_filename_free() to deallocate any memory used to store the
114114
** returned pointer when done.
115115
*/
116
-char *fossil_filename_to_utf8(const void *zFilename){
116
+char *fossil_filename_to_utf8(const char *zFilename){
117117
#if defined(_WIN32)
118118
int nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
119119
char *zUtf = sqlite3_malloc( nByte );
120120
if( zUtf==0 ){
121121
return 0;
@@ -126,18 +126,22 @@
126126
char *zOut;
127127
iconv_t cd;
128128
size_t n, x;
129129
for(n=0; zFilename[n]>0 && zFilename[n]<=0x7f; n++){}
130130
if( zFilename[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
131
- n = strlen(zFilename);
132
- zOut = fossil_malloc( n+100 );
133
- x = iconv(cd, zFilename, n, zOut, n+100);
131
+ char *zIn = (char*)zFilename;
132
+ char *zOutx;
133
+ size_t nIn, nOutx;
134
+ nIn = n = strlen(zFilename);
135
+ nOutx = nIn+100;
136
+ zOutx = zOut = fossil_malloc( nOutx+1 );
137
+ x = iconv(cd, &zIn, &nIn, &zOutx, &nOutx);
134138
if( x==(size_t)-1 ){
135139
fossil_free(zOut);
136140
zOut = fossil_strdup(zFilename);
137141
}else{
138
- zOut[x] = 0;
142
+ zOut[n+100-nOutx] = 0;
139143
}
140144
iconv_close(cd);
141145
}else{
142146
zOut = fossil_strdup(zFilename);
143147
}
144148
--- src/utf8.c
+++ src/utf8.c
@@ -42,11 +42,11 @@
42
43 /*
44 ** After translating from UTF8 to MBCS, invoke this routine to deallocate
45 ** any memory used to hold the translation
46 */
47 void fossil_mbcs_free(void *zOld){
48 #ifdef _WIN32
49 sqlite3_free(zOld);
50 #else
51 /* No-op on unix */
52 #endif
@@ -56,11 +56,11 @@
56 ** Translate Unicode text into UTF8.
57 ** Return a pointer to the translated text.
58 ** Call fossil_unicode_free() to deallocate any memory used to store the
59 ** returned pointer when done.
60 */
61 char *fossil_unicode_to_utf8(const void *zUnicode){
62 #ifdef _WIN32
63 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
64 char *zUtf = sqlite3_malloc( nByte );
65 if( zUtf==0 ){
66 return 0;
@@ -111,11 +111,11 @@
111 ** Translate text from the filename character set into
112 ** to precomposed UTF8. Return a pointer to the translated text.
113 ** Call fossil_filename_free() to deallocate any memory used to store the
114 ** returned pointer when done.
115 */
116 char *fossil_filename_to_utf8(const void *zFilename){
117 #if defined(_WIN32)
118 int nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
119 char *zUtf = sqlite3_malloc( nByte );
120 if( zUtf==0 ){
121 return 0;
@@ -126,18 +126,22 @@
126 char *zOut;
127 iconv_t cd;
128 size_t n, x;
129 for(n=0; zFilename[n]>0 && zFilename[n]<=0x7f; n++){}
130 if( zFilename[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
131 n = strlen(zFilename);
132 zOut = fossil_malloc( n+100 );
133 x = iconv(cd, zFilename, n, zOut, n+100);
 
 
 
 
134 if( x==(size_t)-1 ){
135 fossil_free(zOut);
136 zOut = fossil_strdup(zFilename);
137 }else{
138 zOut[x] = 0;
139 }
140 iconv_close(cd);
141 }else{
142 zOut = fossil_strdup(zFilename);
143 }
144
--- src/utf8.c
+++ src/utf8.c
@@ -42,11 +42,11 @@
42
43 /*
44 ** After translating from UTF8 to MBCS, invoke this routine to deallocate
45 ** any memory used to hold the translation
46 */
47 void fossil_mbcs_free(char *zOld){
48 #ifdef _WIN32
49 sqlite3_free(zOld);
50 #else
51 /* No-op on unix */
52 #endif
@@ -56,11 +56,11 @@
56 ** Translate Unicode text into UTF8.
57 ** Return a pointer to the translated text.
58 ** Call fossil_unicode_free() to deallocate any memory used to store the
59 ** returned pointer when done.
60 */
61 char *fossil_unicode_to_utf8(const char *zUnicode){
62 #ifdef _WIN32
63 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
64 char *zUtf = sqlite3_malloc( nByte );
65 if( zUtf==0 ){
66 return 0;
@@ -111,11 +111,11 @@
111 ** Translate text from the filename character set into
112 ** to precomposed UTF8. Return a pointer to the translated text.
113 ** Call fossil_filename_free() to deallocate any memory used to store the
114 ** returned pointer when done.
115 */
116 char *fossil_filename_to_utf8(const char *zFilename){
117 #if defined(_WIN32)
118 int nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
119 char *zUtf = sqlite3_malloc( nByte );
120 if( zUtf==0 ){
121 return 0;
@@ -126,18 +126,22 @@
126 char *zOut;
127 iconv_t cd;
128 size_t n, x;
129 for(n=0; zFilename[n]>0 && zFilename[n]<=0x7f; n++){}
130 if( zFilename[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
131 char *zIn = (char*)zFilename;
132 char *zOutx;
133 size_t nIn, nOutx;
134 nIn = n = strlen(zFilename);
135 nOutx = nIn+100;
136 zOutx = zOut = fossil_malloc( nOutx+1 );
137 x = iconv(cd, &zIn, &nIn, &zOutx, &nOutx);
138 if( x==(size_t)-1 ){
139 fossil_free(zOut);
140 zOut = fossil_strdup(zFilename);
141 }else{
142 zOut[n+100-nOutx] = 0;
143 }
144 iconv_close(cd);
145 }else{
146 zOut = fossil_strdup(zFilename);
147 }
148

Keyboard Shortcuts

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