Changes On Branch fossil_utf8_to_filename
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch fossil_utf8_to_filename Excluding Merge-Ins

This is equivalent to a diff from a98467b661 to cc3976fd30

2013-02-18
13:46
Fixed ticket [5df2715635b99bd46a] (check-in count mismatch). check-in: b27c0d6d3f user: stephan tags: trunk
10:03
New function fossil_utf8_to_filename, such that fossil_unicode_to_utf8/fossil_utf8_to_unicode/fossil_unicode_free are not used on UNIX/MAC any more: On UNIX those 3 functions were only no-ops, but this allows to re-implement then for real unicode <-> utf-8 conversions. There is an "#ifdef _WIN32" around those 3 functions and 2 more (fossil_mbcs_to... Leaf check-in: cc3976fd30 user: jan.nijtmans tags: fossil_utf8_to_filename
08:30
merge trunk Leaf check-in: fdd51b617c user: jan.nijtmans tags: ticket-d17d6e5b17
2013-02-17
21:37
merge trunk Leaf check-in: fdf9050c4b user: jan.nijtmans tags: improve_commit_warning
14:47
More simplification in UTF-16 bom detection Leaf check-in: 1e70f211f9 user: jan.nijtmans tags: utf16Bom
14:43
Remove two unused variables check-in: a98467b661 user: jan.nijtmans tags: trunk
2013-02-16
14:12
Limit the complexity of the diff display on check-in information pages. check-in: 4f95ea8c56 user: drh tags: trunk

Changes to src/file.c.

    70     70     if( isWd && g.allowSymlinks ){
    71     71       return lstat(zFilename, buf);
    72     72     }else{
    73     73       return stat(zFilename, buf);
    74     74     }
    75     75   #else
    76     76     int rc = 0;
    77         -  wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
           77  +  wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
    78     78     rc = _wstati64(zMbcs, buf);
    79         -  fossil_unicode_free(zMbcs);
           79  +  fossil_filename_free(zMbcs);
    80     80     return rc;
    81     81   #endif
    82     82   }
    83     83   
    84     84   /*
    85     85   ** Fill in the fileStat variable for the file named zFilename.
    86     86   ** If zFilename==0, then use the previous value of fileStat if
................................................................................
   301    301   
   302    302   
   303    303   /*
   304    304   ** Wrapper around the access() system call.
   305    305   */
   306    306   int file_access(const char *zFilename, int flags){
   307    307   #ifdef _WIN32
   308         -  wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
          308  +  wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
   309    309     int rc = _waccess(zMbcs, flags);
   310         -  fossil_unicode_free(zMbcs);
          310  +  fossil_filename_free(zMbcs);
   311    311   #else
   312    312     int rc = access(zFilename, flags);
   313    313   #endif
   314    314     return rc;
   315    315   }
   316    316   
   317    317   /*
................................................................................
   403    403     struct timeval tv[2];
   404    404     memset(tv, 0, sizeof(tv[0])*2);
   405    405     tv[0].tv_sec = newMTime;
   406    406     tv[1].tv_sec = newMTime;
   407    407     utimes(zFilename, tv);
   408    408   #else
   409    409     struct _utimbuf tb;
   410         -  wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
          410  +  wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
   411    411     tb.actime = newMTime;
   412    412     tb.modtime = newMTime;
   413    413     _wutime(zMbcs, &tb);
   414         -  fossil_unicode_free(zMbcs);
          414  +  fossil_filename_free(zMbcs);
   415    415   #endif
   416    416   }
   417    417   
   418    418   /*
   419    419   ** COMMAND: test-set-mtime
   420    420   **
   421    421   ** Usage: %fossil test-set-mtime FILENAME DATE/TIME
................................................................................
   439    439   }
   440    440   
   441    441   /*
   442    442   ** Delete a file.
   443    443   */
   444    444   void file_delete(const char *zFilename){
   445    445   #ifdef _WIN32
   446         -  wchar_t *z = fossil_utf8_to_unicode(zFilename);
          446  +  wchar_t *z = fossil_utf8_to_filename(zFilename);
   447    447     _wunlink(z);
   448         -  fossil_unicode_free(z);
          448  +  fossil_filename_free(z);
   449    449   #else
   450    450     unlink(zFilename);
   451    451   #endif
   452    452   }
   453    453   
   454    454   /*
   455    455   ** Create the directory named in the argument, if it does not already
................................................................................
   463    463     if( rc==2 ){
   464    464       if( !forceFlag ) return 1;
   465    465       file_delete(zName);
   466    466     }
   467    467     if( rc!=1 ){
   468    468   #if defined(_WIN32)
   469    469       int rc;
   470         -    wchar_t *zMbcs = fossil_utf8_to_unicode(zName);
          470  +    wchar_t *zMbcs = fossil_utf8_to_filename(zName);
   471    471       rc = _wmkdir(zMbcs);
   472         -    fossil_unicode_free(zMbcs);
          472  +    fossil_filename_free(zMbcs);
   473    473       return rc;
   474    474   #else
   475    475       return mkdir(zName, 0755);
   476    476   #endif
   477    477     }
   478    478     return 0;
   479    479   }
................................................................................
  1119   1119   
  1120   1120   /*
  1121   1121   ** Return the value of an environment variable as UTF8.
  1122   1122   ** Use fossil_filename_free() to release resources.
  1123   1123   */
  1124   1124   char *fossil_getenv(const char *zName){
  1125   1125   #ifdef _WIN32
  1126         -  wchar_t *uName = fossil_utf8_to_unicode(zName);
         1126  +  wchar_t *uName = fossil_utf8_to_filename(zName);
  1127   1127     void *zValue = _wgetenv(uName);
  1128         -  fossil_unicode_free(uName);
         1128  +  fossil_filename_free(uName);
  1129   1129   #else
  1130   1130     char *zValue = getenv(zName);
  1131   1131   #endif
  1132   1132     if( zValue ) zValue = fossil_filename_to_utf8(zValue);
  1133   1133     return zValue;
  1134   1134   }
  1135   1135   
  1136   1136   /*
  1137   1137   ** Like fopen() but always takes a UTF8 argument.
  1138   1138   */
  1139   1139   FILE *fossil_fopen(const char *zName, const char *zMode){
  1140   1140   #ifdef _WIN32
  1141   1141     wchar_t *uMode = fossil_utf8_to_unicode(zMode);
  1142         -  wchar_t *uName = fossil_utf8_to_unicode(zName);
         1142  +  wchar_t *uName = fossil_utf8_to_filename(zName);
  1143   1143     FILE *f = _wfopen(uName, uMode);
  1144         -  fossil_unicode_free(uName);
         1144  +  fossil_filename_free(uName);
  1145   1145     fossil_unicode_free(uMode);
  1146   1146   #else
  1147   1147     FILE *f = fopen(zName, zMode);
  1148   1148   #endif
  1149   1149     return f;
  1150   1150   }

Changes to src/rebuild.c.

   839    839     DIR *d;
   840    840     struct dirent *pEntry;
   841    841     Blob aContent; /* content of the just read artifact */
   842    842     static int nFileRead = 0;
   843    843     void *zUnicodePath;
   844    844     char *zUtf8Name;
   845    845   
   846         -  zUnicodePath = fossil_utf8_to_unicode(zPath);
          846  +  zUnicodePath = fossil_utf8_to_filename(zPath);
   847    847     d = opendir(zUnicodePath);
   848    848     if( d ){
   849    849       while( (pEntry=readdir(d))!=0 ){
   850    850         Blob path;
   851    851         char *zSubpath;
   852    852   
   853    853         if( pEntry->d_name[0]=='.' ){
................................................................................
   873    873         fflush(stdout);
   874    874       }
   875    875       closedir(d);
   876    876     }else {
   877    877       fossil_panic("encountered error %d while trying to open \"%s\".",
   878    878                     errno, g.argv[3]);
   879    879     }
   880         -  fossil_unicode_free(zUnicodePath);
          880  +  fossil_filename_free(zUnicodePath);
   881    881   }
   882    882   
   883    883   /*
   884    884   ** COMMAND: reconstruct*
   885    885   **
   886    886   ** Usage: %fossil reconstruct FILENAME DIRECTORY
   887    887   **

Changes to src/utf8.c.

    22     22   #include "config.h"
    23     23   #include "utf8.h"
    24     24   #include <sqlite3.h>
    25     25   #ifdef _WIN32
    26     26   # include <windows.h>
    27     27   #endif
    28     28   
           29  +#ifdef _WIN32
    29     30   /*
    30     31   ** Translate MBCS to UTF8.  Return a pointer to the translated text.
    31     32   ** Call fossil_mbcs_free() to deallocate any memory used to store the
    32     33   ** returned pointer when done.
    33     34   */
    34     35   char *fossil_mbcs_to_utf8(const char *zMbcs){
    35         -#ifdef _WIN32
    36     36     extern char *sqlite3_win32_mbcs_to_utf8(const char*);
    37     37     return sqlite3_win32_mbcs_to_utf8(zMbcs);
    38         -#else
    39         -  return (char*)zMbcs;  /* No-op on unix */
    40         -#endif
    41     38   }
    42     39   
    43     40   /*
    44     41   ** After translating from UTF8 to MBCS, invoke this routine to deallocate
    45     42   ** any memory used to hold the translation
    46     43   */
    47     44   void fossil_mbcs_free(char *zOld){
    48         -#ifdef _WIN32
    49     45     sqlite3_free(zOld);
    50         -#else
    51         -  /* No-op on unix */
    52         -#endif
    53     46   }
    54     47   
    55     48   /*
    56     49   ** Translate Unicode text into UTF8.
    57     50   ** Return a pointer to the translated text.
    58     51   ** Call fossil_unicode_free() to deallocate any memory used to store the
    59     52   ** returned pointer when done.
................................................................................
    64     57     char *zUtf = sqlite3_malloc( nByte );
    65     58     if( zUtf==0 ){
    66     59       return 0;
    67     60     }
    68     61     WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
    69     62     return zUtf;
    70     63   #else
    71         -  return (char *)zUnicode;  /* No-op on unix */
           64  +  return (char *)zUnicode;  /* TODO: implement for unix */
    72     65   #endif
    73     66   }
    74     67   
    75     68   /*
    76     69   ** Translate UTF8 to unicode for use in system calls.  Return a pointer to the
    77     70   ** translated text..  Call fossil_unicode_free() to deallocate any memory
    78     71   ** used to store the returned pointer when done.
................................................................................
    83     76     wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
    84     77     if( zUnicode==0 ){
    85     78       return 0;
    86     79     }
    87     80     MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
    88     81     return zUnicode;
    89     82   #else
    90         -  return (void *)zUtf8;  /* No-op on unix */
           83  +  return (void *)zUtf8;  /* TODO: implement for unix */
    91     84   #endif
    92     85   }
    93     86   
    94     87   /*
    95     88   ** Deallocate any memory that was previously allocated by
    96     89   ** fossil_unicode_to_utf8().
    97     90   */
    98     91   void fossil_unicode_free(void *pOld){
    99     92   #ifdef _WIN32
   100     93     sqlite3_free(pOld);
   101     94   #else
   102         -  /* No-op on unix */
           95  +  /* TODO: implement for unix */
   103     96   #endif
   104     97   }
           98  +#endif /* _WIN32 */
   105     99   
   106    100   #if defined(__APPLE__) && !defined(WITHOUT_ICONV)
   107    101   # include <iconv.h>
   108    102   #endif
   109    103   
   110    104   /*
   111    105   ** Translate text from the filename character set into
................................................................................
   147    141       zOut = fossil_strdup(zFilename);
   148    142     }
   149    143     return zOut;
   150    144   #else
   151    145     return (char *)zFilename;  /* No-op on non-mac unix */
   152    146   #endif
   153    147   }
          148  +
          149  +/*
          150  +** Translate UTF8 to unicode for use in filename translations.
          151  +** Return a pointer to the translated text..  Call fossil_filename_free()
          152  +** to deallocate any memory used to store the returned pointer when done.
          153  +**
          154  +*/
          155  +void *fossil_utf8_to_filename(const char *zUtf8){
          156  +#ifdef _WIN32
          157  +  int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
          158  +  wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
          159  +  if( zUnicode==0 ){
          160  +    return 0;
          161  +  }
          162  +  MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
          163  +  return zUnicode;
          164  +#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
          165  +  return fossil_strdup(zUtf8);
          166  +#else
          167  +  return (void *)zUtf8;  /* No-op on unix */
          168  +#endif
          169  +}
   154    170   
   155    171   /*
   156    172   ** Deallocate any memory that was previously allocated by
   157         -** fossil_filename_to_utf8().
          173  +** fossil_filename_to_utf8() or fossil_utf8_to_filename().
   158    174   */
   159         -void fossil_filename_free(char *pOld){
          175  +void fossil_filename_free(void *pOld){
   160    176   #if defined(_WIN32)
   161    177     sqlite3_free(pOld);
   162    178   #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
   163    179     fossil_free(pOld);
   164    180   #else
   165    181     /* No-op on all other unix */
   166    182   #endif

Changes to src/vfile.c.

   457    457          "INSERT OR IGNORE INTO sfile(x) SELECT :file"
   458    458          "  WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE pathname=:file)"
   459    459       );
   460    460     }
   461    461     depth++;
   462    462   
   463    463     zDir = blob_str(pPath);
   464         -  zNative = fossil_utf8_to_unicode(zDir);
          464  +  zNative = fossil_utf8_to_filename(zDir);
   465    465     d = opendir(zNative);
   466    466     if( d ){
   467    467       while( (pEntry=readdir(d))!=0 ){
   468    468         char *zPath;
   469    469         char *zUtf8;
   470    470         if( pEntry->d_name[0]=='.' ){
   471    471           if( (scanFlags & SCAN_ALL)==0 ) continue;
................................................................................
   489    489           }
   490    490         }
   491    491         fossil_filename_free(zUtf8);
   492    492         blob_resize(pPath, origSize);
   493    493       }
   494    494       closedir(d);
   495    495     }
   496         -  fossil_unicode_free(zNative);
          496  +  fossil_filename_free(zNative);
   497    497   
   498    498     depth--;
   499    499     if( depth==0 ){
   500    500       db_finalize(&ins);
   501    501     }
   502    502   }
   503    503