note description: "Files viewed as persistent sequences of ASCII characters" library: "Free implementation of ELKS library" status: "See notice at end of class." legal: "See notice at end of class." date: "$Date: 2019-01-10 14:55:46 +0000 (Thu, 10 Jan 2019) $" revision: "$Revision: 102700 $" class PLAIN_TEXT_FILE inherit FILE rename index as position redefine is_plain_text end create make, make_with_name, make_with_path, make_open_read, make_open_write, make_open_append, make_open_read_write, make_create_read_write, make_open_read_append, make_open_temporary, make_open_temporary_with_prefix feature -- Status report is_plain_text: BOOLEAN -- Is file reserved for text (character sequences)? (Yes) do Result := True end Support_storable: BOOLEAN = False -- Can medium be used to store an Eiffel structure? feature -- Output 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. do put_string (i.out) 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. do put_string (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. do put_string (i.out) end put_integer_64 (i: INTEGER_64) -- Write ASCII value of i at current position. do put_string (i.out) end put_integer_16 (i: INTEGER_16) -- Write ASCII value of i at current position. do put_string (i.out) end put_integer_8 (i: INTEGER_8) -- Write ASCII value of i at current position. do put_string (i.out) end put_natural_64 (i: NATURAL_64) -- Write ASCII value of i at current position. do put_string (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. do put_string (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. do put_string (i.out) end put_natural_16 (i: NATURAL_16) -- Write ASCII value of i at current position. do put_string (i.out) end put_natural_8 (i: NATURAL_8) -- Write ASCII value of i at current position. do put_string (i.out) end put_boolean (b: BOOLEAN) -- Write ASCII value of b at current position. -- Was declared in PLAIN_TEXT_FILE as synonym of putbool. local ext_bool_str: ANY do if b then ext_bool_str := True_string.to_c file_ps (file_pointer, $ext_bool_str.to_pointer, True_string.count) else ext_bool_str := False_string.to_c file_ps (file_pointer, $ext_bool_str.to_pointer, False_string.count) end end putbool (b: BOOLEAN) -- Write ASCII value of b at current position. -- Was declared in PLAIN_TEXT_FILE as synonym of put_boolean. local ext_bool_str: ANY do if b then ext_bool_str := True_string.to_c file_ps (file_pointer, $ext_bool_str.to_pointer, True_string.count) else ext_bool_str := False_string.to_c file_ps (file_pointer, $ext_bool_str.to_pointer, False_string.count) end end put_real (r: REAL_32) -- Write ASCII value of r at current position. -- Was declared in PLAIN_TEXT_FILE as synonym of putreal. do file_pr (file_pointer, r) end putreal (r: REAL_32) -- Write ASCII value of r at current position. -- Was declared in PLAIN_TEXT_FILE as synonym of put_real. do file_pr (file_pointer, r) end put_double (d: REAL_64) -- Write ASCII value d at current position. -- Was declared in PLAIN_TEXT_FILE as synonym of putdouble. do file_pd (file_pointer, d) end putdouble (d: REAL_64) -- Write ASCII value d at current position. -- Was declared in PLAIN_TEXT_FILE as synonym of put_double. do file_pd (file_pointer, d) end feature -- Input read_integer_64 do read_integer_with_no_type last_integer_64 := Ctoi_convertor.parsed_integer_64 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. do read_integer_with_no_type last_integer := Ctoi_convertor.parsed_integer_32 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. do read_integer_with_no_type last_integer := Ctoi_convertor.parsed_integer_32 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. 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. do read_integer_with_no_type last_integer_16 := Ctoi_convertor.parsed_integer_16 end read_integer_8 -- Read the ASCII representation of a new 8-bit integer -- from file. Make result available in last_integer_8. do read_integer_with_no_type last_integer_8 := Ctoi_convertor.parsed_integer_8 end read_natural_64 -- Read the ASCII representation of a new 64-bit natural -- from file. Make result available in last_natural_64. do read_integer_with_no_type last_natural_64 := Ctoi_convertor.parsed_natural_64 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. do read_integer_with_no_type last_natural := Ctoi_convertor.parsed_natural_32 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. 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. do read_integer_with_no_type last_natural_16 := Ctoi_convertor.parsed_natural_16 end read_natural_8 -- Read the ASCII representation of a new 8-bit natural -- from file. Make result available in last_natural_8. do read_integer_with_no_type last_natural_8 := Ctoi_convertor.parsed_natural_8 end read_real -- 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 readreal. do last_real := file_gr (file_pointer) end readreal -- 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. do last_real := file_gr (file_pointer) end read_double -- 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 readdouble. do last_double := file_gd (file_pointer) end readdouble -- 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. do last_double := file_gd (file_pointer) end 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. do Result := file_gss (file_pointer, a_string.area.item_address (pos - 1), nb) a_string.reset_hash_codes end feature {NONE} -- Implementation 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 Internal_leading_separators: STRING_8 = " %N%R%T" -- Characters that are considered as leading separators is_sequence_an_expected_numeric: BOOLEAN -- Is last number sequence read by read_number_sequence an expected numeric? 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. 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 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) if not is_sequence_an_expected_numeric then return_characters end end return_characters -- Return character(s) do if last_character = '%N' and {PLATFORM}.is_windows then back end back end file_gi (file: POINTER): INTEGER_32 -- Get an integer from file external "C signature (FILE *): EIF_INTEGER use %"eif_file.h%"" alias "eif_file_gi" end file_gr (file: POINTER): REAL_32 -- Read a real from file external "C signature (FILE *): EIF_REAL_32 use %"eif_file.h%"" alias "eif_file_gr" end file_gd (file: POINTER): REAL_64 -- Read a double from file external "C signature (FILE *): EIF_REAL_64 use %"eif_file.h%"" alias "eif_file_gd" end file_pi (file: POINTER; n: INTEGER_32) -- Put n to end of 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. external "C signature (FILE *, EIF_REAL_32) use %"eif_file.h%"" alias "eif_file_pr" end file_pd (file: POINTER; d: REAL_64) -- Put d to end of file. external "C signature (FILE *, EIF_REAL_64) use %"eif_file.h%"" alias "eif_file_pd" end invariant plain_text: is_plain_text note copyright: "Copyright (c) 1984-2019, 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 PLAIN_TEXT_FILE
Generated by ISE EiffelStudio