------------------------------------------------------------ -------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . P R I N T E R -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2007, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina 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 distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Namet; with Output; with Ocarina.Messages; with GNAT.Table; package body Ocarina.Printer is use Types; type printer_function is record Module : name_id; Printer_Access : printing_facility_access; end record; package Ocarina_Printers is new GNAT.Table (printer_function, nat, 1, 5, 20); function Select_Printer (Module : name_id) return printing_facility_access; -- Return the printing facility that corresponds to Module, or -- null if the corresponding facility was not found. ---------------------- -- Register_Printer -- ---------------------- procedure Register_Printer (Module : String; Printer : printing_facility_access) is use Namet; use Ocarina_Printers; The_Printer : printer_function; begin if Module'length > 0 then Set_Str_To_Name_Buffer (Module); The_Printer.Module := Name_Find; The_Printer.Printer_Access := Printer; Increment_Last; Table (Last) := The_Printer; end if; end Register_Printer; -------------------- -- Reset_Printers -- -------------------- procedure Reset_Printers is begin Ocarina_Printers.Init; end Reset_Printers; --------------------- -- Get_Output_File -- --------------------- function Create_Output_File (Options : output_options) return GNAT.OS_Lib.File_Descriptor is use GNAT.OS_Lib; use Ocarina.Messages; use Namet; Output_Desc : File_Descriptor := Standout; begin -- If the user gave an output directory assume to create the -- file inside the output directory. if Options.Output_File /= No_Name then -- If the user gave an output directory assume to create the -- file inside the output directory. if Options.Output_Directory /= No_Name then Get_Name_String (Options.Output_Directory); -- Add a separator if necessary if Name_Buffer (Name_Len) /= Directory_Separator then Add_Char_To_Name_Buffer (Directory_Separator); end if; Get_Name_String_And_Append (Options.Output_File); else Get_Name_String (Options.Output_File); end if; declare File_Name : constant String := Name_Buffer (1 .. Name_Len); begin Output_Desc := Create_File (File_Name, Binary); if Output_Desc = Invalid_FD then Display_Cannot_Create_File (File_Name); OS_Exit (2); end if; end; end if; return Output_Desc; end Create_Output_File; ----------- -- Print -- ----------- function Print (Root : node_id; Options : output_options) return Boolean is Current_Printer : constant printing_facility_access := Select_Printer (Options.Printer_Name); begin if Current_Printer = null then return False; else Current_Printer.all (Root, Options); return True; end if; end Print; -------------------- -- Select_Printer -- -------------------- function Select_Printer (Module : name_id) return printing_facility_access is use Ocarina_Printers; Index : nat := First; begin while Index <= Last loop if Table (Index).Module = Module then return Table (Index).Printer_Access; end if; Index := Index + 1; end loop; return null; end Select_Printer; -------------------- -- Write_Printers -- -------------------- procedure Write_Printers (Indent : Natural) is use Output; use Namet; use Ocarina_Printers; P_Index : nat := First; begin for Index in 1 .. Indent loop Write_Char (' '); end loop; Write_Line ("Registered printers:"); while P_Index <= Last loop for Index in 1 .. Indent + 1 loop Write_Char (' '); end loop; Write_Name (Table (P_Index).Module); Write_Eol; P_Index := P_Index + 1; end loop; end Write_Printers; end Ocarina.Printer;