errors.adb 7.68 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                               E R R O R S                                --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
jhugues's avatar
jhugues committed
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2012 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- 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.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
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
--                                                                          --
------------------------------------------------------------------------------

with Ada.Command_Line;          use Ada.Command_Line;
with GNAT.OS_Lib;               use GNAT.OS_Lib;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with Output;                    use Output;
with Namet;                     use Namet;

package body Errors is

   procedure Internal_Display_Message (S : String);

   procedure Check_Space;
   --  Check there is a trailing space in order to append a string to
   --  name buffer.

   -----------------
   -- Check_Space --
   -----------------

   procedure Check_Space is
   begin
      if Name_Len > 0 and then Name_Buffer (Name_Len) /= ' ' then
         Add_Char_To_Name_Buffer (' ');
      end if;
   end Check_Space;

   ------------------------------
   -- Internal_Display_Message --
   ------------------------------

yoogx's avatar
yoogx committed
63
   procedure Internal_Display_Message (S : String) is
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
      L : Natural := 1;
      I : Natural := 1;
      N : Natural := 1;
      M : Boolean := False; --  Meta-character
      J : Natural := S'First;

   begin
      if Error_Loc (L) = No_Location then
         Set_Str_To_Name_Buffer
           (Base_Name (Command_Name, Get_Executable_Suffix.all));
      else
         Set_Str_To_Name_Buffer (Image (Error_Loc (L)));
      end if;

      L := L + 1;
      Add_Str_To_Name_Buffer (": ");

      while J <= S'Last loop

         --  Escape meta-character

         if S (J) = '|' then
            if J < S'Last then
               J := J + 1;
            end if;
            Add_Char_To_Name_Buffer (S (J));

         elsif S (J) = '%' then
            Check_Space;
            Get_Name_String_And_Append (Error_Name (N));
            N := N + 1;
            M := True;

         elsif S (J) = '#' then
            Check_Space;
            Add_Char_To_Name_Buffer ('"'); -- "
            Get_Name_String_And_Append (Error_Name (N));
            Add_Char_To_Name_Buffer ('"'); -- "
            N := N + 1;
            M := True;

         elsif S (J) = '!' then
            if Error_Loc (1).Base_Name = Error_Loc (L).Base_Name then
               Check_Space;
               Add_Str_To_Name_Buffer ("at line ");
               Add_Nat_To_Name_Buffer (Error_Loc (L).Line);

            else
               Check_Space;
               Add_Str_To_Name_Buffer ("in ");
               Add_Str_To_Name_Buffer (Image (Error_Loc (L)));
            end if;
            L := L + 1;
            M := True;

         elsif S (J) = '$' then
            Add_Nat_To_Name_Buffer (Error_Int (I));
            I := I + 1;
            M := False;

         else
            if M then
               Add_Char_To_Name_Buffer (' ');
               M := False;
            end if;
            Add_Char_To_Name_Buffer (S (J));
         end if;

         J := J + 1;
      end loop;

      Set_Standard_Error;
      Write_Line (Name_Buffer (1 .. Name_Len));
      Set_Standard_Output;

      Initialize;
   end Internal_Display_Message;

   -------------------
   -- Display_Error --
   -------------------

   procedure Display_Error (S : String) is
   begin
      N_Errors := N_Errors + 1;
      Internal_Display_Message (S);
   end Display_Error;

   ---------------------
   -- Display_Message --
   ---------------------

   procedure Display_Message (S : String) is
   begin
      Internal_Display_Message (S);
   end Display_Message;

   ---------------------
   -- Display_Warning --
   ---------------------

   procedure Display_Warning (S : String) is
   begin
      N_Warnings := N_Warnings + 1;
      Internal_Display_Message ("warning: " & S);
   end Display_Warning;

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize is
   begin
      Error_Loc  := (others => No_Location);
      Error_Name := (others => No_Name);
      Error_Int  := (others => 0);
   end Initialize;

   ---------------------
   -- Display_Bug_Box --
   ---------------------

   procedure Display_Bug_Box (E : Ada.Exceptions.Exception_Occurrence) is
      Exception_String : constant String := "| Detected exception: "
        & Ada.Exceptions.Exception_Name (E);
      Error_String : constant String :=
        "| Error: "
        & Ada.Exceptions.Exception_Message (E);
   begin
      Set_Standard_Error;

      Write_Line ("+========================== OCARINA BUG DETECTED"
                    & " =========================+");

      Write_Str (Exception_String);
      for J in Exception_String'Length .. 72 loop
         Write_Str (" ");
      end loop;
      Write_Str (" |");
      Write_Eol;

      Write_Str (Error_String);
      for J in Error_String'Length .. 72 loop
         Write_Str (" ");
      end loop;
      Write_Str (" |");
      Write_Eol;

      Write_Str ("| Please refer to the User's Guide for more details."
                   & "                      |");
      Write_Eol;
      Write_Line ("+============================================="
                    & "============================+");
      Write_Eol;
      Write_Line (Ada.Exceptions.Exception_Information (E));

      OS_Exit (3);
   end Display_Bug_Box;

223
224
225
226
227
228
229
230
231
232
233
234
235
   -------------------
   -- Exit_On_Error --
   -------------------

   procedure Exit_On_Error (Error : Boolean; Reason : String) is
   begin
      if Error then
         Set_Standard_Error;
         Write_Line (Reason);
         OS_Exit (1);
      end if;
   end Exit_On_Error;

236
end Errors;