Full UNICODE support in libnetxms
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 21 Sep 2004 08:32:19 +0000 (08:32 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 21 Sep 2004 08:32:19 +0000 (08:32 +0000)
.gitattributes
include/nms_agent.h
include/nms_common.h
include/nms_threads.h
include/nms_util.h
include/unicode.h [copied from src/libnetxms/libnetxms.h with 51% similarity]
src/libnetxms/config.cpp
src/libnetxms/dload.cpp
src/libnetxms/libnetxms.dsp
src/libnetxms/libnetxms.h
src/libnetxms/tools.cpp

index 446acbd..f41e1ed 100644 (file)
@@ -46,6 +46,7 @@ include/nxcscpapi.h -text
 include/nxevent.h -text
 include/nximage.h -text
 include/nxqueue.h -text
+include/unicode.h -text
 m4/Makefile.am -text
 netware/Makefile.inc -text
 netware/bin/.keep -text
index a370818..050b12c 100644 (file)
@@ -23,8 +23,6 @@
 #ifndef _nms_agent_h_
 #define _nms_agent_h_
 
-#include <stdio.h>
-#include <string.h>
 #include <nms_common.h>
 #include <nms_util.h>
 
index 71b4c1b..52fecb9 100644 (file)
 #ifndef _nms_common_h_
 #define _nms_common_h_
 
+#include <unicode.h>
 #include <ctype.h>
+#include <stdio.h>
+#include <string.h>
 
 
 //
 // Platform dependent includes and defines
 //
 
-#ifdef UNDER_CE
-inline unsigned long _beginthreadex(void *security,
-                                                                       unsigned stack_size,
-                                                                       unsigned (__stdcall *start_address)(void *),
-                                                                       void *arglist, unsigned initflag, 
-                                                                       unsigned *thrdaddr)
-{
-       return (unsigned long)CreateThread((LPSECURITY_ATTRIBUTES)security,
-               (DWORD)stack_size,
-               (LPTHREAD_START_ROUTINE)start_address,
-               (LPVOID)arglist,
-               (DWORD)initflag | CREATE_SUSPENDED,
-               (LPDWORD)thrdaddr);
-}
-
-inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
-{
-       SYSTEMTIME sysTime;
-       
-       GetSystemTime(&sysTime);
-       SystemTimeToFileTime(&sysTime, pFt);
-}
-
-#endif // UNDER_CE
-
 #if defined(_WIN32) || defined(UNDER_CE)
 
 /********** WINDOWS ********************/
index 2a4d2c4..0bd3392 100644 (file)
@@ -66,7 +66,12 @@ inline BOOL ThreadCreate(THREAD_RESULT (THREAD_CALL *start_address )(void *), in
    HANDLE hThread;
    unsigned int dwThreadId;
 
+#ifdef UNDER_CE
+       hThread = CreateThread(NULL, (DWORD)stack_size, start_address,
+                                   arglist, 0, &dwThreadId);
+#else
    hThread = (HANDLE)_beginthreadex(NULL, stack_size, start_address, args, 0, &dwThreadId);
+#endif
    if (hThread != NULL)
       CloseHandle(hThread);
    return (hThread != NULL);
@@ -81,10 +86,10 @@ inline THREAD ThreadCreateEx(THREAD_RESULT (THREAD_CALL *start_address )(void *)
 
 inline void ThreadExit(void)
 {
-#ifndef UNDER_CE
-   _endthread();
-#else
+#ifdef UNDER_CE
    ExitThread(0);
+#else
+   _endthreadex(0);
 #endif
 }
 
index 636e1cb..1bb1d9e 100644 (file)
@@ -106,6 +106,23 @@ typedef struct
 
 
 //
+// Win32 API functions missing under WinCE
+//
+
+#ifdef UNDER_CE
+
+inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
+{
+       SYSTEMTIME sysTime;
+       
+       GetSystemTime(&sysTime);
+       SystemTimeToFileTime(&sysTime, pFt);
+}
+
+#endif // UNDER_CE
+
+
+//
 // Functions
 //
 
similarity index 51%
copy from src/libnetxms/libnetxms.h
copy to include/unicode.h
index 7601ca4..f96793d 100644 (file)
@@ -1,6 +1,5 @@
 /* 
 ** NetXMS - Network Management System
-** Utility Library
 ** Copyright (C) 2003, 2004 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: libnetxms.h
+** $module: unicode.h
 **
 **/
 
-#ifndef _libnetxms_h_
-#define _libnetxms_h_
+#ifndef _unicode_h_
+#define _unicode_h_
 
-#include <stdio.h>
+#ifdef _WIN32
+
+// Ensure that both UNICODE and _UNICODE are defined
+#ifdef _UNICODE
+#ifndef UNICODE
+#define UNICODE
+#endif
+#endif
+
+#ifdef UNICODE
+#ifndef _UNICODE
+#define _UNICODE
+#endif
+#endif
+
+#include <tchar.h>
 
-#if defined(_WIN32) || defined(UNDER_CE)
-#include <windows.h>
 #else    /* _WIN32 */
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#endif   /* _WIN32 */
 
-#include <nms_common.h>
-#include <nms_util.h>
-#include <nms_agent.h>
+#define _T(x)     x
+
+#define TCHAR     char
+
+#define _tcscpy   strcpy
+#define _tcsncpy  strncpy
+#define _tcslen   strlen
+#define _tcschr   strchr
+#define _tcsrchr  strrchr
+#define _tcscmp   strcmp
+#define _tcsicmp  stricmp
+#define _tprintf  printf
+#define _stprintf sprintf
+#define _tfopen   fopen
+#define _fgetts   fgets
+#define _tcstol   strtol
+#define _tcstoul  strtoul
+#define _tcstod   strtod
+#define _tcsdup   strdup
+#define _tcsupr   strupr
+#define _tcsspn   strspn
+
+#endif
+
 
-#endif   /* _libnetxms_h_ */
+#endif   /* _unicode_h_ */
index 189d4a4..a03694c 100644 (file)
@@ -41,8 +41,12 @@ DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(TCHAR *pszFileName, TCHAR *pszSection,
    {
       if (bPrint)
 #ifndef UNDER_CE
-         _tprintf(_T("Unable to open configuration file: %s\n"), _tcserror(errno));
-#endif // UNDER_CE
+#ifdef UNICODE
+         wprintf(L"Unable to open configuration file\n");
+#else
+         printf("Unable to open configuration file: %s\n", strerror(errno));
+#endif   /* UNICODE */
+#endif   /* UNDER_CE */
       return NXCFG_ERR_NOFILE;
    }
 
index e0ee692..2bc3028 100644 (file)
@@ -68,19 +68,27 @@ void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule)
 //
 
 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule,
-                                                                                  TCHAR *szSymbol,
+                                                                                  TCHAR *pszSymbol,
                                                                                   TCHAR *pszErrorText)
 {
    void *pAddr;
 
 #ifdef _WIN32
-   pAddr = GetProcAddress(hModule, szSymbol);
+#if !defined(UNDER_CE) && defined(UNICODE)
+   char szBuffer[256];
+
+   WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,
+                       pszSymbol, -1, szBuffer, 256, NULL, NULL);
+   pAddr = GetProcAddress(hModule, szBuffer);
+#else
+   pAddr = GetProcAddress(hModule, pszSymbol);
+#endif
    if (pAddr == NULL)
       GetSystemErrorText(GetLastError(), pszErrorText, 255);
 #else    /* _WIN32 */
    pAddr = dlsym(hModule, szSymbol);
    if (pAddr == NULL)
-      strncpy(pszErrorText, dlerror(), 255);
+      _tscncpy(pszErrorText, dlerror(), 255);
 #endif
    return pAddr;
 }
index c27fbc5..3424a8a 100644 (file)
@@ -172,6 +172,10 @@ SOURCE=..\..\include\nms_util.h
 
 SOURCE=.\sha1.h
 # End Source File
+# Begin Source File
+
+SOURCE=..\..\include\unicode.h
+# End Source File
 # End Group
 # Begin Group "Resource Files"
 
index 7601ca4..8d55639 100644 (file)
 #ifndef _libnetxms_h_
 #define _libnetxms_h_
 
-#include <stdio.h>
-
-#if defined(_WIN32) || defined(UNDER_CE)
-#include <windows.h>
-#else    /* _WIN32 */
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#endif   /* _WIN32 */
-
 #include <nms_common.h>
 #include <nms_util.h>
 #include <nms_agent.h>
index 04c371b..a97dfc8 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "libnetxms.h"
 
-#if !defined(_WIN32) || !defined(UNDER_CE)
+#if !defined(_WIN32) && !defined(UNDER_CE)
 #include <sys/time.h>
 #endif