Automatic generation produced by ISE Eiffel
indexing description: "Files viewed as persistent sequences of ASCII characters" status: "See notice at end of class" date: "$Date: 2001/11/16 20:34:13 $" revision: "$Revision: 1.1.1.1 $" class PLAIN_TEXT_FILE create make, make_open_read, make_open_write, make_open_append, make_open_read_write, make_create_read_write, make_open_read_append feature -- Initialization make (fn: STRING) is -- 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 name := fn mode := closed_file create last_string.make (256) ensure -- from FILE file_named: name.is_equal (fn) file_closed: is_closed end make_create_read_write (fn: STRING) is -- 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 (fn) create_read_write ensure -- from FILE exists: exists open_read: is_open_read open_write: is_open_write end make_open_append (fn: STRING) is -- 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 (fn) open_append ensure -- from FILE exists: exists open_append: is_open_append end make_open_read (fn: STRING) is -- Create file object with fn as file name -- and open file in read mode. -- (from FILE) require -- from FILE string_exists: fn /= void string_not_empty: not fn.is_empty do make (fn) open_read ensure -- from FILE exists: exists open_read: is_open_read end make_open_read_append (fn: STRING) is -- 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 (fn) open_read_append ensure -- from FILE exists: exists open_read: is_open_read open_append: is_open_append end make_open_read_write (fn: STRING) is -- 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 (fn) open_read_write ensure -- from FILE exists: exists open_read: is_open_read open_write: is_open_write end make_open_write (fn: STRING) is -- Create file object with fn as file name -- and open file for 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 (fn) open_write ensure -- from FILE exists: exists open_write: is_open_write end feature -- Access access_date: INTEGER is -- Time stamp of last access made to the inode. -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.access_date end date: INTEGER is -- Time stamp (time of last modification) -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.date end descriptor: INTEGER is -- 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 -- (from FILE) file_info: UNIX_FILE_INFO is -- Collected information about the file. -- (from FILE) do set_buffer Result := clone (buffered_file_info) end file_pointer: POINTER -- File pointer as required in C -- (from FILE) group_id: INTEGER is -- 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 is -- Does structure include an occurrence of v? -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) 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): INTEGER is -- 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 do if object_comparison and v /= void then from start pos := 1 until off or (occur = i) loop if item /= void and then v.is_equal (item) then occur := occur + 1 end forth pos := pos + 1 end else from start pos := 1 until off 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 is -- I-node number -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.inode end item: CHARACTER is -- Current item -- (from FILE) require -- from TRAVERSABLE not_off: not off require -- from ACTIVE readable: readable do read_character Result := last_character back end links: INTEGER is -- Number of links on file -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.links end name: STRING -- File name -- (from FILE) occurrences (v: CHARACTER): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) 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 is -- Name of owner -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.owner_name end position: INTEGER is -- Current cursor position. -- (from FILE) do if not is_closed then Result := file_tell (file_pointer) end end protection: INTEGER is -- Protection mode, in decimal value -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.protection end retrieved: ANY is -- 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 exists: exists is_open_read: is_open_read support_storable: support_storable do Result := c_retrieved (descriptor) ensure -- from IO_MEDIUM result_exists: Result /= void end separator: CHARACTER -- ASCII code of character following last word read -- (from FILE) user_id: INTEGER is -- User identification of owner -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.user_id end feature {NONE} -- Access C_memory: INTEGER is 2 -- Code for the C memory managed -- by the garbage collector -- (from MEM_CONST) Eiffel_memory: INTEGER is 1 -- Code for the Eiffel memory managed -- by the garbage collector -- (from MEM_CONST) Full_collector: INTEGER is 0 -- Statistics for full collections -- (from MEM_CONST) Incremental_collector: INTEGER is 1 -- Statistics for incremental collections -- (from MEM_CONST) sequential_search (v: like item) is -- Move to first position (at or after current -- position) where item and v are equal. -- (Reference or object equality, -- based on object_comparison.) -- If no such position ensure that exhausted will be true. -- (from LINEAR) do if object_comparison and v /= void then from until exhausted or else (item /= void and then v.is_equal (item)) loop forth end else from until exhausted or else v = item loop forth end end ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, item) item_found: (not exhausted and not object_comparison) implies v = item end Total_memory: INTEGER is 0 -- Code for all the memory managed -- by the garbage collector -- (from MEM_CONST) feature -- Measurement count: INTEGER is -- Size in bytes (0 if no associated physical file) -- (from FILE) do if exists then if not is_open_write then set_buffer Result := buffered_file_info.size else Result := file_size (file_pointer) end end end feature {NONE} -- Measurement gc_statistics (collector_type: INTEGER): GC_INFO is -- Garbage collection information for collector_type. -- (from MEMORY) require -- from MEMORY type_ok: collector_type = full_collector or collector_type = incremental_collector do create Result.make (collector_type) end memory_statistics (memory_type: INTEGER): MEM_INFO is -- Memory usage information for memory_type -- (from MEMORY) require -- from MEMORY type_ok: memory_type = total_memory or memory_type = eiffel_memory or memory_type = c_memory do create Result.make (memory_type) end feature -- Status report access_exists: BOOLEAN is -- Does physical file exist? -- (Uses real UID.) -- (from FILE) local external_name: ANY do external_name := name.to_c Result := file_access ($external_name, 0) end after: BOOLEAN is -- 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 -- Is there no valid cursor position to the left of cursor position? -- (from FILE) do Result := is_closed end changeable_comparison_criterion: BOOLEAN is -- May object_comparison be changed? -- (Answer: yes by default.) -- (from CONTAINER) do Result := True end empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_empty end end_of_file: BOOLEAN is -- Has an EOF been detected? -- (from FILE) require -- from FILE opened: not is_closed do Result := file_feof (file_pointer) end exhausted: BOOLEAN is -- Has structure been completely explored? -- (from LINEAR) do Result := off ensure -- from LINEAR exhausted_when_off: off implies Result end exists: BOOLEAN is -- Does physical file exist? -- (Uses effective UID.) -- (from FILE) local external_name: ANY do external_name := name.to_c Result := file_exists ($external_name) ensure then -- from FILE unchanged_mode: mode = old mode end extendible: BOOLEAN is -- May new items be added? -- (from FILE) do Result := mode >= write_file end file_prunable: BOOLEAN is -- May items be removed? -- (from FILE) do Result := mode >= write_file and prunable end file_readable: BOOLEAN is -- 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 -- Is there a current item that may be modified? -- (from FILE) do Result := mode >= write_file end Full: BOOLEAN is False -- Is structure filled to capacity? -- (from FILE) is_access_executable: BOOLEAN is -- 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 -- 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 -- 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 -- 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 -- 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 -- 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 -- Is file closed? -- (from FILE) do Result := mode = closed_file end is_creatable: BOOLEAN is -- Is file creatable in parent directory? -- (Uses effective UID to check that parent is writable -- and file does not exist.) -- (from FILE) local external_name: ANY do external_name := name.to_c Result := file_creatable ($external_name) end is_device: BOOLEAN is -- 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 -- Is file a directory? -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.is_directory end is_empty: BOOLEAN is -- Is structure empty? -- (from FINITE) do Result := (count = 0) end is_executable: BOOLEAN is -- 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 -- 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): BOOLEAN is -- 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 -- Is file open for appending? -- (from FILE) do Result := mode = append_file or else mode = append_read_file end is_open_read: BOOLEAN is -- 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 -- 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 -- 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 -- 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 -- Is file reserved for text (character sequences)? (Yes) do Result := True end is_readable: BOOLEAN is -- 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 -- 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 -- 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 -- 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 -- 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 -- Is file a symbolic link? -- (from FILE) require -- from FILE file_exists: exists do set_buffer Result := buffered_file_info.is_symlink end is_writable: BOOLEAN is -- 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 -- Last character read by read_character -- (from IO_MEDIUM) last_double: DOUBLE -- Last double read by read_double -- (from IO_MEDIUM) last_integer: INTEGER -- Last integer read by read_integer -- (from IO_MEDIUM) last_real: REAL -- Last real read by read_real -- (from IO_MEDIUM) last_string: STRING -- 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 -- Is there no item? -- (from FILE) do Result := (count = 0) or else is_closed or else end_of_file end readable: BOOLEAN is -- 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 Support_storable: BOOLEAN is False -- Can medium be used to store an Eiffel structure? writable: BOOLEAN is -- Is there a current item that may be modified? -- (from SEQUENCE) do Result := not off end feature {NONE} -- Status report chunk_size: INTEGER is -- Minimal size of a memory chunk. The run-time always -- allocates a multiple of this size. -- If the environment variable EIF_MEMORY_CHUNK -- is defined, it is set to the closest reasonable -- value from it. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_get_chunk_size" end coalesce_period: INTEGER is -- Period of full coalesce (in number of collections) -- If the environment variable EIF_FULL_COALESCE_PERIOD -- is defined, it is set to the closest reasonable -- value from it. -- If null, no full coalescing is launched. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_coalesce_period" end collecting: BOOLEAN is -- Is garbage collection enabled? -- <