Fossil SCM

Convert the changes that support microsoft character sets so that they work (so that they are #ifdef-ed out) on other platforms.

drh 2008-11-04 12:13 trunk merge
Commit c6a9e4ed41e5132ba53404c373c64f62c9b253fb
2 files changed +85 +85
+85
--- src/db.c
+++ src/db.c
@@ -36,10 +36,13 @@
3636
*/
3737
#include "config.h"
3838
#ifndef __MINGW32__
3939
# include <pwd.h>
4040
#endif
41
+#ifdef __MINGW32__
42
+# include <windows.h>
43
+#endif
4144
#include <sqlite3.h>
4245
#include <sys/types.h>
4346
#include <sys/stat.h>
4447
#include <unistd.h>
4548
#include "db.h"
@@ -495,10 +498,86 @@
495498
z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
496499
}
497500
db_finalize(&s);
498501
return z;
499502
}
503
+
504
+#ifdef __MINGW32__
505
+/*
506
+** These routines (copied out of the os_win.c driver for SQLite) convert
507
+** character strings in various microsoft multi-byte character formats
508
+** into UTF-8. Fossil and SQLite always use only UTF-8 internally. These
509
+** routines are needed in order to convert from the default character set
510
+** currently in use by windows into UTF-8 when strings are imported from
511
+** the outside world.
512
+*/
513
+/*
514
+** Convert microsoft unicode to UTF-8. Space to hold the returned string is
515
+** obtained from malloc().
516
+** Copied from sqlite3.c as is (petr)
517
+*/
518
+static char *unicodeToUtf8(const WCHAR *zWideFilename){
519
+ int nByte;
520
+ char *zFilename;
521
+
522
+ nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
523
+ zFilename = malloc( nByte );
524
+ if( zFilename==0 ){
525
+ return 0;
526
+ }
527
+ nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
528
+ 0, 0);
529
+ if( nByte == 0 ){
530
+ free(zFilename);
531
+ zFilename = 0;
532
+ }
533
+ return zFilename;
534
+}
535
+/*
536
+** Convert an ansi string to microsoft unicode, based on the
537
+** current codepage settings for file apis.
538
+**
539
+** Space to hold the returned string is obtained
540
+** from malloc.
541
+*/
542
+static WCHAR *mbcsToUnicode(const char *zFilename){
543
+ int nByte;
544
+ WCHAR *zMbcsFilename;
545
+ int codepage = CP_ACP;
546
+
547
+ nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
548
+ zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
549
+ if( zMbcsFilename==0 ){
550
+ return 0;
551
+ }
552
+
553
+ nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
554
+ if( nByte==0 ){
555
+ free(zMbcsFilename);
556
+ zMbcsFilename = 0;
557
+ }
558
+ return zMbcsFilename;
559
+}
560
+/*
561
+** Convert multibyte character string to UTF-8. Space to hold the
562
+** returned string is obtained from malloc().
563
+*/
564
+static char *mbcsToUtf8(const char *zFilename){
565
+ char *zFilenameUtf8;
566
+ WCHAR *zTmpWide;
567
+
568
+ zTmpWide = mbcsToUnicode(zFilename);
569
+ if( zTmpWide==0 ){
570
+ return 0;
571
+ }
572
+
573
+ zFilenameUtf8 = unicodeToUtf8(zTmpWide);
574
+ free(zTmpWide);
575
+ return zFilenameUtf8;
576
+}
577
+#endif /* __MINGW32__ */
578
+
500579
501580
/*
502581
** Initialize a new database file with the given schema. If anything
503582
** goes wrong, call db_err() to exit.
504583
*/
@@ -510,10 +589,13 @@
510589
sqlite3 *db;
511590
int rc;
512591
const char *zSql;
513592
va_list ap;
514593
594
+#ifdef __MINGW32__
595
+ zFileName = mbcsToUtf8(zFileName);
596
+#endif
515597
rc = sqlite3_open(zFileName, &db);
516598
if( rc!=SQLITE_OK ){
517599
db_err(sqlite3_errmsg(db));
518600
}
519601
sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
@@ -537,10 +619,13 @@
537619
** zDbName is the name of a database file. If no other database
538620
** file is open, then open this one. If another database file is
539621
** already open, then attach zDbName using the name zLabel.
540622
*/
541623
void db_open_or_attach(const char *zDbName, const char *zLabel){
624
+#ifdef __MINGW32__
625
+ zDbName = mbcsToUtf8(zDbName);
626
+#endif
542627
if( !g.db ){
543628
int rc = sqlite3_open(zDbName, &g.db);
544629
if( rc!=SQLITE_OK ){
545630
db_err(sqlite3_errmsg(g.db));
546631
}
547632
--- src/db.c
+++ src/db.c
@@ -36,10 +36,13 @@
36 */
37 #include "config.h"
38 #ifndef __MINGW32__
39 # include <pwd.h>
40 #endif
 
 
 
41 #include <sqlite3.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <unistd.h>
45 #include "db.h"
@@ -495,10 +498,86 @@
495 z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
496 }
497 db_finalize(&s);
498 return z;
499 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
501 /*
502 ** Initialize a new database file with the given schema. If anything
503 ** goes wrong, call db_err() to exit.
504 */
@@ -510,10 +589,13 @@
510 sqlite3 *db;
511 int rc;
512 const char *zSql;
513 va_list ap;
514
 
 
 
515 rc = sqlite3_open(zFileName, &db);
516 if( rc!=SQLITE_OK ){
517 db_err(sqlite3_errmsg(db));
518 }
519 sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
@@ -537,10 +619,13 @@
537 ** zDbName is the name of a database file. If no other database
538 ** file is open, then open this one. If another database file is
539 ** already open, then attach zDbName using the name zLabel.
540 */
541 void db_open_or_attach(const char *zDbName, const char *zLabel){
 
 
 
542 if( !g.db ){
543 int rc = sqlite3_open(zDbName, &g.db);
544 if( rc!=SQLITE_OK ){
545 db_err(sqlite3_errmsg(g.db));
546 }
547
--- src/db.c
+++ src/db.c
@@ -36,10 +36,13 @@
36 */
37 #include "config.h"
38 #ifndef __MINGW32__
39 # include <pwd.h>
40 #endif
41 #ifdef __MINGW32__
42 # include <windows.h>
43 #endif
44 #include <sqlite3.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <unistd.h>
48 #include "db.h"
@@ -495,10 +498,86 @@
498 z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
499 }
500 db_finalize(&s);
501 return z;
502 }
503
504 #ifdef __MINGW32__
505 /*
506 ** These routines (copied out of the os_win.c driver for SQLite) convert
507 ** character strings in various microsoft multi-byte character formats
508 ** into UTF-8. Fossil and SQLite always use only UTF-8 internally. These
509 ** routines are needed in order to convert from the default character set
510 ** currently in use by windows into UTF-8 when strings are imported from
511 ** the outside world.
512 */
513 /*
514 ** Convert microsoft unicode to UTF-8. Space to hold the returned string is
515 ** obtained from malloc().
516 ** Copied from sqlite3.c as is (petr)
517 */
518 static char *unicodeToUtf8(const WCHAR *zWideFilename){
519 int nByte;
520 char *zFilename;
521
522 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
523 zFilename = malloc( nByte );
524 if( zFilename==0 ){
525 return 0;
526 }
527 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
528 0, 0);
529 if( nByte == 0 ){
530 free(zFilename);
531 zFilename = 0;
532 }
533 return zFilename;
534 }
535 /*
536 ** Convert an ansi string to microsoft unicode, based on the
537 ** current codepage settings for file apis.
538 **
539 ** Space to hold the returned string is obtained
540 ** from malloc.
541 */
542 static WCHAR *mbcsToUnicode(const char *zFilename){
543 int nByte;
544 WCHAR *zMbcsFilename;
545 int codepage = CP_ACP;
546
547 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
548 zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
549 if( zMbcsFilename==0 ){
550 return 0;
551 }
552
553 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
554 if( nByte==0 ){
555 free(zMbcsFilename);
556 zMbcsFilename = 0;
557 }
558 return zMbcsFilename;
559 }
560 /*
561 ** Convert multibyte character string to UTF-8. Space to hold the
562 ** returned string is obtained from malloc().
563 */
564 static char *mbcsToUtf8(const char *zFilename){
565 char *zFilenameUtf8;
566 WCHAR *zTmpWide;
567
568 zTmpWide = mbcsToUnicode(zFilename);
569 if( zTmpWide==0 ){
570 return 0;
571 }
572
573 zFilenameUtf8 = unicodeToUtf8(zTmpWide);
574 free(zTmpWide);
575 return zFilenameUtf8;
576 }
577 #endif /* __MINGW32__ */
578
579
580 /*
581 ** Initialize a new database file with the given schema. If anything
582 ** goes wrong, call db_err() to exit.
583 */
@@ -510,10 +589,13 @@
589 sqlite3 *db;
590 int rc;
591 const char *zSql;
592 va_list ap;
593
594 #ifdef __MINGW32__
595 zFileName = mbcsToUtf8(zFileName);
596 #endif
597 rc = sqlite3_open(zFileName, &db);
598 if( rc!=SQLITE_OK ){
599 db_err(sqlite3_errmsg(db));
600 }
601 sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
@@ -537,10 +619,13 @@
619 ** zDbName is the name of a database file. If no other database
620 ** file is open, then open this one. If another database file is
621 ** already open, then attach zDbName using the name zLabel.
622 */
623 void db_open_or_attach(const char *zDbName, const char *zLabel){
624 #ifdef __MINGW32__
625 zDbName = mbcsToUtf8(zDbName);
626 #endif
627 if( !g.db ){
628 int rc = sqlite3_open(zDbName, &g.db);
629 if( rc!=SQLITE_OK ){
630 db_err(sqlite3_errmsg(g.db));
631 }
632
+85
--- src/db.c
+++ src/db.c
@@ -36,10 +36,13 @@
3636
*/
3737
#include "config.h"
3838
#ifndef __MINGW32__
3939
# include <pwd.h>
4040
#endif
41
+#ifdef __MINGW32__
42
+# include <windows.h>
43
+#endif
4144
#include <sqlite3.h>
4245
#include <sys/types.h>
4346
#include <sys/stat.h>
4447
#include <unistd.h>
4548
#include "db.h"
@@ -495,10 +498,86 @@
495498
z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
496499
}
497500
db_finalize(&s);
498501
return z;
499502
}
503
+
504
+#ifdef __MINGW32__
505
+/*
506
+** These routines (copied out of the os_win.c driver for SQLite) convert
507
+** character strings in various microsoft multi-byte character formats
508
+** into UTF-8. Fossil and SQLite always use only UTF-8 internally. These
509
+** routines are needed in order to convert from the default character set
510
+** currently in use by windows into UTF-8 when strings are imported from
511
+** the outside world.
512
+*/
513
+/*
514
+** Convert microsoft unicode to UTF-8. Space to hold the returned string is
515
+** obtained from malloc().
516
+** Copied from sqlite3.c as is (petr)
517
+*/
518
+static char *unicodeToUtf8(const WCHAR *zWideFilename){
519
+ int nByte;
520
+ char *zFilename;
521
+
522
+ nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
523
+ zFilename = malloc( nByte );
524
+ if( zFilename==0 ){
525
+ return 0;
526
+ }
527
+ nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
528
+ 0, 0);
529
+ if( nByte == 0 ){
530
+ free(zFilename);
531
+ zFilename = 0;
532
+ }
533
+ return zFilename;
534
+}
535
+/*
536
+** Convert an ansi string to microsoft unicode, based on the
537
+** current codepage settings for file apis.
538
+**
539
+** Space to hold the returned string is obtained
540
+** from malloc.
541
+*/
542
+static WCHAR *mbcsToUnicode(const char *zFilename){
543
+ int nByte;
544
+ WCHAR *zMbcsFilename;
545
+ int codepage = CP_ACP;
546
+
547
+ nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
548
+ zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
549
+ if( zMbcsFilename==0 ){
550
+ return 0;
551
+ }
552
+
553
+ nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
554
+ if( nByte==0 ){
555
+ free(zMbcsFilename);
556
+ zMbcsFilename = 0;
557
+ }
558
+ return zMbcsFilename;
559
+}
560
+/*
561
+** Convert multibyte character string to UTF-8. Space to hold the
562
+** returned string is obtained from malloc().
563
+*/
564
+static char *mbcsToUtf8(const char *zFilename){
565
+ char *zFilenameUtf8;
566
+ WCHAR *zTmpWide;
567
+
568
+ zTmpWide = mbcsToUnicode(zFilename);
569
+ if( zTmpWide==0 ){
570
+ return 0;
571
+ }
572
+
573
+ zFilenameUtf8 = unicodeToUtf8(zTmpWide);
574
+ free(zTmpWide);
575
+ return zFilenameUtf8;
576
+}
577
+#endif /* __MINGW32__ */
578
+
500579
501580
/*
502581
** Initialize a new database file with the given schema. If anything
503582
** goes wrong, call db_err() to exit.
504583
*/
@@ -510,10 +589,13 @@
510589
sqlite3 *db;
511590
int rc;
512591
const char *zSql;
513592
va_list ap;
514593
594
+#ifdef __MINGW32__
595
+ zFileName = mbcsToUtf8(zFileName);
596
+#endif
515597
rc = sqlite3_open(zFileName, &db);
516598
if( rc!=SQLITE_OK ){
517599
db_err(sqlite3_errmsg(db));
518600
}
519601
sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
@@ -537,10 +619,13 @@
537619
** zDbName is the name of a database file. If no other database
538620
** file is open, then open this one. If another database file is
539621
** already open, then attach zDbName using the name zLabel.
540622
*/
541623
void db_open_or_attach(const char *zDbName, const char *zLabel){
624
+#ifdef __MINGW32__
625
+ zDbName = mbcsToUtf8(zDbName);
626
+#endif
542627
if( !g.db ){
543628
int rc = sqlite3_open(zDbName, &g.db);
544629
if( rc!=SQLITE_OK ){
545630
db_err(sqlite3_errmsg(g.db));
546631
}
547632
--- src/db.c
+++ src/db.c
@@ -36,10 +36,13 @@
36 */
37 #include "config.h"
38 #ifndef __MINGW32__
39 # include <pwd.h>
40 #endif
 
 
 
41 #include <sqlite3.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <unistd.h>
45 #include "db.h"
@@ -495,10 +498,86 @@
495 z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
496 }
497 db_finalize(&s);
498 return z;
499 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
501 /*
502 ** Initialize a new database file with the given schema. If anything
503 ** goes wrong, call db_err() to exit.
504 */
@@ -510,10 +589,13 @@
510 sqlite3 *db;
511 int rc;
512 const char *zSql;
513 va_list ap;
514
 
 
 
515 rc = sqlite3_open(zFileName, &db);
516 if( rc!=SQLITE_OK ){
517 db_err(sqlite3_errmsg(db));
518 }
519 sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
@@ -537,10 +619,13 @@
537 ** zDbName is the name of a database file. If no other database
538 ** file is open, then open this one. If another database file is
539 ** already open, then attach zDbName using the name zLabel.
540 */
541 void db_open_or_attach(const char *zDbName, const char *zLabel){
 
 
 
542 if( !g.db ){
543 int rc = sqlite3_open(zDbName, &g.db);
544 if( rc!=SQLITE_OK ){
545 db_err(sqlite3_errmsg(g.db));
546 }
547
--- src/db.c
+++ src/db.c
@@ -36,10 +36,13 @@
36 */
37 #include "config.h"
38 #ifndef __MINGW32__
39 # include <pwd.h>
40 #endif
41 #ifdef __MINGW32__
42 # include <windows.h>
43 #endif
44 #include <sqlite3.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <unistd.h>
48 #include "db.h"
@@ -495,10 +498,86 @@
498 z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
499 }
500 db_finalize(&s);
501 return z;
502 }
503
504 #ifdef __MINGW32__
505 /*
506 ** These routines (copied out of the os_win.c driver for SQLite) convert
507 ** character strings in various microsoft multi-byte character formats
508 ** into UTF-8. Fossil and SQLite always use only UTF-8 internally. These
509 ** routines are needed in order to convert from the default character set
510 ** currently in use by windows into UTF-8 when strings are imported from
511 ** the outside world.
512 */
513 /*
514 ** Convert microsoft unicode to UTF-8. Space to hold the returned string is
515 ** obtained from malloc().
516 ** Copied from sqlite3.c as is (petr)
517 */
518 static char *unicodeToUtf8(const WCHAR *zWideFilename){
519 int nByte;
520 char *zFilename;
521
522 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
523 zFilename = malloc( nByte );
524 if( zFilename==0 ){
525 return 0;
526 }
527 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
528 0, 0);
529 if( nByte == 0 ){
530 free(zFilename);
531 zFilename = 0;
532 }
533 return zFilename;
534 }
535 /*
536 ** Convert an ansi string to microsoft unicode, based on the
537 ** current codepage settings for file apis.
538 **
539 ** Space to hold the returned string is obtained
540 ** from malloc.
541 */
542 static WCHAR *mbcsToUnicode(const char *zFilename){
543 int nByte;
544 WCHAR *zMbcsFilename;
545 int codepage = CP_ACP;
546
547 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
548 zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
549 if( zMbcsFilename==0 ){
550 return 0;
551 }
552
553 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
554 if( nByte==0 ){
555 free(zMbcsFilename);
556 zMbcsFilename = 0;
557 }
558 return zMbcsFilename;
559 }
560 /*
561 ** Convert multibyte character string to UTF-8. Space to hold the
562 ** returned string is obtained from malloc().
563 */
564 static char *mbcsToUtf8(const char *zFilename){
565 char *zFilenameUtf8;
566 WCHAR *zTmpWide;
567
568 zTmpWide = mbcsToUnicode(zFilename);
569 if( zTmpWide==0 ){
570 return 0;
571 }
572
573 zFilenameUtf8 = unicodeToUtf8(zTmpWide);
574 free(zTmpWide);
575 return zFilenameUtf8;
576 }
577 #endif /* __MINGW32__ */
578
579
580 /*
581 ** Initialize a new database file with the given schema. If anything
582 ** goes wrong, call db_err() to exit.
583 */
@@ -510,10 +589,13 @@
589 sqlite3 *db;
590 int rc;
591 const char *zSql;
592 va_list ap;
593
594 #ifdef __MINGW32__
595 zFileName = mbcsToUtf8(zFileName);
596 #endif
597 rc = sqlite3_open(zFileName, &db);
598 if( rc!=SQLITE_OK ){
599 db_err(sqlite3_errmsg(db));
600 }
601 sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
@@ -537,10 +619,13 @@
619 ** zDbName is the name of a database file. If no other database
620 ** file is open, then open this one. If another database file is
621 ** already open, then attach zDbName using the name zLabel.
622 */
623 void db_open_or_attach(const char *zDbName, const char *zLabel){
624 #ifdef __MINGW32__
625 zDbName = mbcsToUtf8(zDbName);
626 #endif
627 if( !g.db ){
628 int rc = sqlite3_open(zDbName, &g.db);
629 if( rc!=SQLITE_OK ){
630 db_err(sqlite3_errmsg(g.db));
631 }
632

Keyboard Shortcuts

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