Author: janderwald
Date: Sun Nov 5 23:51:02 2006
New Revision: 24688
URL:
http://svn.reactos.org/svn/reactos?rev=24688&view=rev
Log:
- read lines into a vector of string lines
- move os specific functions into an own file
- fix a bug in command line options parsing
- add function for converting ansi2Unicode
Added:
trunk/reactos/tools/sysreg/os_support.cpp
trunk/reactos/tools/sysreg/os_support.h
trunk/reactos/tools/sysreg/unicode.cpp
trunk/reactos/tools/sysreg/unicode.h
Modified:
trunk/reactos/tools/sysreg/conf_parser.cpp
trunk/reactos/tools/sysreg/namedpipe_reader.cpp
trunk/reactos/tools/sysreg/namedpipe_reader.h
trunk/reactos/tools/sysreg/rosboot_test.cpp
trunk/reactos/tools/sysreg/sample.cfg
trunk/reactos/tools/sysreg/sysreg.cpp
trunk/reactos/tools/sysreg/sysreg.mak
Modified: trunk/reactos/tools/sysreg/conf_parser.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/conf_parser.c…
==============================================================================
--- trunk/reactos/tools/sysreg/conf_parser.cpp (original)
+++ trunk/reactos/tools/sysreg/conf_parser.cpp Sun Nov 5 23:51:02 2006
@@ -38,7 +38,7 @@
#endif
if (!file)
{
- cerr << " Error: ConfigParser::parseFile failed to open configuration file
" <<endl;
+ cerr << "Error: ConfigParser::parseFile failed to open configuration file
" << FileName << endl;
return false;
}
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_rea…
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (original)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Sun Nov 5 23:51:02 2006
@@ -9,6 +9,7 @@
*/
#include "namedpipe_reader.h"
+#include "unicode.h"
#include <iostream>
#include <assert.h>
@@ -17,6 +18,7 @@
{
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+ using std::vector;
//---------------------------------------------------------------------------------------
NamedPipeReader::NamedPipeReader() : h_Pipe(NULL)
{
@@ -90,71 +92,126 @@
h_Pipe = NULL;
return true;
}
-
-//---------------------------------------------------------------------------------------
-
- string::size_type NamedPipeReader::readPipe(string &Buffer)
- {
- TCHAR * buf = (TCHAR *)Buffer.c_str();
- string::size_type buffer_size = Buffer.capacity();
- string::size_type bytes_read = 0;
- DWORD cbRead;
+//---------------------------------------------------------------------------------------
+ void NamedPipeReader::extractLines(TCHAR * buffer, std::vector<string> & vect,
bool & append_line, unsigned long cbRead)
+ {
+ TCHAR * offset = _tcsstr(buffer, _T("\x0D"));
+ DWORD buf_offset = 0;
+ while(offset)
+ {
+ offset[0] = _T('\0');
+ string line = buffer;
+ if (append_line)
+ {
+ assert(vect.empty () == false);
+ string prev_line = vect[vect.size () -1];
+ prev_line += line;
+ vect.pop_back ();
+ vect.push_back (prev_line);
+ append_line = false;
+ }
+ else
+ {
+ vect.push_back (line);
+ }
+
+ offset += 2;
+
+ buf_offset += line.length () + 2;
+ if (buf_offset >= cbRead)
+ {
+ break;
+ }
+ buffer = offset;
+ offset = _tcsstr(buffer, _T("\n"));
+ }
+ if (buf_offset < cbRead)
+ {
+ string line = buffer;
+ if (append_line)
+ {
+ assert(vect.empty () == false);
+ string prev_line = vect[vect.size () -1];
+ vect.pop_back ();
+ prev_line += line;
+ vect.push_back (prev_line);
+ }
+ else
+ {
+ vect.push_back (line);
+ append_line = true;
+ }
+ }
+ else
+ {
+ append_line = false;
+ }
+ }
+
+//---------------------------------------------------------------------------------------
+
+ size_t NamedPipeReader::readPipe(vector<string> & vect)
+ {
+ char * localbuf;
+ DWORD localsize = 100;
+ size_t lines = vect.size ();
+
+#ifdef WIN32
BOOL fSuccess;
- TCHAR * localbuf;
- DWORD localsize = MIN(100, buffer_size);
-
-//#ifdef NDEBUG
- memset(buf, 0x0, sizeof(TCHAR) * buffer_size);
-//#endif
-
-#ifdef __LINUX__
-
-#else
- localbuf = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(TCHAR));
+ localbuf = (char*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(char));
+#ifdef UNICODE
+ wchar_t * wbuf = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(wchar_t));
+#endif
if (localbuf != NULL)
{
-
+ bool append_line = false;
do
{
+ DWORD cbRead;
do
{
- ZeroMemory(localbuf, localsize * sizeof(TCHAR));
+ ZeroMemory(localbuf, localsize * sizeof(char));
+#ifdef UNICODE
+ ZeroMemory(wbuf, localsize * sizeof(wchar_t));
+#endif
fSuccess = ReadFile(
h_Pipe,
localbuf,
- localsize * sizeof(TCHAR),
+ (localsize-1) * sizeof(char),
&cbRead,
NULL);
if (! fSuccess && GetLastError() != ERROR_MORE_DATA)
break;
-
- if(bytes_read + cbRead > buffer_size)
+
+#ifdef UNICODE
+ if (UnicodeConverter::ansi2Unicode(localbuf, wbuf, cbRead))
{
- Buffer.reserve(bytes_read + localsize * 3);
- buf = (TCHAR *)Buffer.c_str();
- buffer_size = Buffer.capacity();
+ extractLines(wbuf, vect, append_line, cbRead);
}
-
- memcpy(&buf[bytes_read], localbuf, cbRead);
- bytes_read += cbRead;
+#else
+ extractLines(localbuf, vect, append_line, cbRead);
+#endif
} while (!fSuccess); // repeat loop if ERROR_MORE_DATA
- } while (localbuf[_tcslen(localbuf)-1] != '\n');
+ } while (localbuf[strlen(localbuf)-1] != '\n');
if (!fSuccess)
return 0;
HeapFree(GetProcessHeap(), 0, localbuf);
+#ifdef UNICODE
+ HeapFree(GetProcessHeap(), 0, wbuf);
+#endif
}
else
{
return 0;
}
#endif
- buf[_tcslen(buf)-_tcslen(_T("\n"))-1] = '\0';
- return _tcslen(buf);
+
+ return (vect.size () - lines);
}
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_rea…
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.h (original)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.h Sun Nov 5 23:51:02 2006
@@ -14,12 +14,13 @@
#include "user_types.h"
+#include <vector>
#include <stdio.h>
#include <stdlib.h>
#ifdef __LINUX__
-#else
+#elif defined(WIN32)
#include <windows.h>
#endif
@@ -82,9 +83,9 @@
/// false, call PipeReader::isEoF() to determine if the pipe should be closed
///
/// @param Buffer to be written to
-/// @return string::size_type
+/// @return size_t
- string::size_type readPipe(string & Buffer);
+ size_t readPipe(std::vector<string> & vect);
//---------------------------------------------------------------------------------------
///
@@ -96,6 +97,21 @@
bool isEof();
protected:
+//---------------------------------------------------------------------------------------
+///
+/// extractLines
+///
+/// Description: this functions extract lines from a buffer and pushes them into the
supplied vector
+///
+/// @param buffer from which the lines are extracted from
+/// @param vect vector storing the extracted lines
+/// @param append_line if the line isnt fully read, the line is appended
+
+ void extractLines(TCHAR * buffer, std::vector<string> & vect, bool &
append_line, unsigned long cbRead);
+
+
+
+
HANDLE h_Pipe;
}; // end of class NamedPipeReader
Added: trunk/reactos/tools/sysreg/os_support.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/os_support.cp…
==============================================================================
--- trunk/reactos/tools/sysreg/os_support.cpp (added)
+++ trunk/reactos/tools/sysreg/os_support.cpp Sun Nov 5 23:51:02 2006
@@ -1,0 +1,76 @@
+/* $Id: os_support.h 24643 2006-10-24 11:45:21Z janderwald $
+ *
+ * PROJECT: System regression tool for ReactOS
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: tools/sysreg/conf_parser.h
+ * PURPOSE: operating systems specific code
+ * PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
+ */
+
+#include "os_support.h"
+
+namespace System_
+{
+#ifdef WIN32
+ bool OsSupport::terminateProcess(OsSupport::ProcessID pid)
+ {
+ HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
+ if (!hProcess)
+ {
+ return false;
+ }
+
+ bool ret = TerminateProcess(hProcess, 0);
+ CloseHandle(hProcess);
+ return ret;
+ }
+
+ OsSupport::ProcessID OsSupport::createProcess(TCHAR *procname, int procargsnum, TCHAR
**procargs)
+ {
+ STARTUPINFO siStartInfo;
+ PROCESS_INFORMATION piProcInfo;
+ OsSupport::ProcessID pid;
+
+ UNREFERENCED_PARAMETER(procargsnum);
+ UNREFERENCED_PARAMETER(procargs);
+
+ ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
+ ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
+
+ siStartInfo.cb = sizeof(STARTUPINFO);
+ siStartInfo.wShowWindow = SW_SHOWNORMAL;
+ siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
+
+ LPTSTR command = _tcsdup(procname);
+
+ if (!CreateProcess(NULL, procname, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL,
NULL, &siStartInfo, &piProcInfo))
+ {
+ cerr << "Error: CreateProcess failed " << command <<endl;
+ pid = 0;
+ }
+ else
+ {
+ pid = piProcInfo.dwProcessId;
+ CloseHandle(piProcInfo.hProcess);
+ CloseHandle(piProcInfo.hThread);
+ }
+ free(command);
+ return pid;
+ }
+#elif defined (__LINUX__)
+/********************************************************************************************************************/
+ OsSupport::ProcessID OsSupport::createProcess(TCHAR *procname, int procargsnum, TCHAR
**procargs)
+ {
+ ProcessID pid;
+
+ if ((pid = fork()) < 0)
+ {
+ cerr << "OsSupport::createProcess> fork failed" << endl;
+ return pid;
+ }
+
+ }
+
+#endif
+
+} // end of namespace System_
Added: trunk/reactos/tools/sysreg/os_support.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/os_support.h?…
==============================================================================
--- trunk/reactos/tools/sysreg/os_support.h (added)
+++ trunk/reactos/tools/sysreg/os_support.h Sun Nov 5 23:51:02 2006
@@ -1,0 +1,95 @@
+#ifndef OS_SUPPORT_H__
+#define OS_SUPPORT_H__
+
+/* $Id: os_support.h 24643 2006-10-24 11:45:21Z janderwald $
+ *
+ * PROJECT: System regression tool for ReactOS
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: tools/sysreg/conf_parser.h
+ * PURPOSE: operating systems specific code
+ * PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
+ */
+
+#ifdef WIN32
+#include <windows.h>
+#elif defined(__LINUX__)
+#include <unistd.h>
+#endif
+
+#include "user_types.h"
+
+namespace System_
+{
+//---------------------------------------------------------------------------------------
+///
+/// class OsSupport
+///
+/// Description: this class encapsulates operating system specific functions
+///
+///
+
+ class OsSupport
+ {
+ public:
+#ifdef WIN32
+
+ typedef DWORD ProcessID;
+
+#elif defined(__LINUX__)
+
+ typedef pid_t ProcessID;
+
+#else
+#error you need to define pid handle type for your platform
+#endif
+
+//---------------------------------------------------------------------------------------
+///
+/// OsSupport
+///
+/// Description: constructor of class OsSupport
+
+ virtual ~OsSupport()
+ {}
+
+//---------------------------------------------------------------------------------------
+///
+/// createProcess
+///
+/// Description: this functions creates a new process and returns its pid on success
+///
+/// @param procname name of the file to execute
+/// @param procargsnum num of arguments for the new process
+/// @param procargs arguments for the new process
+///
+///
+
+ static ProcessID createProcess(TCHAR * procname, int procargsnum, TCHAR ** procargs);
+
+//---------------------------------------------------------------------------------------
+///
+/// terminateProcess
+///
+/// Description: this function terminates a process given by its pid
+///
+/// Note: returns true if the process with the given pid was terminated
+///
+/// @param pid process id of the process to terminate
+
+ static bool terminateProcess(ProcessID pid);
+
+ protected:
+//---------------------------------------------------------------------------------------
+///
+/// OsSupport
+///
+/// Description: constructor of class OsSupport
+
+ OsSupport()
+ {}
+
+ }; // end of class OsSupport
+
+} // end of namespace System_
+
+#endif /* end of OS_SUPPORT_H__ */
Modified: trunk/reactos/tools/sysreg/rosboot_test.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/rosboot_test.…
==============================================================================
--- trunk/reactos/tools/sysreg/rosboot_test.cpp (original)
+++ trunk/reactos/tools/sysreg/rosboot_test.cpp Sun Nov 5 23:51:02 2006
@@ -14,6 +14,7 @@
#include "namedpipe_reader.h"
#include "sym_file.h"
#include "file_reader.h"
+#include "os_support.h"
#include <iostream>
#include <vector>
@@ -24,11 +25,6 @@
#include <assert.h>
-#ifndef __LINUX__
-#include <windows.h>
-#endif
-
-
namespace Sysreg_
{
using std::vector;
@@ -36,6 +32,7 @@
using System_::NamedPipeReader;
using System_::SymbolFile;
using System_::FileReader;
+ using System_::OsSupport;
string RosBootTest::VARIABLE_NAME = _T("ROSBOOT_CMD");
string RosBootTest::CLASS_NAME = _T("rosboot");
@@ -113,9 +110,11 @@
///
conf_parser.getStringValue (RosBootTest::CHECK_POINT, m_Checkpoint);
- conf_parser.getStringValue (RosBootTest::PID_FILE, m_PidFile);
conf_parser.getStringValue (RosBootTest::CRITICAL_APP, m_CriticalApp);
-
+ if (conf_parser.getStringValue (RosBootTest::PID_FILE, m_PidFile))
+ {
+ _tremove(m_PidFile.c_str ());
+ }
if (!_tcscmp(debug_port.c_str(), _T("pipe")))
{
@@ -318,40 +317,19 @@
{
NamedPipeReader namedpipe_reader;
string pipecmd = _T("");
-
-#ifdef __LINUX__
- pid_t pid;
-#else
- STARTUPINFO siStartInfo;
- PROCESS_INFORMATION piProcInfo;
- DWORD pid;
-
- ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
- ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
-
- siStartInfo.cb = sizeof(STARTUPINFO);
- siStartInfo.wShowWindow = SW_SHOWNORMAL;
- siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
-
- LPTSTR command = _tcsdup(boot_cmd.c_str());
-
- if (!CreateProcess(NULL, command, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL,
&siStartInfo, &piProcInfo))
- {
- cerr << "Error: CreateProcess failed " << boot_cmd
<<endl;
- return false;
- }
- else
- {
- pid = piProcInfo.dwProcessId;
- }
-#endif
+
+ ///
+ /// FIXME
+ /// split up arguments
+
+ OsSupport::ProcessID pid = OsSupport::createProcess ((TCHAR*)boot_cmd.c_str (), 0,
NULL);
string::size_type pipe_pos = boot_cmd.find (_T("serial pipe:"));
pipe_pos += 12;
string::size_type pipe_pos_end = boot_cmd.find (_T(" "), pipe_pos);
if (pipe_pos != string::npos && pipe_pos > 0 && pipe_pos <
boot_cmd.size())
{
- pipecmd = "\\\\.\\pipe\\" + boot_cmd.substr (pipe_pos, pipe_pos_end -
pipe_pos);
+ pipecmd = _T("\\\\.\\pipe\\") + boot_cmd.substr (pipe_pos, pipe_pos_end -
pipe_pos);
}
else
{
@@ -385,10 +363,8 @@
break;
}
- if (namedpipe_reader.readPipe (Buffer) != 0)
- {
- vect.push_back (Buffer.c_str());
-
+ if (namedpipe_reader.readPipe (vect) != 0)
+ {
DebugState state = checkDebugData(vect);
if (state == DebugStateBSODDetected || state == DebugStateUMEDetected)
{
@@ -402,17 +378,8 @@
}
}
namedpipe_reader.closePipe ();
-
-#ifdef __LINUX__
- kill(pid, SIGTERM);
-#else
- HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
- if (hProcess)
- {
- TerminateProcess(hProcess, 0);
- }
- CloseHandle(hProcess);
-#endif
+ _sleep(3* CLOCKS_PER_SEC);
+ OsSupport::terminateProcess (pid);
return ret;
}
@@ -421,7 +388,7 @@
{
PipeReader pipe_reader;
_tremove(debug_log.c_str ());
- _tremove(m_PidFile.c_str ());
+
if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
{
cerr << "Error: failed to open pipe with cmd: " << boot_cmd
<< endl;
@@ -437,7 +404,7 @@
_sleep( (clock_t)m_Delayread * CLOCKS_PER_SEC );
}
- int pid = 0;
+ OsSupport::ProcessID pid = 0;
if (m_PidFile != _T(""))
{
@@ -502,17 +469,9 @@
if (pid)
{
-#ifdef __LINUX__
- kill(pid, SIGTERM);
-#else
- HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
- if (hProcess)
- {
- TerminateProcess(hProcess, 0);
- }
- CloseHandle(hProcess);
-#endif
- }
+ OsSupport::terminateProcess (pid);
+ }
+
pipe_reader.closePipe ();
return ret;
}
Modified: trunk/reactos/tools/sysreg/sample.cfg
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sample.cfg?re…
==============================================================================
--- trunk/reactos/tools/sysreg/sample.cfg (original)
+++ trunk/reactos/tools/sysreg/sample.cfg Sun Nov 5 23:51:02 2006
@@ -27,7 +27,7 @@
; This value is the command which is executed to gain debugging data
; this value is mandatory
-ROSBOOT_CMD=D:\sysreg\qemu\qemu.exe -serial file:debug.log -boot c -m 128 -L
D:\sysreg\qemu\ D:\sysreg\qemu\RosVM.vmdk -cdrom D:\Reactos\ReactOS-RegTest.iso -pidfile
pid.txt
+ROSBOOT_CMD=D:\sysreg\qemu\qemu.exe -serial pipe:qemu -boot c -m 128 -L D:\sysreg\qemu\
D:\sysreg\qemu\RosVM.vmdk -cdrom D:\Reactos\ReactOS-RegTest.iso -pidfile pid.txt
;
; ROSBOOT_PIDFILE
@@ -47,8 +47,8 @@
; If the value is set to pipe, then sysreg will read from pipe created by the
; ROSBOOT_CMD
;
-;ROSBOOT_DEBUG_PORT=pipe
-ROSBOOT_DEBUG_PORT=file
+;ROSBOOT_DEBUG_PORT=file
+ROSBOOT_DEBUG_PORT=pipe
;
; ROSBOOT_DEBUG_FILE
Modified: trunk/reactos/tools/sysreg/sysreg.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sysreg.cpp?re…
==============================================================================
--- trunk/reactos/tools/sysreg/sysreg.cpp (original)
+++ trunk/reactos/tools/sysreg/sysreg.cpp Sun Nov 5 23:51:02 2006
@@ -36,6 +36,7 @@
ComponentFactory comp_factory;
TCHAR DefaultConfig[] = _T("sysreg.cfg");
TCHAR *ConfigFile;
+ TCHAR * TestName;
if ((argc != 3) && (argc != 2))
{
@@ -59,9 +60,15 @@
}
if (argc == 2)
- _tcscpy(ConfigFile, DefaultConfig);
+ {
+ ConfigFile = DefaultConfig;
+ TestName = argv[1];
+ }
else
+ {
ConfigFile = argv[1];
+ TestName = argv[2];
+ }
if (!config.parseFile (ConfigFile))
@@ -70,7 +77,7 @@
return -1;
}
- RegressionTest * regtest = comp_factory.createComponent (argv[2]);
+ RegressionTest * regtest = comp_factory.createComponent (TestName);
if (!regtest)
{
cerr << "Error: the requested regression test does not exist" <<
endl;
@@ -82,7 +89,7 @@
config.getStringValue (ros, envvar);
SymbolFile::initialize (config, envvar);
-
+
if (regtest->execute (config))
{
cout << "The regression test " << regtest->getName () <<
" completed successfully" << endl;
Modified: trunk/reactos/tools/sysreg/sysreg.mak
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sysreg.mak?re…
==============================================================================
--- trunk/reactos/tools/sysreg/sysreg.mak (original)
+++ trunk/reactos/tools/sysreg/sysreg.mak Sun Nov 5 23:51:02 2006
@@ -27,6 +27,8 @@
sym_file.cpp \
sysreg.cpp \
file_reader.cpp \
+ os_support.cpp \
+ unicode.cpp \
)
SYSREGBUILD_OBJECTS = \
@@ -76,6 +78,14 @@
$(ECHO_CC)
${host_gpp} $(SYSREGBUILD_HOST_CFLAGS) -c $< -o $@
+$(SYSREGBUILD_INT_)os_support.o: $(SYSREGBUILD_BASE_)os_support.cpp | $(SYSREGBUILD_INT)
+ $(ECHO_CC)
+ ${host_gpp} $(SYSREGBUILD_HOST_CFLAGS) -c $< -o $@
+
+$(SYSREGBUILD_INT_)unicode.o: $(SYSREGBUILD_BASE_)unicode.cpp | $(SYSREGBUILD_INT)
+ $(ECHO_CC)
+ ${host_gpp} $(SYSREGBUILD_HOST_CFLAGS) -c $< -o $@
+
.PHONY: sysregbuild_clean
sysreg_clean:
-@$(rm) $(SYSREGBUILD_TARGET) $(SYSREGBUILD_OBJECTS) 2>$(NUL)
Added: trunk/reactos/tools/sysreg/unicode.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/unicode.cpp?r…
==============================================================================
--- trunk/reactos/tools/sysreg/unicode.cpp (added)
+++ trunk/reactos/tools/sysreg/unicode.cpp Sun Nov 5 23:51:02 2006
@@ -1,0 +1,31 @@
+#include "unicode.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+namespace System_
+{
+//---------------------------------------------------------------------------------------
+ bool UnicodeConverter::ansi2Unicode(char * abuf, wchar_t *outbuf, size_t length)
+ {
+ size_t i = 0;
+ int conv;
+
+ while((conv = mbtowc(&outbuf[i], &abuf[i], length - i)))
+ {
+ i += conv;
+ if (i == length)
+ break;
+ }
+ outbuf[i] = L'\0';
+
+ if (i)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+} // end of namespace System_
Added: trunk/reactos/tools/sysreg/unicode.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/unicode.h?rev…
==============================================================================
--- trunk/reactos/tools/sysreg/unicode.h (added)
+++ trunk/reactos/tools/sysreg/unicode.h Sun Nov 5 23:51:02 2006
@@ -1,0 +1,55 @@
+#ifndef UNICODE_H__
+#define UNICODE_H__ // unicode.h
+
+#include "user_types.h"
+
+namespace System_
+{
+
+ class UnicodeConverter
+ {
+ public:
+//---------------------------------------------------------------------------------------
+///
+/// UnicodeConverter
+///
+/// Description: destructor of class UnicodeConverter
+
+ virtual ~UnicodeConverter()
+ {}
+
+//---------------------------------------------------------------------------------------
+///
+/// UnicodeConverter
+///
+/// Description: converts an ANSI buffer to wide character buffer
+/// using standard c routines
+///
+/// Note: make sure before calling that outbuf is big enough to receive the result
+///
+/// @param abuf ansi buffer used a source
+/// @param outbuf wide character buffer receives result
+/// @param length length of abuf
+///
+/// @return bool
+
+ static bool ansi2Unicode(char * abuf, wchar_t * outbuf, size_t length);
+
+
+ protected:
+//---------------------------------------------------------------------------------------
+///
+/// UnicodeConverter
+///
+/// Description: constructor of class UnicodeConverter
+
+ UnicodeConverter()
+ {}
+
+ }; // end of class UnicodeConverter
+
+
+
+} // end of namespace System_
+
+#endif /* end of UNICODE_H__ */