------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2023, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in README.md -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev$ -- $Date$ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Text_IO; use Text_IO; with Ada.Sequential_IO; with Ada.Directories; use Ada.Directories; with unbounded_strings; use unbounded_strings; package body io_tools is -- Check is a file can be read -- Return True if the file can be read -- function can_be_read (file_name : Unbounded_String) return Boolean is a_file : File_Type; result : Boolean := True; begin begin Open (a_file, In_File, To_String (file_name)); Close (a_file); exception when others => result := False; end; return result; end can_be_read; procedure reraise; pragma No_Return (reraise); pragma Import (C, reraise, "__gnat_reraise"); -- Reraises the exception referenced by the Current_Excep field of -- the TSD (all fields of this exception occurrence are set). Abort -- is deferred before the reraise operation. procedure write_sequential_file (file_name : in Unbounded_String; data : in Unbounded_String) is package set_file is new Ada.Sequential_IO (Character); use set_file; a_file : set_file.File_Type; begin Create (a_file, Mode => Out_File, Name => To_String (file_name)); if not Is_Open (a_file) then raise can_not_open_file_for_writing; end if; for i in 1 .. Length (data) loop Write (a_file, Element (data, i)); end loop; Close (a_file); exception when others => Close (a_file); reraise; end write_sequential_file; procedure write_sequential_file (file_name : in String; data : in Unbounded_String) is begin write_sequential_file (To_Unbounded_String (file_name), data); end write_sequential_file; function read_sequential_file (file_name : String) return Unbounded_String is begin return read_sequential_file (To_Unbounded_String (file_name)); end read_sequential_file; function read_sequential_file (file_name : Unbounded_String) return Unbounded_String is desc : Character; result : Unbounded_String; package set_file is new Ada.Sequential_IO (Character); use set_file; a_file : set_file.File_Type; begin Open (a_file, Mode => In_File, Name => To_String (file_name)); if not Is_Open (a_file) then raise can_not_open_file_for_reading; end if; while not End_Of_File (a_file) loop Read (a_file, desc); result := result & desc; end loop; Close (a_file); return result; exception when others => Close (a_file); reraise; end read_sequential_file; function simple_name (path : in Unbounded_String) return Unbounded_String is begin if (path = empty_string) then return path; else return To_Unbounded_String (Simple_Name (To_String (path))); end if; end simple_name; end io_tools;