missing ncurses sources
[tomato.git] / release / src / router / libncurses / Ada95 / src / terminal_interface-curses-termcap.adb
blob643865781fd3efc283eefb82ff26bf30fd375847
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT ncurses Binding --
4 -- --
5 -- Terminal_Interface.Curses.Termcap --
6 -- --
7 -- B O D Y --
8 -- --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 2000-2006,2009 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.12 $
39 -- $Date: 2009/12/26 17:38:58 $
40 -- Binding Version 01.00
41 ------------------------------------------------------------------------------
43 with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
44 with Interfaces.C; use Interfaces.C;
45 with Interfaces.C.Strings; use Interfaces.C.Strings;
47 package body Terminal_Interface.Curses.Termcap is
49 function Get_Entry (Name : String) return Boolean
51 function tgetent (name : char_array; val : char_array)
52 return C_Int;
53 pragma Import (C, tgetent, "tgetent");
54 NameTxt : char_array (0 .. Name'Length);
55 Length : size_t;
56 ignored : constant char_array (0 .. 0) := (0 => nul);
57 result : C_Int;
58 begin
59 To_C (Name, NameTxt, Length);
60 result := tgetent (char_array (ignored), NameTxt);
61 if result = -1 then
62 raise Curses_Exception;
63 else
64 return Boolean'Val (result);
65 end if;
66 end Get_Entry;
68 ------------------------------------------------------------------------------
69 function Get_Flag (Name : String) return Boolean
71 function tgetflag (id : char_array) return C_Int;
72 pragma Import (C, tgetflag, "tgetflag");
73 Txt : char_array (0 .. Name'Length);
74 Length : size_t;
75 begin
76 To_C (Name, Txt, Length);
77 if tgetflag (Txt) = 0 then
78 return False;
79 else
80 return True;
81 end if;
82 end Get_Flag;
84 ------------------------------------------------------------------------------
85 procedure Get_Number (Name : String;
86 Value : out Integer;
87 Result : out Boolean)
89 function tgetnum (id : char_array) return C_Int;
90 pragma Import (C, tgetnum, "tgetnum");
91 Txt : char_array (0 .. Name'Length);
92 Length : size_t;
93 begin
94 To_C (Name, Txt, Length);
95 Value := Integer (tgetnum (Txt));
96 if Value = -1 then
97 Result := False;
98 else
99 Result := True;
100 end if;
101 end Get_Number;
103 ------------------------------------------------------------------------------
104 procedure Get_String (Name : String;
105 Value : out String;
106 Result : out Boolean)
108 function tgetstr (id : char_array;
109 buf : char_array) return chars_ptr;
110 pragma Import (C, tgetstr, "tgetstr");
111 Txt : char_array (0 .. Name'Length);
112 Length : size_t;
113 Txt2 : chars_ptr;
114 type t is new char_array (0 .. 1024); -- does it need to be 1024?
115 Return_Buffer : constant t := (others => nul);
116 begin
117 To_C (Name, Txt, Length);
118 Txt2 := tgetstr (Txt, char_array (Return_Buffer));
119 if Txt2 = Null_Ptr then
120 Result := False;
121 else
122 Value := Fill_String (Txt2);
123 Result := True;
124 end if;
125 end Get_String;
127 function Get_String (Name : String) return Boolean
129 function tgetstr (Id : char_array;
130 buf : char_array) return chars_ptr;
131 pragma Import (C, tgetstr, "tgetstr");
132 Txt : char_array (0 .. Name'Length);
133 Length : size_t;
134 Txt2 : chars_ptr;
135 type t is new char_array (0 .. 1024); -- does it need to be 1024?
136 Phony_Txt : constant t := (others => nul);
137 begin
138 To_C (Name, Txt, Length);
139 Txt2 := tgetstr (Txt, char_array (Phony_Txt));
140 if Txt2 = Null_Ptr then
141 return False;
142 else
143 return True;
144 end if;
145 end Get_String;
147 ------------------------------------------------------------------------------
148 function TGoto (Cap : String;
149 Col : Column_Position;
150 Row : Line_Position) return Termcap_String is
151 function tgoto (cap : char_array;
152 col : C_Int;
153 row : C_Int) return chars_ptr;
154 pragma Import (C, tgoto);
155 Txt : char_array (0 .. Cap'Length);
156 Length : size_t;
157 begin
158 To_C (Cap, Txt, Length);
159 return Termcap_String (Fill_String
160 (tgoto (Txt, C_Int (Col), C_Int (Row))));
161 end TGoto;
163 end Terminal_Interface.Curses.Termcap;