Ada_Web_Server_43225d60/src/bbs-web-html.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
--
--  Author: Brent Seidel
--  Date: 6-Aug-2024
--
--  This file is part of Simple Ada Web Server.
--  Simple Ada Web Server is free software: you can redistribute it and/or
--  modify it under the terms of the GNU General Public License as published
--  by the Free Software Foundation, either version 3 of the License, or (at
--  your option) any later version.
--
--  Simple Ada Web Server 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 along
--  with Simple Ada Web Server. If not, see <https://www.gnu.org/licenses/>.--
--
with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
package body BBS.web.html is
   --
   --  Generate a standard HTML heading.  This just has a title attribute
   --
   procedure html_head(s : GNAT.Sockets.Stream_Access; title: String) is
   begin
      String'Write(s, "<html><head><title>" & title & "</title></head><body>" & CRLF);
   end html_head;
   --
   --  Generate a simple HTML heading with style sheet
   --
   procedure html_head(s : GNAT.Sockets.Stream_Access; title: String; style : String) is
   begin
      String'Write(s, "<html><head>" & CRLF);
      String'Write(s, "<title>" & title & "</title>" & CRLF);
      String'Write(s, "<link rel=""stylesheet"" type=""text/css"" href=""" & style & """>" & CRLF);
      String'Write(s, "</head><body>" & CRLF);
   end html_head;
   --
   --  Generate a standard HTML ending.  The ending should be in a file.  If the
   --  file can't be found, a minimal ending is substatuted.
   --
   procedure html_end(s : GNAT.Sockets.Stream_Access; name: String) is
      line : Ada.Strings.Unbounded.Unbounded_String;
      file : Ada.Text_IO.File_Type;
   begin
      begin
         Ada.Text_IO.Open(File => file,
                          Mode => Ada.Text_IO.In_File,
                          Name => name);
      exception
         when others =>
            String'Write(s, "</body></html>" & CRLF);
            return;
      end;
      while not Ada.Text_IO.End_Of_File(file) loop
         line := Ada.Text_IO.Unbounded_IO.Get_Line(file);
         String'Write(s, Ada.Strings.Unbounded.To_String(line) & CRLF);
      end loop;
      Ada.Text_IO.Close(file);
   end html_end;

end BBS.web.html;