1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Terminfo --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998-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
;
46 with Ada
.Unchecked_Conversion
;
48 package body Terminal_Interface
.Curses
.Terminfo
is
50 function Is_MinusOne_Pointer
(P
: chars_ptr
) return Boolean;
52 function Is_MinusOne_Pointer
(P
: chars_ptr
) return Boolean is
53 type Weird_Address
is new System
.Storage_Elements
.Integer_Address
;
54 Invalid_Pointer
: constant Weird_Address
:= -1;
55 function To_Weird
is new Ada
.Unchecked_Conversion
56 (Source
=> chars_ptr
, Target
=> Weird_Address
);
58 if To_Weird
(P
) = Invalid_Pointer
then
63 end Is_MinusOne_Pointer
;
64 pragma Inline
(Is_MinusOne_Pointer
);
66 ------------------------------------------------------------------------------
67 function Get_Flag
(Name
: String) return Boolean
69 function tigetflag
(id
: char_array
) return Curses_Bool
;
70 pragma Import
(C
, tigetflag
);
71 Txt
: char_array
(0 .. Name
'Length);
74 To_C
(Name
, Txt
, Length
);
75 if tigetflag
(Txt
) = Curses_Bool
(Curses_True
) then
82 ------------------------------------------------------------------------------
83 procedure Get_String
(Name
: String;
84 Value
: out Terminfo_String
;
87 function tigetstr
(id
: char_array
) return chars_ptr
;
88 pragma Import
(C
, tigetstr
, "tigetstr");
89 Txt
: char_array
(0 .. Name
'Length);
93 To_C
(Name
, Txt
, Length
);
94 Txt2
:= tigetstr
(Txt
);
95 if Txt2
= Null_Ptr
then
97 elsif Is_MinusOne_Pointer
(Txt2
) then
98 raise Curses_Exception
;
100 Value
:= Terminfo_String
(Fill_String
(Txt2
));
105 ------------------------------------------------------------------------------
106 function Has_String
(Name
: String) return Boolean
108 function tigetstr
(id
: char_array
) return chars_ptr
;
109 pragma Import
(C
, tigetstr
, "tigetstr");
110 Txt
: char_array
(0 .. Name
'Length);
114 To_C
(Name
, Txt
, Length
);
115 Txt2
:= tigetstr
(Txt
);
116 if Txt2
= Null_Ptr
then
118 elsif Is_MinusOne_Pointer
(Txt2
) then
119 raise Curses_Exception
;
125 ------------------------------------------------------------------------------
126 function Get_Number
(Name
: String) return Integer is
127 function tigetstr
(s
: char_array
) return C_Int
;
128 pragma Import
(C
, tigetstr
);
129 Txt
: char_array
(0 .. Name
'Length);
132 To_C
(Name
, Txt
, Length
);
133 return Integer (tigetstr
(Txt
));
136 ------------------------------------------------------------------------------
137 procedure Put_String
(Str
: Terminfo_String
;
138 affcnt
: Natural := 1;
139 putc
: putctype
:= null) is
140 function tputs
(str
: char_array
;
142 putc
: putctype
) return C_Int
;
143 function putp
(str
: char_array
) return C_Int
;
144 pragma Import
(C
, tputs
);
145 pragma Import
(C
, putp
);
146 Txt
: char_array
(0 .. Str
'Length);
150 To_C
(String (Str
), Txt
, Length
);
154 Err
:= tputs
(Txt
, C_Int
(affcnt
), putc
);
156 if Err
= Curses_Err
then
157 raise Curses_Exception
;
161 end Terminal_Interface
.Curses
.Terminfo
;