From cd7a02bec5ce87e8e1aa26b9fffc3caa0cda8ae8 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Mon, 20 Dec 2010 10:13:37 +0100 Subject: Add 256 colors support Changes: - new section "palette" in weechat.conf - new API functions: list_search_pos and list_casesearch_pos --- src/plugins/scripts/python/weechat-python-api.c | 69 +++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/plugins/scripts/python') diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 6429ad383..3aed89013 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -768,6 +768,39 @@ weechat_python_api_list_search (PyObject *self, PyObject *args) PYTHON_RETURN_STRING_FREE(result); } +/* + * weechat_python_api_list_search_pos: search position of a string in list + */ + +static PyObject * +weechat_python_api_list_search_pos (PyObject *self, PyObject *args) +{ + char *weelist, *data; + int pos; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script || !python_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_search_pos"); + PYTHON_RETURN_INT(-1); + } + + weelist = NULL; + data = NULL; + + if (!PyArg_ParseTuple (args, "ss", &weelist, &data)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_search_pos"); + PYTHON_RETURN_INT(-1); + } + + pos = weechat_list_search_pos (script_str2ptr (weelist), data); + + PYTHON_RETURN_INT(pos); +} + /* * weechat_python_api_list_casesearch: search a string in list (ignore case) */ @@ -802,6 +835,40 @@ weechat_python_api_list_casesearch (PyObject *self, PyObject *args) PYTHON_RETURN_STRING_FREE(result); } +/* + * weechat_python_api_list_casesearch_pos: search position of a string in list + * (ignore case) + */ + +static PyObject * +weechat_python_api_list_casesearch_pos (PyObject *self, PyObject *args) +{ + char *weelist, *data; + int pos; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script || !python_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_casesearch_pos"); + PYTHON_RETURN_INT(-1); + } + + weelist = NULL; + data = NULL; + + if (!PyArg_ParseTuple (args, "ss", &weelist, &data)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_casesearch_pos"); + PYTHON_RETURN_INT(-1); + } + + pos = weechat_list_casesearch_pos (script_str2ptr (weelist), data); + + PYTHON_RETURN_INT(pos); +} + /* * weechat_python_api_list_get: get item by position */ @@ -6886,7 +6953,9 @@ PyMethodDef weechat_python_funcs[] = { "list_new", &weechat_python_api_list_new, METH_VARARGS, "" }, { "list_add", &weechat_python_api_list_add, METH_VARARGS, "" }, { "list_search", &weechat_python_api_list_search, METH_VARARGS, "" }, + { "list_search_pos", &weechat_python_api_list_search_pos, METH_VARARGS, "" }, { "list_casesearch", &weechat_python_api_list_casesearch, METH_VARARGS, "" }, + { "list_casesearch_pos", &weechat_python_api_list_casesearch_pos, METH_VARARGS, "" }, { "list_get", &weechat_python_api_list_get, METH_VARARGS, "" }, { "list_set", &weechat_python_api_list_set, METH_VARARGS, "" }, { "list_next", &weechat_python_api_list_next, METH_VARARGS, "" }, -- cgit v1.2.3