From 593766766d7d892b469acda29bdb8d848a68dd3b Mon Sep 17 00:00:00 2001 From: Detlev Casanova Date: Fri, 9 Jul 2010 14:45:37 +0200 Subject: Add basic Config and DbBase implemntation (not tested) --- src/config.c | 33 +++++++++++++++++++++++++++++++++ src/config.h | 12 ++++++++++++ src/dbbase.c | 32 ++++++++++++++++++++++++++++++++ src/dbbase.h | 10 ++++++++++ 4 files changed, 87 insertions(+) create mode 100644 src/config.c create mode 100644 src/config.h create mode 100644 src/dbbase.c create mode 100644 src/dbbase.h (limited to 'src') 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 + +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 + +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 + +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 -- cgit v1.2.3-1-g7c22