[Python-checkins] CVS: python/dist/src/Modules readline.c,2.21,2.22
Skip Montanaro
python-dev@python.org
Wed, 19 Jul 2000 09:54:56 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv9408
Modified Files:
readline.c
Log Message:
added history file truncation based upon code from Johannes Zellner.
Index: readline.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v
retrieving revision 2.21
retrieving revision 2.22
diff -C2 -r2.21 -r2.22
*** readline.c 2000/07/10 09:53:12 2.21
--- readline.c 2000/07/19 16:54:53 2.22
***************
*** 106,109 ****
--- 106,110 ----
}
+ static int history_length = -1; /* do not truncate history by default */
static char doc_read_history_file[] = "\
read_history_file([filename]) -> None\n\
***************
*** 122,125 ****
--- 123,128 ----
return NULL;
errno = write_history(s);
+ if (!errno && history_length >= 0)
+ history_truncate_file(s, history_length);
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
***************
*** 135,138 ****
--- 138,178 ----
+ static char set_history_length_doc[] = "\
+ set_history_length(length) -> None\n\
+ set the maximal number of items which will be written to\n\
+ the history file. A negative length is used to inhibit\n\
+ history truncation.\n\
+ ";
+
+ static PyObject*
+ set_history_length(PyObject *self, PyObject *args)
+ {
+ int length = history_length;
+ PyObject* ob;
+ if (!PyArg_ParseTuple(args, "i:set_history_length", &length))
+ return NULL;
+ history_length = length;
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+
+
+ static char get_history_length_doc[] = "\
+ get_history_length() -> int\n\
+ return the current history length value.\n\
+ ";
+
+ static PyObject*
+ get_history_length(PyObject *self, PyObject *args)
+ {
+ PyObject* ob;
+ if (!PyArg_ParseTuple(args, ":get_history_length"))
+ return NULL;
+ return Py_BuildValue("i", history_length);
+ }
+
+
+
/* Exported function to specify a word completer in Python */
***************
*** 290,293 ****
--- 330,335 ----
{"read_history_file", read_history_file, 1, doc_read_history_file},
{"write_history_file", write_history_file, 1, doc_write_history_file},
+ {"set_history_length", set_history_length, 1, set_history_length_doc},
+ {"get_history_length", get_history_length, 1, get_history_length_doc},
{"set_completer", set_completer, 1, doc_set_completer},
{"get_begidx", get_begidx, 0, doc_get_begidx},