Back to index

python-biopython  1.60
MMCIFlexmodule.c
Go to the documentation of this file.
00001 #include <Python.h>
00002 #include "lex.yy.h"
00003 
00004 
00005 FILE *fp;
00006 
00007 static PyObject *MMCIFlex_open_file(PyObject *self, PyObject *args)
00008 {
00009        char *filename;
00010 
00011        if (!PyArg_ParseTuple(args, "s", &filename))
00012               return NULL;
00013 
00014        fp=fopen(filename, "r");    
00015 
00016        mmcif_set_file(fp);
00017 
00018        Py_INCREF(Py_None);
00019 
00020        return Py_None;
00021 }      
00022 
00023 
00024 static PyObject *MMCIFlex_close_file(PyObject *self, PyObject *args)
00025 {
00026        /* verify no arguments */
00027        if (!PyArg_ParseTuple(args, ""))
00028               return NULL;
00029 
00030        fclose(fp);
00031 
00032        Py_INCREF(Py_None);
00033 
00034        return Py_None;
00035 }      
00036 
00037 
00038 static PyObject *MMCIFlex_get_token(PyObject *self, PyObject *args)
00039 {
00040        int flag;
00041        char *value="";
00042 
00043        /* get token number */
00044        flag=mmcif_get_token();
00045 
00046        /* if flag==0 we are EOF */
00047        if(flag)
00048        {
00049               value=mmcif_get_string();
00050        }      
00051 
00052        /* return the (tokennumber, string) tuple */
00053        return Py_BuildValue("(is)", flag, value);
00054 }
00055 
00056 
00057 static PyMethodDef MMCIFlexMethods[]=
00058 {
00059        {"open_file", MMCIFlex_open_file,  METH_VARARGS},
00060        {"close_file",       MMCIFlex_close_file, METH_VARARGS},
00061        {"get_token",        MMCIFlex_get_token,  METH_VARARGS},
00062        {NULL,        NULL}                       /* Sentinel */
00063 };
00064 
00065 
00066 void initMMCIFlex(void)
00067 {
00068        (void) Py_InitModule("MMCIFlex", MMCIFlexMethods);
00069 }