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. * ostrshrt.cpp - definitions for ostream class operator<<(short) member functions
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the member function definitions for ostream operator<<(short).
  8. *
  9. *Revision History:
  10. * 09-23-91 KRS Created. Split out from ostream.cxx for granularity.
  11. * 06-14-95 CFW Comment cleanup.
  12. *
  13. *******************************************************************************/
  14. #include <cruntime.h>
  15. #include <internal.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <iostream.h>
  19. #pragma hdrstop
  20. ostream& ostream::operator<<(short n)
  21. {
  22. _WINSTATIC char obuffer[8]; // assumes max int is 65535
  23. _WINSTATIC char fmt[4] = "%hd";
  24. _WINSTATIC char leader[4] = "\0\0";
  25. if (opfx()) {
  26. if (n)
  27. {
  28. if (x_flags & (hex|oct))
  29. {
  30. if (x_flags & hex)
  31. {
  32. if (x_flags & uppercase)
  33. fmt[2] = 'X';
  34. else
  35. fmt[2] = 'x';
  36. leader[1] = fmt[2]; // 0x or 0X (or \0X)
  37. }
  38. else
  39. fmt[2] = 'o';
  40. if (x_flags & showbase)
  41. leader[0] = '0';
  42. }
  43. else if ((n>0) && (x_flags & showpos))
  44. {
  45. leader[0] = '+';
  46. }
  47. }
  48. sprintf(obuffer,fmt,n);
  49. writepad(leader,obuffer);
  50. osfx();
  51. }
  52. return *this;
  53. }