* [gentoo-commits] proj/layman:c-layman commit in: c-layman/src/
@ 2011-10-12 6:39 Brian Dolbec
0 siblings, 0 replies; only message in thread
From: Brian Dolbec @ 2011-10-12 6:39 UTC (permalink / raw
To: gentoo-commits
commit: 6e320b36f8aaba92a6a6605da737b7877dece01f
Author: dol-sen <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Wed Oct 12 06:36:10 2011 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Oct 12 06:36:10 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=6e320b36
continued restructure, begin fixing my last screwups.
---
c-layman/src/config.c | 23 ++-
c-layman/src/internal.h | 17 ++-
c-layman/src/interpreter.c | 325 ++++++++++++++++++++++--------------------
c-layman/src/interpreter.h | 12 ++-
c-layman/src/layman.c | 81 ++++++-----
c-layman/src/laymanapi.c | 37 +++++-
c-layman/src/laymanapi.h | 1 +
c-layman/src/message.c | 345 +++++++++++++++++++++++---------------------
c-layman/src/message.h | 17 ++-
c-layman/src/stringlist.c | 3 +
c-layman/src/stringlist.h | 1 -
11 files changed, 490 insertions(+), 372 deletions(-)
diff --git a/c-layman/src/config.c b/c-layman/src/config.c
index f420235..7046dfb 100644
--- a/c-layman/src/config.c
+++ b/c-layman/src/config.c
@@ -1,4 +1,7 @@
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
#include <stdio.h>
#include "config.h"
@@ -29,7 +32,7 @@
struct BareConfigStruct
{
PyObject *object;
-}
+};
/**
* \internal
@@ -38,7 +41,7 @@ struct BareConfigStruct
PyObject *
_ConfigObject(BareConfigStruct *c)
{
- if (c && c->object)
+ if ((c != NULL) && (c->object != NULL))
return c->object;
else
Py_RETURN_NONE;
@@ -57,11 +60,16 @@ BareConfigStruct *
bareConfigCreate(MessageStruct *m, FILE *outFd, FILE *inFd, FILE *errFd)
{
if(!m)
- return NULL;
+ {
+ BareConfigStruct *n = NULL;
+ return n;
+ }
- if (!outFd || fileno(outFd) <= 0)
+ int fo = fileno(outFd);
+ int fi = fileno(inFd);
+ if (!outFd || fo <= 0)
outFd = stdout;
- if (!inFd || fileno(inFd) <= 0)
+ if (!inFd || fi <= 0)
inFd = stdin;
if (!errFd || fileno(errFd) <= 0)
errFd = stderr;
@@ -78,7 +86,8 @@ bareConfigCreate(MessageStruct *m, FILE *outFd, FILE *inFd, FILE *errFd)
if (!obj)
{
debug("The execution failed, Are you sure >=app-portage/layman-2.0* is properly installed ?\n");
- return NULL;
+ BareConfigStruct *n = NULL;
+ return n;
}
BareConfigStruct *ret = malloc(sizeof(BareConfigStruct));
@@ -191,7 +200,7 @@ ConfigSetOptionValue(BareConfigStruct *cfg, const char *opt, const char *val)
* \return a new instance of a OptionConfig object. It must be freed with ConfigFree()
*/
BareConfigStruct *
-optionConfigCreate( Dict *options, Dict *defaults)
+optionConfigCreate(Dict *options, Dict *defaults)
{
PyObject *opts = dictToPyDict(options);
diff --git a/c-layman/src/internal.h b/c-layman/src/internal.h
index cf9cf3e..4fc57d4 100644
--- a/c-layman/src/internal.h
+++ b/c-layman/src/internal.h
@@ -2,6 +2,9 @@
#define INTERNAL_H
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
#include "stringlist.h"
#include "dict.h"
@@ -13,7 +16,7 @@ PyObject *executeFunction(const char *module, const char *funcName, const char *
PyObject *_ConfigObject(BareConfigStruct*);
-PyObject *_messagePyObject(Message *m);
+PyObject *_messagePyObject(MessageStruct *m);
StringList *listToCList(PyObject *list);
PyObject *cListToPyList(StringList*);
@@ -28,14 +31,14 @@ typedef struct PyObjectListElem
{
PyObject *object;
struct PyObjectListElem *next;
-}
+} PyObjectListElem;
typedef struct PyObjectList
{
PyObjectListElem root;
int count;
-}
+} PyObjectList;
/**
@@ -45,7 +48,13 @@ typedef struct PyObjectList
typedef struct PythonInterpreter
{
PyObjectList modules;
-}
+ void (* execute) (PythonInterpreter *interpreter,
+ const char *module,
+ const char *funcName,
+ const char *format,
+ ...);
+
+} PythonInterpreter;
#endif
diff --git a/c-layman/src/interpreter.c b/c-layman/src/interpreter.c
index 129cfea..6daa8bf 100644
--- a/c-layman/src/interpreter.c
+++ b/c-layman/src/interpreter.c
@@ -1,196 +1,215 @@
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
#include <stdio.h>
#include <string.h>
#include "interpreter.h"
#include "internal.h"
-
-/** High level interactive python session structure */
-typedef struct PythonSessionStruct
-{
- private:
+static PyObjectList py_create_ObjectList();
+static void py_ObjectList_insert(PyObjectList list, PyObject *object);
+static int py_ObjectList_Count(PyObjectList list);
+static PyObject * py_moduleNamed(const char *name, PyObjectList list);
+static void py_ObjectList_free(PyObjectList list, int deref);
+static void py_Initialize(PythonInterpreter *interpreter);
+static void py_Finalize(PythonInterpreter *interpreter);
+static PyObject * py_executeFunction(PythonInterpreter *interpreter,
+ const char *module,
+ const char *funcName,
+ const char *format,
+ ...);
- PyObjectList
- createObjectList()
- {
- PyObjectList *ret = malloc(sizeof(PyObjectList));
- ret->count = 0;
- ret->root = 0;
- return ret;
- }
- void
- insert(PyObjectList list, PyObject *object)
- {
- if (!list || !object)
- return;
- PyObjectListElem node = malloc(sizeof(PyObjectListElem));
- node->object = object;
- node->next = list->root;
- list->root = node;
- list->count++;
- }
- PyObject *
- moduleNamed(const char *name, PyObjectList list)
- {
- PyObjectListElem *node = list->root;
- while (node)
- {
- if (strcmp(PyModule_GetName(node->object), name) == 0)
- return node->object;
- node = node->next;
- }
-
- return NULL;
- }
- int
- listCount(PyObjectList list)
+static PyObjectList
+py_create_ObjectList()
+{
+ PyObjectList *ret = malloc(sizeof(PyObjectList));
+ ret->count = 0;
+ ret->root = 0;
+ return ret;
+}
+
+
+static void
+py_ObjectList_insert(PyObjectList list, PyObject *object)
+{
+ if (!list || !object)
+ return;
+ PyObjectListElem node = malloc(sizeof(PyObjectListElem));
+ node->object = object;
+ node->next = list->root;
+ list->root = node;
+ list->count++;
+}
+
+static PyObject *
+py_moduleNamed(const char *name, PyObjectList list)
+{
+ PyObjectListElem *node = list->root;
+ while (node)
{
- return (list ? list->count : 0);
+ if (strcmp(PyModule_GetName(node->object), name) == 0)
+ return node->object;
+ node = node->next;
}
+
+ return NULL;
+}
- void
- freeList(PyObjectList list, int deref)
- {
- if (!list)
- return;
+static int
+py_ObjectList_Count(PyObjectList list)
+{
+ return (list ? list->count : 0);
+}
- PyObjectListElem *node = list->root;
- while (node)
+static void
+py_ObjectList_free(PyObjectList list, int deref)
+{
+ if (!list)
+ return;
+
+ PyObjectListElem *node = list->root;
+ while (node)
+ {
+ PyObjectListElem *tmp = node;
+ node = node->next;
+ if (deref)
{
- PyObjectListElem *tmp = node;
- node = node->next;
- if (deref)
- {
- Py_DECREF(tmp->object);
- }
- free(tmp);
+ Py_DECREF(tmp->object);
}
-
- free(list);
+ free(tmp);
}
- public:
+ free(list);
+}
-
- PythonInterpreter interpreter = 0;
+/** \defgroup base Layman base
+ *
+ * \brief Base functions
+ *
+ * These functions are used when you want to begin or end using the library.
+ */
- /** \defgroup base Layman base
- *
- * \brief Base functions
- *
- * These functions are used when you want to begin or end using the library.
- */
+/** \addtogroup base
+ * @{
+ */
- /** \addtogroup base
- * @{
- */
-
- /**
- * This is the first function that must be called before using the library.
- * It initializes the Python interpreter.
- */
- void
- Initialize()
- {
- if (interpreter)
- return;
+/**
+ * This is the first function that must be called before using the library.
+ * It initializes the Python interpreter.
+ */
+static void
+py_Initialize(PythonInterpreter *interpreter)
+{
+ if (interpreter)
+ return;
+
+ if (!Py_IsInitialized())
+ Py_Initialize();
+
+ interpreter = malloc(sizeof(struct session->Interpreter));
+ interpreter->modules = createObjectList();
+ interpreter->execute = py_executeFunction;
+}
+
+/**
+ * Call this function when you're done using the library.
+ * It will free memory.
+ */
+static void
+py_Finalize(PythonInterpreter *interpreter)
+{
+ if (!nterpreter)
+ return;
+ freeList(interpreter->modules, 1);
+ free(interpreter);
+ interpreter = NULL;
+
+ if (Py_IsInitialized())
+ Py_Finalize();
+}
+
+/** @} */
+
+/**
+ * \internal
+ * printf() like function that executes a python function
+ *
+ * \param module name of the python module in which the function is
+ * \param funcName the function name to call
+ * \param format printf() like list of arguments. See Python documentation
+ * \param ... arguments for the function
+ *
+ * \return the result of the execution. Can be NULL if the call failed.
+ */
+static PyObject *
+py_executeFunction(PythonInterpreter *interpreter, const char *module,
+ const char *funcName, const char *format, ...)
+{
- if (!Py_IsInitialized())
- Py_Initialize();
+ // Make argument list
+ PyObject *args;
+ if (format == NULL || strcmp(format, "") == 0)
+ args = PyTuple_New(0);
+ else
+ {
+ va_list listArgs;
+ va_start(listArgs, format);
- interpreter = malloc(sizeof(struct Interpreter));
- interpreter->modules = createObjectList();
+ args = Py_VaBuildValue(format, listArgs);
}
- /**
- * Call this function when you're done using the library.
- * It will free memory.
- */
- void
- Finalize()
+ // Look for the module.
+ PyObject *mod = 0;
+ if (session->interpreter->modules)
{
- if (!interpreter)
- return;
- freeList(interpreter->modules, 1);
- free(interpreter);
-
- if (Py_IsInitialized())
- Py_Finalize();
+ mod = moduleNamed(module, interpreter->modules);
}
-
- /** @} */
-
- /**
- * \internal
- * printf() like function that executes a python function
- *
- * \param module name of the python module in which the function is
- * \param funcName the function name to call
- * \param format printf() like list of arguments. See Python documentation
- * \param ... arguments for the function
- *
- * \return the result of the execution. Can be NULL if the call failed.
- */
- PyObject *
- executeFunction(const char *module, const char *funcName, const char *format, ...)
+ // If module is not loaded yet, do it.
+ if (!mod)
{
- assert(interpreter);
-
- // Make argument list
- PyObject *args;
- if (format == NULL || strcmp(format, "") == 0)
- args = PyTuple_New(0);
- else
- {
- va_list listArgs;
- va_start(listArgs, format);
-
- args = Py_VaBuildValue(format, listArgs);
- }
-
- // Look for the module.
- PyObject *mod = 0;
- if (interpreter->modules)
- {
- mod = moduleNamed(module, interpreter->modules);
- }
- // If module is not loaded yet, do it.
+ mod = PyImport_ImportModule(module);
if (!mod)
- {
- mod = PyImport_ImportModule(module);
- if (!mod)
- return NULL;
- insert(interpreter->modules, mod);
- }
-
- // Look for the function
- PyObject *func = PyObject_GetAttrString(mod, funcName);
- if (!PyCallable_Check(func))
return NULL;
+ insert(interpreter->modules, mod);
+ }
- // Execute it
- PyObject *val = PyObject_CallObject(func, args);
+ // Look for the function
+ PyObject *func = PyObject_GetAttrString(mod, funcName);
+ if (!PyCallable_Check(func))
+ return NULL;
- is Py_XDECREF(args);
+ // Execute it
+ PyObject *val = PyObject_CallObject(func, args);
- return val;
- }
-};
+ Py_XDECREF(args);
+
+ return val;
+}
/** Opens an interactive python session */
PythonSessionStruct
-PySession()
+PySession_create()
+{
+ PythonSessionStruct session;
+ py_Initialize(session);
+ session->Finalize = py_Finalize;
+ return session;
+}
+
+/** Closes an interactive python session */
+void
+PySession_free(PythonSessionStruct *session)
{
- PythonSessionStruct interpreter;
- interpreter.Initialize();
- return interpreter;
-}
\ No newline at end of file
+ py_Finalize(session->interpreter);
+ free(session);
+}
diff --git a/c-layman/src/interpreter.h b/c-layman/src/interpreter.h
index c3cb819..c69fe78 100644
--- a/c-layman/src/interpreter.h
+++ b/c-layman/src/interpreter.h
@@ -2,7 +2,17 @@
#define INTERPRETER_H
-typedef struct PythonSessionStruct PythonSessionStruct;
+/** High level interactive python session structure */
+typedef struct PythonSessionStruct
+{
+ // variables
+ PythonInterpreter interpreter;
+
+ // Functions
+
+ static void Finalize(PythonSessionStruct *session)
+} PythonSessionStruct;
+
PythonSessionStruct PySession();
diff --git a/c-layman/src/layman.c b/c-layman/src/layman.c
index f2e3702..c14916c 100644
--- a/c-layman/src/layman.c
+++ b/c-layman/src/layman.c
@@ -1,4 +1,7 @@
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
#include "config.h"
#include "internal.h"
@@ -13,58 +16,60 @@
/** High level object structure to hold a complete layman instance */
typedef struct LaymanObject
{
- // Python (auto-magic)
- bool initialized = False;
+ // Python session placeholder
+ bool pyinitialized = False;
PythonSessionStruct *pysession;
- initialized = (pysession.interpreter != NULL);
- // Layman
+ // Layman, placeholders for our primary modules
BareConfigStruct *config = NULL;
MessageStruct *output = NULL;
LaymanAPI *api = NULL;
-
+ bool initialized = False;
// Functions
- // Creates the highest level Layman class instance
- int Layman(FILE *outfd, FILE *infd, FILE *errfd,
- BareConfigStruct *cfg, int *read_configfile, int *quiet, int *quietness,
- int *verbose, int *nocolor, int *width);
- {
-
- LaymanAPI *layman = laymanCreate(
- FILE *outfd, FILE *infd, FILE *errfd,
+ /** Creates the highest level Layman class instance,
+ * the config will default if not passed in.
+ * the message class is automatic.
+ */
+ static int (* Layman) (FILE *outfd, FILE *infd, FILE *errfd,
BareConfigStruct *cfg, int *read_configfile, int *quiet, int *quietness,
int *verbose, int *nocolor, int *width);
- // ...
-
- return True;
- }
- // Create a Bare Config class instance
- BareConfigStruct *
- BareConfig()
- {
-
- }
+ /** Create a Bare Config class instance
+ * edit the options as desired.
+ */
+ static BareConfigStruct (* BareConfig) (MessageStruct *m, FILE *outFd, FILE *inFd, FILE *errFd);
+ /** Create an Option Config class instance
+ * pass in the options and default overrides in
+ * as desired.
+ */
+ static BareConfigStruct (* OptionConfig) (Dict *options, Dict *defaults);
- // Create a Option Config class instance
- BareConfigStruct *
- OptionConfig()
- {
-
- }
-
+ /** Create an Output Message class instance
+ */
+ static MessageStruct (* Message) (FILE *out, FILE *err, int infolevel, int warnlevel, int col);
- // Create an Output Message class instance
- MessageStruct *
- Message()
- {
+ /** Creates a LaymanAPI class instance
+ */
+ static laymanAPI (* LaymanAPI) (FILE *outfd, FILE *infd, FILE *errfd,
+ BareConfigStruct *cfg, int *read_configfile, int *quiet, int *quietness,
+ int *verbose, int *nocolor, int *width);
- }
-
-
- // Creates a LaymanAPI class instance
};
+static LaymanObject
+Layman_session_create()
+{
+ LaymanObject *layman_session = malloc(sizeof(LaymanObject));
+
+ PythonSessionStruct *pysession = PySession_create();
+ layman_session->pysession = pysession;
+ layman_session->pyinitialized = (pysession.interpreter != NULL);
+
+ // now assign the function pointers
+ assign_api_functions(layman_session);
+
+ return layman_session;
+}
diff --git a/c-layman/src/laymanapi.c b/c-layman/src/laymanapi.c
index af96b1a..d15d847 100644
--- a/c-layman/src/laymanapi.c
+++ b/c-layman/src/laymanapi.c
@@ -1,4 +1,7 @@
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
#include "internal.h"
#include "laymanapi.h"
@@ -245,7 +248,7 @@ laymanAPIGetInfoStrList(LaymanAPI *l, StringList *overlays, OverlayInfo *results
// Check if the returned value is a dict as expected.
if (!obj || !PyDict_Check(obj))
{
- is Py_XDECREF(obj);
+ Py_XDECREF(obj);
return False;
}
@@ -742,5 +745,37 @@ LaymanAPI *laymanCreate(
/**
+ * Creates a fully capable layman api
+*/
+static int
+Layman(FILE *outfd, FILE *infd, FILE *errfd,
+ BareConfigStruct *cfg, int *read_configfile, int *quiet, int *quietness,
+ int *verbose, int *nocolor, int *width);
+{
+
+ LaymanAPI *layman = laymanCreate(
+ FILE *outfd, FILE *infd, FILE *errfd,
+ BareConfigStruct *cfg, int *read_configfile, int *quiet, int *quietness,
+ int *verbose, int *nocolor, int *width);
+ // ...
+
+ return True;
+}
+
+
+void
+assign_api_functions(LaymanObject *layman_session)
+{
+ layman_session->Layman = Layman;
+ layman_session->BareConfig = bareConfigCreate;
+ layman_session->OptionConfig = optionConfigCreate;
+ layman_session->Message = messageCreate;
+ layman_session->LaymanAPI = laymanCreate;
+}
+
+
+
+
+/**
* @}
*/
diff --git a/c-layman/src/laymanapi.h b/c-layman/src/laymanapi.h
index 63ea812..e9fcbd8 100644
--- a/c-layman/src/laymanapi.h
+++ b/c-layman/src/laymanapi.h
@@ -63,4 +63,5 @@ LaymanAPI *laymanCreate(
BareConfigStruct *cfg, int *read_configfile, int *quiet, int *quietness,
int *verbose, int *nocolor, int *width);
+void assign_api_functions(LaymanObject *layman_session);
#endif
diff --git a/c-layman/src/message.c b/c-layman/src/message.c
index 8175706..63e5af9 100644
--- a/c-layman/src/message.c
+++ b/c-layman/src/message.c
@@ -1,4 +1,9 @@
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
+#include <stdio.h>
+
#include "message.h"
#include "internal.h"
@@ -13,215 +18,233 @@
*/
+PyObject *messageCreate (PythonSessionStruct *_pysession,
+ FILE *out, FILE *err,
+ int infolevel, int warnlevel,
+ int col);
+int SetDebugLevel (int debug_level);
+int SetInfoLevel (int info_level);
+int SetWarnLevel (int warn_level);
+int SetColorsOn ();
+int SetColorsOff ();
+
+
+
+
/** \addtogroup message
* @{
*/
+ /** \internal */
/**
* Message structure that is used in all functions
*/
struct MessageStruct
{
-
- private:
/**
- * \internal
+ * placeholders
*/
- PyObject * message = NULL;
- PythonSessionStruct *pysession = NULL;
-
-
- public:
-
+ PyObject * message;
+ PythonSessionStruct *pysession;
+
/**
- * Creates a Message instance with default values.
- * To modify those values, use the corresponding functions.
- *
- * \param _pysession. pointer to our running PythonSessionStruct
- * \param out where to write info
- * \param err where to write errors
- * \param dbg where to write debug information
- *
- * \return a new instance of a Message object. It must be freed with messageFree()
- */
- PyObject *
- Create(PythonSessionStruct *_pysession,
- FILE *out, FILE *err,
- int infolevel, int warnlevel,
- int col)
- {
- // record the pysession pointer to the structure
- pysession = _pysession;
-
- PyObject *pyout, *pyerr;
+ * Functions
+ */
+ int (* SetDebugLevel) (int debug_level);
+ int (* SetInfoLevel) (int info_level);
+ int (* SetWarnLevel) (int warn_level);
+ int (* SetColorsOn) ();
+ int (* SetColorsOff) ();
+
+
+};
- if (!out || fileno(out) <= 0)
- out = stdout;
- if (!err || fileno(err) <= 0)
- err = stderr;
+/**
+ * Creates a Message instance with default values.
+ * To modify those values, use the corresponding functions.
+ *
+ * \param _pysession. pointer to our running PythonSessionStruct
+ * \param out where to write info
+ * \param err where to write errors
+ * \param dbg where to write debug information
+ *
+ * \return a new instance of a Message object. It must be freed with messageFree()
+ */
+PyObject *
+messageCreate(PythonSessionStruct *_pysession,
+ FILE *out, FILE *err,
+ int infolevel, int warnlevel,
+ int col)
+{
+ // record the pysession pointer to the structure
+ pysession = _pysession;
- pyout = PyFile_FromFile(out, "", "w", 0);
- pyerr = PyFile_FromFile(err, "", "w", 0);
+ PyObject *pyout, *pyerr;
- PyObject *object = pysession.executeFunction(
- "layman.output",
- "Message",
- "(sOOO)",
- pyout,
- pyerr,
- PyInt_FromLong(infolevel),
- PyInt_FromLong(warnlevel),
- PyBool_FromLong(col)
- );
+ if (!out || fileno(out) <= 0)
+ out = stdout;
+ if (!err || fileno(err) <= 0)
+ err = stderr;
- Py_DECREF(pyout);
- Py_DECREF(pyerr);
+ pyout = PyFile_FromFile(out, "", "w", 0);
+ pyerr = PyFile_FromFile(err, "", "w", 0);
- if (!object)
- return NULL;
+ PyObject *object = pysession.executeFunction(
+ "layman.output",
+ "Message",
+ "(sOOO)",
+ pyout,
+ pyerr,
+ PyInt_FromLong(infolevel),
+ PyInt_FromLong(warnlevel),
+ PyBool_FromLong(col)
+ );
- return object;
- }
+ Py_DECREF(pyout);
+ Py_DECREF(pyerr);
+ if (!object)
+ return NULL;
- /**
- * Set the debug level.
- *
- * \param debug_level the debug level
- *
- * \return True on success, False on failure.
- */
- int
- SetDebugLevel(int debug_level)
- {
- if (!message)
- return False;
+ return object;
+}
- PyObject *obj = pysession.PyObject_CallMethod(
- message, "set_debug_level", "(I)", debug_level);
- int ret;
- if (obj)
- ret = True;
- else
- ret = False;
+/**
+ * Set the debug level.
+ *
+ * \param debug_level the debug level
+ *
+ * \return True on success, False on failure.
+ */
+int
+SetDebugLevel(int debug_level)
+{
+ if (!message)
+ return False;
- is Py_XDECREF(obj);
+ PyObject *obj = pysession.PyObject_CallMethod(
+ message, "set_debug_level", "(I)", debug_level);
+ int ret;
- return ret;
- }
+ if (obj)
+ ret = True;
+ else
+ ret = False;
+ Py_XDECREF(obj);
- /**
- * Set the info level.
- *
- * \param info_level the info level
- *
- * \return True on success, False on failure.
- */
- int
- SetInfoLevel(int info_level)
- {
- if (!message)
- return False;
+ return ret;
+}
- PyObject *obj = pysession.PyObject_CallMethod(
- message, "set_info_level", "(I)",
- PyInt_FromLong(info_level));
- int ret;
- if (obj)
- ret = True;
- else
- ret = False;
+/**
+ * Set the info level.
+ *
+ * \param info_level the info level
+ *
+ * \return True on success, False on failure.
+ */
+int
+SetInfoLevel(int info_level)
+{
+ if (!message)
+ return False;
- is Py_XDECREF(obj);
+ PyObject *obj = pysession.PyObject_CallMethod(
+ message, "set_info_level", "(I)",
+ PyInt_FromLong(info_level));
+ int ret;
- return ret;
- }
+ if (obj)
+ ret = True;
+ else
+ ret = False;
- /**
- * Set the warning level.
- *
- * \param warn_level the warning level
- *
- * \return True on success, False on failure.
- */
- int
- SetWarnLevel(int warn_level)
- {
- if (!message)
- return False;
+ Py_XDECREF(obj);
- PyObject *obj = pysession.PyObject_CallMethod(
- message, "set_warn_level", "(I)",
- PyInt_FromLong(warn_level));
- int ret;
+ return ret;
+}
- if (obj)
- ret = True;
- else
- ret = False;
+/**
+ * Set the warning level.
+ *
+ * \param warn_level the warning level
+ *
+ * \return True on success, False on failure.
+ */
+int
+SetWarnLevel(int warn_level)
+{
+ if (!message)
+ return False;
- is Py_XDECREF(obj);
+ PyObject *obj = pysession.PyObject_CallMethod(
+ message, "set_warn_level", "(I)",
+ PyInt_FromLong(warn_level));
+ int ret;
- return ret;
- }
+ if (obj)
+ ret = True;
+ else
+ ret = False;
- /**
- * Activates colors in the output
- *
- * \return 1 on success, 0 on failure
- */
- int
- SetColorsOn()
- {
- if (!message)
- return False;
+ Py_XDECREF(obj);
- PyObject *obj = pysession.PyObject_CallMethod(
- message, "set_colorize", Py_True);
- int ret;
+ return ret;
+}
- if (obj)
- ret = True;
- else
- ret = False;
+/**
+ * Activates colors in the output
+ *
+ * \return 1 on success, 0 on failure
+ */
+int
+SetColorsOn()
+{
+ if (!message)
+ return False;
- is Py_XDECREF(obj);
+ PyObject *obj = pysession.PyObject_CallMethod(
+ message, "set_colorize", Py_True);
+ int ret;
- return ret;
- }
+ if (obj)
+ ret = True;
+ else
+ ret = False;
- /**
- * Deactivates colors in the output
- *
- * \return 1 on success, 0 on failure
- */
- int
- SetColorsOff()
- {
- if (!message)
- return False;
+ Py_XDECREF(obj);
- PyObject *obj = pysession.PyObject_CallMethod(
- message, "set_colorize", Py_False);
- int ret;
+ return ret;
+}
- if (obj)
- ret = True;
- else
- ret = False;
+/**
+ * Deactivates colors in the output
+ *
+ * \return 1 on success, 0 on failure
+ */
+int
+SetColorsOff()
+{
+ if (!message)
+ return False;
- is Py_XDECREF(obj);
+ PyObject *obj = pysession.PyObject_CallMethod(
+ message, "set_colorize", Py_False);
+ int ret;
- return ret;
- }
+ if (obj)
+ ret = True;
+ else
+ ret = False;
+ Py_XDECREF(obj);
-};
+ return ret;
+}
/**
@@ -232,7 +255,7 @@ messageFree(MessageStruct *m)
{
if (m && m->interpreter)
{
- is Py_XDECREF(m->interpreter);
+ Py_XDECREF(m->interpreter);
}
if (m)
{
diff --git a/c-layman/src/message.h b/c-layman/src/message.h
index 0c13765..5d12cf1 100644
--- a/c-layman/src/message.h
+++ b/c-layman/src/message.h
@@ -5,13 +5,18 @@
#include "stringlist.h"
-typedef struct Message Message;
+typedef struct MessageStruct MessageStruct;
-Message *messageCreate(FILE *out, FILE *err, int infolevel, int warnlevel, int col);
-void messageFree(Message *m);
-int messageSetDebugLevel(Message *m, int debug_level);
-int messageSetInfoLevel(Message *m, int info_level);
-int messageSetWarnLevel(Message *m, int warn_level);
+MessageStruct *messageCreate(PythonSessionStruct *_pysession,
+ FILE *out,
+ FILE *err,
+ int infolevel,
+ int warnlevel,
+ int col);
+void messageFree(MessageStruct *m);
+int messageSetDebugLevel(MessageStruct *m, int debug_level);
+int messageSetInfoLevel(MessageStruct *m, int info_level);
+int messageSetWarnLevel(MessageStruct *m, int warn_level);
#endif
diff --git a/c-layman/src/stringlist.c b/c-layman/src/stringlist.c
index 1d82d4d..4ea61df 100644
--- a/c-layman/src/stringlist.c
+++ b/c-layman/src/stringlist.c
@@ -1,4 +1,7 @@
#include <Python.h>
+// temp workaround for my environment
+// since at times it fails to find Python.h
+#include <python2.6/Python.h>
#include <stdlib.h>
#include "stringlist.h"
diff --git a/c-layman/src/stringlist.h b/c-layman/src/stringlist.h
index b90cfd2..f37ec8c 100644
--- a/c-layman/src/stringlist.h
+++ b/c-layman/src/stringlist.h
@@ -1,7 +1,6 @@
#ifndef STRINGLIST_H
#define STRINGLIST_H
-#include <sys/types.h>
typedef struct StringList StringList;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-10-12 6:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-12 6:39 [gentoo-commits] proj/layman:c-layman commit in: c-layman/src/ Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox