1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Terminfo --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 2000 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
37 -- Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en
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
51 function Is_MinusOne_Pointer (P : in chars_ptr) return Boolean;
53 function Is_MinusOne_Pointer (P : in chars_ptr) return Boolean is
54 type Weird_Address is new System.Storage_Elements.Integer_Address;
55 Invalid_Pointer : constant Weird_Address := -1;
56 function To_Weird is new Ada.Unchecked_Conversion
57 (Source => chars_ptr, Target => Weird_Address);
59 if To_Weird (P) = Invalid_Pointer then
64 end Is_MinusOne_Pointer;
65 pragma Inline (Is_MinusOne_Pointer);
67 ------------------------------------------------------------------------------
68 function Get_Flag (Name : String) return Boolean
70 function tigetflag (id : char_array) return Curses_Bool;
71 pragma Import (C, tigetflag);
72 Txt : char_array (0 .. Name'Length);
75 To_C (Name, Txt, Length);
76 if tigetflag (Txt) = Curses_Bool (Curses_True) then
83 ------------------------------------------------------------------------------
84 procedure Get_String (Name : String;
85 Value : out Terminfo_String;
88 function tigetstr (id : char_array) return chars_ptr;
89 pragma Import (C, tigetstr, "tigetstr");
90 Txt : char_array (0 .. Name'Length);
94 To_C (Name, Txt, Length);
95 Txt2 := tigetstr (Txt);
96 if Txt2 = Null_Ptr then
98 elsif Is_MinusOne_Pointer (Txt2) then
99 raise Curses_Exception;
101 Value := Terminfo_String (Fill_String (Txt2));
106 ------------------------------------------------------------------------------
107 function Has_String (Name : String) return Boolean
109 function tigetstr (id : char_array) return chars_ptr;
110 pragma Import (C, tigetstr, "tigetstr");
111 Txt : char_array (0 .. Name'Length);
115 To_C (Name, Txt, Length);
116 Txt2 := tigetstr (Txt);
117 if Txt2 = Null_Ptr then
119 elsif Is_MinusOne_Pointer (Txt2) then
120 raise Curses_Exception;
126 ------------------------------------------------------------------------------
127 function Get_Number (Name : String) return Integer is
128 function tigetstr (s : char_array) return C_Int;
129 pragma Import (C, tigetstr);
130 Txt : char_array (0 .. Name'Length);
133 To_C (Name, Txt, Length);
134 return Integer (tigetstr (Txt));
137 ------------------------------------------------------------------------------
138 procedure Put_String (Str : Terminfo_String;
139 affcnt : Natural := 1;
140 putc : putctype := null) is
141 function tputs (str : char_array;
143 putc : putctype) return C_Int;
144 function putp (str : char_array) return C_Int;
145 pragma Import (C, tputs);
146 pragma Import (C, putp);
147 Txt : char_array (0 .. Str'Length);
151 To_C (String (Str), Txt, Length);
155 Err := tputs (Txt, C_Int (affcnt), putc);
157 if Err = Curses_Err then
158 raise Curses_Exception;
162 end Terminal_Interface.Curses.Terminfo;