1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Termcap --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 2000-2006,2009 Free Software Foundation, Inc. --
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: --
20 -- The above copyright notice and this permission notice shall be included --
21 -- in all copies or substantial portions of the Software. --
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. --
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 --
35 ------------------------------------------------------------------------------
36 -- Author: Juergen Pfeifer, 1996
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
)
53 pragma Import
(C
, tgetent
, "tgetent");
54 NameTxt
: char_array
(0 .. Name
'Length);
56 ignored
: constant char_array
(0 .. 0) := (0 => nul
);
59 To_C
(Name
, NameTxt
, Length
);
60 result
:= tgetent
(char_array
(ignored
), NameTxt
);
62 raise Curses_Exception
;
64 return Boolean'Val (result
);
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);
76 To_C
(Name
, Txt
, Length
);
77 if tgetflag
(Txt
) = 0 then
84 ------------------------------------------------------------------------------
85 procedure Get_Number
(Name
: String;
89 function tgetnum
(id
: char_array
) return C_Int
;
90 pragma Import
(C
, tgetnum
, "tgetnum");
91 Txt
: char_array
(0 .. Name
'Length);
94 To_C
(Name
, Txt
, Length
);
95 Value
:= Integer (tgetnum
(Txt
));
103 ------------------------------------------------------------------------------
104 procedure Get_String
(Name
: 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);
114 type t
is new char_array
(0 .. 1024); -- does it need to be 1024?
115 Return_Buffer
: constant t
:= (others => nul
);
117 To_C
(Name
, Txt
, Length
);
118 Txt2
:= tgetstr
(Txt
, char_array
(Return_Buffer
));
119 if Txt2
= Null_Ptr
then
122 Value
:= Fill_String
(Txt2
);
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);
135 type t
is new char_array
(0 .. 1024); -- does it need to be 1024?
136 Phony_Txt
: constant t
:= (others => nul
);
138 To_C
(Name
, Txt
, Length
);
139 Txt2
:= tgetstr
(Txt
, char_array
(Phony_Txt
));
140 if Txt2
= Null_Ptr
then
147 ------------------------------------------------------------------------------
148 function TGoto
(Cap
: String;
149 Col
: Column_Position
;
150 Row
: Line_Position
) return Termcap_String
is
151 function tgoto
(cap
: char_array
;
153 row
: C_Int
) return chars_ptr
;
154 pragma Import
(C
, tgoto
);
155 Txt
: char_array
(0 .. Cap
'Length);
158 To_C
(Cap
, Txt
, Length
);
159 return Termcap_String
(Fill_String
160 (tgoto
(Txt
, C_Int
(Col
), C_Int
(Row
))));
163 end Terminal_Interface
.Curses
.Termcap
;