*** empty log message ***
[bpt/guile.git] / libguile / readline.c
1 /* need copyright assignment from Daniel Risacher */
2
3 #include "_scm.h"
4 #ifdef HAVE_LIBREADLINE
5 #include <libguile.h>
6 #include <gh.h>
7 #include <readline/readline.h>
8 #include <readline/history.h>
9
10 SCM_PROC (s_readline, "readline", 0, 1, 0, scm_readline);
11 SCM
12 scm_readline (SCM txt)
13 {
14 SCM ret;
15 char* s;
16 char* prompt;
17
18 if (! SCM_UNBNDP (txt))
19 {
20 SCM_ASSERT ((SCM_NIMP(txt) && SCM_STRINGP(txt)), txt, SCM_ARG1,
21 s_readline);
22 SCM_COERCE_SUBSTR (txt);
23 }
24
25 SCM_DEFER_INTS;
26 prompt = SCM_UNBNDP (txt) ? "" : SCM_CHARS (txt);
27
28 s = readline(prompt);
29 if (s)
30 ret = gh_str02scm(s);
31 else
32 ret = SCM_EOF_VAL;
33
34 free (s);
35 SCM_ALLOW_INTS;
36
37 return ret;
38 }
39
40 SCM_PROC (s_add_history, "add-history", 1, 0, 0, scm_add_history);
41 SCM
42 scm_add_history (SCM txt)
43 {
44 char* s;
45 SCM_ASSERT ((SCM_NIMP(txt) && SCM_STRINGP(txt)), txt, SCM_ARG1,
46 s_add_history);
47 SCM_COERCE_SUBSTR (txt);
48
49 SCM_DEFER_INTS;
50 s = SCM_CHARS(txt);
51 add_history(s);
52 SCM_ALLOW_INTS;
53
54 return SCM_UNSPECIFIED;
55 }
56
57 void
58 scm_init_readline ()
59 {
60 #include "readline.x"
61 scm_add_feature ("readline");
62 }
63
64 #endif