File: MMCIFlexmodule.c

package info (click to toggle)
python-biopython 1.42-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 17,584 kB
  • ctags: 12,272
  • sloc: python: 80,461; xml: 13,834; ansic: 7,902; cpp: 1,855; sql: 1,144; makefile: 203
file content (69 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <Python.h>

char *mmcif_get_string(void);

FILE *fp;

static PyObject *MMCIFlex_open_file(PyObject *self, PyObject *args)
{
	char *filename;

	if (!PyArg_ParseTuple(args, "s", &filename))
		return NULL;

	fp=fopen(filename, "r");	

	mmcif_set_file(fp);

	Py_INCREF(Py_None);

	return Py_None;
}	


static PyObject *MMCIFlex_close_file(PyObject *self, PyObject *args)
{
	/* verify no arguments */
	if (!PyArg_ParseTuple(args, ""))
		return NULL;

	fclose(fp);

	Py_INCREF(Py_None);

	return Py_None;
}	


static PyObject *MMCIFlex_get_token(PyObject *self, PyObject *args)
{
	int flag;
	char *value="";

	/* get token number */
	flag=mmcif_get_token();

	/* if flag==0 we are EOF */
	if(flag)
	{
		value=mmcif_get_string();
	}	

	/* return the (tokennumber, string) tuple */
	return Py_BuildValue("(is)", flag, value);
}


static PyMethodDef MMCIFlexMethods[]=
{
	{"open_file",	MMCIFlex_open_file, 	METH_VARARGS},
	{"close_file",	MMCIFlex_close_file,	METH_VARARGS},
	{"get_token",  	MMCIFlex_get_token, 	METH_VARARGS},
	{NULL,      	NULL}        			/* Sentinel */
};


void initMMCIFlex()
{
	(void) Py_InitModule("MMCIFlex", MMCIFlexMethods);
}