1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . C G I . D E B U G --
9 -- Copyright (C) 2000-2010, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Strings
.Unbounded
;
34 package body GNAT
.CGI
.Debug
is
36 use Ada
.Strings
.Unbounded
;
38 -- Define the abstract type which act as a template for all debug IO modes.
39 -- To create a new IO mode you must:
40 -- 1. create a new package spec
41 -- 2. create a new type derived from IO.Format
42 -- 3. implement all the abstract routines in IO
46 type Format
is abstract tagged null record;
48 function Output
(Mode
: Format
'Class) return String;
53 Value
: String) return String is abstract;
54 -- Returns variable Name and its associated value
56 function New_Line
(Mode
: Format
) return String is abstract;
57 -- Returns a new line such as this concatenated between two strings
58 -- will display the strings on two lines.
60 function Title
(Mode
: Format
; Str
: String) return String is abstract;
61 -- Returns Str as a Title. A title must be alone and centered on a
62 -- line. Next output will be on the following line.
66 Str
: String) return String is abstract;
67 -- Returns Str as an Header. An header must be alone on its line. Next
68 -- output will be on the following line.
72 ----------------------
73 -- IO for HTML Mode --
74 ----------------------
78 -- See IO for comments about these routines
80 type Format
is new IO
.Format
with null record;
85 Value
: String) return String;
87 function New_Line
(IO
: Format
) return String;
89 function Title
(IO
: Format
; Str
: String) return String;
91 function Header
(IO
: Format
; Str
: String) return String;
95 ----------------------------
96 -- IO for Plain Text Mode --
97 ----------------------------
101 -- See IO for comments about these routines
103 type Format
is new IO
.Format
with null record;
108 Value
: String) return String;
110 function New_Line
(IO
: Format
) return String;
112 function Title
(IO
: Format
; Str
: String) return String;
114 function Header
(IO
: Format
; Str
: String) return String;
128 function Output
(Mode
: Format
'Class) return String is
129 Result
: Unbounded_String
;
134 (Title
(Mode
, "CGI complete runtime environment")
135 & Header
(Mode
, "CGI parameters:")
138 for K
in 1 .. Argument_Count
loop
140 & Variable
(Mode
, Key
(K
), Value
(K
))
146 & Header
(Mode
, "CGI environment variables (Metavariables):")
149 for P
in Metavariable_Name
'Range loop
150 if Metavariable_Exists
(P
) then
153 Metavariable_Name
'Image (P
),
159 return To_String
(Result
);
168 package body HTML_IO
is
170 NL
: constant String := (1 => ASCII
.LF
);
172 function Bold
(S
: String) return String;
173 -- Returns S as an HTML bold string
175 function Italic
(S
: String) return String;
176 -- Returns S as an HTML italic string
182 function Bold
(S
: String) return String is
184 return "<b>" & S
& "</b>";
191 function Header
(IO
: Format
; Str
: String) return String is
192 pragma Unreferenced
(IO
);
194 return "<h2>" & Str
& "</h2>" & NL
;
201 function Italic
(S
: String) return String is
203 return "<i>" & S
& "</i>";
210 function New_Line
(IO
: Format
) return String is
211 pragma Unreferenced
(IO
);
220 function Title
(IO
: Format
; Str
: String) return String is
221 pragma Unreferenced
(IO
);
223 return "<p align=center><font size=+2>" & Str
& "</font></p>" & NL
;
233 Value
: String) return String
235 pragma Unreferenced
(IO
);
237 return Bold
(Name
) & " = " & Italic
(Value
);
246 package body Text_IO
is
252 function Header
(IO
: Format
; Str
: String) return String is
254 return "*** " & Str
& New_Line
(IO
);
261 function New_Line
(IO
: Format
) return String is
262 pragma Unreferenced
(IO
);
264 return String'(1 => ASCII.LF);
271 function Title (IO : Format; Str : String) return String is
272 Spaces : constant Natural := (80 - Str'Length) / 2;
273 Indent : constant String (1 .. Spaces) := (others => ' ');
275 return Indent & Str & New_Line (IO);
285 Value : String) return String
287 pragma Unreferenced (IO);
289 return " " & Name & " = " & Value;
298 function HTML_Output return String is
299 HTML : HTML_IO.Format;
301 return IO.Output (Mode => HTML);
308 function Text_Output return String is
309 Text : Text_IO.Format;
311 return IO.Output (Mode => Text);