--------------------------------------- ----------------------------------------- ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real time scheduling analysis tool. -- This program provides services to automatically check performances -- of real time architectures. -- -- Copyright (C) 2002-2010, by Frank Singhoff, Alain Plantec, Jerome Legrand -- -- The Cheddar project was started in 2002 by -- the LISyC Team, University of Western Britanny. -- -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- 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: 523 $ -- $Date: 2012-09-26 14:09:39 +0100 (Wed, 26 Sep 2012) $ -- $Author: fotsing $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Version; use Version; with Ada.IO_Exceptions; use Ada.IO_Exceptions; with GNAT.Current_Exception; use GNAT.Current_Exception; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with unbounded_strings; use unbounded_strings; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.OS_Lib; use GNAT.OS_Lib; with Text_IO; use Text_IO; procedure Merge is procedure Usage is begin New_Line; Put_Line ("Usage : merge infile"); Put_Line (" switch can be :"); Put_Line (" -t file to be merge on the top of the infile"); Put_Line (" -u get this help"); New_Line; end Usage; Infile : Unbounded_String; Top_File : Unbounded_String; Into : File_Type; Outto : File_Type; Read_String : String (1 .. 100000); Read_String_Size : Natural; begin Copyright ("merge"); -- Get arguments -- loop case Getopt ("u t:") is when ASCII.NUL => exit; when 'u' => Usage; OS_Exit (0); when 't' => Top_File := To_Unbounded_String (Parameter); when others => Usage; OS_Exit (0); end case; end loop; loop declare S : constant String := Get_Argument (Do_Expansion => True); begin exit when S'Length = 0; Infile := Infile & S; end; end loop; if (Infile = empty_string) then Put_Line ("merge.adb : a file name is required"); Usage; OS_Exit (0); end if; -- Copy the first file on the top -- Create (Outto, Mode => Out_File, Name => "merge.txt"); Open (Into, Mode => In_File, Name => To_String (Top_File)); while not End_Of_File (Into) loop Get_Line (Into, Read_String, Read_String_Size); Put_Line (Outto, Read_String (1 .. Read_String_Size)); end loop; Close (Into); Open (Into, Mode => In_File, Name => To_String (Infile)); while not End_Of_File (Into) loop Get_Line (Into, Read_String, Read_String_Size); Put_Line (Outto, Read_String (1 .. Read_String_Size)); end loop; Close (Into); Close (Outto); -- Update the infile with the text to merge -- Open (Into, Mode => In_File, Name => "merge.txt"); Create (Outto, Mode => Out_File, Name => To_String (Infile)); while not End_Of_File (Into) loop Get_Line (Into, Read_String, Read_String_Size); Put_Line (Outto, Read_String (1 .. Read_String_Size)); end loop; Close (Into); Close (Outto); exception when Invalid_Switch => begin Put_Line ("merge.adb : invalid Switch " & Full_Switch); Usage; end; when Invalid_Parameter => Put_Line ("merge.adb : missing parameter for switch " & Full_Switch); when Ada.IO_Exceptions.Name_Error => Put_Line ("merge.adb : Can not access file, Name_Error"); when Ada.IO_Exceptions.Status_Error => Put_Line ("merge.adb : Can not access file, Status_Error"); when Ada.IO_Exceptions.Mode_Error => Put_Line ("merge.adb : Can not access file, Mode_Error"); when Ada.IO_Exceptions.Use_Error => Put_Line ("merge.adb : Can not access file, Use_Error"); when Ada.IO_Exceptions.Device_Error => Put_Line ("merge.adb : Can not access file, Device_Error"); when Ada.IO_Exceptions.End_Error => Put_Line ("merge.adb : Can not access file, End_Error"); when Ada.IO_Exceptions.Data_Error => Put_Line ("merge.adb : Can not access file, Data_Error"); when Ada.IO_Exceptions.Layout_Error => Put_Line ("merge.adb : Can not access file, Layout_Error"); when others => Put_Line ("Exception name : " & Exception_Name); Put_Line ("Exception message : " & Exception_Message); end Merge;