diff options
-rw-r--r-- | src/config.c | 33 | ||||
-rw-r--r-- | src/config.h | 12 | ||||
-rw-r--r-- | src/dbbase.c | 32 | ||||
-rw-r--r-- | src/dbbase.h | 10 |
4 files changed, 87 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..db632f2 --- /dev/null +++ b/src/config.c @@ -0,0 +1,33 @@ +#include "config.h" +#include "interpreter.h" +#include <Python.h> + +struct Config +{ + PyObject *object; +}; + +PyObject *_object(Config *c) +{ + return c ? c->object : NULL; +} + +Config *createConfig(const char *argv[], int argc) +{ + PyObject *pyargs = PyList_New(argc); + for (int i = 0; i < argc; i++) + { + PyObject *arg = PyBytes_FromString(argv[i]); + PyList_Insert(pyargs, i, arg); + } + + PyObject *obj = executeFunction("layman.config", "Config", "O", pyargs); + Py_DECREF(pyargs); + if (!obj) + return NULL; + + Config *ret = malloc(sizeof(Config)); + ret->object = obj; + + return ret; +} diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..e977cdc --- /dev/null +++ b/src/config.h @@ -0,0 +1,12 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include <Python.h> + +typedef struct Config Config; + +Config *createConfig(const char *argv[], int argc); + +PyObject *_object(Config*); + +#endif diff --git a/src/dbbase.c b/src/dbbase.c new file mode 100644 index 0000000..c617326 --- /dev/null +++ b/src/dbbase.c @@ -0,0 +1,32 @@ +#include "config.h" +#include "dbbase.h" +#include "interpreter.h" +#include <Python.h> + +struct DbBase +{ + PyObject *object; +}; + +DbBase* createDbBase(const char *paths[], unsigned int pathCount, Config *c, int ignore, int quiet, int ignore_init_read_errors) +{ + PyObject *pypaths = PyList_New(pathCount); + for (unsigned int i = 0; i < pathCount; i++) + { + PyObject *path = PyBytes_FromString(paths[i]); + PyList_Insert(pypaths, i, path); + } + + PyObject *cfg = _object(c); + + PyObject *obj = executeFunction("layman.dbbase", "DbBase", "OOIII", pypaths, cfg, ignore, quiet, ignore_init_read_errors); + Py_DECREF(pypaths); + + if (!obj) + return NULL; + + DbBase *ret = malloc(sizeof(DbBase)); + ret->object = obj; + + return ret; +} diff --git a/src/dbbase.h b/src/dbbase.h new file mode 100644 index 0000000..12065af --- /dev/null +++ b/src/dbbase.h @@ -0,0 +1,10 @@ +#ifndef DB_BASE_H +#define DB_BASE_H + +#include "config.h" + +typedef struct DbBase DbBase; + +DbBase* createDbBase(const char *paths[], unsigned int path_count, Config *c, int ignore, int quiet, int ignore_init_read_errors); + +#endif |