aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDetlev Casanova <detlev.casanova@gmail.com>2010-07-30 16:22:43 +0200
committerDetlev Casanova <detlev.casanova@gmail.com>2010-07-30 16:22:43 +0200
commitdad0d1551ae5c1092492dd92dc9aa072840671e8 (patch)
tree82aadbd1a240120cb6f3a88744870cbd3de2c341
parentFix Strings/Unicode conversion (diff)
downloadc-portage-dad0d1551ae5c1092492dd92dc9aa072840671e8.tar.gz
c-portage-dad0d1551ae5c1092492dd92dc9aa072840671e8.tar.bz2
c-portage-dad0d1551ae5c1092492dd92dc9aa072840671e8.zip
Add the use flags functions
-rw-r--r--Makefile.am4
-rw-r--r--Makefile.in13
-rw-r--r--src/dataconnect.c1
-rw-r--r--src/flag.c208
-rw-r--r--src/flag.h21
-rw-r--r--src/portage.h1
6 files changed, 241 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index 7734973..d2880b9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,11 +4,11 @@ lib_LTLIBRARIES = libportage.la
AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g
-libportage_la_SOURCES = src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c
+libportage_la_SOURCES = src/flag.c src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c
libportage_la_LIBADD = $(PYTHON_LIBS)
portage_includedir = $(includedir)/portage
-portage_include_HEADERS = src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h
+portage_include_HEADERS = src/flag.h src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h
#bin_PROGRAMS = tester
diff --git a/Makefile.in b/Makefile.in
index e075e95..c831ec4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -77,8 +77,9 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libportage_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am__dirstamp = $(am__leading_dot)dirstamp
-am_libportage_la_OBJECTS = src/dataconnect.lo src/portagesettings.lo \
- src/dict.lo src/interpreter.lo src/stringlist.lo
+am_libportage_la_OBJECTS = src/flag.lo src/dataconnect.lo \
+ src/portagesettings.lo src/dict.lo src/interpreter.lo \
+ src/stringlist.lo
libportage_la_OBJECTS = $(am_libportage_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -226,10 +227,10 @@ AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
lib_LTLIBRARIES = libportage.la
AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g
-libportage_la_SOURCES = src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c
+libportage_la_SOURCES = src/flag.c src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c
libportage_la_LIBADD = $(PYTHON_LIBS)
portage_includedir = $(includedir)/portage
-portage_include_HEADERS = src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h
+portage_include_HEADERS = src/flag.h src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h
all: all-am
.SUFFIXES:
@@ -307,6 +308,7 @@ src/$(am__dirstamp):
src/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) src/$(DEPDIR)
@: > src/$(DEPDIR)/$(am__dirstamp)
+src/flag.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dataconnect.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/portagesettings.lo: src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
@@ -322,6 +324,8 @@ mostlyclean-compile:
-rm -f src/dataconnect.lo
-rm -f src/dict.$(OBJEXT)
-rm -f src/dict.lo
+ -rm -f src/flag.$(OBJEXT)
+ -rm -f src/flag.lo
-rm -f src/interpreter.$(OBJEXT)
-rm -f src/interpreter.lo
-rm -f src/portagesettings.$(OBJEXT)
@@ -334,6 +338,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dataconnect.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dict.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/flag.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/interpreter.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/portagesettings.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/stringlist.Plo@am__quote@
diff --git a/src/dataconnect.c b/src/dataconnect.c
index a82004e..8dacdcc 100644
--- a/src/dataconnect.c
+++ b/src/dataconnect.c
@@ -27,7 +27,6 @@ static char* pyStringToString(PyObject *obj)
return strdup(PyBytes_AsString(obj));
}
-
return NULL;
}
diff --git a/src/flag.c b/src/flag.c
new file mode 100644
index 0000000..64e9c86
--- /dev/null
+++ b/src/flag.c
@@ -0,0 +1,208 @@
+#include "flag.h"
+#include "internal.h"
+
+#include <string.h>
+
+/**
+ * Helper function to convert any type of Python string (Unicode or not) into a C string.
+ * The object won't be DECREF'd but the returned char will be a copy of the data.
+ * The Python Object can then be safely DECREF'd.
+ */
+static char* pyStringToString(PyObject *obj)
+{
+ if (!obj)
+ return NULL;
+
+ if (PyString_Check(obj))
+ {
+ return strdup(PyString_AsString(obj));
+ }
+ else if(PyUnicode_Check(obj))
+ {
+ PyObject *tmp = PyUnicode_AsUTF8String(obj);
+ char *ret = strdup(PyString_AsString(tmp));
+ Py_DECREF(tmp);
+ return ret;
+ }
+ else if (PyBytes_Check(obj))
+ {
+ return strdup(PyBytes_AsString(obj));
+ }
+
+ return NULL;
+}
+
+StringList* portageGetIUse(const char* pkg)
+{
+ assert(pkg);
+ PyObject *obj = executeFunction("portage.api.flag", "get_iuse", "(z)", pkg);
+ if (!obj)
+ return NULL;
+
+ StringList *ret = listToCList(obj);
+
+ Py_DECREF(obj);
+
+ return ret;
+}
+
+StringList* portageGetInstalledUse(const char* pkg)
+{
+ assert(pkg);
+ PyObject *obj = executeFunction("portage.api.flag", "get_installed_use", "(z)", pkg);
+ if (!obj)
+ return NULL;
+
+ StringList *ret = listToCList(obj);
+
+ Py_DECREF(obj);
+
+ return ret;
+}
+
+StringList* portageGetInstalledPkgUse(const char* pkg)
+{
+ assert(pkg);
+ PyObject *obj = executeFunction("portage.api.flag", "get_installed_use", "(zz)", pkg, "PKGUSE");
+ if (!obj)
+ return NULL;
+
+ StringList *ret = listToCList(obj);
+
+ Py_DECREF(obj);
+
+ return ret;
+}
+
+
+char* portageReduceFlag(const char* flag)
+{
+ assert(flag);
+ PyObject *obj = executeFunction("portage.api.flag", "reduce_flag", "(z)", flag);
+ if (!obj)
+ return NULL;
+
+ char *ret = pyStringToString(obj);
+
+ Py_DECREF(obj);
+
+ return ret;
+}
+
+
+StringList* portageFilterFlags(StringList* use, StringList* use_expand_hidden, StringList* usemasked, StringList* useforced)
+{
+ PyObject *pyuse, *pyuseexp, *pyusemasked, *pyuseforced;
+ pyuse = cListToPyList(use);
+ pyuseexp = cListToPyList(use_expand_hidden);
+ pyusemasked = cListToPyList(usemasked);
+ pyuseforced = cListToPyList(useforced);
+ PyObject *obj = executeFunction("portage.api.flag", "filter_flags", "(OOOO)", pyuse, pyuseexp, pyusemasked, pyuseforced);
+
+ Py_DECREF(pyuse);
+ Py_DECREF(pyuseexp);
+ Py_DECREF(pyusemasked);
+ Py_DECREF(pyuseforced);
+
+ if (!obj)
+ return NULL;
+
+ StringList *ret = listToCList(obj);
+
+ Py_DECREF(obj);
+
+ return ret;
+}
+
+
+int portageGetAllCpvUse(const char* pkg, StringList** use, StringList** use_expand_hidden, StringList** usemasked, StringList** useforced)
+{
+ assert(pkg);
+ assert(use);
+ assert(use_expand_hidden);
+ assert(usemasked);
+ assert(useforced);
+
+ PyObject *obj = executeFunction("portage.api.flag", "get_installed_use", "(z)", pkg);
+ if (!obj || !PySequence_Check(obj))
+ {
+ *use = stringListCreate(0);
+ *use_expand_hidden = stringListCreate(0);
+ *usemasked = stringListCreate(0);
+ *useforced = stringListCreate(0);
+ if (obj)
+ {
+ Py_DECREF(obj);
+ }
+ return 0;
+ }
+
+ PyObject *pyuse, *pyuseexp, *pyusemasked, *pyuseforced;
+ pyuse = PySequence_GetItem(obj, 0);
+ pyuseexp = PySequence_GetItem(obj, 1);
+ pyusemasked = PySequence_GetItem(obj, 2);
+ pyuseforced = PySequence_GetItem(obj, 3);
+
+ *use = listToCList(pyuse);
+ *use_expand_hidden = listToCList(pyuseexp);
+ *usemasked = listToCList(pyusemasked);
+ *useforced = listToCList(pyuseforced);
+
+ Py_DECREF(pyuse);
+ Py_DECREF(pyuseexp);
+ Py_DECREF(pyusemasked);
+ Py_DECREF(pyuseforced);
+ Py_DECREF(obj);
+
+ return 1;
+}
+
+
+StringList* portageGetFlags(const char* pkg)
+{
+ assert(pkg);
+ PyObject *obj = executeFunction("portage.api.flag", "get_installed_use", "(z)", pkg);
+ if (!obj)
+ return NULL;
+
+ StringList *ret = listToCList(obj);
+
+ Py_DECREF(obj);
+
+ return ret;
+}
+
+int portageGetFlagsFinal(const char* pkg, StringList** iuse_flags, StringList** final_flags)
+{
+ assert(pkg);
+ PyObject *obj = executeFunction("portage.api.flag", "get_installed_use", "(zI)", pkg, 1);
+ if (!obj || !PySequence_Check(obj))
+ {
+ *iuse_flags = stringListCreate(0);
+ *final_flags = stringListCreate(0);
+ if (obj)
+ {
+ Py_DECREF(obj);
+ }
+ return 0;
+ }
+
+ PyObject *pyiuse, *pyfinal;
+ pyiuse = PySequence_GetItem(obj, 0);
+ pyfinal = PySequence_GetItem(obj, 1);
+
+ *iuse_flags = listToCList(pyiuse);
+ *final_flags = listToCList(pyfinal);
+
+ Py_DECREF(pyiuse);
+ Py_DECREF(pyfinal);
+ Py_DECREF(obj);
+
+ return 1;
+}
+
+
+//int portageGetUseFlagDict()
+//{
+//}
+
diff --git a/src/flag.h b/src/flag.h
new file mode 100644
index 0000000..d1c6bac
--- /dev/null
+++ b/src/flag.h
@@ -0,0 +1,21 @@
+#ifndef FLAG_H
+#define FLAG_H
+
+#include "stringlist.h"
+
+StringList* portageGetIUse(const char*);
+StringList* portageGetInstalledUse(const char*);
+StringList* portageGetInstalledPkgUse(const char*);
+
+char* portageReduceFlag(const char*);
+
+StringList* portageFilterFlags(StringList*, StringList*, StringList*, StringList*);
+
+int portageGetAllCpvUse(const char*, StringList**, StringList**, StringList**, StringList**);
+
+StringList* portageGetFlags(const char*);
+int portageGetFlagsFinal(const char*, StringList**, StringList**);
+
+//int portageGetUseFlagDict();
+
+#endif
diff --git a/src/portage.h b/src/portage.h
index e7ecfb9..427df9d 100644
--- a/src/portage.h
+++ b/src/portage.h
@@ -5,6 +5,7 @@
#include "dict.h"
#include "portagesettings.h"
#include "dataconnect.h"
+#include "flag.h"
#include "interpreter.h"
#endif