summaryrefslogtreecommitdiffstats
path: root/glib/pygoptioncontext.c
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-08-02 08:29:37 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-08-02 08:29:37 +0000
commitb69db173aa177bf13a4e3a2caec87ca8810baee4 (patch)
tree9b9d6cfa13f9a6d88c473a4d573a6b5c74af150a /glib/pygoptioncontext.c
parentc5dc87ea088613158d527f5b1b1cd947db8d12b8 (diff)
downloadpygobject-b69db173aa177bf13a4e3a2caec87ca8810baee4.tar.gz
pygobject-b69db173aa177bf13a4e3a2caec87ca8810baee4.tar.xz
pygobject-b69db173aa177bf13a4e3a2caec87ca8810baee4.zip
Fix compilation warnings, clean up style and indentation.
2008-08-02 Johan Dahlin <johan@gnome.org> * glib/glibmodule.c (pyglib_set_prgname): * glib/pygoptioncontext.c (pyg_option_context_init), (pyg_option_context_set_help_enabled), (pyg_option_context_set_ignore_unknown_options), (pyg_option_context_set_main_group), (pyg_option_context_add_group): * glib/pygoptiongroup.c (arg_func), (pyg_option_group_add_entries), (pyg_option_group_set_translation_domain), (pyg_option_group_compare), (pyglib_option_group_register_types): Fix compilation warnings, clean up style and indentation. svn path=/trunk/; revision=913
Diffstat (limited to 'glib/pygoptioncontext.c')
-rw-r--r--glib/pygoptioncontext.c87
1 files changed, 50 insertions, 37 deletions
diff --git a/glib/pygoptioncontext.c b/glib/pygoptioncontext.c
index a180565..cf82744 100644
--- a/glib/pygoptioncontext.c
+++ b/glib/pygoptioncontext.c
@@ -31,15 +31,16 @@
PYGLIB_DEFINE_TYPE("glib.OptionContext", PyGOptionContext_Type, PyGOptionContext)
static int
-pyg_option_context_init(PyGOptionContext *self,
+pyg_option_context_init(PyGOptionContext *self,
PyObject *args,
PyObject *kwargs)
{
char *parameter_string;
+
if (!PyArg_ParseTuple(args, "s:glib.GOptionContext.__init__",
&parameter_string))
return -1;
-
+
self->context = g_option_context_new(parameter_string);
return 0;
}
@@ -48,7 +49,7 @@ static void
pyg_option_context_dealloc(PyGOptionContext *self)
{
Py_CLEAR(self->main_group);
-
+
if (self->context != NULL)
{
GOptionContext *tmp = self->context;
@@ -60,8 +61,8 @@ pyg_option_context_dealloc(PyGOptionContext *self)
}
static PyObject *
-pyg_option_context_parse(PyGOptionContext *self,
- PyObject *args,
+pyg_option_context_parse(PyGOptionContext *self,
+ PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "argv", NULL };
@@ -72,26 +73,26 @@ pyg_option_context_parse(PyGOptionContext *self,
char **argv_content, **original;
GError *error = NULL;
gboolean result;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GOptionContext.parse",
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GOptionContext.parse",
kwlist, &argv))
return NULL;
-
+
if (!PyList_Check(argv))
{
- PyErr_SetString(PyExc_TypeError,
+ PyErr_SetString(PyExc_TypeError,
"GOptionContext.parse expects a list of strings.");
return NULL;
}
-
+
argv_length = PyList_Size(argv);
if (argv_length == -1)
{
- PyErr_SetString(PyExc_TypeError,
+ PyErr_SetString(PyExc_TypeError,
"GOptionContext.parse expects a list of strings.");
return NULL;
}
-
+
argv_content = g_new(char*, argv_length + 1);
argv_content[argv_length] = NULL;
for (pos = 0; pos < argv_length; pos++)
@@ -121,31 +122,34 @@ pyg_option_context_parse(PyGOptionContext *self,
pyglib_error_check(&error);
return NULL;
}
-
+
new_argv = PyList_New(g_strv_length(argv_content));
for (pos = 0; pos < argv_length; pos++)
{
arg = _PyUnicode_FromString(argv_content[pos]);
PyList_SetItem(new_argv, pos, arg);
}
-
+
g_strfreev(original);
g_strfreev(argv_content);
return new_argv;
}
static PyObject *
-pyg_option_context_set_help_enabled(PyGOptionContext *self,
+pyg_option_context_set_help_enabled(PyGOptionContext *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "help_enable", NULL };
+
PyObject *help_enabled;
- if (! PyArg_ParseTupleAndKeywords(args, kwargs,
- "O:GOptionContext.set_help_enabled",
+ if (! PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:GOptionContext.set_help_enabled",
kwlist, &help_enabled))
return NULL;
+
g_option_context_set_help_enabled(self->context, PyObject_IsTrue(help_enabled));
+
Py_INCREF(Py_None);
return Py_None;
}
@@ -157,18 +161,22 @@ pyg_option_context_get_help_enabled(PyGOptionContext *self)
}
static PyObject *
-pyg_option_context_set_ignore_unknown_options(PyGOptionContext *self,
+pyg_option_context_set_ignore_unknown_options(PyGOptionContext *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "ignore_unknown_options", NULL };
PyObject *ignore_unknown_options;
- if (! PyArg_ParseTupleAndKeywords(args, kwargs,
- "O:GOptionContext.set_ignore_unknown_options",
+
+ if (! PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:GOptionContext.set_ignore_unknown_options",
kwlist, &ignore_unknown_options))
return NULL;
- g_option_context_set_ignore_unknown_options(self->context,
- PyObject_IsTrue(ignore_unknown_options));
+
+ g_option_context_set_ignore_unknown_options(self->context,
+ PyObject_IsTrue(ignore_unknown_options));
+
+
Py_INCREF(Py_None);
return Py_None;
}
@@ -181,21 +189,21 @@ pyg_option_context_get_ignore_unknown_options(PyGOptionContext *self)
}
static PyObject *
-pyg_option_context_set_main_group(PyGOptionContext *self,
- PyObject *args,
+pyg_option_context_set_main_group(PyGOptionContext *self,
+ PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "group", NULL };
GOptionGroup *g_group;
PyObject *group;
-
- if (! PyArg_ParseTupleAndKeywords(args, kwargs,
- "O:GOptionContext.set_main_group",
+
+ if (! PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:GOptionContext.set_main_group",
kwlist, &group))
return NULL;
if (PyObject_IsInstance(group, (PyObject*) &PyGOptionGroup_Type) != 1) {
- PyErr_SetString(PyExc_TypeError,
+ PyErr_SetString(PyExc_TypeError,
"GOptionContext.set_main_group expects a GOptionGroup.");
return NULL;
}
@@ -209,9 +217,10 @@ pyg_option_context_set_main_group(PyGOptionContext *self,
}
g_option_context_set_main_group(self->context, g_group);
+
Py_INCREF(group);
self->main_group = (PyGOptionGroup*) group;
-
+
Py_INCREF(Py_None);
return Py_None;
}
@@ -223,41 +232,45 @@ pyg_option_context_get_main_group(PyGOptionContext *self)
{
Py_INCREF(Py_None);
return Py_None;
- }
+ }
Py_INCREF(self->main_group);
return (PyObject*) self->main_group;
}
static PyObject *
-pyg_option_context_add_group(PyGOptionContext *self,
- PyObject *args,
+pyg_option_context_add_group(PyGOptionContext *self,
+ PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "group", NULL };
GOptionGroup *g_group;
PyObject *group;
- if (! PyArg_ParseTupleAndKeywords(args, kwargs,
- "O:GOptionContext.add_group",
+
+ if (! PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:GOptionContext.add_group",
kwlist, &group))
return NULL;
+
if (PyObject_IsInstance(group, (PyObject*) &PyGOptionGroup_Type) != 1) {
PyErr_SetString(PyExc_TypeError,
"GOptionContext.add_group expects a GOptionGroup.");
return NULL;
}
+
g_group = pyglib_option_group_transfer_group(group);
if (g_group == NULL)
{
- PyErr_SetString(PyExc_RuntimeError,
+ PyErr_SetString(PyExc_RuntimeError,
"Group is already in a OptionContext.");
return NULL;
}
Py_INCREF(group);
+
g_option_context_add_group(self->context, g_group);
-
+
Py_INCREF(Py_None);
return Py_None;
-}
+}
static int
pyg_option_context_compare(PyGOptionContext *self, PyGOptionContext *context)