[ros-diffs] [janderwald] 24697: - improve namedpipe_reader parsing of lines code - it should now be able handle partial / full lines

janderwald at svn.reactos.org janderwald at svn.reactos.org
Tue Nov 7 00:50:04 CET 2006


Author: janderwald
Date: Tue Nov  7 02:50:03 2006
New Revision: 24697

URL: http://svn.reactos.org/svn/reactos?rev=24697&view=rev
Log:
- improve namedpipe_reader parsing of lines code
- it should now be able handle partial / full lines

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/namedpipe_reader.cpp?rev=24697&r1=24696&r2=24697&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (original)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Tue Nov  7 02:50:03 2006
@@ -95,11 +95,43 @@
 //---------------------------------------------------------------------------------------
 	void NamedPipeReader::extractLines(TCHAR * buffer, std::vector<string> & vect, bool & append_line, unsigned long cbRead)
 	{
-		TCHAR * offset = _tcsstr(buffer, _T("\x0D"));
+		TCHAR * offset = _tcschr(buffer, _T('\x0D'));
 		DWORD buf_offset = 0;
 		while(offset)
 		{
-			offset[0] = _T('\0');
+			///
+			/// HACKHACK
+			/// due to some mysterious reason, _tcschr / _tcsstr sometimes returns
+			/// not always the offset to the CR character but to the next LF
+			/// in MSVC 2005 (Debug Modus)
+
+			if (offset[0] == _T('\x0A'))
+			{
+				if (buf_offset)
+				{
+					offset--;
+				}
+				else
+				{
+					//TODO
+					// implement me special case
+				}
+			}
+
+			if (offset[0] == _T('\x0D'))
+			{
+				buf_offset += 2;
+				offset[0] = _T('\0');
+				offset +=2;
+			}
+			else
+			{
+				///
+				/// BUG detected in parsing code
+				///
+				abort();
+			}
+
 			string line = buffer;
 			if (append_line)
 			{
@@ -115,18 +147,18 @@
 				vect.push_back (line);
 			}
 
-			offset += 2;
-						
-			buf_offset += line.length () + 2;
+			buf_offset += line.length();
 			if (buf_offset >= cbRead)
 			{
 				break;
 			}
 			buffer = offset;
+
 			offset = _tcsstr(buffer, _T("\n"));
 		}
 		if (buf_offset < cbRead)
 		{
+			buffer[cbRead - buf_offset] = _T('\0');
 			string line = buffer;
 			if (append_line)
 			{
@@ -195,7 +227,7 @@
 #endif
 
 				} while (!fSuccess);  // repeat loop if ERROR_MORE_DATA 
-			} while (localbuf[strlen(localbuf)-1] != '\n');
+			} while (append_line);
 
 			if (!fSuccess)
 				return 0;




More information about the Ros-diffs mailing list