opentoken_6.0.3_b278f6ad/wisi/wisi-utils.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
--  Abstract :
--
--  See spec
--
--  Copyright (C) 2012, 2013 Stephen Leake.  All Rights Reserved.
--
--  This program 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 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
--  distributed with this program; see file COPYING. If not, write to
--  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston,
--  MA 02110-1335, USA.

pragma License (GPL);

with Ada.Directories;
with Ada.Strings.Fixed;
package body Wisi.Utils is

   function Skip_Comments (File : in Standard.Ada.Text_IO.File_Type) return String
   is
      use Standard.Ada.Strings;
      use Standard.Ada.Strings.Fixed;
   begin
      loop
         declare
            Line      : constant String  := Standard.Ada.Text_IO.Get_Line (File);
            Comment   : constant Integer := Standard.Ada.Strings.Fixed.Index (Pattern => ";;", Source => Line);
            Non_Blank : constant Integer := Standard.Ada.Strings.Fixed.Index_Non_Blank (Line);
         begin
            if Non_Blank > 0 then
               if Comment = 0 then
                  return Trim (Line, Both);
               else
                  if Comment = Non_Blank then
                     null;
                  else
                     return Trim (Line (Non_Blank .. Comment - 1), Right);
                  end if;
               end if;
            end if;
         end;
      end loop;
   end Skip_Comments;

   procedure Put_Error
     (File_Name : in String;
      File_Line : in Standard.Ada.Text_IO.Positive_Count;
      Message   : in String)
   is
      use Standard.Ada.Directories;
      use Standard.Ada.Strings.Fixed;
      use Standard.Ada.Strings;
      use Standard.Ada.Text_IO;
      Prefix : constant String := Simple_Name (File_Name) & ":" &
        Trim (Positive_Count'Image (File_Line), Left) & ":0: ";
   begin
      Put_Line (Standard_Error, Prefix & Message);
   end Put_Error;

   procedure Put_Error (File : in Standard.Ada.Text_IO.File_Type; Message : in String)
   is
      use Standard.Ada.Text_IO;
   begin
      Put_Error (Name (File), Line (File) - 1, Message);
   end Put_Error;

end Wisi.Utils;