note
	description: "[
		Commonly used console input and output mechanisms. 
		This class may be used as ancestor by classes needing its facilities.
	]"
	library: "Free implementation of ELKS library"
	status: "See notice at end of class."
	legal: "See notice at end of class."
	date: "$Date: 2020-05-28 16:02:59 +0000 (Thu, 28 May 2020) $"
	revision: "$Revision: 104378 $"

class 
	CONSOLE

create {STD_FILES}
	make_open_stdin,
	make_open_stdout,
	make_open_stderr

feature -- Initialization

	make (fn: STRING_8)
		obsolete "Use any of the `make_...' routines instead to benefit from Unicode file names. [2017-05-31]"
			-- Create file object with fn as file name.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
		ensure -- from FILE
			file_named: internal_name = fn
			file_closed: is_closed
		end

	make_create_read_write (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for both reading and writing;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			create_read_write
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_append (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file in append-only mode.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_append
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_append: is_open_append
		end

	make_open_read_append (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for reading anywhere
			-- but writing at the end only.
			-- Create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_read_append
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	make_open_read_write (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for both reading and writing.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_read_write
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_stderr (fn: READABLE_STRING_GENERAL)
			-- Create a standard error file.
		do
			make_with_name (fn)
			file_pointer := console_def (2)
			set_write_mode
		end

	make_open_stdin (fn: READABLE_STRING_GENERAL)
			-- Create a standard input file.
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			file_pointer := console_def (0)
			set_read_mode
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
		end

	make_open_stdout (fn: READABLE_STRING_GENERAL)
			-- Create a standard output file.
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			file_pointer := console_def (1)
			set_write_mode
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_write: is_open_write
		end

	make_open_temporary
			-- Create a file object with a unique temporary file name,
			-- with read/write mode.
			-- (from FILE)
		do
			make_open_temporary_with_prefix ("eiftmp")
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_temporary_with_prefix (a_prefix: READABLE_STRING_GENERAL)
			-- Create a file object with a unique temporary file name with prefix a_prefix,
			-- with read/write mode.
			-- (from FILE)
		local
			l_fd: INTEGER_32
		do
			set_name (a_prefix.as_string_32 + {STRING_32}"XXXXXX")
			l_fd := eif_temp_file (internal_name_pointer.item, is_plain_text)
			make_with_name (Buffered_file_info.pointer_to_file_name_32 (internal_name_pointer.item))
			fd_open_read_write (l_fd)
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end
	
feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end
	
feature -- Access

	access_date: INTEGER_32
			-- Time stamp of last access made to the inode.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			Result := eif_file_access_date (internal_name_pointer.item)
		end

	date: INTEGER_32
			-- Time stamp (time of last modification)
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			Result := eif_file_date (internal_name_pointer.item)
		end

	descriptor: INTEGER_32
			-- File descriptor as used by the operating system.
			-- (from FILE)
		require -- from IO_MEDIUM
			valid_handle: descriptor_available
		require else -- from FILE
			file_opened: not is_closed
		do
			Result := file_fd (file_pointer)
			descriptor_available := True
		end

	descriptor_available: BOOLEAN
			-- Is the handle available after class has been
			-- created?
			-- (from FILE)

	file_info: FILE_INFO
			-- Collected information about the file.
			-- (from FILE)
		do
			set_buffer
			Result := Buffered_file_info.twin
		end

	file_pointer: POINTER
			-- File pointer as required in C
			-- (from FILE)

	generating_type: TYPE [detachable CONSOLE]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	group_id: INTEGER_32
			-- Group identification of owner
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.group_id
		end

	has (v: like item): BOOLEAN
			-- Does structure include an occurrence of v?
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from LINEAR)
		require -- from  CONTAINER
			True
		do
			start
			if not off then
				search (v)
			end
			Result := not exhausted
		ensure -- from CONTAINER
			not_found_in_empty: Result implies not Is_empty
		end

	index_of (v: like item; i: INTEGER_32): INTEGER_32
			-- Index of i-th occurrence of v.
			-- 0 if none.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from LINEAR)
		require -- from LINEAR
			positive_occurrences: i > 0
		local
			occur, pos: INTEGER_32
		do
			if object_comparison and v /= Void then
				from
					start
					pos := 1
				until
					exhausted or (occur = i)
				loop
					if item ~ v then
						occur := occur + 1
					end
					forth
					pos := pos + 1
				end
			else
				from
					start
					pos := 1
				until
					exhausted or (occur = i)
				loop
					if item = v then
						occur := occur + 1
					end
					forth
					pos := pos + 1
				end
			end
			if occur = i then
				Result := pos - 1
			end
		ensure -- from LINEAR
			non_negative_result: Result >= 0
		end

	inode: INTEGER_32
			-- I-node number
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.inode
		end

	item: CHARACTER_8
			-- Current item
			-- (from FILE)
		require -- from ACTIVE
			readable: readable
		require -- from TRAVERSABLE
			not_off: not off
		do
			read_character
			Result := last_character
			back
		end

	item_for_iteration: CHARACTER_8
			-- Item at current position
			-- (from LINEAR)
		require -- from LINEAR
			not_off: not off
		do
			Result := item
		end

	links: INTEGER_32
			-- Number of links on file
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.links
		end

	name: STRING_8
		obsolete "Use `path.name' to ensure that Unicode filenames are not truncated. [2017-05-31]"
			-- File name as a STRING_8 instance. The value might be truncated
			-- from the original name used to create the current FILE instance.
			-- (from FILE)
		require -- from  IO_MEDIUM
			True
		do
			Result := internal_name.as_string_8
		ensure then -- from FILE
			name_not_empty: not Result.is_empty
		end

	null_name: STRING_8
			-- Null device name.
			-- (from FILE)
		do
			if {PLATFORM}.is_windows then
				Result := "nul"
			elseif {PLATFORM}.is_vms then
				Result := "NL:"
			elseif {PLATFORM}.is_vxworks then
				Result := "/null"
			else
				Result := "/dev/null"
			end
		ensure -- from FILE
			instance_free: class
		end

	null_path: PATH
			-- Null device path.
			-- (from FILE)
		do
			create Result.make_from_string (null_name)
		ensure -- from FILE
			instance_free: class
		end

	occurrences (v: like item): INTEGER_32
			-- Number of times v appears.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from LINEAR)
		require -- from  BAG
			True
		do
			from
				start
				search (v)
			until
				exhausted
			loop
				Result := Result + 1
				forth
				search (v)
			end
		ensure -- from BAG
			non_negative_occurrences: Result >= 0
		end

	owner_name: STRING_8
			-- Name of owner
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.owner_name
		end

	path: PATH
			-- Associated path of Current.
			-- (from FILE)
		do
			create Result.make_from_pointer (internal_name_pointer.item)
		ensure -- from FILE
			entry_not_empty: not Result.is_empty
		end

	position: INTEGER_32
			-- Current cursor position.
			-- (from FILE)
		require -- from  LINEAR
			True
		do
			if not is_closed then
				Result := file_tell (file_pointer)
			end
		end

	protection: INTEGER_32
			-- Protection mode, in decimal value
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.protection
		end

	retrieved: detachable ANY
			-- Retrieved object structure
			-- To access resulting object under correct type,
			-- use assignment attempt.
			-- Will raise an exception (code Retrieve_exception)
			-- if content is not a stored Eiffel structure.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
			support_storable: Support_storable
		do
			(create {MISMATCH_CORRECTOR}).Mismatch_information.do_nothing
			Result := c_retrieved (descriptor)
		end

	separator: CHARACTER_8
			-- ASCII code of character following last word read
			-- (from FILE)

	user_id: INTEGER_32
			-- User identification of owner
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.user_id
		end
	
feature {NATIVE_STRING_HANDLER} -- Access

	pointer_length_in_bytes (a_ptr: POINTER): INTEGER_32
			-- Length in bytes of a platform specific file name pointer, not
			-- including the null-terminating character. If size is too large
			-- to fit into an {INTEGER} instance, the size is truncated to
			-- {INTEGER_32}.max_value.
			-- (from NATIVE_STRING_HANDLER)
		require -- from NATIVE_STRING_HANDLER
			a_ptr_not_null: a_ptr /= default_pointer
		local
			l_length: NATURAL_64
		do
			l_length := c_pointer_length_in_bytes (a_ptr)
			if l_length <= {INTEGER_32}.max_value.to_natural_64 then
				Result := l_length.to_integer_32
			else
				Result := {INTEGER_32}.max_value
			end
		end
	
feature {NONE} -- Measurement

	estimated_count_of (other: ITERABLE [CHARACTER_8]): INTEGER_32
			-- Estimated number of elements in other.
			-- (from CONTAINER)
		do
			if attached {FINITE [CHARACTER_8]} other as f then
				Result := f.count
			elseif attached {READABLE_INDEXABLE [CHARACTER_8]} other as r then
				Result := r.upper - r.lower + 1
			end
		ensure -- from CONTAINER
			instance_free: class
			non_negative_result: Result >= 0
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal alias "≡≡≡" (other: CONSOLE): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: CONSOLE): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	same_file (fn: READABLE_STRING_GENERAL): BOOLEAN
			-- Is current file the same as a_filename?
			-- (from FILE)
		require -- from FILE
			fn_not_void: fn /= Void
			fn_not_empty: not fn.is_empty
		do
			Result := path.is_same_file_as (create {PATH}.make_from_string (fn))
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "≜" (other: CONSOLE): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	access_exists: BOOLEAN
			-- Does physical file exist?
			-- (Uses real UID.)
			-- (from FILE)
		do
			if is_closed then
				Result := file_access (internal_name_pointer.item, 0)
			else
				Result := True
			end
		end

	after: BOOLEAN
			-- Is there no valid cursor position to the right of cursor position?
			-- (from FILE)
		do
			Result := not is_closed and then (end_of_file or Count = 0)
		end

	before: BOOLEAN
			-- Is there no valid cursor position to the left of cursor position?
			-- (from FILE)
		do
			Result := is_closed
		end

	bytes_read: INTEGER_32
			-- Last number of bytes read by read_to_managed_pointer.
			-- (from IO_MEDIUM)

	changeable_comparison_criterion: BOOLEAN
			-- May object_comparison be changed?
			-- (Answer: yes by default.)
			-- (from CONTAINER)
		do
			Result := True
		end

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	Count: INTEGER_32 = 1
			-- Useless for CONSOLE class.

	empty: BOOLEAN
		obsolete "ELKS 2000: Use `is_empty' instead. [2017-05-31]"
			-- Is there no element?
			-- (from CONTAINER)
		do
			Result := Is_empty
		end

	end_of_file: BOOLEAN
			-- Have we reached the end of file?
		require -- from FILE
			opened: not is_closed
		do
			Result := console_eof (file_pointer)
		end

	exhausted: BOOLEAN
			-- Has structure been completely explored?
			-- (from LINEAR)
		do
			Result := off
		ensure -- from LINEAR
			exhausted_when_off: off implies Result
		end

	exists: BOOLEAN
			-- Does file exist?
		require -- from  IO_MEDIUM
			True
		do
			Result := True
		ensure then -- from FILE
			unchanged_mode: mode = old mode
		end

	extendible: BOOLEAN
			-- May new items be added?
			-- (from FILE)
		require -- from  COLLECTION
			True
		require -- from  IO_MEDIUM
			True
		do
			Result := mode >= Write_file
		end

	file_prunable: BOOLEAN
		obsolete "Use `prunable' instead. [2017-05-31]"
			-- May items be removed?
			-- (from FILE)
		do
		end

	file_readable: BOOLEAN
			-- Is there a current item that may be read?
			-- (from FILE)
		do
			Result := (mode >= Read_write_file or mode = Read_file) and readable
		end

	file_writable: BOOLEAN
			-- Is there a current item that may be modified?
			-- (from FILE)
		do
			Result := mode >= Write_file
		end

	Full: BOOLEAN = False
			-- Is structure filled to capacity?
			-- (from FILE)

	is_access_executable: BOOLEAN
			-- Is file executable by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_executable
		end

	is_access_owner: BOOLEAN
			-- Is file owned by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_owner
		end

	is_access_readable: BOOLEAN
			-- Is file readable by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_readable
		end

	is_access_writable: BOOLEAN
			-- Is file writable by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_writable
		end

	is_block: BOOLEAN
			-- Is file a block special file?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_block
		end

	is_character: BOOLEAN
			-- Is file a character special file?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_character
		end

	is_closed: BOOLEAN
			-- Is file closed?
			-- (from FILE)
		do
			Result := mode = Closed_file
		end

	is_creatable: BOOLEAN
			-- Is file creatable in parent directory?
			-- (Uses effective UID to check that parent is writable
			-- and file does not exist.)
			-- (from FILE)
		do
			Result := file_creatable (internal_name_pointer.item, internal_name_pointer.count)
		end

	is_device: BOOLEAN
			-- Is file a device?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_device
		end

	is_directory: BOOLEAN
			-- Is file a directory?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_directory
		end

	is_executable: BOOLEAN
			-- Is file executable?
			-- (Checks execute permission for effective UID.)
			-- (from FILE)
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_executable
		end

	is_fifo: BOOLEAN
			-- Is file a named pipe?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_fifo
		end

	is_inserted (v: CHARACTER_8): BOOLEAN
			-- Has v been inserted by the most recent insertion?
			-- (By default, the value returned is equivalent to calling 
			-- has (v). However, descendants might be able to provide more
			-- efficient implementations.)
			-- (from COLLECTION)
		do
			Result := has (v)
		end

	is_open_append: BOOLEAN
			-- Is file open for appending?
			-- (from FILE)
		do
			Result := mode = Append_file or else mode = Append_read_file
		end

	is_open_read: BOOLEAN
			-- Is file open for reading?
			-- (from FILE)
		do
			Result := mode = Read_file or else mode = Read_write_file or else mode = Append_read_file
		end

	is_open_write: BOOLEAN
			-- Is file open for writing?
			-- (from FILE)
		do
			Result := mode = Write_file or else mode = Read_write_file or else mode = Append_read_file or else mode = Append_file
		end

	is_owner: BOOLEAN
			-- Is file owned by effective UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_owner
		end

	is_plain: BOOLEAN
			-- Is file a plain file?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_plain
		end

	is_plain_text: BOOLEAN
			-- Is file reserved for text (character sequences)? (Yes)
			-- (from PLAIN_TEXT_FILE)
		do
			Result := True
		end

	is_readable: BOOLEAN
			-- Is file readable?
			-- (Checks permission for effective UID.)
			-- (from FILE)
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_readable
		end

	is_setgid: BOOLEAN
			-- Is file setgid?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_setgid
		end

	is_setuid: BOOLEAN
			-- Is file setuid?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_setuid
		end

	is_socket: BOOLEAN
			-- Is file a named socket?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_socket
		end

	is_sticky: BOOLEAN
			-- Is file sticky (for memory swaps)?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_sticky
		end

	is_symlink: BOOLEAN
			-- Is file a symbolic link?
			-- (from FILE)
		require -- from FILE
			file_exists: path_exists
		local
			l_buffer: like Buffered_file_info
			l_is_following_symbolic_links: BOOLEAN
		do
			l_buffer := Buffered_file_info
			l_is_following_symbolic_links := l_buffer.is_following_symlinks;
			l_buffer.set_is_following_symlinks (False);
			l_buffer.fast_update (internal_name, internal_name_pointer)
			Result := l_buffer.is_symlink;
			l_buffer.set_is_following_symlinks (l_is_following_symbolic_links)
		end

	is_writable: BOOLEAN
			-- Is file writable?
			-- (Checks write permission for effective UID.)
			-- (from FILE)
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_writable
		end

	last_character: CHARACTER_8
			-- Last character read by read_character.
			-- (from IO_MEDIUM)

	last_double: REAL_64
			-- Last double read by read_double
			-- (from IO_MEDIUM)

	last_integer: INTEGER_32
			-- Last integer read by read_integer
			-- (from IO_MEDIUM)

	last_integer_16: INTEGER_16
			-- Last 16-bit integer read by read_integer_16
			-- (from IO_MEDIUM)

	last_integer_32: INTEGER_32
			-- Synonymy of last_integer
			-- (from IO_MEDIUM)
		do
			Result := last_integer
		end

	last_integer_64: INTEGER_64
			-- Last 64-bit integer read by read_integer_64
			-- (from IO_MEDIUM)

	last_integer_8: INTEGER_8
			-- Last 8-bit integer read by read_integer_8
			-- (from IO_MEDIUM)

	last_natural: NATURAL_32
			-- Last 32-bit natural read by read_natural
			-- (from IO_MEDIUM)

	last_natural_16: NATURAL_16
			-- Last 16-bit natural read by read_natural_16
			-- (from IO_MEDIUM)

	last_natural_32: NATURAL_32
			-- Synonymy of last_natural
			-- (from IO_MEDIUM)
		do
			Result := last_natural
		end

	last_natural_64: NATURAL_64
			-- Last 64-bit natural read by read_natural_64
			-- (from IO_MEDIUM)

	last_natural_8: NATURAL_8
			-- Last 8-bit natural read by read_natural_8
			-- (from IO_MEDIUM)

	last_real: REAL_32
			-- Last real read by read_real
			-- (from IO_MEDIUM)

	last_real_32: REAL_32
			-- Last 32-bit real read by read_real_32.
			-- Synonym of last_real.
			-- (from IO_MEDIUM)
		do
			Result := last_real
		end

	last_real_64: REAL_64
			-- Last 64-bit real read by read_real_64.
			-- Synonym of last_double.
			-- (from IO_MEDIUM)
		do
			Result := last_double
		end

	last_string: STRING_8
			-- Last string read
			-- (from IO_MEDIUM)

	object_comparison: BOOLEAN
			-- Must search operations use equal rather than =
			-- for comparing references? (Default: no, use =.)
			-- (from CONTAINER)

	off: BOOLEAN
			-- Is there no item?
			-- (from FILE)
		require -- from  TRAVERSABLE
			True
		do
			Result := (Count = 0) or else is_closed or else end_of_file
		end

	path_exists: BOOLEAN
			-- Does physical file name exist without resolving
			-- symbolic links?
			-- (from FILE)
		do
			Result := file_path_exists (internal_name_pointer.item)
		ensure then -- from FILE
			unchanged_mode: mode = old mode
		end

	prunable: BOOLEAN
			-- Is there an item to be removed?
			-- (from FILE)
		do
		end

	readable: BOOLEAN
			-- Is there a current item that may be read?
			-- (from SEQUENCE)
		require -- from  ACTIVE
			True
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			Result := not off
		end

	replaceable: BOOLEAN
			-- Can current item be replaced?
			-- (from FILE)
		do
			Result := False
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end

	Support_storable: BOOLEAN = False
			-- Can medium be used to store an Eiffel structure?
			-- (from PLAIN_TEXT_FILE)

	writable: BOOLEAN
			-- Is there a current item that may be modified?
			-- (from SEQUENCE)
		do
			Result := not off
		end
	
feature {NONE} -- Status report

	is_in_final_collect: BOOLEAN
			-- Is GC currently performing final collection
			-- after execution of current program?
			-- Safe to use in dispose.
			-- (from DISPOSABLE)
		external
			"C inline use %"eif_memory.h%""
		alias
			"return eif_is_in_final_collect;"
		end
	
feature -- Status setting

	close
			-- Close file.
			-- (from FILE)
		require -- from IO_MEDIUM
			medium_is_open: not is_closed
		do
			file_close (file_pointer)
			mode := Closed_file
			file_pointer := default_pointer
			descriptor_available := False
		ensure then -- from FILE
			is_closed: is_closed
		end

	compare_objects
			-- Ensure that future search operations will use equal
			-- rather than = for comparing references.
			-- (from CONTAINER)
		require -- from CONTAINER
			changeable_comparison_criterion: changeable_comparison_criterion
		do
			object_comparison := True
		ensure -- from CONTAINER
				object_comparison
		end

	compare_references
			-- Ensure that future search operations will use =
			-- rather than equal for comparing references.
			-- (from CONTAINER)
		require -- from CONTAINER
			changeable_comparison_criterion: changeable_comparison_criterion
		do
			object_comparison := False
		ensure -- from CONTAINER
			reference_comparison: not object_comparison
		end

	create_read_write
			-- Open file in read and write mode;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 4)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	fd_open_append (fd: INTEGER_32)
			-- Open file of descriptor fd in append mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 2)
			mode := Append_file
		ensure -- from FILE
			exists: exists
			open_append: is_open_append
		end

	fd_open_read (fd: INTEGER_32)
			-- Open file of descriptor fd in read-only mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 0)
			mode := Read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
		end

	fd_open_read_append (fd: INTEGER_32)
			-- Open file of descriptor fd
			-- in read and write-at-end mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 5)
			mode := Append_read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	fd_open_read_write (fd: INTEGER_32)
			-- Open file of descriptor fd in read-write mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 3)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	fd_open_write (fd: INTEGER_32)
			-- Open file of descriptor fd in write mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 1)
			mode := Write_file
		ensure -- from FILE
			exists: exists
			open_write: is_open_write
		end

	open_append
			-- Open file in append-only mode;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 2)
			mode := Append_file
		ensure -- from FILE
			exists: exists
			open_append: is_open_append
		end

	open_read
			-- Open file in read-only mode.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 0)
			mode := Read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
		end

	open_read_append
			-- Open file in read and write-at-end mode;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 5)
			mode := Append_read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	open_read_write
			-- Open file in read and write mode.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 3)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	open_write
			-- Open file in write-only mode;
			-- create it if it does not exist.
			-- (from FILE)
		do
			file_pointer := file_open (internal_name_pointer.item, 1)
			mode := Write_file
		ensure -- from FILE
			exists: exists
			open_write: is_open_write
		end

	recreate_read_write (fname: READABLE_STRING_GENERAL)
			-- Reopen in read-write mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 4, file_pointer)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	reopen_append (fname: READABLE_STRING_GENERAL)
			-- Reopen in append mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 2, file_pointer)
			mode := Append_file
		ensure -- from FILE
			exists: exists
			open_append: is_open_append
		end

	reopen_read (fname: READABLE_STRING_GENERAL)
			-- Reopen in read-only mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 0, file_pointer)
			mode := Read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
		end

	reopen_read_append (fname: READABLE_STRING_GENERAL)
			-- Reopen in read and write-at-end mode with file
			-- of name fname; create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 5, file_pointer)
			mode := Append_read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	reopen_read_write (fname: READABLE_STRING_GENERAL)
			-- Reopen in read-write mode with file of name fname.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 3, file_pointer)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	reopen_write (fname: READABLE_STRING_GENERAL)
			-- Reopen in write-only mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 1, file_pointer)
			mode := Write_file
		ensure -- from FILE
			exists: exists
			open_write: is_open_write
		end
	
feature -- Cursor movement

	back
			-- Not supported on console
		require -- from BILINEAR
			not_before: not before
		do
		end

	finish
			-- Go to last position.
			-- (from FILE)
		require -- from  LINEAR
			True
		require else -- from FILE
			file_opened: not is_closed
		do
			file_recede (file_pointer, 0)
		end

	forth
			-- Go to next position.
			-- (from FILE)
		require -- from LINEAR
			not_after: not after
		require else -- from FILE
			file_opened: not is_closed
		do
			file_move (file_pointer, 1);
			file_gc (file_pointer).do_nothing
			if not end_of_file then
				back
			end
		end

	go (abs_position: INTEGER_32)
			-- Go to the absolute position.
			-- (New position may be beyond physical length.)
			-- (from FILE)
		require -- from FILE
			file_opened: not is_closed
			non_negative_argument: abs_position >= 0
		do
			file_go (file_pointer, abs_position)
		end

	move (offset: INTEGER_32)
			-- Advance by offset from current location.
			-- (from FILE)
		require -- from FILE
			file_opened: not is_closed
		do
			file_move (file_pointer, offset)
		end

	recede (abs_position: INTEGER_32)
			-- Go to the absolute position backwards,
			-- starting from end of file.
			-- (from FILE)
		require -- from FILE
			file_opened: not is_closed
			non_negative_argument: abs_position >= 0
		do
			file_recede (file_pointer, abs_position)
		end

	search (v: like item)
			-- Move to first position (at or after current
			-- position) where item and v are equal.
			-- If structure does not include v ensure that
			-- exhausted will be true.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from BILINEAR)
		do
			if before and not Is_empty then
				forth
			end
			Precursor (v)
		ensure -- from LINEAR
			object_found: (not exhausted and object_comparison) implies v ~ item
			item_found: (not exhausted and not object_comparison) implies v = item
		end

	start
			-- Go to first position.
			-- (from FILE)
		require -- from  TRAVERSABLE
			True
		require else -- from FILE
			file_opened: not is_closed
		do
			file_go (file_pointer, 0)
		end
	
feature -- Element change

	add_permission (who, what: STRING_8)
			-- Add read, write, execute or setuid permission
			-- for who ('u', 'g' or 'o') to what.
			-- (from FILE)
		require -- from FILE
			who_is_not_void: who /= Void
			what_is_not_void: what /= Void
			file_descriptor_exists: exists
		local
			ext_who, ext_what: ANY
		do
			ext_who := who.to_c
			ext_what := what.to_c
			file_perm (internal_name_pointer.item, $ext_who.to_pointer, $ext_what.to_pointer, 1)
		end

	append (f: CONSOLE)
			-- Append a copy of the contents of f.
			-- (from FILE)
		require -- from SEQUENCE
			argument_not_void: f /= Void
		require else -- from FILE
			target_is_closed: is_closed
			source_is_closed: f.is_closed
		do
			open_append;
			f.open_read
			file_append (file_pointer, f.file_pointer, f.Count)
			close;
			f.close
		ensure -- from SEQUENCE
			new_count: Count >= old Count
		ensure then -- from FILE
			new_count: Count = old Count + f.Count
			files_closed: f.is_closed and is_closed
		end

	basic_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from object.
			-- Retrievable within current system only.
			-- (from FILE)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: Support_storable
		do
			c_basic_store (descriptor, $object.to_pointer)
		end

	change_date: INTEGER_32
			-- Time stamp of last change.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.change_date
		end

	change_group (new_group_id: INTEGER_32)
			-- Change group of file to new_group_id found in
			-- system password file.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_chgrp (internal_name_pointer.item, new_group_id)
		end

	change_mode (mask: INTEGER_32)
			-- Replace mode by mask.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_chmod (internal_name_pointer.item, mask)
		end

	change_name (new_name: STRING_8)
		obsolete "Use `rename_file' instead. [2017-05-31]"
			-- Change file name to new_name.
			-- (from FILE)
		require -- from FILE
			new_name_not_void: new_name /= Void
			new_name_not_empty: not new_name.is_empty
			file_exists: exists
		do
			rename_file (new_name)
		ensure -- from FILE
			name_changed: internal_name = new_name
		end

	change_owner (new_owner_id: INTEGER_32)
			-- Change owner of file to new_owner_id found in
			-- system password file. On some systems this
			-- requires super-user privileges.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_chown (internal_name_pointer.item, new_owner_id)
		end

	extend (v: like item)
			-- Include v at end.
			-- (from FILE)
		require -- from COLLECTION
			extendible: extendible
		do
			put_character (v)
		ensure -- from COLLECTION
			item_inserted: is_inserted (v)
		end

	fill (other: CONTAINER [CHARACTER_8])
			-- Fill with as many items of other as possible.
			-- The representations of other and current structure
			-- need not be the same.
			-- (from COLLECTION)
		require -- from COLLECTION
			other_not_void: other /= Void
			extendible: extendible
		local
			lin_rep: LINEAR [CHARACTER_8]
		do
			lin_rep := other.linear_representation
			from
				lin_rep.start
			until
				not extendible or else lin_rep.off
			loop
				extend (lin_rep.item);
				lin_rep.forth
			end
		end

	flush
			-- Flush buffered data to disk.
			-- Note that there is no guarantee that the operating
			-- system will physically write the data to the disk.
			-- At least it will end up in the buffer cache,
			-- making the data visible to other processes.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
		do
			file_flush (file_pointer)
		end

	force (v: like item)
			-- Add v to end.
			-- (from SEQUENCE)
		require -- from SEQUENCE
			extendible: extendible
		do
			extend (v)
		ensure then -- from SEQUENCE
			new_count: Count = old Count + 1
			item_inserted: has (v)
		end

	general_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from object.
			-- Retrievable from other systems for same platform
			-- (machine architecture).
			-- (from FILE)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: Support_storable
		do
			c_general_store (descriptor, $object.to_pointer)
		end

	independent_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from object.
			-- Retrievable from other systems for the same or other
			-- platform (machine architecture).
			-- (from FILE)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: Support_storable
		do
			c_independent_store (descriptor, $object.to_pointer)
		end

	link (fn: READABLE_STRING_GENERAL)
			-- Link current file to fn.
			-- fn must not already exist.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		local
			l_ptr: MANAGED_POINTER
		do
			l_ptr := Buffered_file_info.file_name_to_pointer (fn, Void)
			file_link (internal_name_pointer.item, l_ptr.item)
		end

	put (v: like item)
			-- Add v to end.
			-- (from SEQUENCE)
		require -- from COLLECTION
			extendible: extendible
		do
			extend (v)
		ensure -- from COLLECTION
			item_inserted: is_inserted (v)
		ensure then -- from SEQUENCE
			new_count: Count = old Count + 1
		end

	put_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER_32)
			-- Put data of length nb_bytes pointed by start_pos index in p at
			-- current position.
			-- (from FILE)
		require -- from IO_MEDIUM
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			nb_bytes_non_negative: nb_bytes >= 0
			extendible: extendible
		do
			file_ps (file_pointer, p.item + start_pos, nb_bytes)
		end

	remove_permission (who, what: STRING_8)
			-- Remove read, write, execute or setuid permission
			-- for who ('u', 'g' or 'o') to what.
			-- (from FILE)
		require -- from FILE
			who_is_not_void: who /= Void
			what_is_not_void: what /= Void
			file_descriptor_exists: exists
		local
			ext_who, ext_what: ANY
		do
			ext_who := who.to_c
			ext_what := what.to_c
			file_perm (internal_name_pointer.item, $ext_who.to_pointer, $ext_what.to_pointer, 0)
		end

	rename_file (new_name: READABLE_STRING_GENERAL)
			-- Change file name to new_name
			-- (from FILE)
		require -- from FILE
			new_name_not_void: new_name /= Void
			new_name_not_empty: not new_name.is_empty
			file_exists: exists
		local
			l_ptr: MANAGED_POINTER
		do
			l_ptr := Buffered_file_info.file_name_to_pointer (new_name, Void)
			file_rename (internal_name_pointer.item, l_ptr.item)
			set_name (new_name)
		ensure -- from FILE
			name_changed: internal_name = new_name
		end

	rename_path (new_path: PATH)
			-- Change file name to new_path
			-- (from FILE)
		require -- from FILE
			new_path_not_void: new_path /= Void
			new_path_not_empty: not new_path.is_empty
			file_exists: exists
		local
			l_ptr: MANAGED_POINTER
		do
			l_ptr := new_path.to_pointer
			file_rename (internal_name_pointer.item, l_ptr.item)
			set_path (new_path)
		ensure -- from FILE
			name_changed: internal_name.same_string (new_path.name)
		end

	set_access (time: INTEGER_32)
			-- Stamp with time (access only).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_utime (internal_name_pointer.item, time, 0)
		ensure -- from FILE
			acess_date_updated: access_date = time
			date_unchanged: date = old date
		end

	set_date (time: INTEGER_32)
			-- Stamp with time (modification time only).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_utime (internal_name_pointer.item, time, 1)
		ensure -- from FILE
			access_date_unchanged: access_date = old access_date
			date_updated: date = time
		end

	stamp (time: INTEGER_32)
			-- Stamp with time (for both access and modification).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_utime (internal_name_pointer.item, time, 2)
		ensure -- from FILE
			date_updated: date = time
		end

	touch
			-- Update time stamp (for both access and modification).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_touch (internal_name_pointer.item)
		ensure -- from FILE
			date_changed: date /= old date
		end
	
feature -- Removal

	delete
			-- Remove link with physical file.
			-- File does not physically disappear from the disk
			-- until no more processes reference it.
			-- I/O operations on it are still possible.
			-- A directory must be empty to be deleted.
			-- (from FILE)
		require -- from FILE
			exists: path_exists
		do
			file_unlink (internal_name_pointer.item)
		end

	dispose
			-- This is closed by the operating system at completion.
		require -- from  DISPOSABLE
			True
		do
		end

	prune_all (v: like item)
			-- Remove all occurrences of v; go off.
			-- (from SEQUENCE)
		require -- from COLLECTION
			prunable: prunable
		do
			from
				start
			until
				exhausted
			loop
				search (v)
				if not exhausted then
					remove
				end
			end
		ensure -- from COLLECTION
			no_more_occurrences: not has (v)
		end

	reset (fn: READABLE_STRING_GENERAL)
			-- Change file name to fn and reset
			-- file descriptor and all information.
			-- (from FILE)
		require -- from FILE
			valid_file_name: fn /= Void
		do
			set_name (fn)
			if mode /= Closed_file then
				close
			end
			last_integer := 0
			last_real := 0.0
			last_double := 0.0
			last_character := '%U';
			last_string.wipe_out
		ensure -- from FILE
			file_renamed: internal_name = fn
			file_closed: is_closed
		end

	reset_path (fp: PATH)
			-- Change file name to fp and reset
			-- file descriptor and all information.
			-- (from FILE)
		require -- from FILE
			valid_file_name: fp /= Void
		do
			set_path (fp)
			if mode /= Closed_file then
				close
			end
			last_integer := 0
			last_real := 0.0
			last_double := 0.0
			last_character := '%U';
			last_string.wipe_out
		ensure -- from FILE
			file_closed: is_closed
		end

	wipe_out
			-- Remove all items.
			-- (from FILE)
		require -- from COLLECTION
			prunable: prunable
		require else -- from FILE
			is_closed: is_closed
		do
			open_write
			close
		ensure -- from COLLECTION
			wiped_out: Is_empty
		end
	
feature -- Conversion

	linear_representation: LINEAR [CHARACTER_8]
			-- Representation as a linear structure
			-- (from LINEAR)
		require -- from  CONTAINER
			True
		do
			Result := Current
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: CONSOLE)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: CONSOLE)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: CONSOLE
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: CONSOLE)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: CONSOLE
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: CONSOLE
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached CONSOLE
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable CONSOLE
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature -- Obsolete

	lastchar: CHARACTER_8
			-- Last character read by read_character
			-- (from IO_MEDIUM)
		do
			Result := last_character
		end

	lastdouble: REAL_64
			-- Last double read by read_double
			-- (from IO_MEDIUM)
		do
			Result := last_double
		end

	lastint: INTEGER_32
			-- Last integer read by read_integer
			-- (from IO_MEDIUM)
		do
			Result := last_integer
		end

	lastreal: REAL_32
			-- Last real read by read_real
			-- (from IO_MEDIUM)
		do
			Result := last_real
		end

	laststring: like last_string
			-- Last string read
			-- (from IO_MEDIUM)
		do
			Result := last_string
		end
	
feature -- Inapplicable

	Is_empty: BOOLEAN = False
			-- Useless for CONSOLE class.

	prune (v: like item)
			-- Remove an occurrence of v if any.
			-- (from FILE)
		require -- from COLLECTION
			prunable: prunable
		do
		ensure then -- from FILE
				Count <= old Count
		end

	remove
			-- Remove current item.
			-- (from FILE)
		require -- from ACTIVE
			prunable: prunable
			writable: writable
		do
		end

	replace (v: like item)
			-- Replace current item by v.
			-- (from FILE)
		require -- from ACTIVE
			writable: writable
			replaceable: replaceable
		do
		ensure -- from ACTIVE
			item_replaced: item = v
		end
	
feature {NONE} -- Inapplicable

	go_to (r: CURSOR)
			-- Move to position marked r.
			-- (from FILE)
		do
		end
	
feature {NONE} -- Implementation

	Buffered_file_info: FILE_INFO
			-- Information about the file.
			-- (from FILE)
		once
			create Result.make
		end

	c_basic_store (file_handle: INTEGER_32; object: POINTER)
			-- Store object structure reachable form current object
			-- in file pointer file_ptr.
			-- (from FILE)
		external
			"C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
		alias
			"estore"
		end

	c_general_store (file_handle: INTEGER_32; object: POINTER)
			-- Store object structure reachable form current object
			-- in file pointer file_ptr.
			-- (from FILE)
		external
			"C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
		alias
			"eestore"
		end

	c_independent_store (file_handle: INTEGER_32; object: POINTER)
			-- Store object structure reachable form current object
			-- in file pointer file_ptr.
			-- (from FILE)
		external
			"C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
		alias
			"sstore"
		end

	c_pointer_length_in_bytes (a_ptr: POINTER): NATURAL_64
			-- Length in bytes of a platform specific file name pointer, not
			-- including the null-terminating character.
			-- (from NATIVE_STRING_HANDLER)
		require -- from NATIVE_STRING_HANDLER
			a_ptr_not_null: a_ptr /= default_pointer
		external
			"C inline use %"eif_eiffel.h%""
		alias
			"{
			#ifdef EIF_WINDOWS
				return (EIF_NATURAL_64) wcslen($a_ptr) * sizeof(wchar_t);
			#else
				return (EIF_NATURAL_64) strlen($a_ptr) * sizeof(char);
			#endif
			}"
		end

	c_retrieved (file_handle: INTEGER_32): detachable ANY
			-- Object structured retrieved from file of pointer
			-- file_ptr
			-- (from FILE)
		external
			"C use %"eif_retrieve.h%""
		alias
			"eretrieve"
		end

	console_eof (file: POINTER): BOOLEAN
		external
			"C signature (FILE *): EIF_BOOLEAN use %"eif_console.h%""
		end

	console_next_line (file: POINTER)
			-- Move to next input line on standard input.
		external
			"C blocking signature (FILE *) use %"eif_console.h%""
		end

	console_pc (file: POINTER; c: CHARACTER_8)
			-- Write character c at end of file
		external
			"C signature (FILE *, EIF_CHARACTER) use %"eif_console.h%""
		end

	console_pd (file: POINTER; d: REAL_64)
			-- Write double d at end of file
		external
			"C signature (FILE *, EIF_DOUBLE) use %"eif_console.h%""
		end

	console_pi (file: POINTER; i: INTEGER_32)
			-- Write integer i at end of file
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_console.h%""
		end

	console_pr (file: POINTER; r: REAL_32)
			-- Write real r at end of file
		external
			"C signature (FILE *, EIF_REAL) use %"eif_console.h%""
		end

	console_ps (file: POINTER; s: POINTER; length: INTEGER_32)
			-- Write string s at end of file
		external
			"C signature (FILE *, char *, EIF_INTEGER) use %"eif_console.h%""
		end

	console_readchar (file: POINTER): CHARACTER_8
			-- Read a character from the console
		external
			"C blocking signature (FILE *): EIF_CHARACTER use %"eif_console.h%""
		end

	console_readdouble (file: POINTER): REAL_64
			-- Read a double from the console
		external
			"C blocking signature (FILE *): EIF_DOUBLE use %"eif_console.h%""
		end

	console_readint (file: POINTER): INTEGER_32
			-- Read an integer from the console
		external
			"C blocking signature (FILE *): EIF_INTEGER use %"eif_console.h%""
		end

	console_readline (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Read a stream from the console
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_console.h%""
		end

	console_readreal (file: POINTER): REAL_32
			-- Read a real number from the console
		external
			"C blocking signature (FILE *): EIF_REAL use %"eif_console.h%""
		end

	console_readstream (file: POINTER; a_string: POINTER; length: INTEGER_32): INTEGER_32
			-- Read a stream from the console
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_console.h%""
		end

	console_readword (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Read a string excluding white space and stripping
			-- leading white space from file into a_string.
			-- White space characters are: blank, new_line,
			-- tab, vertical tab, formfeed or end of file.
			-- If it does not fit, result is length - begin + 1,
			-- otherwise result is number of characters read.
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_console.h%""
		end

	console_separator (file: POINTER): CHARACTER_8
			-- ASCII code of character following last word read
		external
			"C signature (FILE *): EIF_CHARACTER use %"eif_console.h%""
		end

	console_tnwl (file: POINTER)
			-- Write a new_line to file
		external
			"C signature (FILE *) use %"eif_console.h%""
		end

	consume_characters
			-- Consume all characters from current position
			-- until we meet a new-line character.
		do
			from
			until
				end_of_file or last_character = '%N'
			loop
				read_character
			end
		end

	create_last_string (a_min_size: INTEGER_32)
		obsolete "Implementors should create `last_string' directly. [2017-05-31]"
			-- Create new instance of last_string with a least a_min_size
			-- as capacity.
			-- (from FILE)
		require -- from FILE
			last_string_void: last_string = Void
			a_min_size_non_negative: a_min_size >= 0
		do
			create last_string.make (Default_last_string_size.max (a_min_size))
		ensure -- from FILE
			last_string_attached: last_string /= Void
			capacity_set: attached last_string as l and then l.capacity >= a_min_size
		end

	Ctoi_convertor: STRING_TO_INTEGER_CONVERTOR
			-- Convertor used to parse string to integer or natural
		once
			create Result.make;
			Result.set_leading_separators (Internal_leading_separators);
			Result.set_leading_separators_acceptable (True);
			Result.set_trailing_separators_acceptable (False)
		end

	Default_last_string_size: INTEGER_32 = 256
			-- Default size for creating last_string
			-- (from FILE)

	eif_file_access_date (a_path: POINTER): INTEGER_32
			-- Access date of a file named a_path.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_access_date"
		end

	eif_file_date (a_path: POINTER): INTEGER_32
			-- Modification date of file named a_path.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_date"
		end

	eif_temp_file (a_name_template: POINTER; a_text_mode: BOOLEAN): INTEGER_32
			-- Generate a temporary file and return an file descriptor to the file.
			-- a_name_template: pattern used to create the temporary file.
			-- a_text_mode:, if text mode is True, the temporary file is created in text mode,
			-- otherwise in binary mode.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_BOOLEAN): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_mkstemp"
		end

	False_string: STRING_8
			-- Character string "false"
			-- (from FILE)
		once
			Result := "False"
		end

	file_access (fname: POINTER; which: INTEGER_32): BOOLEAN
			-- Perform access test which on fname using real UID.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_access"
		end

	file_append (file, from_file: POINTER; length: INTEGER_32)
			-- Append a copy of from_file to file
			-- (from FILE)
		external
			"C signature (FILE *, FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_append"
		end

	file_chgrp (fname: POINTER; new_group: INTEGER_32)
			-- Change group of fname to new_group
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int) use %"eif_file.h%""
		alias
			"eif_file_chgrp"
		end

	file_chmod (fname: POINTER; mask: INTEGER_32)
			-- Change mode of fname to mask.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int) use %"eif_file.h%""
		alias
			"eif_file_chmod"
		end

	file_chown (fname: POINTER; new_owner: INTEGER_32)
			-- Change owner of fname to new_owner
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int) use %"eif_file.h%""
		alias
			"eif_file_chown"
		end

	file_creatable (fname: POINTER; n: INTEGER_32): BOOLEAN
			-- Is fname with n bytes creatable.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_creatable"
		end

	file_dopen (fd, how: INTEGER_32): POINTER
			-- File pointer for file of descriptor fd in mode how
			-- (which must fit the way fd was obtained).
			-- (from FILE)
		external
			"C signature (int, int): EIF_POINTER use %"eif_file.h%""
		alias
			"eif_file_dopen"
		end

	file_exists (fname: POINTER): BOOLEAN
			-- Does fname exist.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_exists"
		end

	file_fd (file: POINTER): INTEGER_32
			-- Operating system's file descriptor
			-- (from FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_fd"
		end

	file_feof (file: POINTER): BOOLEAN
			-- End of file?
			-- (from FILE)
		external
			"C signature (FILE *): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_feof"
		end

	file_flush (file: POINTER)
			-- Flush file.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_flush"
		end

	file_gc (file: POINTER): CHARACTER_8
			-- Access the next character
			-- (from FILE)
		external
			"C blocking signature (FILE *): EIF_CHARACTER use %"eif_file.h%""
		alias
			"eif_file_gc"
		end

	file_gd (file: POINTER): REAL_64
			-- Read a double from file
			-- (from PLAIN_TEXT_FILE)
		external
			"C signature (FILE *): EIF_REAL_64 use %"eif_file.h%""
		alias
			"eif_file_gd"
		end

	file_gi (file: POINTER): INTEGER_32
			-- Get an integer from file
			-- (from PLAIN_TEXT_FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gi"
		end

	file_go (file: POINTER; abs_position: INTEGER_32)
			-- Go to absolute position, originated from start.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_go"
		end

	file_gr (file: POINTER): REAL_32
			-- Read a real from file
			-- (from PLAIN_TEXT_FILE)
		external
			"C signature (FILE *): EIF_REAL_32 use %"eif_file.h%""
		alias
			"eif_file_gr"
		end

	file_gs (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- a_string updated with characters read from file
			-- until new line, with begin characters already read.
			-- If it does not fit, result is length - begin + 1.
			-- If it fits, result is number of characters read.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gs"
		end

	file_gs_ta (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Same as file_gs but it won't prevent garbage collection from occurring
			-- while blocked waiting for data.			
			-- (from FILE)
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gs"
		end

	file_gss (file: POINTER; a_string: POINTER; length: INTEGER_32): INTEGER_32
			-- Read min (length, remaining bytes in file) characters
			-- into a_string. If it does not fit, result is length + 1.
			-- Otherwise, result is the number of characters read.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gss"
		end

	file_gss_ta (file: POINTER; a_string: POINTER; length: INTEGER_32): INTEGER_32
			-- Same as file_gss but it won't prevent garbage collection from occurring
			-- while blocked waiting for data.			
			-- (from FILE)
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gss"
		end

	file_gw (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Read a string excluding white space and stripping
			-- leading white space from file into a_string.
			-- White space characters are: blank, new_line,
			-- tab, vertical tab, formfeed or end of file.
			-- If it does not fit, result is length - begin + 1,
			-- otherwise result is number of characters read.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gw"
		end

	file_gw_ta (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Same as file_gw but it won't prevent garbage collection from occurring
			-- while blocked waiting for data.			
			-- (from FILE)
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gw"
		end

	file_lh (file: POINTER): CHARACTER_8
			-- Look ahead in file and find out the value of the next
			-- character. Do not read over character.
			-- (from FILE)
		external
			"C signature (FILE *): EIF_CHARACTER use %"eif_file.h%""
		alias
			"eif_file_lh"
		end

	file_link (from_name, to_name: POINTER)
			-- Link to_name to from_name
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_link"
		end

	file_move (file: POINTER; offset: INTEGER_32)
			-- Move file pointer by offset.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_move"
		end

	file_path_exists (fname: POINTER): BOOLEAN
			-- Does fname exist.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_path_exists"
		end

	file_pc (file: POINTER; c: CHARACTER_8)
			-- Put c to end of file.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_CHARACTER) use %"eif_file.h%""
		alias
			"eif_file_pc"
		end

	file_pd (file: POINTER; d: REAL_64)
			-- Put d to end of file.
			-- (from PLAIN_TEXT_FILE)
		external
			"C signature (FILE *, EIF_REAL_64) use %"eif_file.h%""
		alias
			"eif_file_pd"
		end

	file_perm (fname, who, what: POINTER; flag: INTEGER_32)
			-- Change permissions for fname to who and what.
			-- flag = 1 -> add permissions,
			-- flag = 0 -> remove permissions.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, char *, char *, int) use %"eif_file.h%""
		alias
			"eif_file_perm"
		end

	file_pi (file: POINTER; n: INTEGER_32)
			-- Put n to end of file.
			-- (from PLAIN_TEXT_FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_pi"
		end

	file_pr (file: POINTER; r: REAL_32)
			-- Put r to end of file.
			-- (from PLAIN_TEXT_FILE)
		external
			"C signature (FILE *, EIF_REAL_32) use %"eif_file.h%""
		alias
			"eif_file_pr"
		end

	file_ps (file: POINTER; a_string: POINTER; length: INTEGER_32)
			-- Print a_string to file.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_ps"
		end

	file_recede (file: POINTER; abs_position: INTEGER_32)
			-- Go to absolute position, originated from end.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_recede"
		end

	file_rename (old_name, new_name: POINTER)
			-- Change file name from old_name to new_name.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_rename"
		end

	file_reopen (fname: POINTER; how: INTEGER_32; file: POINTER): POINTER
			-- File pointer to file, reopened to have new name fname
			-- in a mode specified by how.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int, FILE *): EIF_POINTER use %"eif_file.h%""
		alias
			"eif_file_reopen"
		end

	file_size (file: POINTER): INTEGER_32
			-- Size of file
			-- (from FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_size"
		end

	file_tell (file: POINTER): INTEGER_32
			-- Current cursor position in file.
			-- (from FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_tell"
		end

	file_tnil (file: POINTER)
			-- Read upto next input line.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_tnil"
		end

	file_tnwl (file: POINTER)
			-- Print a new-line to file.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_tnwl"
		end

	file_touch (fname: POINTER)
			-- Touch file fname.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_touch"
		end

	file_unlink (fname: POINTER)
			-- Delete file fname.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_unlink"
		end

	file_utime (fname: POINTER; time, how: INTEGER_32)
			-- Set access, modification time or both (how = 0,1,2) on
			-- fname, using time as time stamp.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int, int) use %"eif_file.h%""
		alias
			"eif_file_utime"
		end

	internal_detachable_name_pointer: detachable MANAGED_POINTER
			-- (from FILE)
		note
			option: stable, transient
		attribute
		end

	Internal_leading_separators: STRING_8 = " %N%R%T"
			-- Characters that are considered as leading separators
			-- (from PLAIN_TEXT_FILE)

	internal_name: READABLE_STRING_GENERAL
			-- Store the name of the file as it was given to us by the user
			-- to avoid conversion on storing as it is not necessary.
			-- (from FILE)

	internal_name_pointer: MANAGED_POINTER
			-- File system specific encoding of internal_name.
			-- Typically a UTF-16 sequence on Windows, a UTF-8 sequence on Unix.
			-- (from FILE)
		do
			if attached internal_detachable_name_pointer as l_ptr then
				Result := l_ptr
			else
				check
					internal_name_pointer_set: False
				then
				end
			end
		end

	is_sequence_an_expected_numeric: BOOLEAN
			-- Is last number sequence read by read_number_sequence an expected numeric?
			-- (from PLAIN_TEXT_FILE)

	Read_data_buffer: C_STRING
			-- Buffer to read data in a thread aware context.
			-- (from FILE)
		once
			create Result.make_empty (Default_last_string_size)
		ensure -- from FILE
			read_data_buffer_not_void: Result /= Void
		end

	read_integer_with_no_type
			-- Read a ASCII representation of number of type
			-- at current position.
		do
			read_number_sequence (Ctoi_convertor, {NUMERIC_INFORMATION}.type_no_limitation)
			consume_characters
		end

	read_number_sequence (convertor: STRING_TO_NUMERIC_CONVERTOR; conversion_type: INTEGER_32)
			-- Read a number sequence from current position and parse this
			-- sequence using convertor to see if it is a valid numeric.
			-- Set is_sequence_an_expected_numeric with True if it is valid.
			-- (from PLAIN_TEXT_FILE)
		do
			convertor.reset (conversion_type)
			from
				is_sequence_an_expected_numeric := True
			until
				end_of_file or else not is_sequence_an_expected_numeric
			loop
				read_character
				if not end_of_file then
					convertor.parse_character (last_character)
					is_sequence_an_expected_numeric := convertor.parse_successful
				end
			end
		end

	return_characters
			-- Return character(s)
			-- (from PLAIN_TEXT_FILE)
		do
			if last_character = '%N' and {PLATFORM}.is_windows then
				back
			end
			back
		end

	set_buffer
			-- Resynchronizes information on file
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			Buffered_file_info.fast_update (internal_name, internal_name_pointer)
		end

	set_name (a_name: READABLE_STRING_GENERAL)
			-- Set name with a_name.
			-- (from FILE)
		require -- from FILE
			a_name_not_void: a_name /= Void
		do
			internal_name := a_name
			internal_detachable_name_pointer := Buffered_file_info.file_name_to_pointer (a_name, internal_detachable_name_pointer)
		ensure -- from FILE
			name_set: internal_name = a_name
		end

	set_path (a_path: PATH)
			-- Set internal_name_pointer with a content matching a_path.
			-- (from FILE)
		require -- from FILE
			a_path_not_void: a_path /= Void
		do
			internal_name := a_path.name
			internal_detachable_name_pointer := a_path.to_pointer
		ensure -- from FILE
			path_set: path.same_as (a_path)
		end

	True_string: STRING_8
			-- Character string "true"
			-- (from FILE)
		once
			Result := "True"
		end
	
feature -- Implementation

	read_to_string (a_string: STRING_8; pos, nb: INTEGER_32): INTEGER_32
			-- Fill a_string, starting at position pos with at
			-- most nb characters read from current file.
			-- Return the number of characters actually read.
		require -- from FILE
			is_readable: file_readable
			not_end_of_file: not end_of_file
			a_string_not_void: a_string /= Void
			valid_position: a_string.valid_index (pos)
			nb_large_enough: nb > 0
			nb_small_enough: nb <= a_string.count - pos + 1
		do
			Result := file_gss (file_pointer, a_string.area.item_address (pos - 1), nb);
			a_string.reset_hash_codes
		ensure -- from FILE
			nb_char_read_large_enough: Result >= 0
			nb_char_read_small_enough: Result <= nb
			character_read: not end_of_file implies Result > 0
		end
	
feature {FILE_ITERATION_CURSOR} -- Implementation

	file_close (file: POINTER)
			-- Close file
		external
			"C signature (FILE *) use %"eif_console.h%""
		alias
			"console_file_close"
		end
	
feature {FILE} -- Implementation

	Append_file: INTEGER_32 = 3
			-- (from FILE)

	Append_read_file: INTEGER_32 = 5
			-- (from FILE)

	Closed_file: INTEGER_32 = 0
			-- (from FILE)

	mode: INTEGER_32
			-- Input-output mode
			-- (from FILE)

	Read_file: INTEGER_32 = 1
			-- (from FILE)

	Read_write_file: INTEGER_32 = 4
			-- (from FILE)

	set_read_mode
			-- Define file mode as read.
			-- (from FILE)
		do
			mode := Read_file
		end

	set_write_mode
			-- Define file mode as write.
			-- (from FILE)
		do
			mode := Write_file
		end

	Write_file: INTEGER_32 = 2
			-- (from FILE)
	
feature -- Convenience

	copy_to (file: CONSOLE)
			-- Copy content of current from current cursor
			-- position to end of file into file from
			-- current cursor position of file.
			-- (from FILE)
		require -- from FILE
			file_not_void: file /= Void
			file_is_open_write: file.is_open_write
			current_is_open_read: is_open_read
		local
			l_modulo, l_read, nb: INTEGER_32
			l_pos: INTEGER_32
			l_old_last_string: like last_string
		do
			from
				l_read := 0
				nb := Count
				l_modulo := 51200
				l_old_last_string := last_string
				create last_string.make (l_modulo)
				l_pos := position
				if l_pos /= 0 then
					go (0)
				end
			until
				l_read >= nb
			loop
				read_stream (l_modulo);
				file.put_string (last_string)
				l_read := l_read + l_modulo
			end
			if l_pos /= 0 then
				go (l_pos)
			end
			last_string := l_old_last_string
		end
	
feature -- Encoding

	Default_encoding: ENCODING
			-- Default value for encoding.
		once
			Result := {SYSTEM_ENCODINGS}.console_encoding
		ensure -- from PLAIN_TEXT_FILE
			default_encoding_not_void: Result /= Void
		end

	detect_encoding
			-- Detect and update encoding according to BOM detection.
		require -- from PLAIN_TEXT_FILE
				is_open_read
		do
			set_encoding ({SYSTEM_ENCODINGS}.console_encoding)
		end

	encoding: ENCODING
			-- Associated encoding.
			-- (from PLAIN_TEXT_FILE)
		do
			if attached internal_encoding as l_encoding then
				Result := l_encoding
			else
				Result := Default_encoding
				internal_encoding := Result
			end
		ensure -- from PLAIN_TEXT_FILE
			encoding_not_void: Result /= Void
		end

	put_encoding_bom
			-- Put Byte Order Mark (BOM) related to encoding.
			-- (from PLAIN_TEXT_FILE)
		require -- from PLAIN_TEXT_FILE
			is_open_write: is_open_write
			at_beginning: position = 0
		local
			cp: READABLE_STRING_8
		do
			cp := encoding.code_page
			if cp.is_case_insensitive_equal_general ({CODE_PAGE_CONSTANTS}.utf8) then
				put_character ('ï')
				put_character ('»')
				put_character ('¿')
			elseif cp.is_case_insensitive_equal_general ({CODE_PAGE_CONSTANTS}.utf16_le) then
				put_character ('ÿ')
				put_character ('þ')
			elseif cp.is_case_insensitive_equal_general ({CODE_PAGE_CONSTANTS}.utf16_be) then
				put_character ('þ')
				put_character ('ÿ')
			elseif cp.is_case_insensitive_equal_general ({CODE_PAGE_CONSTANTS}.utf32_le) then
				put_character ('ÿ')
				put_character ('þ')
				put_character ('%U')
				put_character ('%U')
			elseif cp.is_case_insensitive_equal_general ({CODE_PAGE_CONSTANTS}.utf32_be) then
				put_character ('%U')
				put_character ('%U')
				put_character ('þ')
				put_character ('ÿ')
			end
		end

	set_encoding (enc: like encoding)
			-- Set associated encoding with enc.
			-- (from PLAIN_TEXT_FILE)
		require -- from PLAIN_TEXT_FILE
			enc_not_void: enc /= Void
		do
			internal_encoding := enc
		ensure -- from PLAIN_TEXT_FILE
			encoding_set: encoding = enc
		end

	set_utf8_encoding
			-- Set encoding to UTF-8.
			-- (from PLAIN_TEXT_FILE)
		do
			set_encoding ({SYSTEM_ENCODINGS}.utf8)
		ensure -- from PLAIN_TEXT_FILE
			encoding_set: encoding = {SYSTEM_ENCODINGS}.utf8
		end
	
feature {NONE} -- Encoding

	internal_encoding: detachable ENCODING
			-- Internal value for encoding.
			-- (from PLAIN_TEXT_FILE)
	
feature -- Initialization	

	make_with_name (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name.
			-- (from PLAIN_TEXT_FILE)
		require -- from FILE
			fn_exists: fn /= Void
			fn_not_empty: not fn.is_empty
		do
			Precursor (fn)
			create last_string_32.make_empty
		ensure -- from FILE
			file_named: internal_name = fn
			file_closed: is_closed
		end

	make_with_path (a_path: PATH)
			-- Create file object with a_path as path.
			-- (from PLAIN_TEXT_FILE)
		require -- from FILE
			a_path_attached: a_path /= Void
			a_path_not_empty: not a_path.is_empty
		do
			Precursor (a_path)
			create last_string_32.make_empty
		ensure -- from FILE
			path_set: path.same_as (a_path)
			file_closed: is_closed
		end
	
feature -- Input

	next_line
			-- Move to next input line on standard input.
		require -- from FILE
			is_readable: file_readable
		do
			console_next_line (file_pointer)
		end

	read_character
			-- Read a new character from standard input.
			-- Make result available in last_character.
			-- Was declared in CONSOLE as synonym of readchar.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_character := console_readchar (file_pointer)
		end

	read_double
			-- Read a new double from standard input.
			-- Make result available in last_double.
			-- Was declared in CONSOLE as synonym of readdouble.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_double := console_readdouble (file_pointer)
		end

	read_integer
			-- Read the ASCII representation of a new 32-bit integer
			-- from file. Make result available in last_integer.
			-- Was declared in PLAIN_TEXT_FILE as synonym of readint and read_integer_32.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			read_integer_with_no_type
			last_integer := Ctoi_convertor.parsed_integer_32
		end

	read_integer_16
			-- Read the ASCII representation of a new 16-bit integer
			-- from file. Make result available in last_integer_16.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_integer_16 := Ctoi_convertor.parsed_integer_16
		end

	read_integer_32
			-- Read the ASCII representation of a new 32-bit integer
			-- from file. Make result available in last_integer.
			-- Was declared in PLAIN_TEXT_FILE as synonym of read_integer and readint.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_integer := Ctoi_convertor.parsed_integer_32
		end

	read_integer_64
			-- Read the ASCII representation of a new 64-bit integer
			-- from file. Make result available in last_integer_64.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_integer_64 := Ctoi_convertor.parsed_integer_64
		end

	read_integer_8
			-- Read the ASCII representation of a new 8-bit integer
			-- from file. Make result available in last_integer_8.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_integer_8 := Ctoi_convertor.parsed_integer_8
		end

	read_line
			-- Read a string until new line or end of file.
			-- Make result available in last_string.
			-- New line will be consumed but not part of last_string.
			-- Was declared in CONSOLE as synonym of readline.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		require else
			is_readable: file_readable
		do
			read_line_thread_aware
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_line_thread_aware
			-- Read characters until a new line or
			-- end of medium.
			-- Make result available in last_string.
			-- Functionally identical to read_line but
			-- won't prevent garbage collection from occurring
			-- while blocked waiting for data, though data must
			-- be copied an extra time.			
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		require else
			is_readable: file_readable
		local
			str_cap: INTEGER_32
			read: INTEGER_32
			done: BOOLEAN
			l: like last_string
			l_old_count, l_new_count: INTEGER_32
			l_buffer: like Read_data_buffer
		do
			l := last_string
			l_buffer := Read_data_buffer
			from
				l.wipe_out
				str_cap := l_buffer.capacity
			until
				done
			loop
				read := console_readline (file_pointer, l_buffer.item, str_cap, 0)
				l_old_count := l.count
				l_new_count := l_old_count + read.min (str_cap)
				done := read <= str_cap;
				l.grow (l_new_count);
				l.set_count (l_new_count);
				l_buffer.copy_to_string (l, 1, l_old_count + 1, read.min (str_cap))
			end
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_natural
			-- Read the ASCII representation of a new 32-bit natural
			-- from file. Make result available in last_natural.
			-- Was declared in PLAIN_TEXT_FILE as synonym of read_natural_32.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_natural := Ctoi_convertor.parsed_natural_32
		end

	read_natural_16
			-- Read the ASCII representation of a new 16-bit natural
			-- from file. Make result available in last_natural_16.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_natural_16 := Ctoi_convertor.parsed_natural_16
		end

	read_natural_32
			-- Read the ASCII representation of a new 32-bit natural
			-- from file. Make result available in last_natural.
			-- Was declared in PLAIN_TEXT_FILE as synonym of read_natural.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_natural := Ctoi_convertor.parsed_natural_32
		end

	read_natural_64
			-- Read the ASCII representation of a new 64-bit natural
			-- from file. Make result available in last_natural_64.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_natural_64 := Ctoi_convertor.parsed_natural_64
		end

	read_natural_8
			-- Read the ASCII representation of a new 8-bit natural
			-- from file. Make result available in last_natural_8.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_integer_with_no_type
			last_natural_8 := Ctoi_convertor.parsed_natural_8
		end

	read_real
			-- Read a new real from standard input.
			-- Make result available in last_real.
			-- Was declared in CONSOLE as synonym of readreal.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_real := console_readreal (file_pointer)
		end

	read_real_32
			-- Read the ASCII representation of a new real
			-- from file. Make result available in last_real.
			-- Was declared in PLAIN_TEXT_FILE as synonym of read_real and readreal.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_real := file_gr (file_pointer)
		end

	read_real_64
			-- Read the ASCII representation of a new double
			-- from file. Make result available in last_double.
			-- Was declared in PLAIN_TEXT_FILE as synonym of read_double and readdouble.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_double := file_gd (file_pointer)
		end

	read_stream (nb_char: INTEGER_32)
			-- Read a string of at most nb_char bound characters
			-- from standard input.
			-- Make result available in last_string.
			-- Was declared in CONSOLE as synonym of readstream.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			read_stream_thread_aware (nb_char)
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_stream_thread_aware (nb_char: INTEGER_32)
			-- Read a string of at most nb_char bound characters
			-- or until end of medium is encountered.
			-- Make result available in last_string.
			-- Functionally identical to read_stream but
			-- won't prevent garbage collection from occurring
			-- while blocked waiting for data, though data must
			-- be copied an extra time.			
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			new_count: INTEGER_32
			l_buffer: like Read_data_buffer
			l_str: like last_string
		do
			l_str := last_string
			l_buffer := Read_data_buffer;
			l_buffer.set_count (nb_char)
			new_count := console_readstream (file_pointer, l_buffer.item, nb_char);
			l_buffer.set_count (new_count);
			l_str.grow (new_count);
			l_str.set_count (new_count);
			l_buffer.read_string_into (l_str)
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER_32)
			-- Read at most nb_bytes bound bytes and make result
			-- available in p at position start_pos.
			-- (from FILE)
		require -- from IO_MEDIUM
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			nb_bytes_non_negative: nb_bytes >= 0
			is_readable: readable
		require else -- from FILE
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			is_readable: file_readable
		do
			bytes_read := file_gss (file_pointer, p.item + start_pos, nb_bytes)
		ensure -- from IO_MEDIUM
			bytes_read_non_negative: bytes_read >= 0
			bytes_read_not_too_big: bytes_read <= nb_bytes
		end

	read_word
			-- Read a new word from standard input.
			-- Make result available in last_string.
			-- Was declared in CONSOLE as synonym of readword.
		require -- from FILE
			is_readable: file_readable
		do
			read_word_thread_aware
		ensure -- from FILE
			last_string_not_void: last_string /= Void
		end

	read_word_thread_aware
			-- Read a string, excluding white space and stripping
			-- leading white space.
			-- Make result available in last_string.
			-- White space characters are: blank, new_line, tab,
			-- vertical tab, formfeed, end of file.
		require -- from FILE
			is_readable: file_readable
		local
			str_cap: INTEGER_32
			read: INTEGER_32
			done: BOOLEAN
			l: like last_string
			l_old_count, l_new_count: INTEGER_32
			l_buffer: like Read_data_buffer
		do
			l := last_string
			l_buffer := Read_data_buffer
			from
				l.wipe_out
				str_cap := l_buffer.capacity
			until
				done
			loop
				read := console_readword (file_pointer, l_buffer.item, str_cap, 0)
				l_old_count := l.count
				l_new_count := l_old_count + read.min (str_cap)
				done := read <= str_cap;
				l.grow (l_new_count);
				l.set_count (l_new_count);
				l_buffer.copy_to_string (l, 1, l_old_count + 1, read.min (str_cap))
			end
			separator := console_separator (file_pointer)
		ensure -- from FILE
			last_string_not_void: last_string /= Void
		end

	readchar
			-- Read a new character from standard input.
			-- Make result available in last_character.
			-- Was declared in CONSOLE as synonym of read_character.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_character := console_readchar (file_pointer)
		end

	readdouble
			-- Read a new double from standard input.
			-- Make result available in last_double.
			-- Was declared in CONSOLE as synonym of read_double.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_double := console_readdouble (file_pointer)
		end

	readint
			-- Read the ASCII representation of a new 32-bit integer
			-- from file. Make result available in last_integer.
			-- Was declared in PLAIN_TEXT_FILE as synonym of read_integer and read_integer_32.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			read_integer_with_no_type
			last_integer := Ctoi_convertor.parsed_integer_32
		end

	readline
			-- Read a string until new line or end of file.
			-- Make result available in last_string.
			-- New line will be consumed but not part of last_string.
			-- Was declared in CONSOLE as synonym of read_line.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		require else
			is_readable: file_readable
		do
			read_line_thread_aware
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	readreal
			-- Read a new real from standard input.
			-- Make result available in last_real.
			-- Was declared in CONSOLE as synonym of read_real.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_real := console_readreal (file_pointer)
		end

	readstream (nb_char: INTEGER_32)
			-- Read a string of at most nb_char bound characters
			-- from standard input.
			-- Make result available in last_string.
			-- Was declared in CONSOLE as synonym of read_stream.
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			read_stream_thread_aware (nb_char)
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	readword
			-- Read a new word from standard input.
			-- Make result available in last_string.
			-- Was declared in CONSOLE as synonym of read_word.
		require -- from FILE
			is_readable: file_readable
		do
			read_word_thread_aware
		ensure -- from FILE
			last_string_not_void: last_string /= Void
		end
	
feature -- Iteration

	do_all (action: PROCEDURE [CHARACTER_8])
			-- Apply action to every item.
			-- Semantics not guaranteed if action changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			action_exists: action /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
			until
				after
			loop
				action.call ([item])
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		end

	do_if (action: PROCEDURE [CHARACTER_8]; test: FUNCTION [CHARACTER_8, BOOLEAN])
			-- Apply action to every item that satisfies test.
			-- Semantics not guaranteed if action or test changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			action_exists: action /= Void
			test_exists: test /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
			until
				after
			loop
				if test.item ([item]) then
					action.call ([item])
				end
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		end

	for_all (test: FUNCTION [CHARACTER_8, BOOLEAN]): BOOLEAN
			-- Is test true for all items?
			-- Semantics not guaranteed if test changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			test_exists: test /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
				Result := True
			until
				after or not Result
			loop
				Result := test.item ([item])
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		ensure then -- from LINEAR
			empty: Is_empty implies Result
		end

	new_cursor: FILE_ITERATION_CURSOR
			-- Fresh cursor associated with current structure
		require -- from  ITERABLE
			True
		do
			if is_open_read then
				create Result.make_open_stdin
			else
				create Result.make_empty
			end
		ensure -- from ITERABLE
			result_attached: Result /= Void
		end

	there_exists (test: FUNCTION [CHARACTER_8, BOOLEAN]): BOOLEAN
			-- Is test true for at least one item?
			-- Semantics not guaranteed if test changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			test_exists: test /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
			until
				after or Result
			loop
				Result := test.item ([item])
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		end
	
feature {FILE_ITERATION_CURSOR} -- Iteration

	console_def (number: INTEGER_32): POINTER
			-- Convert number to the corresponding
			-- file descriptor.
		external
			"C use %"eif_console.h%""
		end
	
feature {FILE_ITERATION_CURSOR} -- Iteration

	file_open (fname: POINTER; how: INTEGER_32): POINTER
			-- File pointer for file fname, in mode how.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int): EIF_POINTER use %"eif_file.h%""
		alias
			"eif_file_open"
		end
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	new_line
			-- Write line feed at end of default output.
			-- Was declared in CONSOLE as synonym of put_new_line.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_tnwl (file_pointer)
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	put_boolean (b: BOOLEAN)
			-- Write b at end of default output.
			-- Was declared in CONSOLE as synonym of putbool.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			if b then
				put_string ("True")
			else
				put_string ("False")
			end
		end

	put_character (c: CHARACTER_8)
			-- Write c at end of default output.
			-- Was declared in CONSOLE as synonym of putchar.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_pc (file_pointer, c)
		end

	put_double (d: REAL_64)
			-- Write d at end of default output.
			-- Was declared in CONSOLE as synonym of putdouble.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_pd (file_pointer, d)
		end

	put_integer (i: INTEGER_32)
			-- Write ASCII value of i at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of putint and put_integer_32.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_integer_16 (i: INTEGER_16)
			-- Write ASCII value of i at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_integer_32 (i: INTEGER_32)
			-- Write ASCII value of i at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of put_integer and putint.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_integer_64 (i: INTEGER_64)
			-- Write ASCII value of i at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_integer_8 (i: INTEGER_8)
			-- Write ASCII value of i at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_natural (i: NATURAL_32)
			-- Write ASCII value of i at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of put_natural_32.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_natural_16 (i: NATURAL_16)
			-- Write ASCII value of i at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_natural_32 (i: NATURAL_32)
			-- Write ASCII value of i at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of put_natural.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_natural_64 (i: NATURAL_64)
			-- Write ASCII value of i at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_natural_8 (i: NATURAL_8)
			-- Write ASCII value of i at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	put_new_line
			-- Write line feed at end of default output.
			-- Was declared in CONSOLE as synonym of new_line.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_tnwl (file_pointer)
		end

	put_real (r: REAL_32)
			-- Write r at end of default output.
			-- Was declared in CONSOLE as synonym of putreal.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_pr (file_pointer, r)
		end

	put_real_32 (r: REAL_32)
			-- Write ASCII value of r at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of put_real and putreal.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pr (file_pointer, r)
		end

	put_real_64 (d: REAL_64)
			-- Write ASCII value d at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of put_double and putdouble.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pd (file_pointer, d)
		end

	put_string (s: READABLE_STRING_8)
			-- Write s at end of default output.
			-- Was declared in CONSOLE as synonym of putstring.
		require -- from IO_MEDIUM
			extendible: extendible
			non_void: s /= Void
		local
			n: like {READABLE_STRING_8}.count
			external_s: ANY
		do
			n := s.count
			if n > 0 then
				external_s := s.area
				console_ps (file_pointer, $external_s.to_pointer, n)
			end
		end

	put_string_32 (s: READABLE_STRING_32)
			-- Write string s at current position.
			-- (from PLAIN_TEXT_FILE)
		do
			put_string_general (s)
		end

	put_string_general (s: READABLE_STRING_GENERAL)
			-- Write string s at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from PLAIN_TEXT_FILE
			extendible: extendible
			non_void: s /= Void
		local
			str: STRING_8
			utf32, utf8: ENCODING
			l_encoding: like encoding
		do
			l_encoding := encoding
			utf32 := {SYSTEM_ENCODINGS}.utf32;
			utf32.convert_to (l_encoding, s)
			if utf32.last_conversion_successful then
				str := utf32.last_converted_string_8
			else
				utf8 := {SYSTEM_ENCODINGS}.utf8;
				utf32.convert_to (utf8, s)
				if utf32.last_conversion_successful then
					str := utf32.last_converted_string_8
					if not utf8.same_as (l_encoding) then
						utf8.convert_to (l_encoding, str)
						if utf8.last_conversion_successful then
							str := utf8.last_converted_string_8
						end
					end
				elseif s.is_valid_as_string_8 then
					str := s.to_string_8
				else
					str := {UTF_CONVERTER}.string_32_to_utf_8_string_8 (s.as_string_32)
				end
			end
			put_string (str)
		end

	putbool (b: BOOLEAN)
			-- Write b at end of default output.
			-- Was declared in CONSOLE as synonym of put_boolean.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			if b then
				put_string ("True")
			else
				put_string ("False")
			end
		end

	putchar (c: CHARACTER_8)
			-- Write c at end of default output.
			-- Was declared in CONSOLE as synonym of put_character.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_pc (file_pointer, c)
		end

	putdouble (d: REAL_64)
			-- Write d at end of default output.
			-- Was declared in CONSOLE as synonym of put_double.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_pd (file_pointer, d)
		end

	putint (i: INTEGER_32)
			-- Write ASCII value of i at current position.
			-- Was declared in PLAIN_TEXT_FILE as synonym of put_integer and put_integer_32.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			put_string_general (i.out)
		end

	putreal (r: REAL_32)
			-- Write r at end of default output.
			-- Was declared in CONSOLE as synonym of put_real.
		require -- from IO_MEDIUM
			extendible: extendible
		do
			console_pr (file_pointer, r)
		end

	putstring (s: READABLE_STRING_8)
			-- Write s at end of default output.
			-- Was declared in CONSOLE as synonym of put_string.
		require -- from IO_MEDIUM
			extendible: extendible
			non_void: s /= Void
		local
			n: like {READABLE_STRING_8}.count
			external_s: ANY
		do
			n := s.count
			if n > 0 then
				external_s := s.area
				console_ps (file_pointer, $external_s.to_pointer, n)
			end
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
feature -- Unicode input

	last_string_32: STRING_32
			-- Last unicode string read.
			-- (from PLAIN_TEXT_FILE)

	read_unicode_line
			-- Read a line as STRING_32.
			-- (from PLAIN_TEXT_FILE)
		local
			utf32: ENCODING
		do
			read_line
			utf32 := {SYSTEM_ENCODINGS}.utf32;
			encoding.convert_to (utf32, last_string)
			if encoding.last_conversion_successful then
				last_string_32.wipe_out;
				last_string_32.append (encoding.last_converted_string_32)
			end
		end
	
invariant
		-- from PLAIN_TEXT_FILE
	plain_text: is_plain_text

		-- from FILE
	valid_mode: Closed_file <= mode and mode <= Append_read_file
	name_exists: internal_name /= Void
	name_not_empty: not internal_name.is_empty

		-- from FINITE
	empty_definition: Is_empty = (Count = 0)

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

		-- from ACTIVE
	writable_constraint: writable implies readable
	empty_constraint: Is_empty implies (not readable) and (not writable)

		-- from BILINEAR
	not_both: not (after and before)
	before_constraint: before implies off

		-- from LINEAR
	after_constraint: after implies off

		-- from TRAVERSABLE
	empty_constraint: Is_empty implies off

note
	copyright: "Copyright (c) 1984-2020, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class CONSOLE

Generated by ISE EiffelStudio