/[thuban]/trunk/thuban/extensions/pyshapelib/dbflib_wrap.c
ViewVC logotype

Contents of /trunk/thuban/extensions/pyshapelib/dbflib_wrap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 283 - (show annotations)
Tue Aug 27 14:00:12 2002 UTC (22 years, 6 months ago) by bh
File MIME type: text/plain
File size: 33067 byte(s)
* dbflib.i: Raise an exception if open or create fails.

* shapelib.i: Slightly better wording for the IOError exception
that open and create may raise.

* shapelib_wrap.c, dbflib_wrap.c: Regenerated

1 /* ----------------------------------------------------------------------------
2 * This file was automatically generated by SWIG (http://www.swig.org).
3 * Version 1.3u-20020503-1857 (Alpha 5)
4 *
5 * This file is not intended to be easily readable and contains a number of
6 * coding conventions designed to improve portability and efficiency. Do not make
7 * changes to this file unless you know what you are doing--modify the SWIG
8 * interface file instead.
9 * ----------------------------------------------------------------------------- */
10
11 #define SWIGPYTHON
12 /***********************************************************************
13 * common.swg
14 *
15 * This file contains generic SWIG runtime support for pointer
16 * type checking as well as a few commonly used macros to control
17 * external linkage.
18 *
19 * Author : David Beazley ([email protected])
20 *
21 * Copyright (c) 1999-2000, The University of Chicago
22 *
23 * This file may be freely redistributed without license or fee provided
24 * this copyright message remains intact.
25 ************************************************************************/
26
27 #include <string.h>
28
29 #if defined(_WIN32) || defined(__WIN32__)
30 # if defined(_MSC_VER)
31 # if defined(STATIC_LINKED)
32 # define SWIGEXPORT(a) a
33 # else
34 # define SWIGEXPORT(a) __declspec(dllexport) a
35 # endif
36 # else
37 # if defined(__BORLANDC__)
38 # define SWIGEXPORT(a) a _export
39 # else
40 # define SWIGEXPORT(a) a
41 # endif
42 #endif
43 #else
44 # define SWIGEXPORT(a) a
45 #endif
46
47 #ifdef SWIG_GLOBAL
48 #define SWIGRUNTIME(a) SWIGEXPORT(a)
49 #else
50 #define SWIGRUNTIME(a) static a
51 #endif
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 typedef struct swig_type_info {
58 char *name;
59 void *(*converter)(void *);
60 char *str;
61 struct swig_type_info *next;
62 struct swig_type_info *prev;
63 } swig_type_info;
64
65 #ifdef SWIG_NOINCLUDE
66 SWIGEXPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
67 SWIGEXPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
68 SWIGEXPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
69 #else
70
71 static swig_type_info *swig_type_list = 0;
72
73 /* Register a type mapping with the type-checking */
74 SWIGRUNTIME(swig_type_info *)
75 SWIG_TypeRegister(swig_type_info *ti)
76 {
77 swig_type_info *tc, *head, *ret, *next;
78 /* Check to see if this type has already been registered */
79 tc = swig_type_list;
80 while (tc) {
81 if (strcmp(tc->name, ti->name) == 0) {
82 /* Already exists in the table. Just add additional types to the list */
83 head = tc;
84 next = tc->next;
85 goto l1;
86 }
87 tc = tc->prev;
88 }
89 head = ti;
90 next = 0;
91
92 /* Place in list */
93 ti->prev = swig_type_list;
94 swig_type_list = ti;
95
96 /* Build linked lists */
97 l1:
98 ret = head;
99 tc = ti + 1;
100 /* Patch up the rest of the links */
101 while (tc->name) {
102 head->next = tc;
103 tc->prev = head;
104 head = tc;
105 tc++;
106 }
107 head->next = next;
108 return ret;
109 }
110
111 /* Check the typename */
112 SWIGRUNTIME(swig_type_info *)
113 SWIG_TypeCheck(char *c, swig_type_info *ty)
114 {
115 swig_type_info *s;
116 if (!ty) return 0; /* Void pointer */
117 s = ty->next; /* First element always just a name */
118 while (s) {
119 if (strcmp(s->name,c) == 0) {
120 if (s == ty->next) return s;
121 /* Move s to the top of the linked list */
122 s->prev->next = s->next;
123 if (s->next) {
124 s->next->prev = s->prev;
125 }
126 /* Insert s as second element in the list */
127 s->next = ty->next;
128 if (ty->next) ty->next->prev = s;
129 ty->next = s;
130 return s;
131 }
132 s = s->next;
133 }
134 return 0;
135 }
136
137 /* Cast a pointer (needed for C++ inheritance */
138 SWIGRUNTIME(void *)
139 SWIG_TypeCast(swig_type_info *ty, void *ptr)
140 {
141 if ((!ty) || (!ty->converter)) return ptr;
142 return (*ty->converter)(ptr);
143 }
144
145 /* Search for a swig_type_info structure */
146 SWIGRUNTIME(void *)
147 SWIG_TypeQuery(const char *name) {
148 swig_type_info *ty = swig_type_list;
149 while (ty) {
150 if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
151 if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
152 ty = ty->prev;
153 }
154 return 0;
155 }
156
157 #endif
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163
164
165 /***********************************************************************
166 * python.swg
167 *
168 * This file contains the runtime support for Python modules
169 * and includes code for managing global variables and pointer
170 * type checking.
171 *
172 * Author : David Beazley ([email protected])
173 ************************************************************************/
174
175 #include <stdlib.h>
176 #include "Python.h"
177
178 #ifdef __cplusplus
179 extern "C" {
180 #endif
181
182 #define SWIG_PY_INT 1
183 #define SWIG_PY_FLOAT 2
184 #define SWIG_PY_STRING 3
185 #define SWIG_PY_POINTER 4
186
187 /* Constant information structure */
188 typedef struct swig_const_info {
189 int type;
190 char *name;
191 long lvalue;
192 double dvalue;
193 void *pvalue;
194 swig_type_info **ptype;
195 } swig_const_info;
196
197 #ifdef SWIG_NOINCLUDE
198
199 SWIGEXPORT(PyObject *) SWIG_newvarlink();
200 SWIGEXPORT(void) SWIG_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
201 SWIGEXPORT(int) SWIG_ConvertPtr(PyObject *, void **, swig_type_info *, int);
202 SWIGEXPORT(void) SWIG_MakePtr(char *c, void *, swig_type_info *);
203 SWIGEXPORT(PyObject *) SWIG_NewPointerObj(void *, swig_type_info *);
204 SWIGEXPORT(void) SWIG_InstallConstants(PyObject *d, swig_const_info constants[]);
205
206 #else
207
208 /* -----------------------------------------------------------------------------
209 * global variable support code.
210 * ----------------------------------------------------------------------------- */
211
212 typedef struct swig_globalvar {
213 char *name; /* Name of global variable */
214 PyObject *(*get_attr)(void); /* Return the current value */
215 int (*set_attr)(PyObject *); /* Set the value */
216 struct swig_globalvar *next;
217 } swig_globalvar;
218
219 typedef struct swig_varlinkobject {
220 PyObject_HEAD
221 swig_globalvar *vars;
222 } swig_varlinkobject;
223
224 static PyObject *
225 swig_varlink_repr(swig_varlinkobject *v) {
226 v = v;
227 return PyString_FromString("<Global variables>");
228 }
229
230 static int
231 swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) {
232 swig_globalvar *var;
233 flags = flags;
234 fprintf(fp,"Global variables { ");
235 for (var = v->vars; var; var=var->next) {
236 fprintf(fp,"%s", var->name);
237 if (var->next) fprintf(fp,", ");
238 }
239 fprintf(fp," }\n");
240 return 0;
241 }
242
243 static PyObject *
244 swig_varlink_getattr(swig_varlinkobject *v, char *n) {
245 swig_globalvar *var = v->vars;
246 while (var) {
247 if (strcmp(var->name,n) == 0) {
248 return (*var->get_attr)();
249 }
250 var = var->next;
251 }
252 PyErr_SetString(PyExc_NameError,"Unknown C global variable");
253 return NULL;
254 }
255
256 static int
257 swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
258 swig_globalvar *var = v->vars;
259 while (var) {
260 if (strcmp(var->name,n) == 0) {
261 return (*var->set_attr)(p);
262 }
263 var = var->next;
264 }
265 PyErr_SetString(PyExc_NameError,"Unknown C global variable");
266 return 1;
267 }
268
269 statichere PyTypeObject varlinktype = {
270 PyObject_HEAD_INIT(0)
271 0,
272 "swigvarlink", /* Type name */
273 sizeof(swig_varlinkobject), /* Basic size */
274 0, /* Itemsize */
275 0, /* Deallocator */
276 (printfunc) swig_varlink_print, /* Print */
277 (getattrfunc) swig_varlink_getattr, /* get attr */
278 (setattrfunc) swig_varlink_setattr, /* Set attr */
279 0, /* tp_compare */
280 (reprfunc) swig_varlink_repr, /* tp_repr */
281 0, /* tp_as_number */
282 0, /* tp_as_mapping*/
283 0, /* tp_hash */
284 };
285
286 /* Create a variable linking object for use later */
287 SWIGRUNTIME(PyObject *)
288 SWIG_newvarlink(void) {
289 swig_varlinkobject *result = 0;
290 result = PyMem_NEW(swig_varlinkobject,1);
291 varlinktype.ob_type = &PyType_Type; /* Patch varlinktype into a PyType */
292 result->ob_type = &varlinktype;
293 result->vars = 0;
294 result->ob_refcnt = 0;
295 Py_XINCREF((PyObject *) result);
296 return ((PyObject*) result);
297 }
298
299 SWIGRUNTIME(void)
300 SWIG_addvarlink(PyObject *p, char *name,
301 PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
302 swig_varlinkobject *v;
303 swig_globalvar *gv;
304 v= (swig_varlinkobject *) p;
305 gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
306 gv->name = (char *) malloc(strlen(name)+1);
307 strcpy(gv->name,name);
308 gv->get_attr = get_attr;
309 gv->set_attr = set_attr;
310 gv->next = v->vars;
311 v->vars = gv;
312 }
313 /* Convert a pointer value */
314 SWIGRUNTIME(int)
315 SWIG_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
316 unsigned long p;
317 register int d;
318 swig_type_info *tc;
319 char *c;
320 static PyObject *SWIG_this = 0;
321 int newref = 0;
322
323 if (!obj || (obj == Py_None)) {
324 *ptr = 0;
325 return 0;
326 }
327 #ifdef SWIG_COBJECT_TYPES
328 if (!(PyCObject_Check(obj))) {
329 if (!SWIG_this)
330 SWIG_this = PyString_InternFromString("this");
331 obj = PyObject_GetAttr(obj,SWIG_this);
332 newref = 1;
333 if (!obj) goto type_error;
334 if (!PyCObject_Check(obj)) {
335 Py_DECREF(obj);
336 goto type_error;
337 }
338 }
339 *ptr = PyCObject_AsVoidPtr(obj);
340 c = (char *) PyCObject_GetDesc(obj);
341 if (newref) Py_DECREF(obj);
342 goto cobject;
343 #else
344 if (!(PyString_Check(obj))) {
345 if (!SWIG_this)
346 SWIG_this = PyString_InternFromString("this");
347 obj = PyObject_GetAttr(obj,SWIG_this);
348 newref = 1;
349 if (!obj) goto type_error;
350 if (!PyString_Check(obj)) {
351 Py_DECREF(obj);
352 goto type_error;
353 }
354 }
355 c = PyString_AsString(obj);
356 p = 0;
357 /* Pointer values must start with leading underscore */
358 if (*c != '_') {
359 *ptr = (void *) 0;
360 if (strcmp(c,"NULL") == 0) {
361 if (newref) Py_DECREF(obj);
362 return 0;
363 } else {
364 if (newref) Py_DECREF(obj);
365 goto type_error;
366 }
367 }
368 c++;
369 /* Extract hex value from pointer */
370 while ((d = *c)) {
371 if ((d >= '0') && (d <= '9'))
372 p = (p << 4) + (d - '0');
373 else if ((d >= 'a') && (d <= 'f'))
374 p = (p << 4) + (d - ('a'-10));
375 else
376 break;
377 c++;
378 }
379 *ptr = (void *) p;
380 if (newref) Py_DECREF(obj);
381 #endif
382
383 #ifdef SWIG_COBJECT_TYPES
384 cobject:
385 #endif
386
387 if (ty) {
388 tc = SWIG_TypeCheck(c,ty);
389 if (!tc) goto type_error;
390 *ptr = SWIG_TypeCast(tc,(void*)p);
391 }
392 return 0;
393
394 type_error:
395
396 if (flags) {
397 if (ty) {
398 char *temp = (char *) malloc(64+strlen(ty->name));
399 sprintf(temp,"Type error. Expected %s", ty->name);
400 PyErr_SetString(PyExc_TypeError, temp);
401 free((char *) temp);
402 } else {
403 PyErr_SetString(PyExc_TypeError,"Expected a pointer");
404 }
405 }
406 return -1;
407 }
408
409 /* Take a pointer and convert it to a string */
410 SWIGRUNTIME(void)
411 SWIG_MakePtr(char *c, void *ptr, swig_type_info *ty) {
412 static char hex[17] = "0123456789abcdef";
413 unsigned long p, s;
414 char result[32], *r;
415 r = result;
416 p = (unsigned long) ptr;
417 if (p > 0) {
418 while (p > 0) {
419 s = p & 0xf;
420 *(r++) = hex[s];
421 p = p >> 4;
422 }
423 *r = '_';
424 while (r >= result)
425 *(c++) = *(r--);
426 strcpy (c, ty->name);
427 } else {
428 strcpy (c, "NULL");
429 }
430 }
431
432 /* Create a new pointer object */
433 SWIGRUNTIME(PyObject *)
434 SWIG_NewPointerObj(void *ptr, swig_type_info *type) {
435 char result[512];
436 PyObject *robj;
437 if (!ptr) {
438 Py_INCREF(Py_None);
439 return Py_None;
440 }
441 #ifdef SWIG_COBJECT_TYPES
442 robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);
443 #else
444 SWIG_MakePtr(result,ptr,type);
445 robj = PyString_FromString(result);
446 #endif
447 return robj;
448 }
449
450 /* Install Constants */
451 SWIGRUNTIME(void)
452 SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
453 int i;
454 PyObject *obj;
455 for (i = 0; constants[i].type; i++) {
456 switch(constants[i].type) {
457 case SWIG_PY_INT:
458 obj = PyInt_FromLong(constants[i].lvalue);
459 break;
460 case SWIG_PY_FLOAT:
461 obj = PyFloat_FromDouble(constants[i].dvalue);
462 break;
463 case SWIG_PY_STRING:
464 obj = PyString_FromString((char *) constants[i].pvalue);
465 break;
466 case SWIG_PY_POINTER:
467 obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype);
468 break;
469 default:
470 obj = 0;
471 break;
472 }
473 if (obj) {
474 PyDict_SetItemString(d,constants[i].name,obj);
475 Py_DECREF(obj);
476 }
477 }
478 }
479
480 #endif
481
482 #ifdef __cplusplus
483 }
484 #endif
485
486
487
488 /* -------- TYPES TABLE (BEGIN) -------- */
489
490 #define SWIGTYPE_p_DBFFile swig_types[0]
491 static swig_type_info *swig_types[2];
492
493 /* -------- TYPES TABLE (END) -------- */
494
495
496 /*-----------------------------------------------
497 @(target):= dbflibc.so
498 ------------------------------------------------*/
499 #define SWIG_init initdbflibc
500
501 #define SWIG_name "dbflibc"
502
503 #include "shapefil.h"
504
505 /* the read_record method. Return the record record as a dictionary with
506 * whose keys are the names of the fields, and their values as the
507 * appropriate Python type.
508 *
509 * In case of error, set a python exception and return NULL. Since that
510 * value will be returned to the python interpreter as is, the
511 * interpreter should recognize the exception.
512 */
513
514 static PyObject *
515 DBFInfo_read_record(DBFInfo * handle, int record)
516 {
517 int num_fields;
518 int i;
519 int type, width;
520 char name[12];
521 PyObject *dict;
522 PyObject *value;
523
524 if (record < 0 || record >= DBFGetRecordCount(handle))
525 {
526 PyErr_Format(PyExc_ValueError,
527 "record index %d out of bounds (record count: %d)",
528 record, DBFGetRecordCount(handle));
529 return NULL;
530 }
531
532 dict = PyDict_New();
533 if (!dict)
534 return NULL;
535
536 num_fields = DBFGetFieldCount(handle);
537 for (i = 0; i < num_fields; i++)
538 {
539 type = DBFGetFieldInfo(handle, i, name, &width, NULL);
540 switch (type)
541 {
542 case FTString:
543 value = PyString_FromString(DBFReadStringAttribute(handle, record,
544 i));
545 break;
546 case FTInteger:
547 value = PyInt_FromLong(DBFReadIntegerAttribute(handle, record,
548 i));
549 break;
550 case FTDouble:
551 value = PyFloat_FromDouble(DBFReadDoubleAttribute(handle, record,
552 i));
553 break;
554 default:
555 PyErr_Format(PyExc_TypeError, "Invalid field data type %d", type);
556 value = NULL;
557 }
558 if (!value)
559 goto fail;
560 PyDict_SetItemString(dict, name, value);
561 Py_DECREF(value);
562 }
563
564 return dict;
565 fail:
566 Py_XDECREF(dict);
567 return NULL;
568 }
569
570 /* the write_record method. Write the record record given wither as a
571 * dictionary or a sequence (i.e. a list or a tuple).
572 *
573 * If it's a dictionary the keys must be the names of the fields and
574 * their value must have a suitable type. Only the fields actually
575 * contained in the dictionary are written. Fields for which there's no
576 * item in the dict are not modified.
577 *
578 * If it's a sequence, all fields must be present in the right order.
579 *
580 * In case of error, set a python exception and return NULL. Since that
581 * value will be returned to the python interpreter as is, the
582 * interpreter should recognize the exception.
583 *
584 * The method is implemented with two c-functions, write_field to write
585 * a single field and DBFInfo_write_record as the front-end.
586 */
587
588
589 /* write a single field of a record. */
590 static int
591 write_field(DBFHandle handle, int record, int field, int type,
592 PyObject * value)
593 {
594 char * string_value;
595 int int_value;
596 double double_value;
597
598 switch (type)
599 {
600 case FTString:
601 string_value = PyString_AsString(value);
602 if (!string_value)
603 return 0;
604 if (!DBFWriteStringAttribute(handle, record, field, string_value))
605 {
606 PyErr_Format(PyExc_IOError, "can't write field %d of record %d",
607 field, record);
608 return 0;
609 }
610 break;
611
612 case FTInteger:
613 int_value = PyInt_AsLong(value);
614 if (int_value == -1 && PyErr_Occurred())
615 return 0;
616 if (!DBFWriteIntegerAttribute(handle, record, field, int_value))
617 {
618 PyErr_Format(PyExc_IOError, "can't write field %d of record %d",
619 field, record);
620 return 0;
621 }
622 break;
623
624 case FTDouble:
625 double_value = PyFloat_AsDouble(value);
626 if (double_value == -1 && PyErr_Occurred())
627 return 0;
628 if (!DBFWriteDoubleAttribute(handle, record, field, double_value))
629 {
630 PyErr_Format(PyExc_IOError, "can't write field %d of record %d",
631 field, record);
632 return 0;
633 }
634 break;
635
636 default:
637 PyErr_Format(PyExc_TypeError, "Invalid field data type %d", type);
638 return 0;
639 }
640
641 return 1;
642 }
643
644 static
645 PyObject *
646 DBFInfo_write_record(DBFHandle handle, int record, PyObject *record_object)
647 {
648 int num_fields;
649 int i, length;
650 int type, width;
651 char name[12];
652 PyObject * value = NULL;
653
654 num_fields = DBFGetFieldCount(handle);
655
656 if (PyMapping_Check(record_object))
657 {
658 /* It's a dictionary-like object. Iterate over the names of the
659 * known fields and write the corresponding item
660 */
661 for (i = 0; i < num_fields; i++)
662 {
663 type = DBFGetFieldInfo(handle, i, name, &width, NULL);
664
665 /* if the dictionary has the key name write that object to
666 * the appropriate field, other wise just clear the python
667 * exception and do nothing.
668 */
669 value = PyMapping_GetItemString(record_object, name);
670 if (value)
671 {
672 if (!write_field(handle, record, i, type, value))
673 goto fail;
674 Py_DECREF(value);
675 }
676 else
677 {
678 PyErr_Clear();
679 }
680 }
681 }
682 else
683 {
684 /* It's a sequence object. Iterate through all items in the
685 * sequence and write them to the appropriate field.
686 */
687 length = PySequence_Length(record_object);
688 if (length != num_fields)
689 {
690 PyErr_SetString(PyExc_TypeError,
691 "record must have one item for each field");
692 goto fail;
693 }
694 for (i = 0; i < length; i++)
695 {
696 type = DBFGetFieldInfo(handle, i, name, &width, NULL);
697 value = PySequence_GetItem(record_object, i);
698 if (value)
699 {
700 if (!write_field(handle, record, i, type, value))
701 goto fail;
702 Py_DECREF(value);
703 }
704 else
705 {
706 goto fail;
707 }
708 }
709 }
710
711 Py_INCREF(Py_None);
712 return Py_None;
713
714 fail:
715 Py_XDECREF(value);
716 return NULL;
717 }
718
719 static PyObject* l_output_helper(PyObject* target, PyObject* o) {
720 PyObject* o2;
721 if (!target) {
722 target = o;
723 } else if (target == Py_None) {
724 Py_DECREF(Py_None);
725 target = o;
726 } else {
727 if (!PyList_Check(target)) {
728 o2 = target;
729 target = PyList_New(0);
730 PyList_Append(target, o2);
731 Py_XDECREF(o2);
732 }
733 PyList_Append(target,o);
734 Py_XDECREF(o);
735 }
736 return target;
737 }
738
739 static PyObject* t_output_helper(PyObject* target, PyObject* o) {
740 PyObject* o2;
741 PyObject* o3;
742
743 if (!target) {
744 target = o;
745 } else if (target == Py_None) {
746 Py_DECREF(Py_None);
747 target = o;
748 } else {
749 if (!PyTuple_Check(target)) {
750 o2 = target;
751 target = PyTuple_New(1);
752 PyTuple_SetItem(target, 0, o2);
753 }
754 o3 = PyTuple_New(1);
755 PyTuple_SetItem(o3, 0, o);
756
757 o2 = target;
758 target = PySequence_Concat(o2, o3);
759 Py_DECREF(o2);
760 Py_DECREF(o3);
761 }
762 return target;
763 }
764
765 #define SWIG_MemoryError 1
766 #define SWIG_IOError 2
767 #define SWIG_RuntimeError 3
768 #define SWIG_IndexError 4
769 #define SWIG_TypeError 5
770 #define SWIG_DivisionByZero 6
771 #define SWIG_OverflowError 7
772 #define SWIG_SyntaxError 8
773 #define SWIG_ValueError 9
774 #define SWIG_SystemError 10
775 #define SWIG_UnknownError 99
776
777 static void _SWIG_exception(int code, char *msg) {
778 switch(code) {
779 case SWIG_MemoryError:
780 PyErr_SetString(PyExc_MemoryError,msg);
781 break;
782 case SWIG_IOError:
783 PyErr_SetString(PyExc_IOError,msg);
784 break;
785 case SWIG_RuntimeError:
786 PyErr_SetString(PyExc_RuntimeError,msg);
787 break;
788 case SWIG_IndexError:
789 PyErr_SetString(PyExc_IndexError,msg);
790 break;
791 case SWIG_TypeError:
792 PyErr_SetString(PyExc_TypeError,msg);
793 break;
794 case SWIG_DivisionByZero:
795 PyErr_SetString(PyExc_ZeroDivisionError,msg);
796 break;
797 case SWIG_OverflowError:
798 PyErr_SetString(PyExc_OverflowError,msg);
799 break;
800 case SWIG_SyntaxError:
801 PyErr_SetString(PyExc_SyntaxError,msg);
802 break;
803 case SWIG_ValueError:
804 PyErr_SetString(PyExc_ValueError,msg);
805 break;
806 case SWIG_SystemError:
807 PyErr_SetString(PyExc_SystemError,msg);
808 break;
809 default:
810 PyErr_SetString(PyExc_RuntimeError,msg);
811 break;
812 }
813 }
814
815 #define SWIG_exception(a,b) { _SWIG_exception(a,b); return NULL; }
816
817 typedef struct {
818 DBFHandle handle;
819 } DBFFile;
820
821 #define NOCHECK_delete_DBFFile
822 #define NOCHECK_DBFFile_close
823
824 DBFFile * open_DBFFile(const char * file, const char * mode)
825 {
826 DBFFile * self = malloc(sizeof(DBFFile));
827 if (self)
828 self->handle = DBFOpen(file, mode);
829 return self;
830 }
831
832 DBFFile * create_DBFFile(const char * file)
833 {
834 DBFFile * self = malloc(sizeof(DBFFile));
835 if (self)
836 self->handle = DBFCreate(file);
837 return self;
838 }
839 #ifdef __cplusplus
840 extern "C" {
841 #endif
842 static PyObject *_wrap_open(PyObject *self, PyObject *args) {
843 PyObject *resultobj;
844 char *arg0 ;
845 char *arg1 = "rb" ;
846 DBFFile *result ;
847
848 if(!PyArg_ParseTuple(args,"s|s:open",&arg0,&arg1)) return NULL;
849 {
850 result = (DBFFile *)open_DBFFile((char const *)arg0,(char const *)arg1);
851 ;
852 if (!result)
853 {
854 SWIG_exception(SWIG_MemoryError, "no memory");
855 }
856 else if (!result->handle)
857 {
858 SWIG_exception(SWIG_IOError, "open_DBFFile failed");
859 }
860 }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
861 return resultobj;
862 }
863
864
865 static PyObject *_wrap_create(PyObject *self, PyObject *args) {
866 PyObject *resultobj;
867 char *arg0 ;
868 DBFFile *result ;
869
870 if(!PyArg_ParseTuple(args,"s:create",&arg0)) return NULL;
871 {
872 result = (DBFFile *)create_DBFFile((char const *)arg0);
873 ;
874 if (!result)
875 {
876 SWIG_exception(SWIG_MemoryError, "no memory");
877 }
878 else if (!result->handle)
879 {
880 SWIG_exception(SWIG_IOError, "create_DBFFile failed");
881 }
882 }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
883 return resultobj;
884 }
885
886
887 DBFFile * new_DBFFile(char const *file,char const *mode) {
888 {
889 DBFFile * self = malloc(sizeof(DBFFile));
890 if (self)
891 self->handle = DBFOpen(file, mode);
892 return self;
893 }
894 }
895
896
897 static PyObject *_wrap_new_DBFFile(PyObject *self, PyObject *args) {
898 PyObject *resultobj;
899 char *arg0 ;
900 char *arg1 = "rb" ;
901 DBFFile *result ;
902
903 if(!PyArg_ParseTuple(args,"s|s:new_DBFFile",&arg0,&arg1)) return NULL;
904 {
905 result = (DBFFile *)new_DBFFile((char const *)arg0,(char const *)arg1);
906 ;
907 if (!result)
908 {
909 SWIG_exception(SWIG_MemoryError, "no memory");
910 }
911 else if (!result->handle)
912 {
913 SWIG_exception(SWIG_IOError, "new_DBFFile failed");
914 }
915 }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
916 return resultobj;
917 }
918
919
920 void delete_DBFFile(DBFFile *self) {
921 {
922 if (self->handle)
923 DBFClose(self->handle);
924 free(self);
925 }
926 }
927
928
929 static PyObject *_wrap_delete_DBFFile(PyObject *self, PyObject *args) {
930 PyObject *resultobj;
931 DBFFile *arg0 ;
932 PyObject * argo0 =0 ;
933
934 if(!PyArg_ParseTuple(args,"O:delete_DBFFile",&argo0)) return NULL;
935 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
936 {
937 #ifndef NOCHECK_delete_DBFFile
938 if (!arg0 || !arg0->handle)
939 SWIG_exception(SWIG_TypeError, "dbffile already closed");
940 #endif
941 }
942 delete_DBFFile(arg0);
943 Py_INCREF(Py_None);
944 resultobj = Py_None;
945 return resultobj;
946 }
947
948
949 void DBFFile_close(DBFFile *self) {
950 {
951 if (self->handle)
952 DBFClose(self->handle);
953 self->handle = NULL;
954 }
955 }
956
957
958 static PyObject *_wrap_DBFFile_close(PyObject *self, PyObject *args) {
959 PyObject *resultobj;
960 DBFFile *arg0 ;
961 PyObject * argo0 =0 ;
962
963 if(!PyArg_ParseTuple(args,"O:DBFFile_close",&argo0)) return NULL;
964 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
965 {
966 #ifndef NOCHECK_DBFFile_close
967 if (!arg0 || !arg0->handle)
968 SWIG_exception(SWIG_TypeError, "dbffile already closed");
969 #endif
970 }
971 DBFFile_close(arg0);
972 Py_INCREF(Py_None);
973 resultobj = Py_None;
974 return resultobj;
975 }
976
977
978 int DBFFile_field_count(DBFFile *self) {
979 {
980 return DBFGetFieldCount(self->handle);
981 }
982 }
983
984
985 static PyObject *_wrap_DBFFile_field_count(PyObject *self, PyObject *args) {
986 PyObject *resultobj;
987 DBFFile *arg0 ;
988 PyObject * argo0 =0 ;
989 int result ;
990
991 if(!PyArg_ParseTuple(args,"O:DBFFile_field_count",&argo0)) return NULL;
992 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
993 {
994 #ifndef NOCHECK_DBFFile_field_count
995 if (!arg0 || !arg0->handle)
996 SWIG_exception(SWIG_TypeError, "dbffile already closed");
997 #endif
998 }
999 result = (int )DBFFile_field_count(arg0);
1000 resultobj = PyInt_FromLong((long)result);
1001 return resultobj;
1002 }
1003
1004
1005 int DBFFile_record_count(DBFFile *self) {
1006 {
1007 return DBFGetRecordCount(self->handle);
1008 }
1009 }
1010
1011
1012 static PyObject *_wrap_DBFFile_record_count(PyObject *self, PyObject *args) {
1013 PyObject *resultobj;
1014 DBFFile *arg0 ;
1015 PyObject * argo0 =0 ;
1016 int result ;
1017
1018 if(!PyArg_ParseTuple(args,"O:DBFFile_record_count",&argo0)) return NULL;
1019 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1020 {
1021 #ifndef NOCHECK_DBFFile_record_count
1022 if (!arg0 || !arg0->handle)
1023 SWIG_exception(SWIG_TypeError, "dbffile already closed");
1024 #endif
1025 }
1026 result = (int )DBFFile_record_count(arg0);
1027 resultobj = PyInt_FromLong((long)result);
1028 return resultobj;
1029 }
1030
1031
1032 int DBFFile_field_info(DBFFile *self,int iField,char *fieldname_out,int *output_width,int *output_decimals) {
1033 {
1034 return DBFGetFieldInfo(self->handle, iField, fieldname_out,
1035 output_width, output_decimals);
1036 }
1037 }
1038
1039
1040 static PyObject *_wrap_DBFFile_field_info(PyObject *self, PyObject *args) {
1041 PyObject *resultobj;
1042 DBFFile *arg0 ;
1043 int arg1 ;
1044 char *arg2 ;
1045 int *arg3 ;
1046 int *arg4 ;
1047 char temp[12] ;
1048 int temp0 ;
1049 int temp1 ;
1050 PyObject * argo0 =0 ;
1051 int result ;
1052
1053 {
1054 arg2 = temp;
1055 }
1056 {
1057 arg3 = &temp0;
1058 }
1059 {
1060 arg4 = &temp1;
1061 }
1062 if(!PyArg_ParseTuple(args,"Oi:DBFFile_field_info",&argo0,&arg1)) return NULL;
1063 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1064 {
1065 #ifndef NOCHECK_DBFFile_field_info
1066 if (!arg0 || !arg0->handle)
1067 SWIG_exception(SWIG_TypeError, "dbffile already closed");
1068 #endif
1069 }
1070 result = (int )DBFFile_field_info(arg0,arg1,arg2,arg3,arg4);
1071 resultobj = PyInt_FromLong((long)result);
1072 {
1073 PyObject * string = PyString_FromString(arg2);
1074 resultobj = t_output_helper(resultobj,string);
1075 }
1076 {
1077 PyObject *o;
1078 o = PyInt_FromLong((long) (*arg3));
1079 resultobj = t_output_helper(resultobj, o);
1080 }
1081 {
1082 PyObject *o;
1083 o = PyInt_FromLong((long) (*arg4));
1084 resultobj = t_output_helper(resultobj, o);
1085 }
1086 return resultobj;
1087 }
1088
1089
1090 PyObject * DBFFile_read_record(DBFFile *self,int record) {
1091 {
1092 return DBFInfo_read_record(self->handle, record);
1093 }
1094 }
1095
1096
1097 static PyObject *_wrap_DBFFile_read_record(PyObject *self, PyObject *args) {
1098 PyObject *resultobj;
1099 DBFFile *arg0 ;
1100 int arg1 ;
1101 PyObject * argo0 =0 ;
1102 PyObject *result ;
1103
1104 if(!PyArg_ParseTuple(args,"Oi:DBFFile_read_record",&argo0,&arg1)) return NULL;
1105 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1106 {
1107 #ifndef NOCHECK_DBFFile_read_record
1108 if (!arg0 || !arg0->handle)
1109 SWIG_exception(SWIG_TypeError, "dbffile already closed");
1110 #endif
1111 }
1112 result = (PyObject *)DBFFile_read_record(arg0,arg1);
1113 {
1114 resultobj = result;
1115 }
1116 return resultobj;
1117 }
1118
1119
1120 int DBFFile_add_field(DBFFile *self,char const *pszFieldName,DBFFieldType eType,int nWidth,int nDecimals) {
1121 {
1122 return DBFAddField(self->handle, pszFieldName, eType, nWidth,
1123 nDecimals);
1124 }
1125 }
1126
1127
1128 static PyObject *_wrap_DBFFile_add_field(PyObject *self, PyObject *args) {
1129 PyObject *resultobj;
1130 DBFFile *arg0 ;
1131 char *arg1 ;
1132 int arg2 ;
1133 int arg3 ;
1134 int arg4 ;
1135 PyObject * argo0 =0 ;
1136 int result ;
1137
1138 if(!PyArg_ParseTuple(args,"Osiii:DBFFile_add_field",&argo0,&arg1,&arg2,&arg3,&arg4)) return NULL;
1139 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1140 {
1141 #ifndef NOCHECK_DBFFile_add_field
1142 if (!arg0 || !arg0->handle)
1143 SWIG_exception(SWIG_TypeError, "dbffile already closed");
1144 #endif
1145 }
1146 result = (int )DBFFile_add_field(arg0,(char const *)arg1,(DBFFieldType )arg2,arg3,arg4);
1147 resultobj = PyInt_FromLong((long)result);
1148 return resultobj;
1149 }
1150
1151
1152 PyObject * DBFFile_write_record(DBFFile *self,int record,PyObject *dict_or_sequence) {
1153 {
1154 return DBFInfo_write_record(self->handle, record,
1155 dict_or_sequence);
1156 }
1157 }
1158
1159
1160 static PyObject *_wrap_DBFFile_write_record(PyObject *self, PyObject *args) {
1161 PyObject *resultobj;
1162 DBFFile *arg0 ;
1163 int arg1 ;
1164 PyObject *arg2 ;
1165 PyObject * argo0 =0 ;
1166 PyObject * obj2 = 0 ;
1167 PyObject *result ;
1168
1169 if(!PyArg_ParseTuple(args,"OiO:DBFFile_write_record",&argo0,&arg1,&obj2)) return NULL;
1170 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1171 {
1172 arg2 = obj2;
1173 }
1174 {
1175 #ifndef NOCHECK_DBFFile_write_record
1176 if (!arg0 || !arg0->handle)
1177 SWIG_exception(SWIG_TypeError, "dbffile already closed");
1178 #endif
1179 }
1180 result = (PyObject *)DBFFile_write_record(arg0,arg1,arg2);
1181 {
1182 resultobj = result;
1183 }
1184 return resultobj;
1185 }
1186
1187
1188 int DBFFile_commit(DBFFile *self) {
1189 {
1190 return DBFCommit(self->handle);
1191 }
1192 }
1193
1194
1195 static PyObject *_wrap_DBFFile_commit(PyObject *self, PyObject *args) {
1196 PyObject *resultobj;
1197 DBFFile *arg0 ;
1198 PyObject * argo0 =0 ;
1199 int result ;
1200
1201 if(!PyArg_ParseTuple(args,"O:DBFFile_commit",&argo0)) return NULL;
1202 if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1203 {
1204 #ifndef NOCHECK_DBFFile_commit
1205 if (!arg0 || !arg0->handle)
1206 SWIG_exception(SWIG_TypeError, "dbffile already closed");
1207 #endif
1208 }
1209 result = (int )DBFFile_commit(arg0);
1210 resultobj = PyInt_FromLong((long)result);
1211 return resultobj;
1212 }
1213
1214
1215 static PyMethodDef dbflibcMethods[] = {
1216 { "open", _wrap_open, METH_VARARGS },
1217 { "create", _wrap_create, METH_VARARGS },
1218 { "new_DBFFile", _wrap_new_DBFFile, METH_VARARGS },
1219 { "delete_DBFFile", _wrap_delete_DBFFile, METH_VARARGS },
1220 { "DBFFile_close", _wrap_DBFFile_close, METH_VARARGS },
1221 { "DBFFile_field_count", _wrap_DBFFile_field_count, METH_VARARGS },
1222 { "DBFFile_record_count", _wrap_DBFFile_record_count, METH_VARARGS },
1223 { "DBFFile_field_info", _wrap_DBFFile_field_info, METH_VARARGS },
1224 { "DBFFile_read_record", _wrap_DBFFile_read_record, METH_VARARGS },
1225 { "DBFFile_add_field", _wrap_DBFFile_add_field, METH_VARARGS },
1226 { "DBFFile_write_record", _wrap_DBFFile_write_record, METH_VARARGS },
1227 { "DBFFile_commit", _wrap_DBFFile_commit, METH_VARARGS },
1228 { NULL, NULL }
1229 };
1230
1231 #ifdef __cplusplus
1232 }
1233 #endif
1234
1235 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
1236
1237 static swig_type_info _swigt__p_DBFFile[] = {{"_p_DBFFile", 0, "DBFFile *"},{"_p_DBFFile"},{0}};
1238
1239 static swig_type_info *swig_types_initial[] = {
1240 _swigt__p_DBFFile,
1241 0
1242 };
1243
1244
1245 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
1246
1247 static swig_const_info swig_const_table[] = {
1248 { SWIG_PY_INT, "FTString", (long) FTString, 0, 0, 0},
1249 { SWIG_PY_INT, "FTInteger", (long) FTInteger, 0, 0, 0},
1250 { SWIG_PY_INT, "FTDouble", (long) FTDouble, 0, 0, 0},
1251 { SWIG_PY_INT, "FTInvalid", (long) FTInvalid, 0, 0, 0},
1252 {0}};
1253
1254 static PyObject *SWIG_globals;
1255 #ifdef __cplusplus
1256 extern "C"
1257 #endif
1258 SWIGEXPORT(void) initdbflibc(void) {
1259 PyObject *m, *d;
1260 int i;
1261 SWIG_globals = SWIG_newvarlink();
1262 m = Py_InitModule("dbflibc", dbflibcMethods);
1263 d = PyModule_GetDict(m);
1264 for (i = 0; swig_types_initial[i]; i++) {
1265 swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
1266 }
1267 SWIG_InstallConstants(d,swig_const_table);
1268 }
1269

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26