• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1------------------------------------------------------------------------------
2--                                                                          --
3--                           GNAT ncurses Binding                           --
4--                                                                          --
5--                    Terminal_Interface.Curses.Termcap                     --
6--                                                                          --
7--                                 B O D Y                                  --
8--                                                                          --
9------------------------------------------------------------------------------
10-- Copyright 2020 Thomas E. Dickey                                          --
11-- Copyright 2000-2006,2009 Free Software Foundation, Inc.                  --
12--                                                                          --
13-- Permission is hereby granted, free of charge, to any person obtaining a  --
14-- copy of this software and associated documentation files (the            --
15-- "Software"), to deal in the Software without restriction, including      --
16-- without limitation the rights to use, copy, modify, merge, publish,      --
17-- distribute, distribute with modifications, sublicense, and/or sell       --
18-- copies of the Software, and to permit persons to whom the Software is    --
19-- furnished to do so, subject to the following conditions:                 --
20--                                                                          --
21-- The above copyright notice and this permission notice shall be included  --
22-- in all copies or substantial portions of the Software.                   --
23--                                                                          --
24-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
25-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
26-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
27-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
28-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
29-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
30-- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
31--                                                                          --
32-- Except as contained in this notice, the name(s) of the above copyright   --
33-- holders shall not be used in advertising or otherwise to promote the     --
34-- sale, use or other dealings in this Software without prior written       --
35-- authorization.                                                           --
36------------------------------------------------------------------------------
37--  Author:  Juergen Pfeifer, 1996
38--  Version Control:
39--  $Revision: 1.13 $
40--  $Date: 2020/02/02 23:34:34 $
41--  Binding Version 01.00
42------------------------------------------------------------------------------
43
44with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
45with Interfaces.C; use Interfaces.C;
46with Interfaces.C.Strings; use Interfaces.C.Strings;
47
48package body Terminal_Interface.Curses.Termcap is
49
50   function Get_Entry (Name : String) return Boolean
51   is
52      function tgetent (name : char_array; val : char_array)
53                        return C_Int;
54      pragma Import (C, tgetent, "tgetent");
55      NameTxt : char_array (0 .. Name'Length);
56      Length  : size_t;
57      ignored : constant char_array (0 .. 0) := (0 => nul);
58      result  : C_Int;
59   begin
60      To_C (Name, NameTxt, Length);
61      result := tgetent (char_array (ignored), NameTxt);
62      if result = -1 then
63         raise Curses_Exception;
64      else
65         return Boolean'Val (result);
66      end if;
67   end Get_Entry;
68
69------------------------------------------------------------------------------
70   function Get_Flag (Name : String) return Boolean
71   is
72      function tgetflag (id : char_array) return C_Int;
73      pragma Import (C, tgetflag, "tgetflag");
74      Txt    : char_array (0 .. Name'Length);
75      Length : size_t;
76   begin
77      To_C (Name, Txt, Length);
78      if tgetflag (Txt) = 0 then
79         return False;
80      else
81         return True;
82      end if;
83   end Get_Flag;
84
85------------------------------------------------------------------------------
86   procedure Get_Number (Name   : String;
87                         Value  : out Integer;
88                         Result : out Boolean)
89   is
90      function tgetnum (id : char_array) return C_Int;
91      pragma Import (C, tgetnum, "tgetnum");
92      Txt    : char_array (0 .. Name'Length);
93      Length : size_t;
94   begin
95      To_C (Name, Txt, Length);
96      Value := Integer (tgetnum (Txt));
97      if Value = -1 then
98         Result := False;
99      else
100         Result :=  True;
101      end if;
102   end Get_Number;
103
104------------------------------------------------------------------------------
105   procedure Get_String (Name   : String;
106                         Value  : out String;
107                         Result : out Boolean)
108   is
109      function tgetstr (id  : char_array;
110                        buf : char_array) return chars_ptr;
111      pragma Import (C, tgetstr, "tgetstr");
112      Txt    : char_array (0 .. Name'Length);
113      Length : size_t;
114      Txt2   : chars_ptr;
115      type t is new char_array (0 .. 1024); --  does it need to be 1024?
116      Return_Buffer : constant t := (others => nul);
117   begin
118      To_C (Name, Txt, Length);
119      Txt2 := tgetstr (Txt, char_array (Return_Buffer));
120      if Txt2 = Null_Ptr then
121         Result := False;
122      else
123         Value := Fill_String (Txt2);
124         Result := True;
125      end if;
126   end Get_String;
127
128   function Get_String (Name : String) return Boolean
129   is
130      function tgetstr (Id  : char_array;
131                        buf : char_array) return chars_ptr;
132      pragma Import (C, tgetstr, "tgetstr");
133      Txt    : char_array (0 .. Name'Length);
134      Length : size_t;
135      Txt2   : chars_ptr;
136      type t is new char_array (0 .. 1024); --  does it need to be 1024?
137      Phony_Txt : constant t := (others => nul);
138   begin
139      To_C (Name, Txt, Length);
140      Txt2 := tgetstr (Txt, char_array (Phony_Txt));
141      if Txt2 = Null_Ptr then
142         return False;
143      else
144         return True;
145      end if;
146   end Get_String;
147
148------------------------------------------------------------------------------
149   function TGoto (Cap : String;
150                   Col : Column_Position;
151                   Row : Line_Position) return Termcap_String is
152      function tgoto (cap : char_array;
153                      col : C_Int;
154                      row : C_Int) return chars_ptr;
155      pragma Import (C, tgoto);
156      Txt    : char_array (0 .. Cap'Length);
157      Length : size_t;
158   begin
159      To_C (Cap, Txt, Length);
160      return Termcap_String (Fill_String
161                             (tgoto (Txt, C_Int (Col), C_Int (Row))));
162   end TGoto;
163
164end Terminal_Interface.Curses.Termcap;
165