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