Merge pull request #345 from asarhaddon/ada.2
[jackhill/mal.git] / ada.2 / readline.adb
1 with Interfaces.C.Strings;
2
3 package body Readline is
4
5 function Input (Prompt : in String) return String is
6
7 use Interfaces.C;
8 use Interfaces.C.Strings;
9
10 function C_Readline (Prompt : in char_array) return chars_ptr
11 with Import, Convention => C, External_Name => "readline";
12
13 procedure Add_History (Line : in chars_ptr)
14 with Import, Convention => C, External_Name => "add_history";
15
16 procedure Free (Line : in chars_ptr)
17 with Import, Convention => C, External_Name => "free";
18
19 C_Line : constant chars_ptr := C_Readline (To_C (Prompt));
20 begin
21 if C_Line = Null_Ptr then
22 raise End_Of_File;
23 end if;
24 return Ada_Line : constant String := Value (C_Line) do
25 if Ada_Line /= "" then
26 Add_History (C_Line);
27 end if;
28 Free (C_Line);
29 end return;
30 end Input;
31
32 end Readline;