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.

73 lines
2.2 KiB

  1. /***
  2. * istrgetl.cpp - definitions for istream class get() member function
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Definitions of get and getline member functions istream class.
  8. * [AT&T C++]
  9. *
  10. *Revision History:
  11. * 09-26-91 KRS Created. Split off from istream.cxx for granularity.
  12. * 01-23-92 KRS C700 #5880: Add cast to fix comparison in get().
  13. * 05-11-95 CFW Change delim to int to support ignore(str,EOF).
  14. * 06-14-95 CFW Comment cleanup.
  15. *
  16. *******************************************************************************/
  17. #include <cruntime.h>
  18. #include <internal.h>
  19. #include <iostream.h>
  20. #pragma hdrstop
  21. // unformatted input functions
  22. // signed and unsigned char make inline calls to this:
  23. // all versions of getline also share this code:
  24. istream& istream::get( char *b, int lim, int delim)
  25. {
  26. int c;
  27. unsigned int i = 0;
  28. if (ipfx(1)) // resets x_gcount
  29. {
  30. if (lim--)
  31. {
  32. while (i < (unsigned)lim)
  33. {
  34. c = bp->sgetc();
  35. if (c == EOF)
  36. {
  37. state |= ios::eofbit;
  38. if (!i)
  39. state |= ios::failbit;
  40. break;
  41. }
  42. else if (c == delim)
  43. {
  44. if (_fGline)
  45. {
  46. x_gcount++;
  47. bp->stossc(); // extract delim if called from getline
  48. }
  49. break;
  50. }
  51. else
  52. {
  53. if (b)
  54. b[i] = (char)c;
  55. bp->stossc(); // advance pointer
  56. }
  57. i++;
  58. }
  59. x_gcount += i; // set gcount()
  60. }
  61. isfx();
  62. lim++; // restore lim for test below
  63. }
  64. if ((b) && (lim)) // always null-terminate, if possible
  65. b[i] = '\0';
  66. _fGline = 0;
  67. return *this;
  68. }