Fossil SCM

new functions fossil_unicode_to_utf8 and fossil_utf8_to_unicode. Modify file_delete, file_tempname, fossil_getenv and fossil_fopen to use it, so now they can handle all unicode characters not only the ones from the mbcs This should allow all filenames and environment variables to contain unicode characters, without problems on WIN32. If main.c is compiled with -DUNICODE -D_UNICODE, then command line arguments allow unicode characters on win32 as well. Build system not adapted for that yet.

jan.nijtmans 2012-08-22 13:47 eclipse-project
Commit 65c8ca0571a3ea8dd2cf9a5aeeab54e5a72f0d20
+2 -2
--- src/export.c
+++ src/export.c
@@ -136,11 +136,11 @@
136136
if( markfile_in!=0 ){
137137
Stmt qb,qc;
138138
char line[100];
139139
FILE *f;
140140
141
- f = fopen(markfile_in, "r");
141
+ f = fossil_fopen(markfile_in, "r");
142142
if( f==0 ){
143143
fossil_panic("cannot open %s for reading", markfile_in);
144144
}
145145
db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
146146
db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
@@ -325,11 +325,11 @@
325325
db_finalize(&q);
326326
bag_clear(&vers);
327327
328328
if( markfile_out!=0 ){
329329
FILE *f;
330
- f = fopen(markfile_out, "w");
330
+ f = fossil_fopen(markfile_out, "w");
331331
if( f == 0 ){
332332
fossil_panic("cannot open %s for writing", markfile_out);
333333
}
334334
db_prepare(&q, "SELECT rid FROM oldblob");
335335
while( db_step(&q)==SQLITE_ROW ){
336336
--- src/export.c
+++ src/export.c
@@ -136,11 +136,11 @@
136 if( markfile_in!=0 ){
137 Stmt qb,qc;
138 char line[100];
139 FILE *f;
140
141 f = fopen(markfile_in, "r");
142 if( f==0 ){
143 fossil_panic("cannot open %s for reading", markfile_in);
144 }
145 db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
146 db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
@@ -325,11 +325,11 @@
325 db_finalize(&q);
326 bag_clear(&vers);
327
328 if( markfile_out!=0 ){
329 FILE *f;
330 f = fopen(markfile_out, "w");
331 if( f == 0 ){
332 fossil_panic("cannot open %s for writing", markfile_out);
333 }
334 db_prepare(&q, "SELECT rid FROM oldblob");
335 while( db_step(&q)==SQLITE_ROW ){
336
--- src/export.c
+++ src/export.c
@@ -136,11 +136,11 @@
136 if( markfile_in!=0 ){
137 Stmt qb,qc;
138 char line[100];
139 FILE *f;
140
141 f = fossil_fopen(markfile_in, "r");
142 if( f==0 ){
143 fossil_panic("cannot open %s for reading", markfile_in);
144 }
145 db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
146 db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
@@ -325,11 +325,11 @@
325 db_finalize(&q);
326 bag_clear(&vers);
327
328 if( markfile_out!=0 ){
329 FILE *f;
330 f = fossil_fopen(markfile_out, "w");
331 if( f == 0 ){
332 fossil_panic("cannot open %s for writing", markfile_out);
333 }
334 db_prepare(&q, "SELECT rid FROM oldblob");
335 while( db_step(&q)==SQLITE_ROW ){
336
+63 -11
--- src/file.c
+++ src/file.c
@@ -389,13 +389,17 @@
389389
390390
/*
391391
** Delete a file.
392392
*/
393393
void file_delete(const char *zFilename){
394
- char *z = fossil_utf8_to_mbcs(zFilename);
395
- unlink(z);
394
+#ifdef _WIN32
395
+ wchar_t *z = fossil_utf8_to_unicode(zFilename);
396
+ _wunlink(z);
396397
fossil_mbcs_free(z);
398
+#else
399
+ unlink(zFilename);
400
+#endif
397401
}
398402
399403
/*
400404
** Create the directory named in the argument, if it does not already
401405
** exist. If forceFlag is 1, delete any prior non-directory object
@@ -928,14 +932,14 @@
928932
unsigned int i, j;
929933
const char *zDir = ".";
930934
int cnt = 0;
931935
932936
#if defined(_WIN32)
933
- char zTmpPath[MAX_PATH];
937
+ wchar_t zTmpPath[MAX_PATH];
934938
935
- if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936
- azDirs[0] = zTmpPath;
939
+ if( GetTempPathW(MAX_PATH, zTmpPath) ){
940
+ azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
937941
}
938942
939943
azDirs[1] = fossil_getenv("TEMP");
940944
azDirs[2] = fossil_getenv("TMP");
941945
#endif
@@ -1014,10 +1018,29 @@
10141018
return sqlite3_win32_mbcs_to_utf8(zMbcs);
10151019
#else
10161020
return (char*)zMbcs; /* No-op on unix */
10171021
#endif
10181022
}
1023
+
1024
+/*
1025
+** Translate Unicode to UTF8. Return a pointer to the translated text.
1026
+** Call fossil_mbcs_free() to deallocate any memory used to store the
1027
+** returned pointer when done.
1028
+*/
1029
+char *fossil_unicode_to_utf8(const void *zUnicode){
1030
+#ifdef _WIN32
1031
+ int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1032
+ char *zUtf = sqlite3_malloc( nByte );
1033
+ if( zUtf==0 ){
1034
+ return 0;
1035
+ }
1036
+ WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1037
+ return zUtf;
1038
+#else
1039
+ return (char *)zUnicode; /* No-op on unix */
1040
+#endif
1041
+}
10191042
10201043
/*
10211044
** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
10221045
** translated text.. Call fossil_mbcs_free() to deallocate any memory
10231046
** used to store the returned pointer when done.
@@ -1028,18 +1051,41 @@
10281051
return sqlite3_win32_utf8_to_mbcs(zUtf8);
10291052
#else
10301053
return (char*)zUtf8; /* No-op on unix */
10311054
#endif
10321055
}
1056
+
1057
+/*
1058
+** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1059
+** translated text.. Call fossil_mbcs_free() to deallocate any memory
1060
+** used to store the returned pointer when done.
1061
+*/
1062
+void *fossil_utf8_to_unicode(const char *zUtf8){
1063
+#ifdef _WIN32
1064
+ int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1065
+ wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1066
+ if( zUnicode==0 ){
1067
+ return 0;
1068
+ }
1069
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1070
+ return zUnicode;
1071
+#else
1072
+ return (void *)zUtf8; /* No-op on unix */
1073
+#endif
1074
+}
10331075
10341076
/*
10351077
** Return the value of an environment variable as UTF8.
10361078
*/
10371079
char *fossil_getenv(const char *zName){
1038
- char *zValue = getenv(zName);
10391080
#ifdef _WIN32
1040
- if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
1081
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1082
+ void *zValue = _wgetenv(uName);
1083
+ fossil_mbcs_free(uName);
1084
+ if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1085
+#else
1086
+ char *zValue = getenv(zName);
10411087
#endif
10421088
return zValue;
10431089
}
10441090
10451091
/*
@@ -1085,11 +1131,11 @@
10851131
10861132
/*
10871133
** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
10881134
** to deallocate any memory used to store the returned pointer when done.
10891135
*/
1090
-void fossil_mbcs_free(char *zOld){
1136
+void fossil_mbcs_free(void *zOld){
10911137
#ifdef _WIN32
10921138
extern void sqlite3_free(void*);
10931139
sqlite3_free(zOld);
10941140
#else
10951141
/* No-op on unix */
@@ -1098,10 +1144,16 @@
10981144
10991145
/*
11001146
** Like fopen() but always takes a UTF8 argument.
11011147
*/
11021148
FILE *fossil_fopen(const char *zName, const char *zMode){
1103
- char *zMbcs = fossil_utf8_to_mbcs(zName);
1104
- FILE *f = fopen(zMbcs, zMode);
1105
- fossil_mbcs_free(zMbcs);
1149
+#ifdef _WIN32
1150
+ wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1151
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1152
+ FILE *f = _wfopen(uName, uMode);
1153
+ fossil_mbcs_free(uName);
1154
+ fossil_mbcs_free(uMode);
1155
+#else
1156
+ FILE *f = fopen(zName, zMode);
1157
+#endif
11061158
return f;
11071159
}
11081160
--- src/file.c
+++ src/file.c
@@ -389,13 +389,17 @@
389
390 /*
391 ** Delete a file.
392 */
393 void file_delete(const char *zFilename){
394 char *z = fossil_utf8_to_mbcs(zFilename);
395 unlink(z);
 
396 fossil_mbcs_free(z);
 
 
 
397 }
398
399 /*
400 ** Create the directory named in the argument, if it does not already
401 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -928,14 +932,14 @@
928 unsigned int i, j;
929 const char *zDir = ".";
930 int cnt = 0;
931
932 #if defined(_WIN32)
933 char zTmpPath[MAX_PATH];
934
935 if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936 azDirs[0] = zTmpPath;
937 }
938
939 azDirs[1] = fossil_getenv("TEMP");
940 azDirs[2] = fossil_getenv("TMP");
941 #endif
@@ -1014,10 +1018,29 @@
1014 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1015 #else
1016 return (char*)zMbcs; /* No-op on unix */
1017 #endif
1018 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
1020 /*
1021 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1022 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1023 ** used to store the returned pointer when done.
@@ -1028,18 +1051,41 @@
1028 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1029 #else
1030 return (char*)zUtf8; /* No-op on unix */
1031 #endif
1032 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
1034 /*
1035 ** Return the value of an environment variable as UTF8.
1036 */
1037 char *fossil_getenv(const char *zName){
1038 char *zValue = getenv(zName);
1039 #ifdef _WIN32
1040 if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
 
 
 
 
 
1041 #endif
1042 return zValue;
1043 }
1044
1045 /*
@@ -1085,11 +1131,11 @@
1085
1086 /*
1087 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1088 ** to deallocate any memory used to store the returned pointer when done.
1089 */
1090 void fossil_mbcs_free(char *zOld){
1091 #ifdef _WIN32
1092 extern void sqlite3_free(void*);
1093 sqlite3_free(zOld);
1094 #else
1095 /* No-op on unix */
@@ -1098,10 +1144,16 @@
1098
1099 /*
1100 ** Like fopen() but always takes a UTF8 argument.
1101 */
1102 FILE *fossil_fopen(const char *zName, const char *zMode){
1103 char *zMbcs = fossil_utf8_to_mbcs(zName);
1104 FILE *f = fopen(zMbcs, zMode);
1105 fossil_mbcs_free(zMbcs);
 
 
 
 
 
 
1106 return f;
1107 }
1108
--- src/file.c
+++ src/file.c
@@ -389,13 +389,17 @@
389
390 /*
391 ** Delete a file.
392 */
393 void file_delete(const char *zFilename){
394 #ifdef _WIN32
395 wchar_t *z = fossil_utf8_to_unicode(zFilename);
396 _wunlink(z);
397 fossil_mbcs_free(z);
398 #else
399 unlink(zFilename);
400 #endif
401 }
402
403 /*
404 ** Create the directory named in the argument, if it does not already
405 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -928,14 +932,14 @@
932 unsigned int i, j;
933 const char *zDir = ".";
934 int cnt = 0;
935
936 #if defined(_WIN32)
937 wchar_t zTmpPath[MAX_PATH];
938
939 if( GetTempPathW(MAX_PATH, zTmpPath) ){
940 azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
941 }
942
943 azDirs[1] = fossil_getenv("TEMP");
944 azDirs[2] = fossil_getenv("TMP");
945 #endif
@@ -1014,10 +1018,29 @@
1018 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1019 #else
1020 return (char*)zMbcs; /* No-op on unix */
1021 #endif
1022 }
1023
1024 /*
1025 ** Translate Unicode to UTF8. Return a pointer to the translated text.
1026 ** Call fossil_mbcs_free() to deallocate any memory used to store the
1027 ** returned pointer when done.
1028 */
1029 char *fossil_unicode_to_utf8(const void *zUnicode){
1030 #ifdef _WIN32
1031 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1032 char *zUtf = sqlite3_malloc( nByte );
1033 if( zUtf==0 ){
1034 return 0;
1035 }
1036 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1037 return zUtf;
1038 #else
1039 return (char *)zUnicode; /* No-op on unix */
1040 #endif
1041 }
1042
1043 /*
1044 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1045 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1046 ** used to store the returned pointer when done.
@@ -1028,18 +1051,41 @@
1051 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1052 #else
1053 return (char*)zUtf8; /* No-op on unix */
1054 #endif
1055 }
1056
1057 /*
1058 ** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1059 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1060 ** used to store the returned pointer when done.
1061 */
1062 void *fossil_utf8_to_unicode(const char *zUtf8){
1063 #ifdef _WIN32
1064 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1065 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1066 if( zUnicode==0 ){
1067 return 0;
1068 }
1069 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1070 return zUnicode;
1071 #else
1072 return (void *)zUtf8; /* No-op on unix */
1073 #endif
1074 }
1075
1076 /*
1077 ** Return the value of an environment variable as UTF8.
1078 */
1079 char *fossil_getenv(const char *zName){
 
1080 #ifdef _WIN32
1081 wchar_t *uName = fossil_utf8_to_unicode(zName);
1082 void *zValue = _wgetenv(uName);
1083 fossil_mbcs_free(uName);
1084 if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1085 #else
1086 char *zValue = getenv(zName);
1087 #endif
1088 return zValue;
1089 }
1090
1091 /*
@@ -1085,11 +1131,11 @@
1131
1132 /*
1133 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1134 ** to deallocate any memory used to store the returned pointer when done.
1135 */
1136 void fossil_mbcs_free(void *zOld){
1137 #ifdef _WIN32
1138 extern void sqlite3_free(void*);
1139 sqlite3_free(zOld);
1140 #else
1141 /* No-op on unix */
@@ -1098,10 +1144,16 @@
1144
1145 /*
1146 ** Like fopen() but always takes a UTF8 argument.
1147 */
1148 FILE *fossil_fopen(const char *zName, const char *zMode){
1149 #ifdef _WIN32
1150 wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1151 wchar_t *uName = fossil_utf8_to_unicode(zName);
1152 FILE *f = _wfopen(uName, uMode);
1153 fossil_mbcs_free(uName);
1154 fossil_mbcs_free(uMode);
1155 #else
1156 FILE *f = fopen(zName, zMode);
1157 #endif
1158 return f;
1159 }
1160
+1 -1
--- src/import.c
+++ src/import.c
@@ -732,11 +732,11 @@
732732
verify_all_options();
733733
if( g.argc!=3 && g.argc!=4 ){
734734
usage("REPOSITORY-NAME");
735735
}
736736
if( g.argc==4 ){
737
- pIn = fopen(g.argv[3], "rb");
737
+ pIn = fossil_fopen(g.argv[3], "rb");
738738
}else{
739739
pIn = stdin;
740740
fossil_binary_mode(pIn);
741741
}
742742
if( !incrFlag ){
743743
--- src/import.c
+++ src/import.c
@@ -732,11 +732,11 @@
732 verify_all_options();
733 if( g.argc!=3 && g.argc!=4 ){
734 usage("REPOSITORY-NAME");
735 }
736 if( g.argc==4 ){
737 pIn = fopen(g.argv[3], "rb");
738 }else{
739 pIn = stdin;
740 fossil_binary_mode(pIn);
741 }
742 if( !incrFlag ){
743
--- src/import.c
+++ src/import.c
@@ -732,11 +732,11 @@
732 verify_all_options();
733 if( g.argc!=3 && g.argc!=4 ){
734 usage("REPOSITORY-NAME");
735 }
736 if( g.argc==4 ){
737 pIn = fossil_fopen(g.argv[3], "rb");
738 }else{
739 pIn = stdin;
740 fossil_binary_mode(pIn);
741 }
742 if( !incrFlag ){
743
+1 -1
--- src/json.c
+++ src/json.c
@@ -1104,11 +1104,11 @@
11041104
if(!jfile || !*jfile){
11051105
break;
11061106
}
11071107
inFile = (0==strcmp("-",jfile))
11081108
? stdin
1109
- : fopen(jfile,"rb");
1109
+ : fossil_fopen(jfile,"rb");
11101110
if(!inFile){
11111111
g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
11121112
fossil_fatal("Could not open JSON file [%s].",jfile)
11131113
/* Does not return. */
11141114
;
11151115
--- src/json.c
+++ src/json.c
@@ -1104,11 +1104,11 @@
1104 if(!jfile || !*jfile){
1105 break;
1106 }
1107 inFile = (0==strcmp("-",jfile))
1108 ? stdin
1109 : fopen(jfile,"rb");
1110 if(!inFile){
1111 g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
1112 fossil_fatal("Could not open JSON file [%s].",jfile)
1113 /* Does not return. */
1114 ;
1115
--- src/json.c
+++ src/json.c
@@ -1104,11 +1104,11 @@
1104 if(!jfile || !*jfile){
1105 break;
1106 }
1107 inFile = (0==strcmp("-",jfile))
1108 ? stdin
1109 : fossil_fopen(jfile,"rb");
1110 if(!inFile){
1111 g.json.resultCode = FSL_JSON_E_FILE_OPEN_FAILED;
1112 fossil_fatal("Could not open JSON file [%s].",jfile)
1113 /* Does not return. */
1114 ;
1115
+21 -11
--- src/main.c
+++ src/main.c
@@ -329,29 +329,38 @@
329329
db_close(0);
330330
}
331331
}
332332
333333
/*
334
-** Search g.argv for arguments "--args FILENAME". If found, then
334
+** Convert all arguments from mbcs (or unicode) to UTF-8. Then
335
+** search g.argv for arguments "--args FILENAME". If found, then
335336
** (1) remove the two arguments from g.argv
336337
** (2) Read the file FILENAME
337338
** (3) Use the contents of FILE to replace the two removed arguments:
338339
** (a) Ignore blank lines in the file
339340
** (b) Each non-empty line of the file is an argument, except
340341
** (c) If the line begins with "-" and contains a space, it is broken
341342
** into two arguments at the space.
342343
*/
343
-static void expand_args_option(void){
344
+static void expand_args_option(int argc, void *argv){
344345
Blob file = empty_blob; /* Content of the file */
345346
Blob line = empty_blob; /* One line of the file */
346347
unsigned int nLine; /* Number of lines in the file*/
347348
unsigned int i, j, k; /* Loop counters */
348349
int n; /* Number of bytes in one line */
349350
char *z; /* General use string pointer */
350351
char **newArgv; /* New expanded g.argv under construction */
351352
char const * zFileName; /* input file name */
352353
FILE * zInFile; /* input FILE */
354
+
355
+ g.argc = argc;
356
+ g.argv = argv;
357
+#if defined(_WIN32) && defined(UNICODE)
358
+ for(i=0; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
359
+#else
360
+ for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
361
+#endif
353362
for(i=1; i<g.argc-1; i++){
354363
z = g.argv[i];
355364
if( z[0]!='-' ) continue;
356365
z++;
357366
if( z[0]=='-' ) z++;
@@ -361,11 +370,11 @@
361370
if( i>=g.argc-1 ) return;
362371
363372
zFileName = g.argv[i+1];
364373
zInFile = (0==strcmp("-",zFileName))
365374
? stdin
366
- : fopen(zFileName,"rb");
375
+ : fossil_fopen(zFileName,"rb");
367376
if(!zInFile){
368377
fossil_panic("Cannot open -args file [%s]", zFileName);
369378
}else{
370379
blob_read_from_channel(&file, zInFile, -1);
371380
if(stdin != zInFile){
@@ -385,11 +394,11 @@
385394
z[n-1] = 0;
386395
if((n>1) && ('\r'==z[n-2])){
387396
if(n==2) continue /*empty line*/;
388397
z[n-2] = 0;
389398
}
390
- newArgv[j++] = z;
399
+ newArgv[j++] = z = fossil_mbcs_to_utf8(z);
391400
if( z[0]=='-' ){
392401
for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
393402
if( z[k] ){
394403
z[k] = 0;
395404
k++;
@@ -405,21 +414,23 @@
405414
}
406415
407416
/*
408417
** This procedure runs first.
409418
*/
410
-int main(int argc, char **argv){
419
+#if defined(_WIN32) && defined(UNICODE)
420
+int wmain(int argc, char **argv)
421
+#else
422
+int main(int argc, char **argv)
423
+#endif
424
+{
411425
const char *zCmdName = "unknown";
412426
int idx;
413427
int rc;
414
- int i;
415428
416429
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
417430
memset(&g, 0, sizeof(g));
418431
g.now = time(0);
419
- g.argc = argc;
420
- g.argv = argv;
421432
#ifdef FOSSIL_ENABLE_JSON
422433
#if defined(NDEBUG)
423434
g.json.errorDetailParanoia = 2 /* FIXME: make configurable
424435
One problem we have here is that this
425436
code is needed before the db is opened,
@@ -429,12 +440,11 @@
429440
#endif
430441
g.json.outOpt = cson_output_opt_empty;
431442
g.json.outOpt.addNewline = 1;
432443
g.json.outOpt.indentation = 1 /* in CGI/server mode this can be configured */;
433444
#endif /* FOSSIL_ENABLE_JSON */
434
- expand_args_option();
435
- for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
445
+ expand_args_option(argc, argv);
436446
#ifdef FOSSIL_ENABLE_TCL
437447
g.tcl.argc = g.argc;
438448
g.tcl.argv = g.argv;
439449
g.tcl.interp = 0;
440450
#endif
@@ -1432,11 +1442,11 @@
14321442
blob_read_from_file(&config, zFile);
14331443
while( blob_line(&config, &line) ){
14341444
if( !blob_token(&line, &key) ) continue;
14351445
if( blob_buffer(&key)[0]=='#' ) continue;
14361446
if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
1437
- g.fDebug = fopen(blob_str(&value), "a");
1447
+ g.fDebug = fossil_fopen(blob_str(&value), "a");
14381448
blob_reset(&value);
14391449
continue;
14401450
}
14411451
if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
14421452
cgi_setenv("HOME", blob_str(&value));
14431453
--- src/main.c
+++ src/main.c
@@ -329,29 +329,38 @@
329 db_close(0);
330 }
331 }
332
333 /*
334 ** Search g.argv for arguments "--args FILENAME". If found, then
 
335 ** (1) remove the two arguments from g.argv
336 ** (2) Read the file FILENAME
337 ** (3) Use the contents of FILE to replace the two removed arguments:
338 ** (a) Ignore blank lines in the file
339 ** (b) Each non-empty line of the file is an argument, except
340 ** (c) If the line begins with "-" and contains a space, it is broken
341 ** into two arguments at the space.
342 */
343 static void expand_args_option(void){
344 Blob file = empty_blob; /* Content of the file */
345 Blob line = empty_blob; /* One line of the file */
346 unsigned int nLine; /* Number of lines in the file*/
347 unsigned int i, j, k; /* Loop counters */
348 int n; /* Number of bytes in one line */
349 char *z; /* General use string pointer */
350 char **newArgv; /* New expanded g.argv under construction */
351 char const * zFileName; /* input file name */
352 FILE * zInFile; /* input FILE */
 
 
 
 
 
 
 
 
353 for(i=1; i<g.argc-1; i++){
354 z = g.argv[i];
355 if( z[0]!='-' ) continue;
356 z++;
357 if( z[0]=='-' ) z++;
@@ -361,11 +370,11 @@
361 if( i>=g.argc-1 ) return;
362
363 zFileName = g.argv[i+1];
364 zInFile = (0==strcmp("-",zFileName))
365 ? stdin
366 : fopen(zFileName,"rb");
367 if(!zInFile){
368 fossil_panic("Cannot open -args file [%s]", zFileName);
369 }else{
370 blob_read_from_channel(&file, zInFile, -1);
371 if(stdin != zInFile){
@@ -385,11 +394,11 @@
385 z[n-1] = 0;
386 if((n>1) && ('\r'==z[n-2])){
387 if(n==2) continue /*empty line*/;
388 z[n-2] = 0;
389 }
390 newArgv[j++] = z;
391 if( z[0]=='-' ){
392 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
393 if( z[k] ){
394 z[k] = 0;
395 k++;
@@ -405,21 +414,23 @@
405 }
406
407 /*
408 ** This procedure runs first.
409 */
410 int main(int argc, char **argv){
 
 
 
 
 
411 const char *zCmdName = "unknown";
412 int idx;
413 int rc;
414 int i;
415
416 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
417 memset(&g, 0, sizeof(g));
418 g.now = time(0);
419 g.argc = argc;
420 g.argv = argv;
421 #ifdef FOSSIL_ENABLE_JSON
422 #if defined(NDEBUG)
423 g.json.errorDetailParanoia = 2 /* FIXME: make configurable
424 One problem we have here is that this
425 code is needed before the db is opened,
@@ -429,12 +440,11 @@
429 #endif
430 g.json.outOpt = cson_output_opt_empty;
431 g.json.outOpt.addNewline = 1;
432 g.json.outOpt.indentation = 1 /* in CGI/server mode this can be configured */;
433 #endif /* FOSSIL_ENABLE_JSON */
434 expand_args_option();
435 for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
436 #ifdef FOSSIL_ENABLE_TCL
437 g.tcl.argc = g.argc;
438 g.tcl.argv = g.argv;
439 g.tcl.interp = 0;
440 #endif
@@ -1432,11 +1442,11 @@
1432 blob_read_from_file(&config, zFile);
1433 while( blob_line(&config, &line) ){
1434 if( !blob_token(&line, &key) ) continue;
1435 if( blob_buffer(&key)[0]=='#' ) continue;
1436 if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
1437 g.fDebug = fopen(blob_str(&value), "a");
1438 blob_reset(&value);
1439 continue;
1440 }
1441 if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
1442 cgi_setenv("HOME", blob_str(&value));
1443
--- src/main.c
+++ src/main.c
@@ -329,29 +329,38 @@
329 db_close(0);
330 }
331 }
332
333 /*
334 ** Convert all arguments from mbcs (or unicode) to UTF-8. Then
335 ** search g.argv for arguments "--args FILENAME". If found, then
336 ** (1) remove the two arguments from g.argv
337 ** (2) Read the file FILENAME
338 ** (3) Use the contents of FILE to replace the two removed arguments:
339 ** (a) Ignore blank lines in the file
340 ** (b) Each non-empty line of the file is an argument, except
341 ** (c) If the line begins with "-" and contains a space, it is broken
342 ** into two arguments at the space.
343 */
344 static void expand_args_option(int argc, void *argv){
345 Blob file = empty_blob; /* Content of the file */
346 Blob line = empty_blob; /* One line of the file */
347 unsigned int nLine; /* Number of lines in the file*/
348 unsigned int i, j, k; /* Loop counters */
349 int n; /* Number of bytes in one line */
350 char *z; /* General use string pointer */
351 char **newArgv; /* New expanded g.argv under construction */
352 char const * zFileName; /* input file name */
353 FILE * zInFile; /* input FILE */
354
355 g.argc = argc;
356 g.argv = argv;
357 #if defined(_WIN32) && defined(UNICODE)
358 for(i=0; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
359 #else
360 for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
361 #endif
362 for(i=1; i<g.argc-1; i++){
363 z = g.argv[i];
364 if( z[0]!='-' ) continue;
365 z++;
366 if( z[0]=='-' ) z++;
@@ -361,11 +370,11 @@
370 if( i>=g.argc-1 ) return;
371
372 zFileName = g.argv[i+1];
373 zInFile = (0==strcmp("-",zFileName))
374 ? stdin
375 : fossil_fopen(zFileName,"rb");
376 if(!zInFile){
377 fossil_panic("Cannot open -args file [%s]", zFileName);
378 }else{
379 blob_read_from_channel(&file, zInFile, -1);
380 if(stdin != zInFile){
@@ -385,11 +394,11 @@
394 z[n-1] = 0;
395 if((n>1) && ('\r'==z[n-2])){
396 if(n==2) continue /*empty line*/;
397 z[n-2] = 0;
398 }
399 newArgv[j++] = z = fossil_mbcs_to_utf8(z);
400 if( z[0]=='-' ){
401 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
402 if( z[k] ){
403 z[k] = 0;
404 k++;
@@ -405,21 +414,23 @@
414 }
415
416 /*
417 ** This procedure runs first.
418 */
419 #if defined(_WIN32) && defined(UNICODE)
420 int wmain(int argc, char **argv)
421 #else
422 int main(int argc, char **argv)
423 #endif
424 {
425 const char *zCmdName = "unknown";
426 int idx;
427 int rc;
 
428
429 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
430 memset(&g, 0, sizeof(g));
431 g.now = time(0);
 
 
432 #ifdef FOSSIL_ENABLE_JSON
433 #if defined(NDEBUG)
434 g.json.errorDetailParanoia = 2 /* FIXME: make configurable
435 One problem we have here is that this
436 code is needed before the db is opened,
@@ -429,12 +440,11 @@
440 #endif
441 g.json.outOpt = cson_output_opt_empty;
442 g.json.outOpt.addNewline = 1;
443 g.json.outOpt.indentation = 1 /* in CGI/server mode this can be configured */;
444 #endif /* FOSSIL_ENABLE_JSON */
445 expand_args_option(argc, argv);
 
446 #ifdef FOSSIL_ENABLE_TCL
447 g.tcl.argc = g.argc;
448 g.tcl.argv = g.argv;
449 g.tcl.interp = 0;
450 #endif
@@ -1432,11 +1442,11 @@
1442 blob_read_from_file(&config, zFile);
1443 while( blob_line(&config, &line) ){
1444 if( !blob_token(&line, &key) ) continue;
1445 if( blob_buffer(&key)[0]=='#' ) continue;
1446 if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
1447 g.fDebug = fossil_fopen(blob_str(&value), "a");
1448 blob_reset(&value);
1449 continue;
1450 }
1451 if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
1452 cgi_setenv("HOME", blob_str(&value));
1453

Keyboard Shortcuts

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