-- $Date: 2004/03/01 01:34:21 $
-- $Revision: 1.23 $
-- $Author: jcrocholl $

with Ada.Unchecked_Deallocation;

with Ada.Strings.Maps; use Ada.Strings.Maps;

with Strings; use Strings;
with Messages; use Messages;

package body XML_Readers is

   Tag_Terminators : Character_Set := To_Set("/?>");

   -----------------
   -- Initialization
   -----------------

   -- Initialize a newly created reader instance.
   procedure Initialize_XML_Reader
     (This : access XML_Reader'Class) is
   begin
      Initialize_Token_Reader(This);
      This.Word_Separators := To_Set(" /=""!?>");
      This.Contexts := Create;
   end Initialize_XML_Reader;

   -- Initialize a newly created reader instance with a file to read.
   procedure Initialize_XML_Reader
     (This     : access XML_Reader'Class;
      Filename : in String) is -- Open this file for reading.
   begin
      Initialize_Token_Reader(This, Filename);
      This.Word_Separators := To_Set(" /=""!?>");
      This.Contexts := Create;
   end Initialize_XML_Reader;

   -- Close the input file.
   procedure Finalize_XML_Reader
     (This : access XML_Reader'Class) is -- Object instance.
   begin
      Finalize_Token_Reader(This);
      -- Free(This.Contexts);
   end Finalize_XML_Reader;

   -------------------
   -- Creating readers
   -------------------

   -- Create an XML reader for current input (stdin).
   function Current_Input
     return XML_Reader_Access -- The newly created XML reader instance.
   is
      Result : XML_Reader_Access := new XML_Reader;
   begin
      Initialize_XML_Reader(Result);
      return Result;
   end Current_Input;

   -- Create an XML reader for file input.
   function Open
     (Filename : in String)   -- Open this file.
     return XML_Reader_Access -- The newly created XML reader instance.
   is
      Result : XML_Reader_Access := new XML_Reader;
   begin
      Initialize_XML_Reader(Result, Filename);
      return Result;
   end Open;