[Python-checkins] CVS: python/dist/src/Modules readline.c,2.18,2.19

Skip Montanaro python-dev@python.org
Thu, 6 Jul 2000 11:55:14 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv5168

Modified Files:
	readline.c 
Log Message:
added read_history_file and write_history_file
XXX should perhaps support history truncation as well


Index: readline.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v
retrieving revision 2.18
retrieving revision 2.19
diff -C2 -r2.18 -r2.19
*** readline.c	2000/06/28 21:30:31	2.18
--- readline.c	2000/07/06 18:55:12	2.19
***************
*** 95,98 ****
--- 95,146 ----
  
  
+ /* Exported function to load a readline history file */
+ 
+ static PyObject *
+ read_history_file(self, args)
+ 	PyObject *self;
+ 	PyObject *args;
+ {
+ 	char *s = NULL;
+ 	if (!PyArg_ParseTuple(args, "|z:read_history_file", &s))
+ 		return NULL;
+ 	errno = read_history(s);
+ 	if (errno)
+ 		return PyErr_SetFromErrno(PyExc_IOError);
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+ }
+ 
+ static char doc_read_history_file[] = "\
+ read_history_file([filename]) -> None\n\
+ Load a readline history file.\n\
+ The default filename is ~/.history.\
+ ";
+ 
+ 
+ /* Exported function to save a readline history file */
+ 
+ static PyObject *
+ write_history_file(self, args)
+ 	PyObject *self;
+ 	PyObject *args;
+ {
+ 	char *s = NULL;
+ 	if (!PyArg_ParseTuple(args, "|z:write_history_file", &s))
+ 		return NULL;
+ 	errno = write_history(s);
+ 	if (errno)
+ 		return PyErr_SetFromErrno(PyExc_IOError);
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+ }
+ 
+ static char doc_write_history_file[] = "\
+ write_history_file([filename]) -> None\n\
+ Save a readline history file.\n\
+ The default filename is ~/.history.\
+ ";
+ 
+ 
  /* Exported function to specify a word completer in Python */
  
***************
*** 262,265 ****
--- 310,315 ----
  	{"insert_text", insert_text, 1, doc_insert_text},
  	{"read_init_file", read_init_file, 1, doc_read_init_file},
+ 	{"read_history_file", read_history_file, 1, doc_read_history_file},
+ 	{"write_history_file", write_history_file, 1, doc_write_history_file},
  	{"set_completer", set_completer, 1, doc_set_completer},
  	{"get_begidx", get_begidx, 0, doc_get_begidx},