blob: faa574ffcf71702b2a1807c0d508993954a2d74c [file] [log] [blame]
Guido van Rossum290900a1997-09-26 21:51:21 +00001/* This module makes GNU readline available to Python. It has ideas
2 * contributed by Lee Busby, LLNL, and William Magro, Cornell Theory
3 * Center. The completer interface was inspired by Lele Gaifax.
4 *
5 * More recently, it was largely rewritten by Guido van Rossum who is
6 * now maintaining it.
Guido van Rossum0969d361997-08-05 21:27:50 +00007 */
8
Guido van Rossum290900a1997-09-26 21:51:21 +00009/* Standard definitions */
Guido van Rossum0969d361997-08-05 21:27:50 +000010#include "Python.h"
11#include <setjmp.h>
12#include <signal.h>
Guido van Rossum290900a1997-09-26 21:51:21 +000013#include <errno.h>
Guido van Rossum0969d361997-08-05 21:27:50 +000014
Guido van Rossum73bacfc1998-01-19 22:05:22 +000015#ifdef HAVE_UNISTD_H
16#include <unistd.h> /* For isatty() */
17#endif
18
Guido van Rossum290900a1997-09-26 21:51:21 +000019/* GNU readline definitions */
Guido van Rossumbcc20741998-08-04 22:53:56 +000020/* If you have string.h, you might need to add yourself to this #if... [cjh] */
21#if defined(__BEOS__)
22#undef HAVE_CONFIG_H
23/* At max warnings, we need protos for everything. [cjh] */
24#include <readline/readline.h>
25#include <readline/history.h>
26#include <unistd.h>
27#else
Guido van Rossum290900a1997-09-26 21:51:21 +000028#include <readline/readline.h> /* You may need to add an -I option to Setup */
29
Fred Drake8ce159a2000-08-31 05:18:54 +000030extern int rl_parse_and_bind(char *);
31extern int rl_read_init_file(char *);
32extern int rl_insert_text(char *);
33extern int rl_bind_key(int, Function *);
34extern int rl_bind_key_in_map(int, Function *, Keymap);
35extern int rl_initialize(void);
36extern int add_history(char *);
Guido van Rossumb9ce5ad2000-09-01 02:43:38 +000037extern int read_history(char *);
38extern int write_history(char *);
39extern int history_truncate_file(char *, int);
Guido van Rossum54ecc3d1999-01-27 17:53:11 +000040extern Function *rl_event_hook;
Guido van Rossumbcc20741998-08-04 22:53:56 +000041#endif
Guido van Rossum730806d1998-04-10 22:27:42 +000042
Guido van Rossum290900a1997-09-26 21:51:21 +000043/* Pointers needed from outside (but not declared in a header file). */
Thomas Wouters2c46eaf2000-07-22 23:51:19 +000044extern int (*PyOS_InputHook)(void);
Tim Petersdbd9ba62000-07-09 03:09:57 +000045extern char *(*PyOS_ReadlineFunctionPointer)(char *);
Guido van Rossum0969d361997-08-05 21:27:50 +000046
Guido van Rossum0969d361997-08-05 21:27:50 +000047
Guido van Rossum290900a1997-09-26 21:51:21 +000048/* Exported function to send one line to readline's init file parser */
49
50static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000051parse_and_bind(PyObject *self, PyObject *args)
Guido van Rossum290900a1997-09-26 21:51:21 +000052{
Guido van Rossum3b5330e1998-12-04 15:34:39 +000053 char *s, *copy;
Guido van Rossum43713e52000-02-29 13:59:29 +000054 if (!PyArg_ParseTuple(args, "s:parse_and_bind", &s))
Guido van Rossum290900a1997-09-26 21:51:21 +000055 return NULL;
Guido van Rossum3b5330e1998-12-04 15:34:39 +000056 /* Make a copy -- rl_parse_and_bind() modifies its argument */
57 /* Bernard Herzog */
58 copy = malloc(1 + strlen(s));
59 if (copy == NULL)
60 return PyErr_NoMemory();
61 strcpy(copy, s);
62 rl_parse_and_bind(copy);
63 free(copy); /* Free the copy */
Guido van Rossum290900a1997-09-26 21:51:21 +000064 Py_INCREF(Py_None);
65 return Py_None;
66}
67
68static char doc_parse_and_bind[] = "\
69parse_and_bind(string) -> None\n\
70Parse and execute single line of a readline init file.\
71";
72
73
74/* Exported function to parse a readline init file */
75
76static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000077read_init_file(PyObject *self, PyObject *args)
Guido van Rossum290900a1997-09-26 21:51:21 +000078{
79 char *s = NULL;
Guido van Rossum43713e52000-02-29 13:59:29 +000080 if (!PyArg_ParseTuple(args, "|z:read_init_file", &s))
Guido van Rossum290900a1997-09-26 21:51:21 +000081 return NULL;
82 errno = rl_read_init_file(s);
83 if (errno)
84 return PyErr_SetFromErrno(PyExc_IOError);
85 Py_INCREF(Py_None);
86 return Py_None;
87}
88
89static char doc_read_init_file[] = "\
90read_init_file([filename]) -> None\n\
91Parse a readline initialization file.\n\
92The default filename is the last filename used.\
93";
94
95
Skip Montanaro28067822000-07-06 18:55:12 +000096/* Exported function to load a readline history file */
97
98static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000099read_history_file(PyObject *self, PyObject *args)
Skip Montanaro28067822000-07-06 18:55:12 +0000100{
101 char *s = NULL;
102 if (!PyArg_ParseTuple(args, "|z:read_history_file", &s))
103 return NULL;
104 errno = read_history(s);
105 if (errno)
106 return PyErr_SetFromErrno(PyExc_IOError);
107 Py_INCREF(Py_None);
108 return Py_None;
109}
110
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000111static int history_length = -1; /* do not truncate history by default */
Skip Montanaro28067822000-07-06 18:55:12 +0000112static char doc_read_history_file[] = "\
113read_history_file([filename]) -> None\n\
114Load a readline history file.\n\
115The default filename is ~/.history.\
116";
117
118
119/* Exported function to save a readline history file */
120
121static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000122write_history_file(PyObject *self, PyObject *args)
Skip Montanaro28067822000-07-06 18:55:12 +0000123{
124 char *s = NULL;
125 if (!PyArg_ParseTuple(args, "|z:write_history_file", &s))
126 return NULL;
127 errno = write_history(s);
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000128 if (!errno && history_length >= 0)
129 history_truncate_file(s, history_length);
Skip Montanaro28067822000-07-06 18:55:12 +0000130 if (errno)
131 return PyErr_SetFromErrno(PyExc_IOError);
132 Py_INCREF(Py_None);
133 return Py_None;
134}
135
136static char doc_write_history_file[] = "\
137write_history_file([filename]) -> None\n\
138Save a readline history file.\n\
139The default filename is ~/.history.\
140";
141
142
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000143static char set_history_length_doc[] = "\
144set_history_length(length) -> None\n\
145set the maximal number of items which will be written to\n\
146the history file. A negative length is used to inhibit\n\
147history truncation.\n\
148";
149
150static PyObject*
151set_history_length(PyObject *self, PyObject *args)
152{
153 int length = history_length;
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000154 if (!PyArg_ParseTuple(args, "i:set_history_length", &length))
155 return NULL;
156 history_length = length;
157 Py_INCREF(Py_None);
158 return Py_None;
159}
160
161
162
163static char get_history_length_doc[] = "\
164get_history_length() -> int\n\
165return the current history length value.\n\
166";
167
168static PyObject*
169get_history_length(PyObject *self, PyObject *args)
170{
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000171 if (!PyArg_ParseTuple(args, ":get_history_length"))
172 return NULL;
173 return Py_BuildValue("i", history_length);
174}
175
176
177
Guido van Rossum290900a1997-09-26 21:51:21 +0000178/* Exported function to specify a word completer in Python */
179
180static PyObject *completer = NULL;
181static PyThreadState *tstate = NULL;
182
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000183static PyObject *begidx = NULL;
184static PyObject *endidx = NULL;
185
186/* get the beginning index for the scope of the tab-completion */
187static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000188get_begidx(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000189{
190 if(!PyArg_NoArgs(args)) {
191 return NULL;
192 }
193 Py_INCREF(begidx);
194 return begidx;
195}
196
197static char doc_get_begidx[] = "\
198get_begidx() -> int\n\
199get the beginning index of the readline tab-completion scope";
200
201/* get the ending index for the scope of the tab-completion */
202static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000203get_endidx(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000204{
205 if(!PyArg_NoArgs(args)) {
206 return NULL;
207 }
208 Py_INCREF(endidx);
209 return endidx;
210}
211
212static char doc_get_endidx[] = "\
213get_endidx() -> int\n\
214get the ending index of the readline tab-completion scope";
215
216
217/* set the tab-completion word-delimiters that readline uses */
218
219static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000220set_completer_delims(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000221{
222 char *break_chars;
223
Guido van Rossum43713e52000-02-29 13:59:29 +0000224 if(!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) {
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000225 return NULL;
226 }
227 free(rl_completer_word_break_characters);
228 rl_completer_word_break_characters = strdup(break_chars);
229 Py_INCREF(Py_None);
230 return Py_None;
231}
232
233static char doc_set_completer_delims[] = "\
234set_completer_delims(string) -> None\n\
235set the readline word delimiters for tab-completion";
236
237
238/* get the tab-completion word-delimiters that readline uses */
239
240static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000241get_completer_delims(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000242{
243 if(!PyArg_NoArgs(args)) {
244 return NULL;
245 }
246 return PyString_FromString(rl_completer_word_break_characters);
247}
248
249static char doc_get_completer_delims[] = "\
250get_completer_delims() -> string\n\
251get the readline word delimiters for tab-completion";
252
Guido van Rossum290900a1997-09-26 21:51:21 +0000253static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000254set_completer(PyObject *self, PyObject *args)
Guido van Rossum290900a1997-09-26 21:51:21 +0000255{
256 PyObject *function = Py_None;
Guido van Rossum43713e52000-02-29 13:59:29 +0000257 if (!PyArg_ParseTuple(args, "|O:set_completer", &function))
Guido van Rossum290900a1997-09-26 21:51:21 +0000258 return NULL;
259 if (function == Py_None) {
260 Py_XDECREF(completer);
261 completer = NULL;
262 tstate = NULL;
263 }
264 else if (PyCallable_Check(function)) {
265 PyObject *tmp = completer;
266 Py_INCREF(function);
267 completer = function;
268 Py_XDECREF(tmp);
269 tstate = PyThreadState_Get();
270 }
271 else {
272 PyErr_SetString(PyExc_TypeError,
273 "set_completer(func): argument not callable");
274 return NULL;
275 }
276 Py_INCREF(Py_None);
277 return Py_None;
278}
279
280static char doc_set_completer[] = "\
281set_completer([function]) -> None\n\
282Set or remove the completer function.\n\
283The function is called as function(text, state),\n\
284for i in [0, 1, 2, ...] until it returns a non-string.\n\
285It should return the next possible completion starting with 'text'.\
286";
287
Guido van Rossum79378ff1997-10-07 14:53:21 +0000288/* Exported function to read the current line buffer */
289
290static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000291get_line_buffer(PyObject *self, PyObject *args)
Guido van Rossum79378ff1997-10-07 14:53:21 +0000292{
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000293 if (!PyArg_NoArgs(args))
Guido van Rossum79378ff1997-10-07 14:53:21 +0000294 return NULL;
295 return PyString_FromString(rl_line_buffer);
296}
297
298static char doc_get_line_buffer[] = "\
Guido van Rossuma88c5f31998-05-20 15:50:56 +0000299get_line_buffer() -> string\n\
Guido van Rossum79378ff1997-10-07 14:53:21 +0000300return the current contents of the line buffer.\
301";
302
303/* Exported function to insert text into the line buffer */
304
305static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000306insert_text(PyObject *self, PyObject *args)
Guido van Rossum79378ff1997-10-07 14:53:21 +0000307{
308 char *s;
Guido van Rossum43713e52000-02-29 13:59:29 +0000309 if (!PyArg_ParseTuple(args, "s:insert_text", &s))
Guido van Rossum79378ff1997-10-07 14:53:21 +0000310 return NULL;
311 rl_insert_text(s);
312 Py_INCREF(Py_None);
313 return Py_None;
314}
315
316
317static char doc_insert_text[] = "\
318insert_text(string) -> None\n\
319Insert text into the command line.\
320";
321
Guido van Rossum290900a1997-09-26 21:51:21 +0000322
323/* Table of functions exported by the module */
Guido van Rossum0969d361997-08-05 21:27:50 +0000324
325static struct PyMethodDef readline_methods[] =
Guido van Rossum290900a1997-09-26 21:51:21 +0000326{
Andrew M. Kuchlinge365fb82000-08-03 02:06:16 +0000327 {"parse_and_bind", parse_and_bind, METH_VARARGS, doc_parse_and_bind},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000328 {"get_line_buffer", get_line_buffer,
329 METH_OLDARGS, doc_get_line_buffer},
Andrew M. Kuchlinge365fb82000-08-03 02:06:16 +0000330 {"insert_text", insert_text, METH_VARARGS, doc_insert_text},
331 {"read_init_file", read_init_file, METH_VARARGS, doc_read_init_file},
332 {"read_history_file", read_history_file,
333 METH_VARARGS, doc_read_history_file},
334 {"write_history_file", write_history_file,
335 METH_VARARGS, doc_write_history_file},
336 {"set_history_length", set_history_length,
337 METH_VARARGS, set_history_length_doc},
338 {"get_history_length", get_history_length,
339 METH_VARARGS, get_history_length_doc},
340 {"set_completer", set_completer, METH_VARARGS, doc_set_completer},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000341 {"get_begidx", get_begidx, METH_OLDARGS, doc_get_begidx},
342 {"get_endidx", get_endidx, METH_OLDARGS, doc_get_endidx},
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000343
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000344 {"set_completer_delims", set_completer_delims,
345 METH_VARARGS, doc_set_completer_delims},
346 {"get_completer_delims", get_completer_delims,
347 METH_OLDARGS, doc_get_completer_delims},
Guido van Rossum290900a1997-09-26 21:51:21 +0000348 {0, 0}
Guido van Rossum0969d361997-08-05 21:27:50 +0000349};
350
Guido van Rossum290900a1997-09-26 21:51:21 +0000351/* C function to call the Python completer. */
Guido van Rossum0969d361997-08-05 21:27:50 +0000352
Guido van Rossum290900a1997-09-26 21:51:21 +0000353static char *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000354on_completion(char *text, int state)
Guido van Rossum0969d361997-08-05 21:27:50 +0000355{
Guido van Rossum290900a1997-09-26 21:51:21 +0000356 char *result = NULL;
357 if (completer != NULL) {
358 PyObject *r;
Guido van Rossuma59406a1997-10-10 17:39:19 +0000359 PyThreadState *save_tstate;
Guido van Rossum290900a1997-09-26 21:51:21 +0000360 /* Note that readline is called with the interpreter
361 lock released! */
Guido van Rossuma59406a1997-10-10 17:39:19 +0000362 save_tstate = PyThreadState_Swap(NULL);
Guido van Rossum290900a1997-09-26 21:51:21 +0000363 PyEval_RestoreThread(tstate);
364 r = PyObject_CallFunction(completer, "si", text, state);
365 if (r == NULL)
366 goto error;
367 if (r == Py_None) {
368 result = NULL;
369 }
370 else {
371 char *s = PyString_AsString(r);
372 if (s == NULL)
373 goto error;
374 result = strdup(s);
375 }
376 Py_DECREF(r);
377 goto done;
378 error:
379 PyErr_Clear();
380 Py_XDECREF(r);
381 done:
382 PyEval_SaveThread();
Guido van Rossuma59406a1997-10-10 17:39:19 +0000383 PyThreadState_Swap(save_tstate);
Guido van Rossum290900a1997-09-26 21:51:21 +0000384 }
385 return result;
Guido van Rossum0969d361997-08-05 21:27:50 +0000386}
387
Guido van Rossum290900a1997-09-26 21:51:21 +0000388
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000389/* a more flexible constructor that saves the "begidx" and "endidx"
390 * before calling the normal completer */
391
392char **
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000393flex_complete(char *text, int start, int end)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000394{
395 Py_XDECREF(begidx);
396 Py_XDECREF(endidx);
397 begidx = PyInt_FromLong((long) start);
398 endidx = PyInt_FromLong((long) end);
399 return completion_matches(text, *on_completion);
400}
401
Guido van Rossum290900a1997-09-26 21:51:21 +0000402/* Helper to initialize GNU readline properly. */
403
404static void
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000405setup_readline(void)
Guido van Rossum290900a1997-09-26 21:51:21 +0000406{
407 rl_readline_name = "python";
408 /* Force rebind of TAB to insert-tab */
409 rl_bind_key('\t', rl_insert);
410 /* Bind both ESC-TAB and ESC-ESC to the completion function */
411 rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
412 rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
413 /* Set our completion function */
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000414 rl_attempted_completion_function = (CPPFunction *)flex_complete;
Guido van Rossumb6c935a1997-09-26 23:00:37 +0000415 /* Set Python word break characters */
416 rl_completer_word_break_characters =
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000417 strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
Guido van Rossumb6c935a1997-09-26 23:00:37 +0000418 /* All nonalphanums except '.' */
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000419
420 begidx = PyInt_FromLong(0L);
421 endidx = PyInt_FromLong(0L);
Barry Warsawf7612871999-01-29 21:55:03 +0000422 /* Initialize (allows .inputrc to override)
423 *
424 * XXX: A bug in the readline-2.2 library causes a memory leak
425 * inside this function. Nothing we can do about it.
426 */
Guido van Rossum290900a1997-09-26 21:51:21 +0000427 rl_initialize();
428}
429
430
431/* Interrupt handler */
432
433static jmp_buf jbuf;
434
Guido van Rossum0969d361997-08-05 21:27:50 +0000435/* ARGSUSED */
Tim Peters4f1b2082000-07-23 21:18:09 +0000436static void
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000437onintr(int sig)
Guido van Rossum0969d361997-08-05 21:27:50 +0000438{
Guido van Rossum290900a1997-09-26 21:51:21 +0000439 longjmp(jbuf, 1);
Guido van Rossum0969d361997-08-05 21:27:50 +0000440}
441
Guido van Rossum290900a1997-09-26 21:51:21 +0000442
443/* Wrapper around GNU readline that handles signals differently. */
Guido van Rossum0969d361997-08-05 21:27:50 +0000444
445static char *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000446call_readline(char *prompt)
Guido van Rossum0969d361997-08-05 21:27:50 +0000447{
Guido van Rossum26418a92000-06-28 21:30:31 +0000448 size_t n;
Guido van Rossumb18618d2000-05-03 23:44:39 +0000449 char *p, *q;
Guido van Rossum174efc92000-09-16 16:37:53 +0000450 PyOS_sighandler_t old_inthandler;
451
452 old_inthandler = PyOS_setsig(SIGINT, onintr);
Guido van Rossum0969d361997-08-05 21:27:50 +0000453 if (setjmp(jbuf)) {
454#ifdef HAVE_SIGRELSE
455 /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
456 sigrelse(SIGINT);
457#endif
Guido van Rossum174efc92000-09-16 16:37:53 +0000458 PyOS_setsig(SIGINT, old_inthandler);
Guido van Rossum0969d361997-08-05 21:27:50 +0000459 return NULL;
460 }
Guido van Rossum44620641997-08-11 18:57:29 +0000461 rl_event_hook = PyOS_InputHook;
Guido van Rossum0969d361997-08-05 21:27:50 +0000462 p = readline(prompt);
Guido van Rossum174efc92000-09-16 16:37:53 +0000463 PyOS_setsig(SIGINT, old_inthandler);
Guido van Rossumb18618d2000-05-03 23:44:39 +0000464
465 /* We must return a buffer allocated with PyMem_Malloc. */
Guido van Rossum0969d361997-08-05 21:27:50 +0000466 if (p == NULL) {
Guido van Rossumb18618d2000-05-03 23:44:39 +0000467 p = PyMem_Malloc(1);
Guido van Rossum0969d361997-08-05 21:27:50 +0000468 if (p != NULL)
469 *p = '\0';
470 return p;
471 }
472 n = strlen(p);
473 if (n > 0)
474 add_history(p);
Guido van Rossumb18618d2000-05-03 23:44:39 +0000475 /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
476 release the original. */
477 q = p;
478 p = PyMem_Malloc(n+2);
479 if (p != NULL) {
480 strncpy(p, q, n);
Guido van Rossum0969d361997-08-05 21:27:50 +0000481 p[n] = '\n';
482 p[n+1] = '\0';
483 }
Guido van Rossumb18618d2000-05-03 23:44:39 +0000484 free(q);
Guido van Rossum0969d361997-08-05 21:27:50 +0000485 return p;
486}
487
Guido van Rossum290900a1997-09-26 21:51:21 +0000488
489/* Initialize the module */
490
491static char doc_module[] =
492"Importing this module enables command line editing using GNU readline.";
493
Guido van Rossum3886bb61998-12-04 18:50:17 +0000494DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000495initreadline(void)
Guido van Rossum290900a1997-09-26 21:51:21 +0000496{
Guido van Rossum174efc92000-09-16 16:37:53 +0000497 PyObject *m, *d, *v;
Guido van Rossum290900a1997-09-26 21:51:21 +0000498
499 m = Py_InitModule4("readline", readline_methods, doc_module,
500 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum174efc92000-09-16 16:37:53 +0000501
502 d = PyModule_GetDict(m);
503 v = PyString_FromString(rl_library_version);
504 PyDict_SetItemString(d, "library_version", v);
505 Py_XDECREF(v);
506
Guido van Rossum290900a1997-09-26 21:51:21 +0000507 if (isatty(fileno(stdin))) {
508 PyOS_ReadlineFunctionPointer = call_readline;
509 setup_readline();
510 }
Guido van Rossum0969d361997-08-05 21:27:50 +0000511}