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