indexing
	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"
	copyright: "Copyright (c) 1986-2008, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see forum.txt)"
	date: "$Date: 2008-05-23 17:24:07 -0700 (Fri, 23 May 2008) $"
	revision: "$Revision: 170 $"

class interface
	CONSOLE


create {STD_FILES}
	make_open_stdin (fn: STRING_8)
			-- Create an unix standard input file.
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		ensure -- from FILE
			file_named: name = fn
			exists: exists
			open_read: is_open_read

	make_open_stdout (fn: STRING_8)
			-- Create an unix standard output file.
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		ensure -- from FILE
			file_named: name = fn
			exists: exists
			open_write: is_open_write

	make_open_stderr (fn: STRING_8)
			-- Create an unix standard error file.

feature -- Initialization

	make_open_stderr (fn: STRING_8)
			-- Create an unix standard error file.

	make_open_stdin (fn: STRING_8)
			-- Create an unix standard input file.
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		ensure -- from FILE
			file_named: name = fn
			exists: exists
			open_read: is_open_read

	make_open_stdout (fn: STRING_8)
			-- Create an unix standard output file.
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		ensure -- from FILE
			file_named: name = fn
			exists: exists
			open_write: is_open_write
	
feature -- Access

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

	generating_type: STRING_8
			-- Name of current object's generating type
			-- (type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generating_type_not_void: Result /= Void
			generating_type_not_empty: not Result.is_empty

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

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

	frozen deep_equal (some: ?ANY; other: like arg #1): BOOLEAN
			-- Are `some' and `other' either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		ensure -- from ANY
			shallow_implies_deep: standard_equal (some, other) implies Result
			both_or_none_void: (some = Void) implies (Result = (other = Void))
			same_type: (Result and (some /= Void)) implies (other /= Void and then some.same_type (other))
			symmetric: Result implies deep_equal (other, some)

	frozen equal (some: ?ANY; other: like arg #1): BOOLEAN
			-- Are `some' and `other' either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		ensure -- from ANY
			definition: Result = (some = Void and other = Void) or else ((some /= Void and other /= Void) and then some.is_equal (other))

	frozen is_deep_equal (other: CONSOLE): BOOLEAN
			-- Are `Current' and `other' attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		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)

	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
		ensure -- from ANY
			symmetric: Result implies other.is_equal (Current)
			consistent: standard_is_equal (other) implies Result

	frozen standard_equal (some: ?ANY; other: like arg #1): BOOLEAN
			-- Are `some' and `other' either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		ensure -- from ANY
			definition: Result = (some = Void and other = Void) or else ((some /= Void and other /= Void) and then some.standard_is_equal (other))

	frozen standard_is_equal (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
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
	
feature -- Status report

	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

	count: INTEGER_32 is 1
			-- Useless for CONSOLE class.

	end_of_file: BOOLEAN
			-- Have we reached the end of file?
		require -- from FILE
			opened: not is_closed

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

	extendible: BOOLEAN
			-- May new items be added?
			-- (from FILE)
		require -- from  COLLECTION
			True
		require -- from  IO_MEDIUM
			True

	file_readable: BOOLEAN
			-- Is there a current item that may be read?
			-- (from FILE)

	is_closed: BOOLEAN
			-- Is file closed?
			-- (from FILE)

	is_open_write: BOOLEAN
			-- Is file open for writing?
			-- (from FILE)

	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)

	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)

	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_string: ?STRING_8
			-- Last string read
			-- (from IO_MEDIUM)

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

	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
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
	
feature -- Element change

	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
		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
	
feature -- Removal

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

	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)
		ensure -- from ANY
			is_equal: is_equal (other)

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

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

	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)
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)

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

	frozen twin: CONSOLE
			-- New object equal to `Current'
			-- twin calls copy; to change copying/twining semantics, redefine copy.
			-- (from ANY)
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result.is_equal (Current)
	
feature -- Basic operations

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

	frozen default_pointer: POINTER
			-- Default value of type `POINTER'
			-- (Avoid the need to write `p'.default for
			-- some `p' of type `POINTER'.)
			-- (from ANY)

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

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
	
feature -- Obsolete

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

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

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

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

	laststring: ?STRING_8
			-- Last string read
			-- (from IO_MEDIUM)
	
feature -- Input

	next_line
			-- Move to next input line on standard input.
		require -- from FILE
			is_readable: file_readable

	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

	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

	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

	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

	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

	read_integer_64
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			is_readable: readable

	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

	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
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void

	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

	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

	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

	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

	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

	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

	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
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void

	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
		ensure -- from FILE
			last_string_not_void: last_string /= Void

	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

	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

	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

	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
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void

	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

	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
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void

	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
		ensure -- from FILE
			last_string_not_void: last_string /= Void
	
feature -- Output

	io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		ensure -- from ANY
			io_not_void: Result /= Void

	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

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

	print (some: ?ANY)
			-- Write terse external representation of `some'
			-- on standard output.
			-- (from ANY)

	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

	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

	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

	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

	put_integer_16 (i: INTEGER_16)
			-- Write ASCII value of `i' at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible

	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

	put_integer_64 (i: INTEGER_64)
			-- Write ASCII value of `i' at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible

	put_integer_8 (i: INTEGER_8)
			-- Write ASCII value of `i' at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible

	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

	put_natural_16 (i: NATURAL_16)
			-- Write ASCII value of `i' at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible

	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

	put_natural_64 (i: NATURAL_64)
			-- Write ASCII value of `i' at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible

	put_natural_8 (i: NATURAL_8)
			-- Write ASCII value of `i' at current position.
			-- (from PLAIN_TEXT_FILE)
		require -- from IO_MEDIUM
			extendible: extendible

	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

	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

	put_string (s: 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

	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

	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

	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

	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