/src/lib/io/basic/std_error.e

http://github.com/tybor/Liberty · Specman e · 147 lines · 87 code · 19 blank · 41 comment · 2 complexity · 7511457630d604eae80baa8529d2f1f2 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class STD_ERROR
  5. --
  6. -- To write on the standard error output. As for UNIX, the default standard error file is the screen.
  7. --
  8. -- Note: only one instance of this class should be necessary. Access it through ANY.std_error.
  9. --
  10. -- See also STANDARD_STREAMS
  11. --
  12. inherit
  13. TERMINAL_OUTPUT_STREAM
  14. redefine put_natively_stored_string, dispose
  15. end
  16. insert
  17. REDIRECTION_TOOLS
  18. rename
  19. restore_default as restore_default_error
  20. redefine
  21. restore_default_error
  22. end
  23. create {ANY}
  24. make
  25. feature {ANY}
  26. is_connected: BOOLEAN True
  27. disconnect
  28. do
  29. filter := Void
  30. end
  31. feature {FILTER_OUTPUT_STREAM}
  32. filtered_put_character (c: CHARACTER)
  33. do
  34. io_putc(c, stderr)
  35. end
  36. filtered_flush
  37. do
  38. std_output.flush
  39. io_flush(stderr)
  40. end
  41. feature {ABSTRACT_STRING}
  42. put_natively_stored_string (s: NATIVELY_STORED_STRING)
  43. local
  44. unused_result: INTEGER
  45. fs: FIXED_STRING
  46. do
  47. if fs ?:= s then
  48. fs ::= s
  49. --|*** TODO: replace by an io_fwrite_slice
  50. if fs.is_shared then
  51. fs.unshare
  52. end
  53. end
  54. unused_result := io_fwrite(s.storage, s.count, stderr)
  55. end
  56. feature {FILTER}
  57. filtered_descriptor: INTEGER
  58. do
  59. Result := sequencer_descriptor(stderr)
  60. end
  61. filtered_has_descriptor: BOOLEAN True
  62. filtered_stream_pointer: POINTER
  63. do
  64. Result := stderr
  65. end
  66. filtered_has_stream_pointer: BOOLEAN True
  67. feature {STREAM_HANDLER}
  68. redirect_to (file_name: STRING)
  69. -- Redirect standard error to `file_name' instead of the default standard error. If `file_name'
  70. -- does not exist, it is created. If it exists, its previous content is erased.
  71. --
  72. -- See also `redirection_succeeded'
  73. do
  74. redirect(open_descriptor_for_create(file_name.to_external))
  75. end
  76. redirect_append_to (file_name: STRING)
  77. -- Redirect standard error to `file_name' instead of the default standard error. If `file_name'
  78. -- does not exist, it is created. If it exists, the new error stream is appended to it.
  79. --
  80. -- See also `redirection_succeeded'
  81. do
  82. redirect(open_descriptor_for_append(file_name.to_external))
  83. end
  84. restore_default_error
  85. -- Restore standard error to go to the default standard error.
  86. do
  87. Precursor
  88. end
  89. feature {}
  90. make
  91. do
  92. end
  93. stderr: POINTER
  94. external "plug_in"
  95. alias "{
  96. location: "${sys}/plugins"
  97. module_name: "io"
  98. feature_name: "stderr"
  99. }"
  100. end
  101. dispose
  102. do
  103. check
  104. std_error = Current
  105. end
  106. -- Nothing to dispose for `std_error'.
  107. end
  108. end -- class STD_ERROR
  109. --
  110. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  111. --
  112. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  113. -- of this software and associated documentation files (the "Software"), to deal
  114. -- in the Software without restriction, including without limitation the rights
  115. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  116. -- copies of the Software, and to permit persons to whom the Software is
  117. -- furnished to do so, subject to the following conditions:
  118. --
  119. -- The above copyright notice and this permission notice shall be included in
  120. -- all copies or substantial portions of the Software.
  121. --
  122. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  123. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  124. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  125. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  126. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  127. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  128. -- THE SOFTWARE.