------------------------------------------------------------------------------ -- XML/Ada - An XML suite for Ada95 -- -- -- -- Copyright (C) 2001-2012, AdaCore -- -- -- -- This library 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 3, or (at your option) any later -- -- version. This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- . -- -- -- ------------------------------------------------------------------------------ with Ada.Unchecked_Deallocation; with GNAT.Directory_Operations; use GNAT.Directory_Operations; with Sax.Symbols; use Sax.Symbols; package body Sax.Locators is --------------------- -- Get_Line_Number -- --------------------- function Get_Line_Number (Loc : locator) return Natural is begin return Loc.Line; end Get_Line_Number; ----------------------- -- Get_Column_Number -- ----------------------- function Get_Column_Number (Loc : locator) return Natural is begin return Loc.Column; end Get_Column_Number; ------------------- -- Get_System_Id -- ------------------- function Get_System_Id (Loc : locator) return symbol is begin return Loc.System_Id; end Get_System_Id; ------------------- -- Get_Public_Id -- ------------------- function Get_Public_Id (Loc : locator) return symbol is begin return Loc.Public_Id; end Get_Public_Id; ----------------------- -- Set_Column_Number -- ----------------------- procedure Set_Column_Number (Loc : in out locator; Column : Natural := 0) is begin Loc.Column := Column; end Set_Column_Number; ---------------------------- -- Increase_Column_Number -- ---------------------------- procedure Increase_Column_Number (Loc : in out locator; Inc : Natural := 1) is begin Loc.Column := Loc.Column + Inc; end Increase_Column_Number; -------------------------- -- Increase_Line_Number -- -------------------------- procedure Increase_Line_Number (Loc : in out locator; Inc : Natural := 1) is begin Loc.Line := Loc.Line + Inc; end Increase_Line_Number; --------------------- -- Set_Line_Number -- --------------------- procedure Set_Line_Number (Loc : in out locator; Line : Natural := 0) is begin Loc.Line := Line; end Set_Line_Number; ------------------ -- Get_Location -- ------------------ function Get_Location (Loc : locator) return location is begin if Loc = null then return No_Location; else return Loc.all; end if; end Get_Location; ------------------ -- Set_Location -- ------------------ procedure Set_Location (Loc : in out locator; To : location) is begin Loc.all := To; end Set_Location; ------------------- -- Set_Public_Id -- ------------------- procedure Set_Public_Id (Loc : in out locator; Id : symbol) is begin Loc.Public_Id := Id; end Set_Public_Id; ------------------- -- Set_System_Id -- ------------------- procedure Set_System_Id (Loc : in out locator; Id : symbol) is begin Loc.System_Id := Id; end Set_System_Id; --------------- -- To_String -- --------------- function To_String (Loc : locator; Use_Basename : Boolean := False) return String is begin if Loc = null then return ""; else return To_String (Loc.all, Use_Basename); end if; end To_String; --------------- -- To_String -- --------------- function To_String (Loc : location; Use_Basename : Boolean := False) return String is C : constant Natural := Loc.Column; Line : constant String := Natural'image (Loc.Line); Col : constant String := Natural'image (C); Public : constant symbol := Loc.Public_Id; begin if Public = No_Symbol then return ""; elsif C /= 0 then if Use_Basename then return (Base_Name (Get (Public).all) & ':' & Line (Line'first + 1 .. Line'last) & ':' & Col (Col'first + 1 .. Col'last)); else return (Get (Public).all & ':' & Line (Line'first + 1 .. Line'last) & ':' & Col (Col'first + 1 .. Col'last)); end if; else if Use_Basename then return (Base_Name (Get (Public).all) & ':' & Line (Line'first + 1 .. Line'last)); else return (Get (Public).all & ':' & Line (Line'first + 1 .. Line'last)); end if; end if; end To_String; ---------- -- Free -- ---------- procedure Free (Loc : in out locator) is procedure Unchecked_Free is new Ada.Unchecked_Deallocation (location, locator); begin Unchecked_Free (Loc); end Free; ------------ -- Create -- ------------ function Create return locator is begin return new location; end Create; end Sax.Locators;