Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Support UTF-8 filenames on OS/2 by converting them to and from the local codepage. Ticket 3052. (CVS 5014) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
cafa8ac2687890355a7faa751d71859e |
User & Date: | pweilbacher 2008-04-15 18:50:02.000 |
Context
2008-04-16
| ||
00:28 | Back out the zero-terminator optimization introduced in check-in (4915). Ticket #3056. (CVS 5015) (check-in: cce8deae2d user: drh tags: trunk) | |
2008-04-15
| ||
18:50 | Support UTF-8 filenames on OS/2 by converting them to and from the local codepage. Ticket 3052. (CVS 5014) (check-in: cafa8ac268 user: pweilbacher tags: trunk) | |
14:37 | Increment the version number. (CVS 5013) (check-in: a12fa0252c user: drh tags: trunk) | |
Changes
Changes to src/os.h.
︙ | ︙ | |||
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | # define INCL_DOSFILEMGR # define INCL_DOSERRORS # define INCL_DOSMISC # define INCL_DOSPROCESS # define INCL_DOSMODULEMGR # define INCL_DOSSEMAPHORES # include <os2.h> # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) #else # define SQLITE_TEMPNAME_SIZE 200 #endif /* If the SET_FULLSYNC macro is not defined above, then make it ** a no-op | > | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | # define INCL_DOSFILEMGR # define INCL_DOSERRORS # define INCL_DOSMISC # define INCL_DOSPROCESS # define INCL_DOSMODULEMGR # define INCL_DOSSEMAPHORES # include <os2.h> # include <uconv.h> # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) #else # define SQLITE_TEMPNAME_SIZE 200 #endif /* If the SET_FULLSYNC macro is not defined above, then make it ** a no-op |
︙ | ︙ |
Changes to src/os_os2.c.
︙ | ︙ | |||
287 288 289 290 291 292 293 | memset(&LockArea, 0, sizeof(LockArea)); memset(&UnlockArea, 0, sizeof(UnlockArea)); assert( pFile!=0 ); OSTRACE4( "LOCK %d %d was %d\n", pFile->h, locktype, pFile->locktype ); /* If there is already a lock of this type or more restrictive on the ** os2File, do nothing. Don't use the end_lock: exit path, as | | | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | memset(&LockArea, 0, sizeof(LockArea)); memset(&UnlockArea, 0, sizeof(UnlockArea)); assert( pFile!=0 ); OSTRACE4( "LOCK %d %d was %d\n", pFile->h, locktype, pFile->locktype ); /* If there is already a lock of this type or more restrictive on the ** os2File, do nothing. Don't use the end_lock: exit path, as ** sqlite3_mutex_enter() hasn't been called yet. */ if( pFile->locktype>=locktype ){ OSTRACE3( "LOCK %d %d ok (already held)\n", pFile->h, locktype ); return SQLITE_OK; } /* Make sure the locking sequence is correct |
︙ | ︙ | |||
548 549 550 551 552 553 554 555 556 557 558 559 560 561 | /* ** Return a vector of device characteristics. */ static int os2DeviceCharacteristics(sqlite3_file *id){ return 0; } /* ** This vector defines all the methods that can operate on an ** sqlite3_file for os2. */ static const sqlite3_io_methods os2IoMethod = { 1, /* iVersion */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | /* ** Return a vector of device characteristics. */ static int os2DeviceCharacteristics(sqlite3_file *id){ return 0; } /* ** Helper function to convert UTF-8 filenames to local OS/2 codepage. ** The two-step process: first convert the incoming UTF-8 string ** into UCS-2 and then from UCS-2 to the current codepage. ** The returned char pointer has to be freed. */ char *convertUtf8PathToCp(const char *in) { UconvObject uconv; UniChar ucsUtf8Cp[12], tempPath[CCHMAXPATH]; char *out; int rc = 0; out = (char *)calloc(CCHMAXPATH, 1); /* determine string for the conversion of UTF-8 which is CP1208 */ rc = UniMapCpToUcsCp(1208, ucsUtf8Cp, 12); rc = UniCreateUconvObject(ucsUtf8Cp, &uconv); rc = UniStrToUcs(uconv, tempPath, (char *)in, CCHMAXPATH); rc = UniFreeUconvObject(uconv); /* conversion for current codepage which can be used for paths */ rc = UniCreateUconvObject((UniChar *)L"@path=yes", &uconv); rc = UniStrFromUcs(uconv, out, tempPath, CCHMAXPATH); rc = UniFreeUconvObject(uconv); return out; } /* ** Helper function to convert filenames from local codepage to UTF-8. ** The two-step process: first convert the incoming codepage-specific ** string into UCS-2 and then from UCS-2 to the codepage of UTF-8. ** The returned char pointer has to be freed. */ char *convertCpPathToUtf8(const char *in) { UconvObject uconv; UniChar ucsUtf8Cp[12], tempPath[CCHMAXPATH]; char *out; int rc = 0; out = (char *)calloc(CCHMAXPATH, 1); /* conversion for current codepage which can be used for paths */ rc = UniCreateUconvObject((UniChar *)L"@path=yes", &uconv); rc = UniStrToUcs(uconv, tempPath, (char *)in, CCHMAXPATH); rc = UniFreeUconvObject(uconv); /* determine string for the conversion of UTF-8 which is CP1208 */ rc = UniMapCpToUcsCp(1208, ucsUtf8Cp, 12); rc = UniCreateUconvObject(ucsUtf8Cp, &uconv); rc = UniStrFromUcs(uconv, out, tempPath, CCHMAXPATH); rc = UniFreeUconvObject(uconv); return out; } /* ** This vector defines all the methods that can operate on an ** sqlite3_file for os2. */ static const sqlite3_io_methods os2IoMethod = { 1, /* iVersion */ |
︙ | ︙ | |||
593 594 595 596 597 598 599 | ULONG ulFileAttribute = 0; ULONG ulOpenFlags = 0; ULONG ulOpenMode = 0; os2File *pFile = (os2File*)id; APIRET rc = NO_ERROR; ULONG ulAction; | | | 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | ULONG ulFileAttribute = 0; ULONG ulOpenFlags = 0; ULONG ulOpenMode = 0; os2File *pFile = (os2File*)id; APIRET rc = NO_ERROR; ULONG ulAction; memset( pFile, 0, sizeof(*pFile) ); OSTRACE2( "OPEN want %d\n", flags ); //ulOpenMode = flags & SQLITE_OPEN_READWRITE ? OPEN_ACCESS_READWRITE : OPEN_ACCESS_READONLY; if( flags & SQLITE_OPEN_READWRITE ){ ulOpenMode |= OPEN_ACCESS_READWRITE; OSTRACE1( "OPEN read/write\n" ); |
︙ | ︙ | |||
643 644 645 646 647 648 649 | OSTRACE1( "OPEN normal file attribute\n" ); } /* always open in random access mode for possibly better speed */ ulOpenMode |= OPEN_FLAGS_RANDOM; ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR; | > | > | 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | OSTRACE1( "OPEN normal file attribute\n" ); } /* always open in random access mode for possibly better speed */ ulOpenMode |= OPEN_FLAGS_RANDOM; ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR; char *zNameCp = convertUtf8PathToCp( zName ); rc = DosOpen( (PSZ)zNameCp, &h, &ulAction, 0L, ulFileAttribute, ulOpenFlags, ulOpenMode, (PEAOP2)NULL ); free( zNameCp ); if( rc != NO_ERROR ){ OSTRACE7( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulAttr=%#lx, ulFlags=%#lx, ulMode=%#lx\n", rc, zName, ulAction, ulFileAttribute, ulOpenFlags, ulOpenMode ); if( flags & SQLITE_OPEN_READWRITE ){ OSTRACE2( "OPEN %d Invalid handle\n", ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE) ); return os2Open( 0, zName, id, ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE), |
︙ | ︙ | |||
685 686 687 688 689 690 691 | int os2Delete( sqlite3_vfs *pVfs, /* Not used on os2 */ const char *zFilename, /* Name of file to delete */ int syncDir /* Not used on os2 */ ){ APIRET rc = NO_ERROR; SimulateIOError(return SQLITE_IOERR_DELETE); | > | > | > | > | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | int os2Delete( sqlite3_vfs *pVfs, /* Not used on os2 */ const char *zFilename, /* Name of file to delete */ int syncDir /* Not used on os2 */ ){ APIRET rc = NO_ERROR; SimulateIOError(return SQLITE_IOERR_DELETE); char *zFilenameCp = convertUtf8PathToCp( zFilename ); rc = DosDelete( (PSZ)zFilenameCp ); free( zFilenameCp ); OSTRACE2( "DELETE \"%s\"\n", zFilename ); return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; } /* ** Check the existance and status of a file. */ static int os2Access( sqlite3_vfs *pVfs, /* Not used on os2 */ const char *zFilename, /* Name of file to check */ int flags /* Type of test to make on this file */ ){ FILESTATUS3 fsts3ConfigInfo; APIRET rc = NO_ERROR; memset( &fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo) ); char *zFilenameCp = convertUtf8PathToCp( zFilename ); rc = DosQueryPathInfo( (PSZ)zFilenameCp, FIL_STANDARD, &fsts3ConfigInfo, sizeof(FILESTATUS3) ); free( zFilenameCp ); OSTRACE4( "ACCESS fsts3ConfigInfo.attrFile=%d flags=%d rc=%d\n", fsts3ConfigInfo.attrFile, flags, rc ); switch( flags ){ case SQLITE_ACCESS_READ: case SQLITE_ACCESS_EXISTS: rc = (rc == NO_ERROR); OSTRACE3( "ACCESS %s access of read and exists rc=%d\n", zFilename, rc ); |
︙ | ︙ | |||
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | static const unsigned char zChars[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; char zTempPathBuf[3]; PSZ zTempPath = (PSZ)&zTempPathBuf; if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){ if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){ if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){ ULONG ulDriveNum = 0, ulDriveMap = 0; DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap ); sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) ); } } } /* strip off a trailing slashes or backslashes, otherwise we would get * * multiple (back)slashes which causes DosOpen() to fail */ j = strlen(zTempPath); while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/' ) ){ j--; } zTempPath[j] = '\0'; sqlite3_snprintf( nBuf-30, zBuf, | > > | > | 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | static const unsigned char zChars[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; char zTempPathBuf[3]; PSZ zTempPath = (PSZ)&zTempPathBuf; char *zTempPathUTF; if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){ if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){ if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){ ULONG ulDriveNum = 0, ulDriveMap = 0; DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap ); sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) ); } } } /* strip off a trailing slashes or backslashes, otherwise we would get * * multiple (back)slashes which causes DosOpen() to fail */ j = strlen(zTempPath); while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/' ) ){ j--; } zTempPath[j] = '\0'; zTempPathUTF = convertCpPathToUtf8( zTempPath ); sqlite3_snprintf( nBuf-30, zBuf, "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPathUTF ); free( zTempPathUTF ); j = strlen( zBuf ); sqlite3_randomness( 20, &zBuf[j] ); for( i = 0; i < 20; i++, j++ ){ zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; OSTRACE2( "TEMP FILENAME: %s\n", zBuf ); |
︙ | ︙ | |||
775 776 777 778 779 780 781 | */ static int os2FullPathname( sqlite3_vfs *pVfs, /* Pointer to vfs object */ const char *zRelative, /* Possibly relative input path */ int nFull, /* Size of output buffer in bytes */ char *zFull /* Output buffer */ ){ | > > > | > > > > > > | > | 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 | */ static int os2FullPathname( sqlite3_vfs *pVfs, /* Pointer to vfs object */ const char *zRelative, /* Possibly relative input path */ int nFull, /* Size of output buffer in bytes */ char *zFull /* Output buffer */ ){ char *zRelativeCp = convertUtf8PathToCp( zRelative ); char zFullCp[CCHMAXPATH]; char *zFullUTF; APIRET rc = DosQueryPathInfo( zRelativeCp, FIL_QUERYFULLNAME, zFullCp, CCHMAXPATH ); free( zRelativeCp ); zFullUTF = convertCpPathToUtf8( zFullCp ); sqlite3_snprintf( nFull, zFull, zFullUTF ); free( zFullUTF ); return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; } #ifndef SQLITE_OMIT_LOAD_EXTENSION /* ** Interfaces for opening a shared library, finding entry points ** within the shared library, and closing the shared library. */ /* ** Interfaces for opening a shared library, finding entry points ** within the shared library, and closing the shared library. */ static void *os2DlOpen(sqlite3_vfs *pVfs, const char *zFilename){ UCHAR loadErr[256]; HMODULE hmod; APIRET rc; char *zFilenameCp = convertUtf8PathToCp(zFilename); rc = DosLoadModule((PSZ)loadErr, sizeof(loadErr), zFilenameCp, &hmod); free(zFilenameCp); return rc != NO_ERROR ? 0 : (void*)hmod; } /* ** A no-op since the error code is returned on the DosLoadModule call. ** os2Dlopen returns zero if DosLoadModule is not successful. */ static void os2DlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
︙ | ︙ |
Changes to src/shell.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** ** $Id: shell.c,v 1.177 2008/04/15 18:50:02 pweilbacher Exp $ */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <assert.h> #include "sqlite3.h" #include <ctype.h> |
︙ | ︙ | |||
1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 | i++; }else if( strcmp(argv[i],"-init")==0 ){ i++; zInitFile = argv[i]; } } if( i<argc ){ data.zDbFilename = argv[i++]; }else{ #ifndef SQLITE_OMIT_MEMORYDB data.zDbFilename = ":memory:"; #else data.zDbFilename = 0; #endif } | > > > > | 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 | i++; }else if( strcmp(argv[i],"-init")==0 ){ i++; zInitFile = argv[i]; } } if( i<argc ){ #ifdef OS_OS2 data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] ); #else data.zDbFilename = argv[i++]; #endif }else{ #ifndef SQLITE_OMIT_MEMORYDB data.zDbFilename = ":memory:"; #else data.zDbFilename = 0; #endif } |
︙ | ︙ |