Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

  1. /*****************************************************************************
  2. *
  3. * buffer.cpp
  4. *
  5. * Lame buffering implementation.
  6. *
  7. *****************************************************************************/
  8. #include "sdview.h"
  9. BOOL IOBuffer::NextLine(String &str)
  10. {
  11. str.Reset();
  12. do {
  13. /*
  14. * Drain what we can from the current buffer.
  15. */
  16. int i = 0;
  17. while (i < _cchBufUsed && _rgchBuf[i++] != TEXT('\n')) {
  18. /* Keep looking */
  19. }
  20. if (i) {
  21. /* _rgchBuf[i] is the first char not to append */
  22. str.Append(_rgchBuf, i);
  23. memcpy(_rgchBuf, _rgchBuf+i, _cchBufUsed - i);
  24. _cchBufUsed -= i;
  25. /* Stop if we copied a \n */
  26. if (str[str.Length()-1] == TEXT('\n')) {
  27. return TRUE;
  28. }
  29. }
  30. /*
  31. * Refill from the file until it's all gone.
  32. */
  33. if (_hRead)
  34. {
  35. DWORD dwBytesRead;
  36. if (!ReadFile(_hRead, _rgchBuf, _cchBuf, &dwBytesRead, NULL)) {
  37. _hRead = NULL;
  38. }
  39. #ifdef UNICODE
  40. #error Need to convert from ANSI to UNICODE here
  41. #endif
  42. _cchBufUsed = dwBytesRead;
  43. }
  44. } while (_hRead);
  45. return FALSE;
  46. }