Merge pull request #345 from asarhaddon/ada.2
[jackhill/mal.git] / objpascal / mal_readline.pas
CommitLineData
bc6a1f15
JM
1unit mal_readline;
2
3{$H+} // Use AnsiString
4
5interface
6
7uses sysutils,
8 CTypes;
9
10{$IFDEF USE_READLINE}
11
12{$LINKLIB readline}
13
14{$ELSE}
15
16{$LINKLIB libedit}
17
18{$ENDIF}
19
865b628f
JM
20
21// External libedit/readline functions
22
bc6a1f15
JM
23function readline(Prompt: PChar) : PChar; cdecl; external;
24procedure add_history(Line: PChar); cdecl; external;
25
865b628f
JM
26// API
27
bc6a1f15
JM
28type MalEOF = class(Exception);
29
30function _readline(Prompt: string) : string;
31
865b628f
JM
32////////////////////////////////////////////////////////////
33
bc6a1f15
JM
34implementation
35
36function _readline(Prompt: string) : string;
37var
38 Line : PChar;
39begin
40 Line := readline(PChar(Prompt));
41 if Line = Nil then
42 raise MalEOF.Create('MalEOF');
43 if Line <> '' then
44 add_history(Line);
45
46 _readline := Line;
47end;
48
49end.