Author: cfinck Date: Fri Mar 14 19:35:48 2008 New Revision: 32686
URL: http://svn.reactos.org/svn/reactos?rev=3D32686&view=3Drev Log: - Add <cstring> for "memset", "strchr" and "strstr" - Use the C++ wrapper headers consistently - Fix indentation
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp
Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpip= e_reader.cpp?rev=3D32686&r1=3D32685&r2=3D32686&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (original) +++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Fri Mar 14 19:35:48 2008 @@ -11,7 +11,8 @@ #include "namedpipe_reader.h" =
#include <iostream> -#include <assert.h> +#include <cassert> +#include <cstring> =
namespace System_ { @@ -22,51 +23,51 @@ #else const char * NamedPipeReader::s_LineBreak =3D "\x0D\x0A\0"; #endif - using std::vector; + using std::vector; //------------------------------------------------------------------------= --------------- NamedPipeReader::NamedPipeReader() : DataSource(), h_Pipe(NULLVAL), m_= Buffer(0) - { - } - -//------------------------------------------------------------------------= --------------- - NamedPipeReader::~NamedPipeReader() - { + { + } + +//------------------------------------------------------------------------= --------------- + NamedPipeReader::~NamedPipeReader() + { if (m_Buffer) free(m_Buffer); - } - - bool NamedPipeReader::isSourceOpen() - { - return true; - } - -//------------------------------------------------------------------------= --------------- - - bool NamedPipeReader::openSource(const string & PipeCmd) - { - if (h_Pipe !=3D NULLVAL) - { - cerr << "NamedPipeReader::openPipe> pipe already open" << endl; - return false; - } + } + + bool NamedPipeReader::isSourceOpen() + { + return true; + } + +//------------------------------------------------------------------------= --------------- + + bool NamedPipeReader::openSource(const string & PipeCmd) + { + if (h_Pipe !=3D NULLVAL) + { + cerr << "NamedPipeReader::openPipe> pipe already open" << endl; + return false; + } #ifndef __LINUX__ - h_Pipe =3D CreateFile(PipeCmd.c_str(), - GENERIC_WRITE | GENERIC_READ, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - (HANDLE) - NULL); - - if(INVALID_HANDLE_VALUE =3D=3D h_Pipe) { + h_Pipe =3D CreateFile(PipeCmd.c_str(), + GENERIC_WRITE | GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + (HANDLE) + NULL); + + if(INVALID_HANDLE_VALUE =3D=3D h_Pipe) { cerr << "NamedPipeReader::openPipe> failed to open pipe " << P= ipeCmd << " Error:" << GetLastError() << endl; - h_Pipe =3D NULLVAL; - return false; - } - else - { - cout << "NamedPipeReader::openPipe> successfully opened pipe" << endl; + h_Pipe =3D NULLVAL; + return false; + } + else + { + cout << "NamedPipeReader::openPipe> successfully opened pipe" = << endl; =
if (!m_Buffer) { @@ -74,49 +75,49 @@ m_Buffer =3D (char*)malloc(sizeof(char) * m_BufferLength); } ConnectNamedPipe(h_Pipe, - 0); + 0); return true; - } -#else - h_Pipe =3D open(PipeCmd.c_str(), O_RDONLY); - - if(INVALID_HANDLE_VALUE =3D=3D h_Pipe) { - cerr << "NamedPipeReader::openPipe> failed to open pipe " << PipeCmd <<= endl; - h_Pipe =3D NULLVAL; - return false; - } - else - { + } +#else + h_Pipe =3D open(PipeCmd.c_str(), O_RDONLY); + + if(INVALID_HANDLE_VALUE =3D=3D h_Pipe) { + cerr << "NamedPipeReader::openPipe> failed to open pipe " << P= ipeCmd << endl; + h_Pipe =3D NULLVAL; + return false; + } + else + { cout << "NamedPipeReader::openPipe> successfully opened pipe h= andle: "<< h_Pipe << endl << "Src: " << PipeCmd << endl; if (!m_Buffer) { m_BufferLength =3D 100; m_Buffer =3D (char*)malloc(sizeof(char) * m_BufferLength); } - return true; - } -#endif - } - -//------------------------------------------------------------------------= --------------- - - bool NamedPipeReader::closeSource() =
- { + return true; + } +#endif + } + +//------------------------------------------------------------------------= --------------- + + bool NamedPipeReader::closeSource() =
+ { cerr << "NamedPipeReader::closePipe> entered" << endl; - if (h_Pipe =3D=3D NULLVAL) - { - cerr << "NamedPipeReader::closePipe> pipe is not open" << endl; - return false; - } + if (h_Pipe =3D=3D NULLVAL) + { + cerr << "NamedPipeReader::closePipe> pipe is not open" << endl; + return false; + } #ifdef __LINUX__ close(h_Pipe); #else - DisconnectNamedPipe(h_Pipe); - CloseHandle(h_Pipe); -#endif - h_Pipe =3D NULLVAL; - return true; - } + DisconnectNamedPipe(h_Pipe); + CloseHandle(h_Pipe); +#endif + h_Pipe =3D NULLVAL; + return true; + } //------------------------------------------------------------------------= --------------- void NamedPipeReader::insertLine(std::vector<string> & vect, string li= ne, bool append_line) { @@ -133,14 +134,14 @@ =
} //------------------------------------------------------------------------= --------------- - void NamedPipeReader::extractLines(char * buffer, std::vector<string> & v= ect, bool & append_line, unsigned long cbRead) - { + void NamedPipeReader::extractLines(char * buffer, std::vector<string> = & vect, bool & append_line, unsigned long cbRead) + { #if 0 long offset =3D 0; size_t start_size =3D vect.size (); char * start =3D buffer; buffer[cbRead] =3D '\0'; - char * end =3D strstr(buffer, s_LineBreak); + char * end =3D strstr(buffer, s_LineBreak); =
//cout << "extractLines entered with append_line: " << append_line= << " cbRead: " << cbRead << "buffer: " << buffer << endl; =
@@ -189,90 +190,90 @@ =
#else DWORD buf_offset =3D 0; - char * offset =3D strchr(buffer, '\x0D'); - while(offset) - { - /// - /// HACKHACK - /// due to some mysterious reason, strchr / strstr sometimes returns - /// not always the offset to the CR character but to the next LF - /// in MSVC 2005 (Debug Modus) - - if (offset[0] =3D=3D '\x0A') - { - if (buf_offset) - { - offset--; - } - else - { - //TODO - // implement me special case - } - } - - if (offset[0] =3D=3D '\x0D') - { - buf_offset +=3D 2; - offset[0] =3D '\0'; - offset +=3D2; - } - else - { - /// - /// BUG detected in parsing code - /// - abort(); - } - - string line =3D buffer; - if (append_line) - { - assert(vect.empty () =3D=3D false); - string prev_line =3D vect[vect.size () -1]; - prev_line +=3D line; - vect.pop_back (); - vect.push_back (prev_line); - append_line =3D false; - } - else - { - vect.push_back (line); - } - - buf_offset +=3D line.length(); - if (buf_offset >=3D cbRead) - { - break; - } - buffer =3D offset; - - offset =3D strstr(buffer, "\n"); - } - if (buf_offset < cbRead) - { - buffer[cbRead - buf_offset] =3D '\0'; - string line =3D buffer; - if (append_line) - { - assert(vect.empty () =3D=3D false); - string prev_line =3D vect[vect.size () -1]; - vect.pop_back (); - prev_line +=3D line; - vect.push_back (prev_line); - } - else - { - vect.push_back (line); - append_line =3D true; - } - } - else - { - append_line =3D false; - } -#endif - } + char * offset =3D strchr(buffer, '\x0D'); + while(offset) + { + /// + /// HACKHACK + /// due to some mysterious reason, strchr / strstr sometimes r= eturns + /// not always the offset to the CR character but to the next = LF + /// in MSVC 2005 (Debug Modus) + + if (offset[0] =3D=3D '\x0A') + { + if (buf_offset) + { + offset--; + } + else + { + //TODO + // implement me special case + } + } + + if (offset[0] =3D=3D '\x0D') + { + buf_offset +=3D 2; + offset[0] =3D '\0'; + offset +=3D2; + } + else + { + /// + /// BUG detected in parsing code + /// + abort(); + } + + string line =3D buffer; + if (append_line) + { + assert(vect.empty () =3D=3D false); + string prev_line =3D vect[vect.size () -1]; + prev_line +=3D line; + vect.pop_back (); + vect.push_back (prev_line); + append_line =3D false; + } + else + { + vect.push_back (line); + } + + buf_offset +=3D line.length(); + if (buf_offset >=3D cbRead) + { + break; + } + buffer =3D offset; + + offset =3D strstr(buffer, "\n"); + } + if (buf_offset < cbRead) + { + buffer[cbRead - buf_offset] =3D '\0'; + string line =3D buffer; + if (append_line) + { + assert(vect.empty () =3D=3D false); + string prev_line =3D vect[vect.size () -1]; + vect.pop_back (); + prev_line +=3D line; + vect.push_back (prev_line); + } + else + { + vect.push_back (line); + append_line =3D true; + } + } + else + { + append_line =3D false; + } +#endif + } //------------------------------------------------------------------------= --------------- bool NamedPipeReader::readPipe(char * buffer, int bufferlength, long &= bytesread) { @@ -284,12 +285,12 @@ #else DWORD cbRead =3D 0; BOOL fSuccess =3D ReadFile(h_Pipe, - buffer, - (bufferlength-1) * sizeof(char), - &cbRead, - NULL); - =
- if (!fSuccess && GetLastError() !=3D ERROR_MORE_DATA) + buffer, + (bufferlength-1) * sizeof(char), + &cbRead, + NULL); + =
+ if (!fSuccess && GetLastError() !=3D ERROR_MORE_DATA) return false; #endif =
@@ -298,9 +299,9 @@ } //------------------------------------------------------------------------= --------------- =
- bool NamedPipeReader::readSource(vector<string> & vect) - { - size_t lines =3D vect.size (); + bool NamedPipeReader::readSource(vector<string> & vect) + { + size_t lines =3D vect.size (); =
if (h_Pipe =3D=3D NULLVAL) { @@ -314,9 +315,9 @@ return false; } =
- bool append_line =3D false; - do - { + bool append_line =3D false; + do + { memset(m_Buffer, 0x0, m_BufferLength * sizeof(char)); long cbRead =3D 0; =