[BACK] Return to py_object_trans.cpp CVS log [TXT][DIR] Up to Nevrax / code / nelns / agent_service

File: Nevrax / code / nelns / agent_service / Attic / py_object_trans.cpp (download)
Revision 1.1, Wed Apr 18 13:54:25 2001 UTC (15 months, 1 week ago) by valignat
Branch: MAIN
RENAMED code/server to code/nelns.

#include "py_object_trans.h"
//#include "ag_compile.h"


namespace SRV
{
        static PyObject *commandSell(pyCPyEditWin *self, PyObject *arg)
        {
                char *txt;
                PyObject *argi;
                argi = PyTuple_GetItem (arg, 0);
                PyArg_Parse(argi,"s",&txt);
                txt[strlen(txt)] = 0;
                char command[1024*16];
#ifdef NL_DEBUG
                memset(command,0,sizeof(command));
#endif
                int i = 0,j = 0;

                while(txt[i] != 0)
                {
                        if(txt[i] != '\n')
                        {
                                command[j] = txt[i];
                                j ++;
                        }
                        else
                        {
                                command[j] = 0;
                                self->Instance->commandSell(command);
                                j = 0;                                
                        }
                        i ++;                        
                }                                        
                if(j)
                {
                        command[j] = 0;
                        self->Instance->commandSell(command);                                
                }
                return Py_BuildValue("i",false);
        }

        static PyObject *coord(pyCPyEditWin *self, PyObject *arg)
        {
                char *txt;
                PyObject *argi;
                argi = PyTuple_GetItem (arg, 0);
                PyArg_Parse(argi,"s",&txt);
                //txt[strlen(txt)] = 0;
                char num[1024];                
#ifdef NL_DEBUG
                memset(num,0,sizeof(num));                
#endif
                int i = 0,j = 0;
                int x = -1,y = -1;
                while(txt[i] != 0)
                {
                        if(txt[i] == '.')
                        {
                                num[j] = 0;
                                x = atoi(num);
                                j = 0;
                                i++;
                                break;
                        }
                        else
                        {
                                num[j ++] = txt[i];
                        }
                        i ++;
                }                        

                while(1)
                {
                        if(txt[i] == 0)
                        {
                                num[j] = 0;
                                y = atoi(num);
                                break;
                        }
                        else
                        {
                                num[j ++] = txt[i];
                        }
                        i ++;
                }                        
                return Py_BuildValue("ii",x,y);
        }

        static PyMethodDef V_methods[] = 
        {        
                {"commandSell", (PyCFunction) commandSell,         1, NULL},
                {"coord", (PyCFunction) coord,         1, NULL},
                {NULL,                NULL}                /* sentinel */
        };
        
        static PyObject *getAttribDigitalType(pyCPyEditWin *self,char *name)
        {        
                return Py_FindMethod(V_methods, (PyObject *)self, name);
        }

        static void dealloc(pyCPyEditWin *self)
        {        
                delete self;
        }

        staticforward PyTypeObject V_Type = 
        {
                PyObject_HEAD_INIT(&PyType_Type)
                0,                                        /*ob_size*/
                "Shell",                        /*tp_name*/
                sizeof(pyCPyEditWin),        /*tp_basicsize*/
                0,                        /*tp_itemsize*/
                /* methods */
                (destructor)dealloc, /*tp_dealloc*/
                0,                        /*tp_print*/
                (getattrfunc)getAttribDigitalType, /*tp_getattr*/
                0,
        /*        (setattrfunc)VConnection_setattr,*/ /*tp_setattr*/
                0,                        /*tp_compare*/
                0,                        /*tp_repr*/
                0,                        /*tp_as_number*/
                0,                        /*tp_as_sequence*/
                0,                        /*tp_as_mapping*/
                0,                        /*tp_hash*/
        };        

        pyCPyEditWin *allocPyEditWin(CPyEditWin *classType)
        {
                return NLAIC::CreatePyObjectInstance<CPyEditWin>(classType,&V_Type);
        }
}