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.

159 lines
2.9 KiB

25 years ago
  1. // I/O through <stdio.h> or <iostream.h>
  2. #ifndef _CL_IO_H
  3. #define _CL_IO_H
  4. #include "cl_types.h"
  5. #include "cl_modules.h"
  6. #if !defined(CL_IO_STDIO) && !defined(CL_IO_IOSTREAM)
  7. // Prefer iostream based I/O - this is what people expect.
  8. #define CL_IO_IOSTREAM
  9. #endif
  10. #if defined(CL_IO_STDIO)
  11. // I/O through <stdio.h>
  12. #include <stdio.h>
  13. #define cl_istream FILE *
  14. #define cl_ostream FILE *
  15. #define cl_stdin stdin
  16. #define cl_stdout stdout
  17. #define cl_stderr stderr
  18. extern FILE* cl_debugout;
  19. // Elementary operations on cl_istream
  20. #define cl_EOF EOF
  21. inline int freadchar (cl_istream stream)
  22. {
  23. // return fgetc(stream);
  24. return getc(stream);
  25. }
  26. inline int funreadchar (cl_istream stream, int c)
  27. {
  28. return ungetc(c,stream);
  29. }
  30. // Elementary operations on cl_ostream
  31. inline void fprintchar (cl_ostream stream, char c)
  32. {
  33. // fputc(c,stream);
  34. putc(c,stream);
  35. }
  36. inline void fprint (cl_ostream stream, const char * string)
  37. {
  38. // fprintf(stream,"%s",string);
  39. fputs(string,stream);
  40. }
  41. #endif
  42. #if defined(CL_IO_IOSTREAM)
  43. // I/O through <iostream.h>
  44. #ifdef floor
  45. #undef floor
  46. #include <iostream.h>
  47. #define floor cln_floor
  48. #else
  49. #include <iostream.h>
  50. #endif
  51. #define cl_istream istream&
  52. #define cl_ostream ostream&
  53. #define cl_stdin cin
  54. #define cl_stdout cout
  55. #define cl_stderr cerr
  56. extern ostream* cl_debugout_stream;
  57. #define cl_debugout (*cl_debugout_stream)
  58. // Elementary operations on cl_istream
  59. #define cl_EOF (-1)
  60. inline int freadchar (cl_istream stream)
  61. {
  62. char c;
  63. if (stream.get(c))
  64. return c;
  65. else
  66. // EOF or error
  67. return cl_EOF;
  68. }
  69. inline int funreadchar (cl_istream stream, int c)
  70. {
  71. if (c != cl_EOF)
  72. stream.putback((char)c);
  73. return c;
  74. }
  75. // Elementary operations on cl_ostream
  76. inline void fprintchar (cl_ostream stream, char c)
  77. {
  78. stream.put(c);
  79. }
  80. inline void fprint (cl_ostream stream, const char * string)
  81. {
  82. stream << string;
  83. }
  84. #endif
  85. extern void fprintdecimal (cl_ostream stream, unsigned long x);
  86. extern void fprintdecimal (cl_ostream stream, long x);
  87. inline void fprintdecimal (cl_ostream stream, unsigned int x)
  88. {
  89. fprintdecimal(stream,(unsigned long)x);
  90. }
  91. inline void fprintdecimal (cl_ostream stream, int x)
  92. {
  93. fprintdecimal(stream,(long)x);
  94. }
  95. extern void fprinthexadecimal (cl_ostream stream, unsigned long x);
  96. extern void fprinthexadecimal (cl_ostream stream, long x);
  97. inline void fprinthexadecimal (cl_ostream stream, unsigned int x)
  98. {
  99. fprinthexadecimal(stream,(unsigned long)x);
  100. }
  101. inline void fprinthexadecimal (cl_ostream stream, int x)
  102. {
  103. fprinthexadecimal(stream,(long)x);
  104. }
  105. class cl_print_flags;
  106. class cl_print_number_flags;
  107. class cl_print_real_flags;
  108. class cl_print_rational_flags;
  109. class cl_print_float_flags;
  110. CL_REQUIRE(cl_prin_globals)
  111. // Define the customary << and >> operators.
  112. #define CL_DEFINE_PRINT_OPERATOR(_class_) \
  113. inline cl_ostream operator<< (cl_ostream stream, const _class_& x) \
  114. { \
  115. fprint(stream,x); \
  116. return stream; \
  117. }
  118. #endif /* _CL_IO_H */