summaryrefslogtreecommitdiffstats
path: root/src/libs/7zip/unix/CPP/myWindows
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/7zip/unix/CPP/myWindows')
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/myAddExeFlag.cpp20
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp146
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/myGetTickCount.cpp8
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/mySplitCommandLine.cpp82
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/test_emul.cpp745
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/wine_GetXXXDefaultLangID.cpp741
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/wine_date_and_time.cpp434
7 files changed, 146 insertions, 2030 deletions
diff --git a/src/libs/7zip/unix/CPP/myWindows/myAddExeFlag.cpp b/src/libs/7zip/unix/CPP/myWindows/myAddExeFlag.cpp
deleted file mode 100644
index 6bdc34ac3..000000000
--- a/src/libs/7zip/unix/CPP/myWindows/myAddExeFlag.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "StdAfx.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <windows.h>
-
-#define NEED_NAME_WINDOWS_TO_UNIX
-#include "myPrivate.h"
-
-#include "Common/StringConvert.h"
-
-void myAddExeFlag(const UString &u_name)
-{
- AString filename = UnicodeStringToMultiByte(u_name, CP_ACP); // FIXME
- const char * name = nameWindowToUnix(filename);
- // printf("myAddExeFlag(%s)\n",name);
- chmod(name,0700);
-}
-
diff --git a/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp b/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp
new file mode 100644
index 000000000..1773feb86
--- /dev/null
+++ b/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp
@@ -0,0 +1,146 @@
+/**************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include <QDebug>
+#include <QDateTime>
+#include "windows.h"
+
+void FileTimeToDateTime(const FILETIME *source, QDateTime *target)
+{
+ ULARGE_INTEGER store;
+ QDateTime tempDateTime(QDate(1601, 1, 1));
+
+ store.QuadPart = source->dwHighDateTime;
+ store.QuadPart = store.QuadPart << 32;
+ store.QuadPart += source->dwLowDateTime;
+
+ *target = tempDateTime.addMSecs(store.QuadPart / 10000);
+}
+
+void DateTimeToSystemTime(const QDateTime *source, SYSTEMTIME *target)
+{
+ target->wYear = source->date().year();
+ target->wMonth = source->date().month();
+ target->wDayOfWeek = source->date().dayOfWeek();
+ target->wDay = source->date().day();
+ target->wHour = source->time().hour();
+ target->wMinute = source->time().minute();
+ target->wSecond = source->time().second();
+ target->wMilliseconds = source->time().msec();
+}
+
+
+BOOL WINAPI FileTimeToSystemTime(CONST FILETIME *source,SYSTEMTIME *target)
+{
+ QDateTime tempDateTime;
+ FileTimeToDateTime(source, &tempDateTime);
+ DateTimeToSystemTime(&tempDateTime, target);
+
+ return TRUE;
+}
+
+BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *source,FILETIME *target)
+{
+ // TODO: Implementation!
+ // This doesn't seem to be called at all
+
+ qDebug() << "SystemTimeToFileTime";
+
+ target->dwHighDateTime = 0;
+ target->dwLowDateTime = 0;
+
+ qWarning() << Q_FUNC_INFO;
+
+ return TRUE;
+}
+
+BOOL WINAPI FileTimeToLocalFileTime(CONST FILETIME *source,FILETIME *target)
+{
+ target->dwHighDateTime = source->dwHighDateTime;
+ target->dwLowDateTime = source->dwLowDateTime;
+
+ QDateTime tempDateTime;
+ FileTimeToDateTime(source, &tempDateTime);
+
+ tempDateTime = tempDateTime.toLocalTime();
+
+ return TRUE;
+}
+
+BOOLEAN WINAPI RtlTimeToSecondsSince1970(const LARGE_INTEGER *Time, DWORD *Seconds)
+{
+ SYSTEMTIME tempSystemTime;
+ FILETIME fileTime;
+
+ fileTime.dwLowDateTime = Time->QuadPart;
+ fileTime.dwHighDateTime = Time->QuadPart >> 32;
+
+ FileTimeToSystemTime(&fileTime, &tempSystemTime);
+
+ QDate targetDate(tempSystemTime.wYear, tempSystemTime.wMonth, tempSystemTime.wDay);
+ QTime targetTime(tempSystemTime.wHour, tempSystemTime.wMinute, tempSystemTime.wSecond, tempSystemTime.wMilliseconds);
+ QDateTime targetDateTime(targetDate, targetTime, Qt::UTC);
+
+ quint64 secsSince1970 = targetDateTime.toMSecsSinceEpoch() / 1000;
+
+ *Seconds = secsSince1970;
+
+ return TRUE;
+}
+
+void WINAPI RtlSecondsSince1970ToFileTime(DWORD Seconds, FILETIME *ft)
+{
+ QDateTime fileTimeStartDate(QDate(1601, 1, 1));
+ quint64 hnseconds = Seconds;
+ QDateTime sourceDateTime = QDateTime::fromMSecsSinceEpoch(hnseconds * 1000);
+
+ hnseconds = fileTimeStartDate.msecsTo(sourceDateTime);
+ hnseconds *= 10000;
+
+ ft->dwLowDateTime = hnseconds;
+ ft->dwHighDateTime = hnseconds >> 32;
+}
+
+VOID WINAPI GetSystemTime(SYSTEMTIME *st)
+{
+ QDateTime nowDateTime = QDateTime::currentDateTimeUtc();
+ DateTimeToSystemTime(&nowDateTime, st);
+}
diff --git a/src/libs/7zip/unix/CPP/myWindows/myGetTickCount.cpp b/src/libs/7zip/unix/CPP/myWindows/myGetTickCount.cpp
deleted file mode 100644
index 6a6080b35..000000000
--- a/src/libs/7zip/unix/CPP/myWindows/myGetTickCount.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "StdAfx.h"
-
-#include <time.h>
-
-DWORD WINAPI GetTickCount(VOID) {
- return (DWORD)time(0); // FIXME : but only for the seed of the random generator
-}
-
diff --git a/src/libs/7zip/unix/CPP/myWindows/mySplitCommandLine.cpp b/src/libs/7zip/unix/CPP/myWindows/mySplitCommandLine.cpp
deleted file mode 100644
index 9e0791992..000000000
--- a/src/libs/7zip/unix/CPP/myWindows/mySplitCommandLine.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#include "StdAfx.h"
-
-#include "../Common/StringConvert.h"
-
-#include "myPrivate.h"
-
-#ifdef ENV_HAVE_LOCALE
-#include <locale.h>
-#endif
-
-extern void my_windows_split_path(const AString &p_path, AString &dir , AString &base);
-
-void mySplitCommandLine(int numArguments,const char *arguments[],UStringVector &parts) {
-
- { // define P7ZIP_HOME_DIR
- static char p7zip_home_dir[MAX_PATH];
- AString dir,name;
- my_windows_split_path(arguments[0],dir,name);
- snprintf(p7zip_home_dir,sizeof(p7zip_home_dir),"P7ZIP_HOME_DIR=%s/",(const char *)dir);
- p7zip_home_dir[sizeof(p7zip_home_dir)-1] = 0;
- putenv(p7zip_home_dir);
- }
-
-#ifdef ENV_HAVE_LOCALE
- // set the program's current locale from the user's environment variables
- setlocale(LC_ALL,"");
-
-
- // auto-detect which conversion p7zip should use
- char *locale = setlocale(LC_CTYPE,0);
- if (locale) {
- size_t len = strlen(locale);
- char *locale_upper = (char *)malloc(len+1);
- if (locale_upper) {
- strcpy(locale_upper,locale);
-
- for(size_t i=0;i<len;i++)
- locale_upper[i] = toupper(locale_upper[i] & 255);
-
- if ( (strcmp(locale_upper,"") != 0)
- && (strcmp(locale_upper,"C") != 0)
- && (strcmp(locale_upper,"POSIX") != 0) ) {
- global_use_utf16_conversion = 1;
- }
- free(locale_upper);
- }
- }
-#elif defined(LOCALE_IS_UTF8)
- global_use_utf16_conversion = 1; // assume LC_CTYPE="utf8"
-#else
- global_use_utf16_conversion = 0; // assume LC_CTYPE="C"
-#endif
-
- parts.Clear();
- for(int ind=0;ind < numArguments; ind++) {
- if ((ind <= 2) && (strcmp(arguments[ind],"-no-utf16") == 0)) {
- global_use_utf16_conversion = 0;
- } else if ((ind <= 2) && (strcmp(arguments[ind],"-utf16") == 0)) {
- global_use_utf16_conversion = 1;
- } else {
- UString tmp = MultiByteToUnicodeString(arguments[ind]);
- // tmp.Trim(); " " is a valid filename ...
- if (!tmp.IsEmpty()) {
- parts.Add(tmp);
- }
- }
- }
-}
-
-const char *my_getlocale(void) {
-#ifdef ENV_HAVE_LOCALE
- const char* ret = setlocale(LC_CTYPE,0);
- if (ret == 0)
- ret ="C";
- return ret;
-#elif defined(LOCALE_IS_UTF8)
- return "utf8";
-#else
- return "C";
-#endif
-}
-
diff --git a/src/libs/7zip/unix/CPP/myWindows/test_emul.cpp b/src/libs/7zip/unix/CPP/myWindows/test_emul.cpp
deleted file mode 100644
index 1c8d3261d..000000000
--- a/src/libs/7zip/unix/CPP/myWindows/test_emul.cpp
+++ /dev/null
@@ -1,745 +0,0 @@
-#undef BIG_ENDIAN
-#undef LITTLE_ENDIAN
-
-#include "StdAfx.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <unistd.h>
-
-#ifdef __APPLE_CC__
-#define UInt32 macUIn32
-#include <CoreFoundation/CoreFoundation.h>
-#undef UInt32
-#endif
-
-#ifdef ENV_HAVE_WCHAR__H
-#include <wchar.h>
-#endif
-#ifdef ENV_HAVE_LOCALE
-#include <locale.h>
-#endif
-
-#include <windows.h>
-
-#define NEED_NAME_WINDOWS_TO_UNIX
-// #include "myPrivate.h"
-
-#include "Common/StringConvert.h"
-#include "Common/StdOutStream.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-#include "Common/StringConvert.cpp"
-#include "Common/StdOutStream.cpp"
-#include "Common/IntToString.cpp"
-
-#include "Windows/Synchronization.cpp"
-#include "Windows/FileFind.cpp"
-#include "Windows/Time.cpp"
-#include "../C/Threads.c"
-#include "../../C/Ppmd.h"
-
-using namespace NWindows;
-
-#if defined(ENV_HAVE_WCHAR__H) && defined(ENV_HAVE_MBSTOWCS) && defined(ENV_HAVE_WCSTOMBS)
-void test_mbs(void) {
- wchar_t wstr1[256] = {
- L'e',
- 0xE8, // latin small letter e with grave
- 0xE9, // latin small letter e with acute
- L'a',
- 0xE0, // latin small letter a with grave
- 0x20AC, // euro sign
- L'b',
- 0 };
- wchar_t wstr2[256];
- char astr[256];
-
- global_use_utf16_conversion = 1;
-
- size_t len1 = wcslen(wstr1);
-
- printf("wstr1 - %d - '%ls'\n",(int)len1,wstr1);
-
- size_t len0 = wcstombs(astr,wstr1,sizeof(astr));
- printf("astr - %d - '%s'\n",(int)len0,astr);
-
- size_t len2 = mbstowcs(wstr2,astr,sizeof(wstr2)/sizeof(*wstr2));
- printf("wstr - %d - '%ls'\n",(int)len2,wstr2);
-
- if (wcscmp(wstr1,wstr2) != 0) {
- printf("ERROR during conversions wcs -> mbs -> wcs\n");
- exit(EXIT_FAILURE);
- }
-
- char *ptr = astr;
- size_t len = 0;
- while (*ptr) {
- ptr = CharNextA(ptr);
- len += 1;
- }
- if ((len != len1) && (len != 12)) { // 12 = when locale is UTF8 instead of ISO8859-15
- printf("ERROR CharNextA : len=%d, len1=%d\n",(int)len,(int)len1);
- exit(EXIT_FAILURE);
- }
-
- UString ustr(wstr1);
- assert(ustr.Length() == (int)len1);
-
- AString ansistr(astr);
- assert(ansistr.Length() == (int)len0);
-
- ansistr = UnicodeStringToMultiByte(ustr);
- assert(ansistr.Length() == (int)len0);
-
- assert(strcmp(ansistr,astr) == 0);
- assert(wcscmp(ustr,wstr1) == 0);
-
- UString ustr2 = MultiByteToUnicodeString(astr);
- assert(ustr2.Length() == (int)len1);
- assert(wcscmp(ustr2,wstr1) == 0);
-}
-#endif
-
-static void test_astring(int num) {
- AString strResult;
-
- strResult = "first part : ";
- char number[256];
- sprintf(number,"%d",num);
- strResult += AString(number);
-
- strResult += " : last part";
-
- printf("strResult -%s-\n",(const char *)strResult);
-
-}
-
-
-extern void my_windows_split_path(const AString &p_path, AString &dir , AString &base);
-
-static struct {
- const char *path;
- const char *dir;
- const char *base;
-}
-tabSplit[]=
- {
- { "",".","." },
- { "/","/","/" },
- { ".",".","." },
- { "//","/","/" },
- { "///","/","/" },
- { "dir",".","dir" },
- { "/dir","/","dir" },
- { "/dir/","/","dir" },
- { "/dir/base","/dir","base" },
- { "/dir//base","/dir","base" },
- { "/dir///base","/dir","base" },
- { "//dir/base","//dir","base" },
- { "///dir/base","///dir","base" },
- { "/dir/base/","/dir","base" },
- { 0,0,0 }
- };
-
-static void test_split_astring() {
- int ind = 0;
- while (tabSplit[ind].path) {
- AString path(tabSplit[ind].path);
- AString dir;
- AString base;
-
- my_windows_split_path(path,dir,base);
-
- if ((dir != tabSplit[ind].dir) || (base != tabSplit[ind].base)) {
- printf("ERROR : '%s' '%s' '%s'\n",(const char *)path,(const char *)dir,(const char *)base);
- }
- ind++;
- }
- printf("test_split_astring : done\n");
-}
-
- // Number of 100 nanosecond units from 1/1/1601 to 1/1/1970
-#define EPOCH_BIAS 116444736000000000LL
-static LARGE_INTEGER UnixTimeToUL(time_t tps_unx)
-{
- LARGE_INTEGER ul;
- ul.QuadPart = tps_unx * 10000000LL + EPOCH_BIAS;
- return ul;
-}
-
-static LARGE_INTEGER FileTimeToUL(FILETIME fileTime)
-{
- LARGE_INTEGER lFileTime;
- lFileTime.QuadPart = fileTime.dwHighDateTime;
- lFileTime.QuadPart = (lFileTime.QuadPart << 32) | fileTime.dwLowDateTime;
- return lFileTime;
-}
-
-static void display(const char *txt,SYSTEMTIME systime)
-{
- FILETIME fileTime;
- BOOL ret = SystemTimeToFileTime(&systime,&fileTime);
- assert(ret == TRUE);
- LARGE_INTEGER ulFileTime = FileTimeToUL(fileTime);
-
- const char * day="";
- switch (systime.wDayOfWeek)
- {
- case 0:day = "Sunday";break;
- case 1:day = "Monday";break;
- case 2:day = "Tuesday";break;
- case 3:day = "Wednesday";break;
- case 4:day = "Thursday";break;
- case 5:day = "Friday";break;
- case 6:day = "Saturday";break;
- }
- g_StdOut<< txt << day << " "
- << (int)systime.wYear << "/" << (int)systime.wMonth << "/" << (int)systime.wDay << " "
- << (int)systime.wHour << ":" << (int)systime.wMinute << ":" << (int)systime.wSecond << ":"
- << (int)systime.wMilliseconds
- << " (" << (UInt64)ulFileTime.QuadPart << ")\n";
-}
-
-static void test_time()
-{
- time_t tps_unx = time(0);
-
- printf("Test Time (1):\n");
- printf("===========\n");
- SYSTEMTIME systimeGM;
- GetSystemTime(&systimeGM);
-
- LARGE_INTEGER ul = UnixTimeToUL(tps_unx);
- g_StdOut<<" unix time = " << (UInt64)tps_unx << " (" << (UInt64)ul.QuadPart << ")\n";
-
- g_StdOut<<" gmtime : " << asctime(gmtime(&tps_unx))<<"\n";
- g_StdOut<<" localtime : " << asctime(localtime(&tps_unx))<<"\n";
-
- display(" GetSystemTime : ", systimeGM);
-}
-
-static void test_time2()
-{
- UInt32 dosTime = 0x30d0094C;
- FILETIME utcFileTime;
- FILETIME localFileTime;
- FILETIME localFileTime2;
- UInt32 dosTime2 = 0;
-
- printf("Test Time (2):\n");
- printf("===========\n");
- NTime::DosTimeToFileTime(dosTime, localFileTime);
- NTime::FileTimeToDosTime(localFileTime, dosTime2);
- assert(dosTime == dosTime2);
-
- printf("Test Time (3):\n");
- printf("===========\n");
- /* DosTime To utcFileTime */
-
- if (NTime::DosTimeToFileTime(dosTime, localFileTime)) /* DosDateTimeToFileTime */
- {
- if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- }
-
- printf(" - 0x%x => 0x%x 0x%x => 0x%x 0x%x\n",(unsigned)dosTime,
- (unsigned)localFileTime.dwHighDateTime,(unsigned)localFileTime.dwLowDateTime,
- (unsigned)utcFileTime.dwHighDateTime,(unsigned)utcFileTime.dwLowDateTime);
-
-
- /* utcFileTime to DosTime */
-
- FileTimeToLocalFileTime(&utcFileTime, &localFileTime2);
- NTime::FileTimeToDosTime(localFileTime2, dosTime2); /* FileTimeToDosDateTime */
-
- printf(" - 0x%x <= 0x%x 0x%x <= 0x%x 0x%x\n",(unsigned)dosTime2,
- (unsigned)localFileTime2.dwHighDateTime,(unsigned)localFileTime2.dwLowDateTime,
- (unsigned)utcFileTime.dwHighDateTime,(unsigned)utcFileTime.dwLowDateTime);
-
- assert(dosTime == dosTime2);
- assert(localFileTime.dwHighDateTime == localFileTime2.dwHighDateTime);
- assert(localFileTime.dwLowDateTime == localFileTime2.dwLowDateTime);
-}
-
-static void test_semaphore()
-{
- g_StdOut << "\nTEST SEMAPHORE :\n";
-
- NWindows::NSynchronization::CSynchro sync;
- NWindows::NSynchronization::CSemaphoreWFMO sema;
- bool bres;
- DWORD waitResult;
- int i;
-
- sync.Create();
- sema.Create(&sync,2,10);
-
- g_StdOut << " - Release(1)\n";
- for(i = 0 ;i < 8;i++)
- {
- // g_StdOut << " - Release(1) : "<< i << "\n";
- bres = sema.Release(1);
- assert(bres == S_OK);
- }
- // g_StdOut << " - Release(1) : done\n";
- bres = sema.Release(1);
- assert(bres == S_FALSE);
-
- g_StdOut << " - WaitForMultipleObjects(INFINITE)\n";
- HANDLE events[1] = { sema };
- for(i=0;i<10;i++)
- {
- waitResult = ::WaitForMultipleObjects(1, events, FALSE, INFINITE);
- assert(waitResult == WAIT_OBJECT_0);
- }
-
- g_StdOut << " Done\n";
-}
-
-
-/****************************************************************************************/
-
-
-static int threads_count = 0;
-
-static THREAD_FUNC_RET_TYPE thread_fct(void * /* param */ ) {
- threads_count++;
- return 0;
-}
-
-#define MAX_THREADS 100000
-
-int test_thread(void) {
- ::CThread thread;
-
- Thread_Construct(&thread);
-
- threads_count = 0;
-
- printf("test_thread : %d threads\n",MAX_THREADS);
-
- for(int i=0;i<MAX_THREADS;i++) {
- Thread_Create(&thread, thread_fct, 0);
-
- Thread_Wait(&thread);
-
- Thread_Close(&thread);
- }
-
- assert(threads_count == MAX_THREADS);
-
- return 0;
-}
-
-
-void dumpStr(const char *title,const char *txt)
-{
- size_t i,len = strlen(txt);
-
- printf("%s - %d :",title,(int)len);
-
- for(i = 0 ; i<len;i++) {
- printf(" 0x%02x",(unsigned)(txt[i] & 255));
- }
-
- printf("\n");
-}
-
-
-void dumpWStr(const char *title,const wchar_t *txt)
-{
- size_t i,len = wcslen(txt);
-
- printf("%s - %d :",title,(int)len);
-
- for(i = 0 ; i<len;i++) {
- printf(" 0x%02x",(unsigned)(txt[i]));
- }
-
- printf("\n");
-}
-
-#ifdef __APPLE_CC__
-
-void testMaxOSX_stringConvert()
-{
-/*
- 0xE8, // latin small letter e with grave
- 0xE9, // latin small letter e with acute
- L'a',
- 0xE0, // latin small letter a with grave
- 0x20AC, // euro sign
-*/
- struct
- {
- char astr [256];
- wchar_t ustr [256];
- }
- tab [] =
- {
- {
- // 'a' , 'e with acute' , 'e with grave' , 'a with grave' , 'u with grave' , 'b' , '.' , 't' , 'x' , 't'
- { 0x61, 0x65, 0xcc, 0x81 , 0x65, 0xcc, 0x80, 0x61, 0xcc, 0x80, 0x75, 0xcc, 0x80, 0x62, 0x2e, 0x74, 0x78, 0x74, 0 },
- { 0x61, 0xe9, 0xe8, 0xe0, 0xf9, 0x62, 0x2e, 0x74, 0x78, 0x74, 0 }
- },
- {
- // 'a' , 'euro sign' , 'b' , '.' , 't' , 'x' , 't' , '\n'
- { 0x61, 0xe2, 0x82, 0xac, 0x62, 0x2e, 0x74, 0x78, 0x74, 0x0a, 0 },
- { 0x61, 0x20AC, 0x62, 0x2e, 0x74, 0x78, 0x74, 0x0a, 0 }
- },
- {
- { 0 },
- { 0 }
- }
- };
-
- int i;
-
- printf("testMaxOSX_stringConvert : \n");
-
- i = 0;
- while (tab[i].astr[0])
- {
- printf(" %s\n",tab[i].astr);
-
- UString ustr = GetUnicodeString(tab[i].astr);
-
- // dumpWStr("1",&ustr[0]);
-
- assert(MyStringCompare(&ustr[0],tab[i].ustr) == 0);
- assert(ustr.Length() == wcslen(tab[i].ustr) );
-
-
- AString astr = GetAnsiString(ustr);
- assert(MyStringCompare(&astr[0],tab[i].astr) == 0);
- assert(astr.Length() == strlen(tab[i].astr) );
-
- i++;
- }
-}
-
-void testMacOSX()
-{
-// char texte1[]= { 0xc3 , 0xa9 , 0xc3, 0xa0, 0};
-
- wchar_t wpath1[4096] = {
- 0xE9, // latin small letter e with acute
- 0xE0,
- 0xc7,
- 0x25cc,
- 0x327,
- 0xe4,
- 0xe2,
- 0xc2,
- 0xc3,
- 0x2e,
- 0x74,
- 0x78,
- 0x74,
-/*
- L'e',
- 0xE8, // latin small letter e with grave
- 0xE9, // latin small letter e with acute
- L'a',
- 0xE0, // latin small letter a with grave
- 0x20AC, // euro sign
- L'b',
-*/
- 0 };
-
- char utf8[4096];
- wchar_t wpath2[4096];
-
-
-
- // dumpStr("UTF8 standart",texte1);
-
- dumpWStr("UCS32 standard",wpath1);
-
-// Translate into FS pathname
- {
- const wchar_t * wcs = wpath1;
-
- UniChar unipath[4096];
-
- long n = wcslen(wcs);
-
- for(long i = 0 ; i<= n ;i++) {
- unipath[i] = wcs[i];
- }
-
- CFStringRef cfpath = CFStringCreateWithCharacters(NULL,unipath,n);
-
- CFMutableStringRef cfpath2 = CFStringCreateMutableCopy(NULL,0,cfpath);
- CFRelease(cfpath);
- CFStringNormalize(cfpath2,kCFStringNormalizationFormD);
-
- CFStringGetCString(cfpath2,(char *)utf8,4096,kCFStringEncodingUTF8);
-
- CFRelease(cfpath2);
- }
-
- dumpStr("UTF8 MacOSX",utf8);
-
-// Translate from FS pathname
- {
- const char * path = utf8;
-
- long n = strlen(path);
-
- CFStringRef cfpath = CFStringCreateWithCString(NULL,path,kCFStringEncodingUTF8);
-
- if (cfpath)
- {
-
- CFMutableStringRef cfpath2 = CFStringCreateMutableCopy(NULL,0,cfpath);
- CFRelease(cfpath);
- CFStringNormalize(cfpath2,kCFStringNormalizationFormC);
-
- n = CFStringGetLength(cfpath2);
- for(long i = 0 ; i<= n ;i++) {
- wpath2[i] = CFStringGetCharacterAtIndex(cfpath2,i);
- }
- wpath2[n] = 0;
-
- CFRelease(cfpath2);
- }
- else
- {
- wpath2[0] = 0;
- }
- }
-
- dumpWStr("UCS32 standard (2)",wpath2);
-
-/*
- {
- CFStringRef cfpath;
-
- cfpath = CFStringCreateWithCString(kCFAllocatorDefault, texte1, kCFStringEncodingUTF8);
-
- // TODO str = null ?
-
- CFMutableStringRef cfpath2 = CFStringCreateMutableCopy(NULL,0,cfpaht);
- CFRealease(cfpath);
-
-
-
-
- }
-*/
-
-
-}
-#endif // __APPLE_CC__
-
-
-static const TCHAR *kMainDll = TEXT("7z.dll");
-
-static CSysString ConvertUInt32ToString(UInt32 value)
-{
- TCHAR buffer[32];
- ConvertUInt32ToString(value, buffer);
- return buffer;
-}
-
-
-void test_csystring(void)
-{
- {
- const CSysString baseFolder = TEXT("bin/");
- const CSysString b2 = baseFolder + kMainDll;
-
- assert(MyStringCompare(&b2[0],TEXT("bin/7z.dll")) == 0);
- }
-
- {
- LPCTSTR dirPath=TEXT("/tmp/");
- LPCTSTR prefix=TEXT("foo");
- CSysString resultPath;
-
- UINT number = 12345;
- UInt32 count = 6789;
-
-/*
- TCHAR * buf = resultPath.GetBuffer(MAX_PATH);
- ::swprintf(buf,MAX_PATH,L"%ls%ls#%d@%d.tmp",dirPath,prefix,(unsigned)number,count);
- buf[MAX_PATH-1]=0;
- resultPath.ReleaseBuffer();
-*/
- resultPath = dirPath;
- resultPath += prefix;
- resultPath += TEXT('#');
- resultPath += ConvertUInt32ToString(number);
- resultPath += TEXT('@');
- resultPath += ConvertUInt32ToString(count);
- resultPath += TEXT(".tmp");
-
- // printf("##%ls##\n",&resultPath[0]);
-
- assert(MyStringCompare(&resultPath[0],TEXT("/tmp/foo#12345@6789.tmp")) == 0);
- }
-
-}
-
-static void test_AString()
-{
- AString a;
-
- a = "abc";
- assert(MyStringCompare(&a[0],"abc") == 0);
- assert(a.Length() == 3);
-
- a = GetAnsiString(L"abc");
- assert(MyStringCompare(&a[0],"abc") == 0);
- assert(a.Length() == 3);
-}
-
-
-const TCHAR kAnyStringWildcard = '*';
-
-static void test_UString2(const UString &phyPrefix)
-{
- UString tmp = phyPrefix + wchar_t(kAnyStringWildcard);
- printf("Enum(%ls-%ls-%lc)\n",&tmp[0],&phyPrefix[0],wchar_t(kAnyStringWildcard));
-}
-
-
-
-static void test_UString()
-{
- UString us = L"7za433_tar";
-
- test_UString2(L"7za433_tar");
-
- UString u1(us);
- test_UString2(u1);
- u1 = L"";
- test_UString2(u1);
- u1 = us;
- test_UString2(u1);
-
- UString u2 = us;
- test_UString2(u2);
- u2 = L"";
- test_UString2(u2);
- u2 = u1;
- test_UString2(u2);
-
- u1 = L"abc";
- assert(MyStringCompare(&u1[0],L"abc") == 0);
- assert(u1.Length() == 3);
-
- u1 = GetUnicodeString("abc");
- assert(MyStringCompare(&u1[0],L"abc") == 0);
- assert(u1.Length() == 3);
-}
-
-/****************************************************************************************/
-int main() {
-
- // return test_thread();
-
-
-#ifdef ENV_HAVE_LOCALE
- setlocale(LC_ALL,"");
-#endif
-
-#if defined(BIG_ENDIAN)
- printf("BIG_ENDIAN : %d\n",(int)BIG_ENDIAN);
-#endif
-#if defined(LITTLE_ENDIAN)
- printf("LITTLE_ENDIAN : %d\n",(int)LITTLE_ENDIAN);
-#endif
-
- printf("sizeof(Byte) : %d\n",(int)sizeof(Byte));
- printf("sizeof(UInt16) : %d\n",(int)sizeof(UInt16));
- printf("sizeof(UInt32) : %d\n",(int)sizeof(UInt32));
- printf("sizeof(UINT32) : %d\n",(int)sizeof(UINT32));
- printf("sizeof(UInt64) : %d\n",(int)sizeof(UInt64));
- printf("sizeof(UINT64) : %d\n",(int)sizeof(UINT64));
- printf("sizeof(void *) : %d\n",(int)sizeof(void *));
- printf("sizeof(size_t) : %d\n",(int)sizeof(size_t));
- printf("sizeof(ptrdiff_t) : %d\n",(int)sizeof(ptrdiff_t));
- printf("sizeof(off_t) : %d\n",(int)sizeof(off_t));
- printf("sizeof(wchar_t) : %d\n",(int)sizeof(wchar_t));
-#ifdef __APPLE_CC__
- printf("sizeof(UniChar) : %d\n",(int)sizeof(UniChar));
-#endif
- printf("sizeof(CPpmd_See) : %d\n",(int)sizeof(CPpmd_See));
- printf("sizeof(CPpmd_State) : %d\n",(int)sizeof(CPpmd_State));
-
- // size tests
- assert(sizeof(Byte)==1);
- assert(sizeof(UInt16)==2);
- assert(sizeof(UInt32)==4);
- assert(sizeof(UINT32)==4);
- assert(sizeof(UInt64)==8);
- assert(sizeof(UINT64)==8);
-
- // alignement tests
- assert(sizeof(CPpmd_See)==4);
- assert(sizeof(CPpmd_State)==6);
-
- union {
- Byte b[2];
- UInt16 s;
- } u;
- u.s = 0x1234;
-
- if ((u.b[0] == 0x12) && (u.b[1] == 0x34)) {
- printf("CPU : big endian\n");
- } else if ((u.b[0] == 0x34) && (u.b[1] == 0x12)) {
- printf("CPU : little endian\n");
- } else {
- printf("CPU : unknown endianess\n");
- }
-
-#if defined(ENV_HAVE_WCHAR__H) && defined(ENV_HAVE_MBSTOWCS) && defined(ENV_HAVE_WCSTOMBS)
- test_mbs();
-#endif
-
- test_astring(12345);
- test_split_astring();
-
- test_csystring();
- test_AString();
- test_UString();
-
- test_time();
-
- test_time2();
-
- test_semaphore();
-
-#ifdef __APPLE_CC__
- testMacOSX();
- testMaxOSX_stringConvert();
-#endif
-
-
-{
- LANGID langID;
- WORD primLang;
- WORD subLang;
-
- langID = GetUserDefaultLangID();
- printf("langID=0x%x\n",langID);
-
- primLang = (WORD)(PRIMARYLANGID(langID));
- subLang = (WORD)(SUBLANGID(langID));
-
- printf("primLang=%d subLang=%d\n",(unsigned)primLang,(unsigned)subLang);
-}
-
- printf("\n### All Done ###\n\n");
-
- return 0;
-}
-
diff --git a/src/libs/7zip/unix/CPP/myWindows/wine_GetXXXDefaultLangID.cpp b/src/libs/7zip/unix/CPP/myWindows/wine_GetXXXDefaultLangID.cpp
deleted file mode 100644
index 918c4372c..000000000
--- a/src/libs/7zip/unix/CPP/myWindows/wine_GetXXXDefaultLangID.cpp
+++ /dev/null
@@ -1,741 +0,0 @@
-
-#include "StdAfx.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <locale.h>
-#include <wchar.h>
-#include <ctype.h>
-#include <string.h>
-
-#ifdef __APPLE__
-#define UInt32 mac_UInt32
-#include <CoreFoundation/CoreFoundation.h>
-#undef UInt32
-#endif // __APPLE__
-
-
-// #define TRACE printf
-
-typedef DWORD LCID;
-typedef void * ULONG_PTR; /* typedef unsigned long ULONG_PTR; */
-
-#define SORT_DEFAULT 0x0
-
-#define LANG_NEUTRAL 0x00
-#define LANG_ENGLISH 0x09
-
-#define SUBLANG_DEFAULT 0x01 /* user default */
-
-#define MAKELCID(l, s) ( (l & 0xFFFF) | ((s & 0xFFFF)<<16))
-#define MAKELANGID(p, s) ((((WORD)(s))<<10) | (WORD)(p))
-
-#define LANGIDFROMLCID(lcid) ((WORD)(lcid))
-
-static LCID lcid_LC_MESSAGES = 0;
-static LCID lcid_LC_CTYPE = 0;
-
-struct locale_name
-{
- WCHAR win_name[128]; /* Windows name ("en-US") */
- WCHAR lang[128]; /* language ("en") (note: buffer contains the other strings too) */
- WCHAR *country; /* country ("US") */
- WCHAR *charset; /* charset ("UTF-8") for Unix format only */
- WCHAR *script; /* script ("Latn") for Windows format only */
- WCHAR *modifier; /* modifier or sort order */
- LCID lcid; /* corresponding LCID */
- int matches; /* number of elements matching LCID (0..4) */
- UINT codepage; /* codepage corresponding to charset */
-};
-#define WINE_UNICODE_INLINE static
-
-/***********************************************************/
-typedef struct {
- const WCHAR * LOCALE_SNAME;
- const WCHAR * LOCALE_SISO639LANGNAME;
- const WCHAR * LOCALE_SISO3166CTRYNAME;
- unsigned int LOCALE_IDEFAULTUNIXCODEPAGE;
- unsigned int LOCALE_ILANGUAGE;
-} t_info;
-
-static t_info g_langInfo[] = {
- { L"af-ZA" , L"af" , L"ZA" , 28591 , 0x0436 }, /* afk.nls */
- { L"ar-SA" , L"ar" , L"SA" , 28596 , 0x0401 }, /* ara.nls */
- { L"ar-LB" , L"ar" , L"LB" , 28596 , 0x3001 }, /* arb.nls */
- { L"ar-EG" , L"ar" , L"EG" , 28596 , 0x0c01 }, /* are.nls */
- { L"ar-DZ" , L"ar" , L"DZ" , 28596 , 0x1401 }, /* arg.nls */
- { L"ar-BH" , L"ar" , L"BH" , 28596 , 0x3c01 }, /* arh.nls */
- { L"ar-IQ" , L"ar" , L"IQ" , 28596 , 0x0801 }, /* ari.nls */
- { L"ar-JO" , L"ar" , L"JO" , 28596 , 0x2c01 }, /* arj.nls */
- { L"ar-KW" , L"ar" , L"KW" , 28596 , 0x3401 }, /* ark.nls */
- { L"ar-LY" , L"ar" , L"LY" , 28596 , 0x1001 }, /* arl.nls */
- { L"ar-MA" , L"ar" , L"MA" , 28596 , 0x1801 }, /* arm.nls */
- { L"ar-OM" , L"ar" , L"OM" , 28596 , 0x2001 }, /* aro.nls */
- { L"ar-QA" , L"ar" , L"QA" , 28596 , 0x4001 }, /* arq.nls */
- { L"ar-SY" , L"ar" , L"SY" , 28596 , 0x2801 }, /* ars.nls */
- { L"ar-TN" , L"ar" , L"TN" , 28596 , 0x1c01 }, /* art.nls */
- { L"ar-AE" , L"ar" , L"AE" , 28596 , 0x3801 }, /* aru.nls */
- { L"ar-YE" , L"ar" , L"YE" , 28596 , 0x2401 }, /* ary.nls */
- { L"az-AZ" , L"az" , L"AZ" , 28595 , 0x082c }, /* aze.nls */
- { L"az-Latn-AZ" , L"az" , L"AZ" , 28599 , 0x042c }, /* azl.nls */
- { L"be-BY" , L"be" , L"BY" , 1251 , 0x0423 }, /* bel.nls */
- { L"bg-BG" , L"bg" , L"BG" , 1251 , 0x0402 }, /* bgr.nls */
- { L"br-FR" , L"br" , L"FR" , 28605 , 0x0493 }, /* brf.nls */
- { L"ca-ES" , L"ca" , L"ES" , 28605 , 0x0403 }, /* cat.nls */
- { L"zh-CN" , L"zh" , L"CN" , 936 , 0x0804 }, /* chs.nls */
- { L"zh-TW" , L"zh" , L"TW" , 950 , 0x0404 }, /* cht.nls */
- { L"kw-GB" , L"kw" , L"GB" , 28605 , 0x04891 }, /* cor.nls */
- { L"cs-CZ" , L"cs" , L"CZ" , 28592 , 0x0405 }, /* csy.nls */
- { L"cy-GB" , L"cy" , L"GB" , 28604 , 0x0492 }, /* cym.nls */
- { L"da-DK" , L"da" , L"DK" , 28605 , 0x0406 }, /* dan.nls */
- { L"de-AT" , L"de" , L"AT" , 28605 , 0x0c07 }, /* dea.nls */
- { L"de-LI" , L"de" , L"LI" , 28605 , 0x1407 }, /* dec.nls */
- { L"de-LU" , L"de" , L"LU" , 28605 , 0x1007 }, /* del.nls */
- { L"de-CH" , L"de" , L"CH" , 28605 , 0x0807 }, /* des.nls */
- { L"de-DE" , L"de" , L"DE" , 28605 , 0x0407 }, /* deu.nls */
- { L"dv-MV" , L"dv" , L"MV" , 65001 , 0x0465 }, /* div.nls */
- { L"el-GR" , L"el" , L"GR" , 28597 , 0x0408 }, /* ell.nls */
- { L"en-AU" , L"en" , L"AU" , 28591 , 0x0c09 }, /* ena.nls */
- { L"en-CB" , L"en" , L"CB" , 28591 , 0x2409 }, /* enb.nls */
- { L"en-CA" , L"en" , L"CA" , 28591 , 0x1009 }, /* enc.nls */
- { L"en-GB" , L"en" , L"GB" , 28605 , 0x0809 }, /* eng.nls */
- { L"en-IE" , L"en" , L"IE" , 28605 , 0x1809 }, /* eni.nls */
- { L"en-JM" , L"en" , L"JM" , 28591 , 0x2009 }, /* enj.nls */
- { L"en-BZ" , L"en" , L"BZ" , 28591 , 0x2809 }, /* enl.nls */
- { L"en-PH" , L"en" , L"PH" , 28591 , 0x3409 }, /* enp.nls */
- { L"en-ZA" , L"en" , L"ZA" , 28591 , 0x1c09 }, /* ens.nls */
- { L"en-TT" , L"en" , L"TT" , 28591 , 0x2c09 }, /* ent.nls */
- { L"en-US" , L"en" , L"US" , 28591 , 0x0409 }, /* enu.nls */
- { L"en-ZW" , L"en" , L"ZW" , 28591 , 0x3009 }, /* enw.nls */
- { L"en-NZ" , L"en" , L"NZ" , 28591 , 0x1409 }, /* enz.nls */
- { L"eo" , L"eo" , L"" , 65001 , 0x048f }, /* eox.nls */
- { L"es-PA" , L"es" , L"PA" , 28591 , 0x180a }, /* esa.nls */
- { L"es-BO" , L"es" , L"BO" , 28591 , 0x400a }, /* esb.nls */
- { L"es-CR" , L"es" , L"CR" , 28591 , 0x140a }, /* esc.nls */
- { L"es-DO" , L"es" , L"DO" , 28591 , 0x1c0a }, /* esd.nls */
- { L"es-SV" , L"es" , L"SV" , 28591 , 0x440a }, /* ese.nls */
- { L"es-EC" , L"es" , L"EC" , 28591 , 0x300a }, /* esf.nls */
- { L"es-GT" , L"es" , L"GT" , 28591 , 0x100a }, /* esg.nls */
- { L"es-HN" , L"es" , L"HN" , 28591 , 0x480a }, /* esh.nls */
- { L"es-NI" , L"es" , L"NI" , 28591 , 0x4c0a }, /* esi.nls */
- { L"es-C" , L"es" , L"C" , 28591 , 0x340a }, /* esl.nls */
- { L"es-MX" , L"es" , L"MX" , 28591 , 0x080a }, /* esm.nls */
- { L"es-ES_modern" , L"es" , L"ES" , 28605 , 0x0c0a }, /* esn.nls */
- { L"es-CO" , L"es" , L"CO" , 28591 , 0x240a }, /* eso.nls */
- { L"es-ES" , L"es" , L"ES" , 28605 , 0x040a }, /* esp.nls */
- { L"es-PE" , L"es" , L"PE" , 28591 , 0x280a }, /* esr.nls */
- { L"es-AR" , L"es" , L"AR" , 28591 , 0x2c0a }, /* ess.nls */
- { L"es-PR" , L"es" , L"PR" , 28591 , 0x500a }, /* esu.nls */
- { L"es-VE" , L"es" , L"VE" , 28591 , 0x200a }, /* esv.nls */
- { L"es-UY" , L"es" , L"UY" , 28591 , 0x380a }, /* esy.nls */
- { L"es-PY" , L"es" , L"PY" , 28591 , 0x3c0a }, /* esz.nls */
- { L"et-EE" , L"et" , L"EE" , 28605 , 0x0425 }, /* eti.nls */
- { L"eu-ES" , L"eu" , L"ES" , 28605 , 0x042d }, /* euq.nls */
- { L"fa-IR" , L"fa" , L"IR" , 65001 , 0x0429 }, /* far.nls */
- { L"fi-FI" , L"fi" , L"FI" , 28605 , 0x040b }, /* fin.nls */
- { L"fo-FO" , L"fo" , L"FO" , 28605 , 0x0438 }, /* fos.nls */
- { L"fr-FR" , L"fr" , L"FR" , 28605 , 0x040c }, /* fra.nls */
- { L"fr-BE" , L"fr" , L"BE" , 28605 , 0x080c }, /* frb.nls */
- { L"fr-CA" , L"fr" , L"CA" , 28591 , 0x0c0c }, /* frc.nls */
- { L"fr-LU" , L"fr" , L"LU" , 28605 , 0x140c }, /* frl.nls */
- { L"fr-MC" , L"fr" , L"MC" , 28605 , 0x180c }, /* frm.nls */
- { L"fr-CH" , L"fr" , L"CH" , 28605 , 0x100c }, /* frs.nls */
- { L"ga-IE" , L"ga" , L"IE" , 28605 , 0x043c }, /* gae.nls */
- { L"gd-GB" , L"gd" , L"GB" , 28605 , 0x083c }, /* gdh.nls */
- { L"gv-GB" , L"gv" , L"GB" , 28605 , 0x0c3c }, /* gdv.nls */
- { L"gl-ES" , L"gl" , L"ES" , 28605 , 0x0456 }, /* glc.nls */
- { L"gu-IN" , L"gu" , L"IN" , 65001 , 0x0447 }, /* guj.nls */
- { L"he-I" , L"he" , L"I" , 28598 , 0x040d }, /* heb.nls */
- { L"hi-IN" , L"hi" , L"IN" , 65001 , 0x0439 }, /* hin.nls */
- { L"hr-HR" , L"hr" , L"HR" , 28592 , 0x041a }, /* hrv.nls */
- { L"hu-HU" , L"hu" , L"HU" , 28592 , 0x040e }, /* hun.nls */
- { L"hy-AM" , L"hy" , L"AM" , 65001 , 0x042b }, /* hye.nls */
- { L"id-ID" , L"id" , L"ID" , 28591 , 0x0421 }, /* ind.nls */
- { L"is-IS" , L"is" , L"IS" , 28605 , 0x040f }, /* isl.nls */
- { L"it-IT" , L"it" , L"IT" , 28605 , 0x0410 }, /* ita.nls */
- { L"it-CH" , L"it" , L"CH" , 28605 , 0x0810 }, /* its.nls */
- { L"ja-JP" , L"ja" , L"JP" , 20932 , 0x0411 }, /* jpn.nls */
- { L"kn-IN" , L"kn" , L"IN" , 65001 , 0x044b }, /* kan.nls */
- { L"ka-GE" , L"ka" , L"GE" , 65001 , 0x0437 }, /* kat.nls */
- { L"kk-KZ" , L"kk" , L"KZ" , 28595 , 0x043f }, /* kkz.nls */
- { L"kok-IN" , L"kok" , L"IN" , 65001 , 0x0457 }, /* knk.nls */
- { L"ko-KR" , L"ko" , L"KR" , 949 , 0x0412 }, /* kor.nls */
- { L"ky-KG" , L"ky" , L"KG" , 28595 , 0x0440 }, /* kyr.nls */
- { L"lt-LT" , L"lt" , L"LT" , 28603 , 0x0427 }, /* lth.nls */
- { L"lv-LV" , L"lv" , L"LV" , 28603 , 0x0426 }, /* lvi.nls */
- { L"mr-IN" , L"mr" , L"IN" , 65001 , 0x044e }, /* mar.nls */
- { L"mk-MK" , L"mk" , L"MK" , 28595 , 0x042f }, /* mki.nls */
- { L"mn-MN" , L"mn" , L"MN" , 28595 , 0x0450 }, /* mon.nls */
- { L"ms-BN" , L"ms" , L"BN" , 28591 , 0x083e }, /* msb.nls */
- { L"ms-MY" , L"ms" , L"MY" , 28591 , 0x043e }, /* msl.nls */
- { L"nl-BE" , L"nl" , L"BE" , 28605 , 0x0813 }, /* nlb.nls */
- { L"nl-N" , L"nl" , L"N" , 28605 , 0x0413 }, /* nld.nls */
- { L"nl-SR" , L"nl" , L"SR" , 28605 , 0x0c13 }, /* nls.nls */
- { L"nn-NO" , L"nn" , L"NO" , 28605 , 0x0814 }, /* non.nls */
- { L"nb-NO" , L"nb" , L"NO" , 28605 , 0x0414 }, /* nor.nls */
- { L"pa-IN" , L"pa" , L"IN" , 65001 , 0x0446 }, /* pan.nls */
- { L"pl-P" , L"pl" , L"P" , 28592 , 0x0415 }, /* plk.nls */
- { L"pt-BR" , L"pt" , L"BR" , 28591 , 0x0416 }, /* ptb.nls */
- { L"pt-PT" , L"pt" , L"PT" , 28605 , 0x0816 }, /* ptg.nls */
- { L"rm-CH" , L"rm" , L"CH" , 28605 , 0x0417 }, /* rmc.nls */
- { L"ro-RO" , L"ro" , L"RO" , 28592 , 0x0418 }, /* rom.nls */
- { L"ru-RU" , L"ru" , L"RU" , 20866 , 0x0419 }, /* rus.nls */
- { L"sa-IN" , L"sa" , L"IN" , 65001 , 0x044f }, /* san.nls */
- { L"sk-SK" , L"sk" , L"SK" , 28592 , 0x041b }, /* sky.nls */
- { L"sl-SI" , L"sl" , L"SI" , 28592 , 0x0424 }, /* slv.nls */
- { L"sq-A" , L"sq" , L"A" , 28592 , 0x041c }, /* sqi.nls */
- { L"sr-SP" , L"sr" , L"SP" , 28595 , 0x0c1a }, /* srb.nls */
- { L"sr-Latn-SP" , L"sr" , L"SP" , 28592 , 0x081a }, /* srl.nls */
- { L"sv-SE" , L"sv" , L"SE" , 28605 , 0x041d }, /* sve.nls */
- { L"sv-FI" , L"sv" , L"FI" , 28605 , 0x081d }, /* svf.nls */
- { L"sw-KE" , L"sw" , L"KE" , 28591 , 0x0441 }, /* swk.nls */
- { L"syr-SY" , L"syr" , L"SY" , 65001 , 0x045a }, /* syr.nls */
- { L"ta-IN" , L"ta" , L"IN" , 65001 , 0x0449 }, /* tam.nls */
- { L"te-IN" , L"te" , L"IN" , 65001 , 0x044a }, /* tel.nls */
- { L"th-TH" , L"th" , L"TH" , 874 , 0x041e }, /* tha.nls */
- { L"tr-TR" , L"tr" , L"TR" , 28599 , 0x041f }, /* trk.nls */
- { L"tt-TA" , L"tt" , L"TA" , 28595 , 0x0444 }, /* ttt.nls */
- { L"uk-UA" , L"uk" , L"UA" , 21866 , 0x0422 }, /* ukr.nls */
- { L"ur-PK" , L"ur" , L"PK" , 1256 , 0x0420 }, /* urd.nls */
- { L"uz-UZ" , L"uz" , L"UZ" , 28595 , 0x0843 }, /* uzb.nls */
- { L"uz-Latn-UZ" , L"uz" , L"UZ" , 28605 , 0x0443 }, /* uzl.nls */
- { L"vi-VN" , L"vi" , L"VN" , 1258 , 0x042a }, /* vit.nls */
- { L"wa-BE" , L"wa" , L"BE" , 28605 , 0x0490 }, /* wal.nls */
- { L"zh-HK" , L"zh" , L"HK" , 950 , 0x0c04 }, /* zhh.nls */
- { L"zh-SG" , L"zh" , L"SG" , 936 , 0x1004 }, /* zhi.nls */
- { L"zh-MO" , L"zh" , L"MO" , 950 , 0x1404 }, /* zhm.nls */
- { 0 , 0 , 0 , 0, 0 }
-};
-
-/***********************************************************/
-WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch )
-{
- do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
- return NULL;
-}
-
-WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
-{
- for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
- return NULL;
-}
-
-
-/***********************************************************/
-
-WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
-{
- const WCHAR *s = str;
- while (*s) s++;
- return s - str;
-}
-
-WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
-{
- WCHAR *p = dst;
- while ((*p++ = *src++));
- return dst;
-}
-
-WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
-{
- strcpyW( dst + strlenW(dst), src );
- return dst;
-}
-
-WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
-{
- while (*str1 && (*str1 == *str2)) { str1++; str2++; }
- return *str1 - *str2;
-}
-
-
-WINE_UNICODE_INLINE LPWSTR lstrcpynW( LPWSTR dst, LPCWSTR src, int n )
-{
- {
- LPWSTR d = dst;
- LPCWSTR s = src;
- UINT count = n;
-
- while ((count > 1) && *s)
- {
- count--;
- *d++ = *s++;
- }
- if (count) *d = 0;
- }
- return dst;
-}
-
-/* Copy Ascii string to Unicode without using codepages */
-static inline void strcpynAtoW( WCHAR *dst, const char *src, size_t n )
-{
- while (n > 1 && *src)
- {
- *dst++ = (unsigned char)*src++;
- n--;
- }
- if (n) *dst = 0;
-}
-
-/*******************************************************/
-
-/* Charset to codepage map, sorted by name. */
-static const struct charset_entry
-{
- const char *charset_name;
- UINT codepage;
-} charset_names[] =
-{
- { "BIG5", 950 },
- { "CP1250", 1250 },
- { "CP1251", 1251 },
- { "CP1252", 1252 },
- { "CP1253", 1253 },
- { "CP1254", 1254 },
- { "CP1255", 1255 },
- { "CP1256", 1256 },
- { "CP1257", 1257 },
- { "CP1258", 1258 },
- { "CP932", 932 },
- { "CP936", 936 },
- { "CP949", 949 },
- { "CP950", 950 },
- { "EUCJP", 20932 },
- { "GB2312", 936 },
- { "IBM037", 37 },
- { "IBM1026", 1026 },
- { "IBM424", 424 },
- { "IBM437", 437 },
- { "IBM500", 500 },
- { "IBM850", 850 },
- { "IBM852", 852 },
- { "IBM855", 855 },
- { "IBM857", 857 },
- { "IBM860", 860 },
- { "IBM861", 861 },
- { "IBM862", 862 },
- { "IBM863", 863 },
- { "IBM864", 864 },
- { "IBM865", 865 },
- { "IBM866", 866 },
- { "IBM869", 869 },
- { "IBM874", 874 },
- { "IBM875", 875 },
- { "ISO88591", 28591 },
- { "ISO885910", 28600 },
- { "ISO885913", 28603 },
- { "ISO885914", 28604 },
- { "ISO885915", 28605 },
- { "ISO885916", 28606 },
- { "ISO88592", 28592 },
- { "ISO88593", 28593 },
- { "ISO88594", 28594 },
- { "ISO88595", 28595 },
- { "ISO88596", 28596 },
- { "ISO88597", 28597 },
- { "ISO88598", 28598 },
- { "ISO88599", 28599 },
- { "KOI8R", 20866 },
- { "KOI8U", 21866 },
- { "UTF8", CP_UTF8 }
-};
-
-static int charset_cmp( const void *name, const void *entry )
-{
- const struct charset_entry *charset = (const struct charset_entry *)entry;
- return strcasecmp( (const char *)name, charset->charset_name );
-}
-
-static UINT find_charset( const WCHAR *name )
-{
- const struct charset_entry *entry;
- char charset_name[16];
- size_t i, j;
-
- /* remove punctuation characters from charset name */
- for (i = j = 0; name[i] && j < sizeof(charset_name)-1; i++)
- if (isalnum((unsigned char)name[i])) charset_name[j++] = name[i];
- charset_name[j] = 0;
-
- entry = (const struct charset_entry *)bsearch( charset_name, charset_names,
- sizeof(charset_names)/sizeof(charset_names[0]),
- sizeof(charset_names[0]), charset_cmp );
- if (entry) return entry->codepage;
-
- return 0;
-}
-/*******************************************************/
-
-static BOOL find_locale_id_callback(/* LPCWSTR name, ? */ const t_info * tab, struct locale_name *data)
-{
- // WCHAR buffer[128];
- int matches = 0;
- WORD LangID = tab->LOCALE_ILANGUAGE & 0xFFFF; /* FIXME */
- LCID lcid = MAKELCID( LangID, SORT_DEFAULT ); /* FIXME: handle sort order */
-
- if (PRIMARYLANGID(LangID) == LANG_NEUTRAL) return TRUE; /* continue search */
-
- /* first check exact name */
- if (data->win_name[0] && tab->LOCALE_SNAME[0])
- /* GetLocaleInfoW( lcid, LOCALE_SNAME | LOCALE_NOUSEROVERRIDE,
- buffer, sizeof(buffer)/sizeof(WCHAR) )) */
- {
- if (!strcmpW( data->win_name, tab->LOCALE_SNAME ))
- {
- matches = 4; /* everything matches */
- goto done;
- }
- }
-
- /*if (!GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME | LOCALE_NOUSEROVERRIDE,
- buffer, sizeof(buffer)/sizeof(WCHAR) )) */
- if (tab->LOCALE_SISO639LANGNAME[0] == 0)
- return TRUE;
-
- if (strcmpW( tab->LOCALE_SISO639LANGNAME , data->lang )) return TRUE;
- matches++; /* language name matched */
-
- if (data->country)
- {
- /* if (GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
- buffer, sizeof(buffer)/sizeof(WCHAR) )) */
- if (tab->LOCALE_SISO3166CTRYNAME[0])
- {
- if (strcmpW(tab->LOCALE_SISO3166CTRYNAME , data->country )) goto done;
- matches++; /* country name matched */
- }
- }
- else /* match default language */
- {
- if (SUBLANGID(LangID) == SUBLANG_DEFAULT) matches++;
- }
-
- if (data->codepage)
- {
- UINT unix_cp;
- /* if (GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
- (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) )) */
- unix_cp = tab->LOCALE_IDEFAULTUNIXCODEPAGE;
- {
- if (unix_cp == data->codepage) matches++;
- }
- }
-
- /* FIXME: check sort order */
-
-done:
- if (matches > data->matches)
- {
- data->lcid = lcid;
- data->matches = matches;
- }
- return (data->matches < 4); /* no need to continue for perfect match */
-}
-
-
-/***********************************************************************
- * parse_locale_name
- *
- * Parse a locale name into a struct locale_name, handling both Windows and Unix formats.
- * Unix format is: lang[_country][.charset][@modifier]
- * Windows format is: lang[-script][-country][_modifier]
- */
-static void parse_locale_name( const WCHAR *str, struct locale_name *name )
-{
- static const WCHAR sepW[] = {'-','_','.','@',0};
- static const WCHAR winsepW[] = {'-','_',0};
- static const WCHAR posixW[] = {'P','O','S','I','X',0};
- static const WCHAR cW[] = {'C',0};
- static const WCHAR latinW[] = {'l','a','t','i','n',0};
- static const WCHAR latnW[] = {'-','L','a','t','n',0};
- WCHAR *p;
- int ind;
-
- // TRACE("%s\n", debugstr_w(str));
-
- name->country = name->charset = name->script = name->modifier = NULL;
- name->lcid = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
- name->matches = 0;
- name->codepage = 0;
- name->win_name[0] = 0;
- lstrcpynW( name->lang, str, sizeof(name->lang)/sizeof(WCHAR) );
-
- if (!(p = strpbrkW( name->lang, sepW )))
- {
- if (!strcmpW( name->lang, posixW ) || !strcmpW( name->lang, cW ))
- {
- name->matches = 4; /* perfect match for default English lcid */
- return;
- }
- strcpyW( name->win_name, name->lang );
- }
- else if (*p == '-') /* Windows format */
- {
- strcpyW( name->win_name, name->lang );
- *p++ = 0;
- name->country = p;
- if (!(p = strpbrkW( p, winsepW ))) goto done;
- if (*p == '-')
- {
- *p++ = 0;
- name->script = name->country;
- name->country = p;
- if (!(p = strpbrkW( p, winsepW ))) goto done;
- }
- *p++ = 0;
- name->modifier = p;
- }
- else /* Unix format */
- {
- if (*p == '_')
- {
- *p++ = 0;
- name->country = p;
- p = strpbrkW( p, sepW + 2 );
- }
- if (p && *p == '.')
- {
- *p++ = 0;
- name->charset = p;
- p = strchrW( p, '@' );
- }
- if (p)
- {
- *p++ = 0;
- name->modifier = p;
- }
-
- if (name->charset)
- name->codepage = find_charset( name->charset );
-
- /* rebuild a Windows name if possible */
-
- if (name->charset) goto done; /* can't specify charset in Windows format */
- if (name->modifier && strcmpW( name->modifier, latinW ))
- goto done; /* only Latn script supported for now */
- strcpyW( name->win_name, name->lang );
- if (name->modifier) strcatW( name->win_name, latnW );
- if (name->country)
- {
- p = name->win_name + strlenW(name->win_name);
- *p++ = '-';
- strcpyW( p, name->country );
- }
- }
-done:
- ;
-
-/* DEBUG
- printf("EnumResourceLanguagesW(...):\n");
- printf(" name->win_name=%ls\n", name->win_name);
- printf(" name->lang=%ls\n", name->lang);
- printf(" name->country=%ls\n", name->country);
- printf(" name->codepage=%d\n", name->codepage);
-*/
-// EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING, (LPCWSTR)LOCALE_ILANGUAGE,
-// find_locale_id_callback, (LPARAM)name );
-
- ind = 0;
- while (g_langInfo[ind].LOCALE_SNAME)
- {
- BOOL ret = find_locale_id_callback(&g_langInfo[ind],name);
- if (ret == FALSE)
- break;
-
- ind++;
- }
-}
-
-
-
-
-/********************************/
-
-static UINT setup_unix_locales(void)
-{
- struct locale_name locale_name;
- // WCHAR buffer[128];
- WCHAR ctype_buff[128];
- char *locale;
- UINT unix_cp = 0;
-
- if ((locale = setlocale( LC_CTYPE, NULL )))
- {
- strcpynAtoW( ctype_buff, locale, sizeof(ctype_buff)/sizeof(WCHAR) );
- parse_locale_name( ctype_buff, &locale_name );
- lcid_LC_CTYPE = locale_name.lcid;
- unix_cp = locale_name.codepage;
- }
- if (!lcid_LC_CTYPE) /* this one needs a default value */
- lcid_LC_CTYPE = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
-
-#if 0
- TRACE( "got lcid %04x (%d matches) for LC_CTYPE=%s\n",
- locale_name.lcid, locale_name.matches, debugstr_a(locale) );
-
-#define GET_UNIX_LOCALE(cat) do \
- if ((locale = setlocale( cat, NULL ))) \
- { \
- strcpynAtoW( buffer, locale, sizeof(buffer)/sizeof(WCHAR) ); \
- if (!strcmpW( buffer, ctype_buff )) lcid_##cat = lcid_LC_CTYPE; \
- else { \
- parse_locale_name( buffer, &locale_name ); \
- lcid_##cat = locale_name.lcid; \
- TRACE( "got lcid %04x (%d matches) for " #cat "=%s\n", \
- locale_name.lcid, locale_name.matches, debugstr_a(locale) ); \
- } \
- } while (0)
-
- GET_UNIX_LOCALE( LC_COLLATE );
- GET_UNIX_LOCALE( LC_MESSAGES );
- GET_UNIX_LOCALE( LC_MONETARY );
- GET_UNIX_LOCALE( LC_NUMERIC );
- GET_UNIX_LOCALE( LC_TIME );
-#ifdef LC_PAPER
- GET_UNIX_LOCALE( LC_PAPER );
-#endif
-#ifdef LC_MEASUREMENT
- GET_UNIX_LOCALE( LC_MEASUREMENT );
-#endif
-#ifdef LC_TELEPHONE
- GET_UNIX_LOCALE( LC_TELEPHONE );
-#endif
-
-#undef GET_UNIX_LOCALE
-
-#endif // #if 0
-
- return unix_cp;
-}
-
-/********************************/
-
-static void LOCALE_Init(void)
-{
- /*
- extern void __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp,
- const union cptable *unix_cp );
- */
-
- // UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp;
- UINT unix_cp = 0;
-
-#ifdef __APPLE__
- /* MacOS doesn't set the locale environment variables so we have to do it ourselves */
- CFArrayRef preferred_locales, all_locales;
- CFStringRef user_language_string_ref = NULL;
- char user_locale[50];
-
- CFLocaleRef user_locale_ref = CFLocaleCopyCurrent();
- CFStringRef user_locale_string_ref = CFLocaleGetIdentifier( user_locale_ref );
-
- CFStringGetCString( user_locale_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
- CFRelease( user_locale_ref );
- if (!strchr( user_locale, '.' )) strcat( user_locale, ".UTF-8" );
- unix_cp = CP_UTF8; /* default to utf-8 even if we don't get a valid locale */
- setenv( "LANG", user_locale, 0 );
- // TRACE( "setting locale to '%s'\n", user_locale );
-
- /* We still want to set the retrieve the preferred language as chosen in
- System Preferences.app, because it can differ from CFLocaleCopyCurrent().
- */
- all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
- preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );
- if (preferred_locales && CFArrayGetCount( preferred_locales ))
- user_language_string_ref = (CFStringRef)CFArrayGetValueAtIndex( preferred_locales, 0 ); // FIXME
- CFRelease( all_locales );
-#endif /* __APPLE__ */
-
- // FIXME setlocale( LC_ALL, "" );
-
- unix_cp = setup_unix_locales();
- if (!lcid_LC_MESSAGES) lcid_LC_MESSAGES = lcid_LC_CTYPE;
-
-#ifdef __APPLE__
- /* Override lcid_LC_MESSAGES with user_language if LC_MESSAGES is set to default */
- if (lcid_LC_MESSAGES == lcid_LC_CTYPE && user_language_string_ref)
- {
- struct locale_name locale_name;
- WCHAR buffer[128];
- CFStringGetCString( user_language_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
- strcpynAtoW( buffer, user_locale, sizeof(buffer)/sizeof(WCHAR) );
- parse_locale_name( buffer, &locale_name );
- lcid_LC_MESSAGES = locale_name.lcid;
- // TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale );
- }
- if (preferred_locales)
- CFRelease( preferred_locales );
-#endif
-
-#if 0 // FIXME
- NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES) );
- NtSetDefaultLocale( TRUE, lcid_LC_MESSAGES );
- NtSetDefaultLocale( FALSE, lcid_LC_CTYPE );
-
- ansi_cp = get_lcid_codepage( LOCALE_USER_DEFAULT );
- GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
- (LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
- GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
- (LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
- if (!unix_cp)
- GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
- (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );
-
- if (!(ansi_cptable = wine_cp_get_table( ansi_cp )))
- ansi_cptable = wine_cp_get_table( 1252 );
- if (!(oem_cptable = wine_cp_get_table( oem_cp )))
- oem_cptable = wine_cp_get_table( 437 );
- if (!(mac_cptable = wine_cp_get_table( mac_cp )))
- mac_cptable = wine_cp_get_table( 10000 );
- if (unix_cp != CP_UTF8)
- {
- if (!(unix_cptable = wine_cp_get_table( unix_cp )))
- unix_cptable = wine_cp_get_table( 28591 );
- }
-
- __wine_init_codepages( ansi_cptable, oem_cptable, unix_cptable );
-
- TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
- ansi_cptable->info.codepage, oem_cptable->info.codepage,
- mac_cptable->info.codepage, unix_cp );
-
- setlocale(LC_NUMERIC, "C"); /* FIXME: oleaut32 depends on this */
-#endif
-}
-
-LANGID GetUserDefaultLangID(void)
-{
- // return LANGIDFROMLCID(GetUserDefaultLCID());
- if (lcid_LC_MESSAGES == 0) LOCALE_Init();
- return LANGIDFROMLCID(lcid_LC_MESSAGES);
-}
-
-LANGID GetSystemDefaultLangID(void)
-{
- // return LANGIDFROMLCID(GetSystemDefaultLCID());
- if (lcid_LC_MESSAGES == 0) LOCALE_Init();
- return LANGIDFROMLCID(lcid_LC_MESSAGES);
-}
-
-#ifdef TEST
-int main()
-{
- LANGID langID;
- WORD primLang;
- WORD subLang;
-
- setlocale( LC_ALL, "" );
-
- langID = GetUserDefaultLangID();
- printf("langID=0x%x\n",langID);
-
- primLang = (WORD)(PRIMARYLANGID(langID));
- subLang = (WORD)(SUBLANGID(langID));
-
- printf("primLang=%d subLang=%d\n",(unsigned)primLang,(unsigned)subLang);
-
- return 0;
-}
-#endif
-
diff --git a/src/libs/7zip/unix/CPP/myWindows/wine_date_and_time.cpp b/src/libs/7zip/unix/CPP/myWindows/wine_date_and_time.cpp
deleted file mode 100644
index 6d7f83a0c..000000000
--- a/src/libs/7zip/unix/CPP/myWindows/wine_date_and_time.cpp
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h> /* gettimeofday */
-#include <dirent.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <windows.h>
-
-// #define TRACEN(u) u;
-#define TRACEN(u) /* */
-
-typedef LONG NTSTATUS;
-#define STATUS_SUCCESS 0x00000000
-
-#define TICKSPERSEC 10000000
-#define TICKSPERMSEC 10000
-#define SECSPERDAY 86400
-#define SECSPERHOUR 3600
-#define SECSPERMIN 60
-#define MINSPERHOUR 60
-#define HOURSPERDAY 24
-#define EPOCHWEEKDAY 1 /* Jan 1, 1601 was Monday */
-#define DAYSPERWEEK 7
-#define EPOCHYEAR 1601
-#define DAYSPERNORMALYEAR 365
-#define DAYSPERLEAPYEAR 366
-#define MONSPERYEAR 12
-#define DAYSPERQUADRICENTENNIUM (365 * 400 + 97)
-#define DAYSPERNORMALCENTURY (365 * 100 + 24)
-#define DAYSPERNORMALQUADRENNIUM (365 * 4 + 1)
-
-/* 1601 to 1970 is 369 years plus 89 leap days */
-#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
-#define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
-/* 1601 to 1980 is 379 years plus 91 leap days */
-#define SECS_1601_TO_1980 ((379 * 365 + 91) * (ULONGLONG)SECSPERDAY)
-#define TICKS_1601_TO_1980 (SECS_1601_TO_1980 * TICKSPERSEC)
-typedef short CSHORT;
-
-static LONG TIME_GetBias() {
- time_t utc = time(NULL);
- struct tm *ptm = localtime(&utc);
- int localdaylight = ptm->tm_isdst; /* daylight for local timezone */
- ptm = gmtime(&utc);
- ptm->tm_isdst = localdaylight; /* use local daylight, not that of Greenwich */
- LONG bias = (int)(mktime(ptm)-utc);
- TRACEN((printf("TIME_GetBias %ld\n",(long)bias)))
- return bias;
-}
-
-static inline void RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
- LARGE_INTEGER *LocalTime ) {
- LONG bias = TIME_GetBias();
- LocalTime->QuadPart = SystemTime->QuadPart - bias * (LONGLONG)TICKSPERSEC;
-}
-
-void WINAPI RtlSecondsSince1970ToFileTime( DWORD Seconds, FILETIME * ft ) {
- ULONGLONG secs = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
- ft->dwLowDateTime = (DWORD)secs;
- ft->dwHighDateTime = (DWORD)(secs >> 32);
- TRACEN((printf("RtlSecondsSince1970ToFileTime %lx => %lx %lx\n",(long)Seconds,(long)ft->dwHighDateTime,(long)ft->dwLowDateTime)))
-}
-
-/*
-void WINAPI RtlSecondsSince1970ToTime( DWORD Seconds, LARGE_INTEGER *Time )
-{
- ULONGLONG secs = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
- // Time->u.LowPart = (DWORD)secs; Time->u.HighPart = (DWORD)(secs >> 32);
- Time->QuadPart = secs;
-}
- */
-
-BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, FILETIME * ft)
-{
- struct tm newtm;
-#ifndef ENV_HAVE_TIMEGM
- struct tm *gtm;
- time_t time1, time2;
-#endif
-
- TRACEN((printf("DosDateTimeToFileTime\n")))
-
- newtm.tm_sec = (fattime & 0x1f) * 2;
- newtm.tm_min = (fattime >> 5) & 0x3f;
- newtm.tm_hour = (fattime >> 11);
- newtm.tm_mday = (fatdate & 0x1f);
- newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
- newtm.tm_year = (fatdate >> 9) + 80;
- newtm.tm_isdst = -1;
-#ifdef ENV_HAVE_TIMEGM
- RtlSecondsSince1970ToFileTime( timegm(&newtm), ft );
-#else
- newtm.tm_isdst = 0;
- time1 = mktime(&newtm);
- gtm = gmtime(&time1);
- time2 = mktime(gtm);
- RtlSecondsSince1970ToFileTime( 2*time1-time2, ft );
-#endif
- TRACEN((printf("DosDateTimeToFileTime(%ld,%ld) => %lx %lx\n",
- (long)fatdate,(long)fattime,
- (long)ft->dwHighDateTime,(long)ft->dwLowDateTime)))
-
- return TRUE;
-}
-
-/*
-BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, FILETIME * ft) {
- struct tm newtm;
-
- TRACEN((printf("DosDateTimeToFileTime\n")))
-
- memset(&newtm,0,sizeof(newtm));
- newtm.tm_sec = (fattime & 0x1f) * 2;
- newtm.tm_min = (fattime >> 5) & 0x3f;
- newtm.tm_hour = (fattime >> 11);
- newtm.tm_mday = (fatdate & 0x1f);
- newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
- newtm.tm_year = (fatdate >> 9) + 80;
- newtm.tm_isdst = -1;
-
- time_t time1 = mktime(&newtm);
- LONG bias = TIME_GetBias();
- RtlSecondsSince1970ToFileTime( time1 - bias, ft );
-
-
- TRACEN((printf("DosDateTimeToFileTime(%ld,%ld) t1=%ld => %lx %lx\n",
- (long)fatdate,(long)fattime,(long)time1,
- (long)ft->dwHighDateTime,(long)ft->dwLowDateTime)))
-
- return TRUE;
-}
-*/
-
-BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds ) {
- ULONGLONG tmp = Time->QuadPart;
- TRACEN((printf("RtlTimeToSecondsSince1970-1 %llx\n",tmp)))
- tmp /= TICKSPERSEC;
- tmp -= SECS_1601_TO_1970;
- TRACEN((printf("RtlTimeToSecondsSince1970-2 %llx\n",tmp)))
- if (tmp > 0xffffffff) return FALSE;
- *Seconds = (DWORD)tmp;
- return TRUE;
-}
-
-BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, WORD *fatdate, WORD *fattime ) {
- LARGE_INTEGER li;
- ULONG t;
- time_t unixtime;
- struct tm* tm;
- WORD fat_d,fat_t;
-
- TRACEN((printf("FileTimeToDosDateTime\n")))
- li.QuadPart = ft->dwHighDateTime;
- li.QuadPart = (li.QuadPart << 32) | ft->dwLowDateTime;
- RtlTimeToSecondsSince1970( &li, &t );
- unixtime = t; /* unixtime = t; * FIXME unixtime = t - TIME_GetBias(); */
-
- tm = gmtime( &unixtime );
-
- fat_t = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
- fat_d = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday;
- if (fattime)
- *fattime = fat_t;
- if (fatdate)
- *fatdate = fat_d;
-
- TRACEN((printf("FileTimeToDosDateTime : %lx %lx => %d %d\n",
- (long)ft->dwHighDateTime,(long)ft->dwLowDateTime,(unsigned)fat_d,(unsigned)fat_t)))
-
- return TRUE;
-}
-
-BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, FILETIME * localft ) {
- LARGE_INTEGER local, utc;
-
- TRACEN((printf("FileTimeToLocalFileTime\n")))
- utc.QuadPart = utcft->dwHighDateTime;
- utc.QuadPart = (utc.QuadPart << 32) | utcft->dwLowDateTime;
- RtlSystemTimeToLocalTime( &utc, &local );
- localft->dwLowDateTime = (DWORD)local.QuadPart;
- localft->dwHighDateTime = (DWORD)(local.QuadPart >> 32);
-
- return TRUE;
-}
-
-typedef struct _TIME_FIELDS {
- CSHORT Year;
- CSHORT Month;
- CSHORT Day;
- CSHORT Hour;
- CSHORT Minute;
- CSHORT Second;
- CSHORT Milliseconds;
- CSHORT Weekday;
-} TIME_FIELDS;
-
-static const int MonthLengths[2][MONSPERYEAR] =
-{
- { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
-};
-
-static inline int IsLeapYear(int Year) {
- return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
-}
-
-static inline VOID WINAPI RtlTimeToTimeFields(
- const LARGE_INTEGER *liTime,
- TIME_FIELDS * TimeFields) {
- int SecondsInDay;
- long int cleaps, years, yearday, months;
- long int Days;
- LONGLONG Time;
-
- /* Extract millisecond from time and convert time into seconds */
- TimeFields->Milliseconds =
- (CSHORT) (( liTime->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
- Time = liTime->QuadPart / TICKSPERSEC;
-
- /* The native version of RtlTimeToTimeFields does not take leap seconds
- * into account */
-
- /* Split the time into days and seconds within the day */
- Days = Time / SECSPERDAY;
- SecondsInDay = Time % SECSPERDAY;
-
- /* compute time of day */
- TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
- SecondsInDay = SecondsInDay % SECSPERHOUR;
- TimeFields->Minute = (CSHORT) (SecondsInDay / SECSPERMIN);
- TimeFields->Second = (CSHORT) (SecondsInDay % SECSPERMIN);
-
- /* compute day of week */
- TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
-
- /* compute year, month and day of month. */
- cleaps=( 3 * ((4 * Days + 1227) / DAYSPERQUADRICENTENNIUM) + 3 ) / 4;
- Days += 28188 + cleaps;
- years = (20 * Days - 2442) / (5 * DAYSPERNORMALQUADRENNIUM);
- yearday = Days - (years * DAYSPERNORMALQUADRENNIUM)/4;
- months = (64 * yearday) / 1959;
- /* the result is based on a year starting on March.
- * To convert take 12 from Januari and Februari and
- * increase the year by one. */
- if( months < 14 ) {
- TimeFields->Month = months - 1;
- TimeFields->Year = years + 1524;
- } else {
- TimeFields->Month = months - 13;
- TimeFields->Year = years + 1525;
- }
- /* calculation of day of month is based on the wonderful
- * sequence of INT( n * 30.6): it reproduces the
- * 31-30-31-30-31-31 month lengths exactly for small n's */
- TimeFields->Day = yearday - (1959 * months) / 64 ;
-}
-
-
-BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, SYSTEMTIME * syst ) {
- TIME_FIELDS tf;
- LARGE_INTEGER t;
-
- TRACEN((printf("FileTimeToSystemTime\n")))
- t.QuadPart = ft->dwHighDateTime;
- t.QuadPart = (t.QuadPart << 32) | ft->dwLowDateTime;
- RtlTimeToTimeFields(&t, &tf);
-
- syst->wYear = tf.Year;
- syst->wMonth = tf.Month;
- syst->wDay = tf.Day;
- syst->wHour = tf.Hour;
- syst->wMinute = tf.Minute;
- syst->wSecond = tf.Second;
- syst->wMilliseconds = tf.Milliseconds;
- syst->wDayOfWeek = tf.Weekday;
- return TRUE;
-}
-
-
-static inline NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
- LARGE_INTEGER *SystemTime) {
-
- TRACEN((printf("RtlLocalTimeToSystemTime\n")))
- LONG bias = TIME_GetBias();
- SystemTime->QuadPart = LocalTime->QuadPart + bias * (LONGLONG)TICKSPERSEC;
- return STATUS_SUCCESS;
-}
-
-BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, FILETIME * utcft ) {
- LARGE_INTEGER local, utc;
-
- TRACEN((printf("LocalFileTimeToFileTime\n")))
- local.QuadPart = localft->dwHighDateTime;
- local.QuadPart = (local.QuadPart << 32) | localft->dwLowDateTime;
- RtlLocalTimeToSystemTime( &local, &utc );
- utcft->dwLowDateTime = (DWORD)utc.QuadPart;
- utcft->dwHighDateTime = (DWORD)(utc.QuadPart >> 32);
-
- return TRUE;
-}
-
-/*********************************************************************
- * GetSystemTime (KERNEL32.@)
- *
- * Get the current system time.
- *
- * RETURNS
- * Nothing.
- */
-VOID WINAPI GetSystemTime(SYSTEMTIME * systime) /* [O] Destination for current time */
-{
- FILETIME ft;
- LARGE_INTEGER t;
-
- TRACEN((printf("GetSystemTime\n")))
-
- struct timeval now;
- gettimeofday( &now, 0 );
- t.QuadPart = now.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
- t.QuadPart += now.tv_usec * 10;
-
- ft.dwLowDateTime = (DWORD)(t.QuadPart);
- ft.dwHighDateTime = (DWORD)(t.QuadPart >> 32);
- FileTimeToSystemTime(&ft, systime);
-}
-
-/******************************************************************************
- * RtlTimeFieldsToTime [NTDLL.@]
- *
- * Convert a TIME_FIELDS structure into a time.
- *
- * PARAMS
- * ftTimeFields [I] TIME_FIELDS structure to convert.
- * Time [O] Destination for the converted time.
- *
- * RETURNS
- * Success: TRUE.
- * Failure: FALSE.
- */
-static BOOLEAN WINAPI RtlTimeFieldsToTime(
- TIME_FIELDS * tfTimeFields,
- LARGE_INTEGER *Time)
-{
- int month, year, cleaps, day;
-
- TRACEN((printf("RtlTimeFieldsToTime\n")))
-
- /* FIXME: normalize the TIME_FIELDS structure here */
- /* No, native just returns 0 (error) if the fields are not */
- if( tfTimeFields->Milliseconds< 0 || tfTimeFields->Milliseconds > 999 ||
- tfTimeFields->Second < 0 || tfTimeFields->Second > 59 ||
- tfTimeFields->Minute < 0 || tfTimeFields->Minute > 59 ||
- tfTimeFields->Hour < 0 || tfTimeFields->Hour > 23 ||
- tfTimeFields->Month < 1 || tfTimeFields->Month > 12 ||
- tfTimeFields->Day < 1 ||
- tfTimeFields->Day > MonthLengths
- [ tfTimeFields->Month ==2 || IsLeapYear(tfTimeFields->Year)]
- [ tfTimeFields->Month - 1] ||
- tfTimeFields->Year < 1601 )
- return FALSE;
-
- /* now calculate a day count from the date
- * First start counting years from March. This way the leap days
- * are added at the end of the year, not somewhere in the middle.
- * Formula's become so much less complicate that way.
- * To convert: add 12 to the month numbers of Jan and Feb, and
- * take 1 from the year */
- if(tfTimeFields->Month < 3) {
- month = tfTimeFields->Month + 13;
- year = tfTimeFields->Year - 1;
- } else {
- month = tfTimeFields->Month + 1;
- year = tfTimeFields->Year;
- }
- cleaps = (3 * (year / 100) + 3) / 4; /* nr of "century leap years"*/
- day = (36525 * year) / 100 - cleaps + /* year * dayperyr, corrected */
- (1959 * month) / 64 + /* months * daypermonth */
- tfTimeFields->Day - /* day of the month */
- 584817 ; /* zero that on 1601-01-01 */
- /* done */
-
- Time->QuadPart = (((((LONGLONG) day * HOURSPERDAY +
- tfTimeFields->Hour) * MINSPERHOUR +
- tfTimeFields->Minute) * SECSPERMIN +
- tfTimeFields->Second ) * 1000 +
- tfTimeFields->Milliseconds ) * TICKSPERMSEC;
-
- return TRUE;
-}
-
-/*********************************************************************
- * SystemTimeToFileTime (KERNEL32.@)
- */
-BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, FILETIME * ft ) {
- TIME_FIELDS tf;
- LARGE_INTEGER t;
-
- TRACEN((printf("SystemTimeToFileTime\n")))
-
- tf.Year = syst->wYear;
- tf.Month = syst->wMonth;
- tf.Day = syst->wDay;
- tf.Hour = syst->wHour;
- tf.Minute = syst->wMinute;
- tf.Second = syst->wSecond;
- tf.Milliseconds = syst->wMilliseconds;
-
- RtlTimeFieldsToTime(&tf, &t);
- ft->dwLowDateTime = (DWORD)t.QuadPart;
- ft->dwHighDateTime = (DWORD)(t.QuadPart>>32);
- return TRUE;
-}
-