home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / stream.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  4.1 KB  |  244 lines

  1. /* 
  2. Copyright (C) 1988 Free Software Foundation
  3.     written by Doug Lea (dl@rocky.oswego.edu)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU CC General Public
  12. License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. GNU CC, but only under the conditions described in the
  16. GNU CC General Public License.   A copy of this license is
  17. supposed to have been given to you along with GNU CC so you
  18. can know your rights and responsibilities.  It should be in a
  19. file named COPYING.  Among other things, the copyright notice
  20. and this notice must be preserved on all copies.  
  21. */
  22.  
  23. #include <stream.h>
  24. #include <stdarg.h>
  25. #include <ctype.h>
  26. #include "libconfig.h"
  27.  
  28. ostream::ostream() {}
  29.  
  30. ostream::ostream(const char* filename, io_mode m, access_mode a)
  31. :(filename, m, a) {}
  32.  
  33. ostream::ostream(const char* filename, const char* m)
  34. :(filename, m) {}
  35.  
  36. ostream::ostream(int filedesc, io_mode m = io_writeonly)
  37. :(filedesc, m) {}
  38.  
  39. ostream::ostream(FILE* fileptr)
  40. :(fileptr) {}
  41.  
  42. ostream::ostream(int sz, char* buf)
  43. :(sz, buf, io_writeonly) {}
  44.  
  45. ostream::~ostream() {}
  46.  
  47. istream::istream()
  48.   tied_to = 0; 
  49. }
  50.  
  51. istream::istream(const char* filename, io_mode m, access_mode a) 
  52. :(filename, m, a) 
  53.   tied_to = 0; 
  54. }
  55.  
  56. istream::istream(const char* filename, const char* m)
  57. :(filename, m) 
  58.   tied_to = 0;
  59. }
  60.  
  61. istream::istream(int filedesc, io_mode m = io_readonly)
  62. :(filedesc, m) 
  63.   tied_to = 0; 
  64. }
  65.  
  66. istream::istream(FILE* fileptr)
  67. :(fileptr) 
  68.   tied_to = 0;
  69. }
  70.  
  71. istream::istream(int sz, char* buf)
  72. :(sz, buf, io_readonly)
  73.   tied_to = 0;
  74. }
  75.  
  76. istream::~istream() {}
  77.  
  78.  
  79. ostream* istream::tie(ostream* s) 
  80.   ostream* t = tied_to; 
  81.   tied_to = s; 
  82.   return t; 
  83. }
  84.  
  85. istream& istream::operator>>(whitespace&)
  86. {
  87.   _flush();
  88.   char ch;
  89.   while((get(ch)) && isspace(ch));
  90.   if (good())
  91.     unget(ch);
  92.   return *this;
  93. }
  94.  
  95. istream& istream::operator>>(char& ch)
  96. {
  97.   _flush();
  98.   while((get(ch)) && isspace(ch));
  99.   return *this;
  100. }
  101.  
  102. istream& istream::scan(const char* fmt ...)
  103. {
  104.   if (readable())
  105.   {
  106.     _flush();
  107.     va_list args;
  108.     va_start(args, fmt);
  109.     stat = _doscan(fp, fmt, args);
  110.     va_end(args);
  111.     failif(stat <= 0);
  112.   }
  113.   return *this;
  114. }
  115.  
  116. istream& istream::operator>>(short&  n)
  117.   return scan("%hd", &n); 
  118. }
  119.  
  120. istream& istream::operator>>(unsigned short& n)
  121.   return scan("%hd", &n); 
  122. }
  123.  
  124. istream& istream::operator>>(int&    n)
  125.   return scan("%d",  &n); 
  126. }
  127.  
  128. istream& istream::operator>>(unsigned int& n)
  129.   return scan("%d",  &n); 
  130. }
  131.  
  132. istream& istream::operator>>(long&   n)
  133.   return scan("%ld", &n); 
  134. }
  135.  
  136. istream& istream::operator>>(unsigned long& n)
  137.   return scan("%ld", &n); 
  138. }
  139.  
  140. istream& istream::operator>>(float&  n)
  141.   return scan("%f",  &n); 
  142. }
  143.  
  144. istream& istream::operator>>(double& n)
  145.   return scan("%lf", &n); 
  146. }
  147.  
  148. istream& istream::operator>>(char*   s)
  149.   return scan("%s",   s); 
  150. }
  151.  
  152. void eatwhite(istream& s)
  153. {
  154.   s >> WS;
  155. }
  156.  
  157.  
  158. ostream& ostream::form(const char* fmt ...)
  159. {
  160.   va_list args;
  161.   va_start(args, fmt);
  162. #ifndef HAVE_VPRINTF
  163.   stat = _doprnt(fmt, args, fp);
  164. #else
  165.   stat = vfprintf(fp, fmt, args);
  166. #endif
  167.   va_end(args);
  168.   failif(stat < 0);
  169.   return *this;
  170. }
  171.  
  172. ostream& ostream::operator<<(const char* s)
  173.   put(s);  return *this;
  174. }
  175.  
  176. ostream& ostream::operator<<(short  n)
  177.   return form("%d",(int)n);
  178. }
  179.  
  180. ostream& ostream::operator<<(unsigned short n)
  181.   return form("%u",(unsigned)n);
  182. }
  183.  
  184. ostream& ostream::operator<<(int    n)
  185.   return form("%d",n);
  186. }
  187.  
  188. ostream& ostream::operator<<(unsigned int n)
  189.   return form("%u",n);
  190. }
  191.  
  192. ostream& ostream::operator<<(long   n)
  193.   return form("%ld",n);
  194. }
  195.  
  196. ostream& ostream::operator<<(unsigned long n)
  197.   return form("%lu",n);
  198. }
  199.  
  200. ostream& ostream::operator<<(float  n)
  201.   return form("%g",(double)n);
  202. }
  203.  
  204. ostream& ostream::operator<<(double n)
  205.   return form("%g",n);
  206. }
  207.  
  208.  
  209. /*
  210.  * predeclared streams
  211.  */
  212.  
  213. istream  cin(stdin);
  214. ostream  cout(stdout);
  215. ostream  cerr(stderr);
  216.  
  217. whitespace WS;
  218.  
  219.