/[thuban]/branches/WIP-pyshapelib-bramz/libraries/pyshapelib/dbflib_wrap.c
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/libraries/pyshapelib/dbflib_wrap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1611 - (hide annotations)
Tue Aug 19 21:24:20 2003 UTC (21 years, 6 months ago) by jan
Original Path: trunk/thuban/libraries/pyshapelib/dbflib_wrap.c
File MIME type: text/plain
File size: 34239 byte(s)
These files have been moved here from thuban/extensions/pyshapelib/
See there in the Attic for the older history.

1 jan 1611 /* ----------------------------------------------------------------------------
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     /* For strings NULL and the empty string are indistinguishable
541     * in DBF files. We prefer empty strings instead for backwards
542     * compatibility reasons because older wrapper versions returned
543     * emtpy strings as empty strings.
544     */
545     if (type != FTString && DBFIsAttributeNULL(handle, record, i))
546     {
547     value = Py_None;
548     Py_INCREF(value);
549     }
550     else
551     {
552     switch (type)
553     {
554     case FTString:
555     {
556     const char * temp = DBFReadStringAttribute(handle, record, i);
557     if (temp)
558     {
559     value = PyString_FromString(temp);
560     }
561     else
562     {
563     PyErr_Format(PyExc_IOError,
564     "Can't read value for row %d column %d",
565     record, i);
566     value = NULL;
567     }
568     break;
569     }
570     case FTInteger:
571     value = PyInt_FromLong(DBFReadIntegerAttribute(handle, record,
572     i));
573     break;
574     case FTDouble:
575     value = PyFloat_FromDouble(DBFReadDoubleAttribute(handle,
576     record, i));
577     break;
578     default:
579     PyErr_Format(PyExc_TypeError, "Invalid field data type %d",
580     type);
581     value = NULL;
582     }
583     }
584     if (!value)
585     goto fail;
586     PyDict_SetItemString(dict, name, value);
587     Py_DECREF(value);
588     }
589    
590     return dict;
591     fail:
592     Py_XDECREF(dict);
593     return NULL;
594     }
595    
596     /* the write_record method. Write the record record given wither as a
597     * dictionary or a sequence (i.e. a list or a tuple).
598     *
599     * If it's a dictionary the keys must be the names of the fields and
600     * their value must have a suitable type. Only the fields actually
601     * contained in the dictionary are written. Fields for which there's no
602     * item in the dict are not modified.
603     *
604     * If it's a sequence, all fields must be present in the right order.
605     *
606     * In case of error, set a python exception and return NULL. Since that
607     * value will be returned to the python interpreter as is, the
608     * interpreter should recognize the exception.
609     *
610     * The method is implemented with two c-functions, write_field to write
611     * a single field and DBFInfo_write_record as the front-end.
612     */
613    
614    
615     /* write a single field of a record. */
616     static int
617     write_field(DBFHandle handle, int record, int field, int type,
618     PyObject * value)
619     {
620     char * string_value;
621     int int_value;
622     double double_value;
623    
624     if (value == Py_None)
625     {
626     if (!DBFWriteNULLAttribute(handle, record, field))
627     {
628     PyErr_Format(PyExc_IOError,
629     "can't write NULL field %d of record %d",
630     field, record);
631     return 0;
632     }
633     }
634     else
635     {
636     switch (type)
637     {
638     case FTString:
639     string_value = PyString_AsString(value);
640     if (!string_value)
641     return 0;
642     if (!DBFWriteStringAttribute(handle, record, field, string_value))
643     {
644     PyErr_Format(PyExc_IOError,
645     "can't write field %d of record %d",
646     field, record);
647     return 0;
648     }
649     break;
650    
651     case FTInteger:
652     int_value = PyInt_AsLong(value);
653     if (int_value == -1 && PyErr_Occurred())
654     return 0;
655     if (!DBFWriteIntegerAttribute(handle, record, field, int_value))
656     {
657     PyErr_Format(PyExc_IOError,
658     "can't write field %d of record %d",
659     field, record);
660     return 0;
661     }
662     break;
663    
664     case FTDouble:
665     double_value = PyFloat_AsDouble(value);
666     if (double_value == -1 && PyErr_Occurred())
667     return 0;
668     if (!DBFWriteDoubleAttribute(handle, record, field, double_value))
669     {
670     PyErr_Format(PyExc_IOError,
671     "can't write field %d of record %d",
672     field, record);
673     return 0;
674     }
675     break;
676    
677     default:
678     PyErr_Format(PyExc_TypeError, "Invalid field data type %d", type);
679     return 0;
680     }
681     }
682    
683     return 1;
684     }
685    
686     static
687     PyObject *
688     DBFInfo_write_record(DBFHandle handle, int record, PyObject *record_object)
689     {
690     int num_fields;
691     int i, length;
692     int type, width;
693     char name[12];
694     PyObject * value = NULL;
695    
696     num_fields = DBFGetFieldCount(handle);
697    
698     /* We used to use PyMapping_Check to test whether record_object is a
699     * dictionary like object instead of PySequence_Check to test
700     * whether it's a sequence. Unfortunately in Python 2.3
701     * PyMapping_Check returns true for lists and tuples too so the old
702     * approach doesn't work anymore.
703     */
704     if (PySequence_Check(record_object))
705     {
706     /* It's a sequence object. Iterate through all items in the
707     * sequence and write them to the appropriate field.
708     */
709     length = PySequence_Length(record_object);
710     if (length != num_fields)
711     {
712     PyErr_SetString(PyExc_TypeError,
713     "record must have one item for each field");
714     goto fail;
715     }
716     for (i = 0; i < length; i++)
717     {
718     type = DBFGetFieldInfo(handle, i, name, &width, NULL);
719     value = PySequence_GetItem(record_object, i);
720     if (value)
721     {
722     if (!write_field(handle, record, i, type, value))
723     goto fail;
724     Py_DECREF(value);
725     }
726     else
727     {
728     goto fail;
729     }
730     }
731     }
732     else
733     {
734     /* It's a dictionary-like object. Iterate over the names of the
735     * known fields and write the corresponding item
736     */
737     for (i = 0; i < num_fields; i++)
738     {
739     type = DBFGetFieldInfo(handle, i, name, &width, NULL);
740    
741     /* if the dictionary has the key name write that object to
742     * the appropriate field, other wise just clear the python
743     * exception and do nothing.
744     */
745     value = PyMapping_GetItemString(record_object, name);
746     if (value)
747     {
748     if (!write_field(handle, record, i, type, value))
749     goto fail;
750     Py_DECREF(value);
751     }
752     else
753     {
754     PyErr_Clear();
755     }
756     }
757     }
758    
759     Py_INCREF(Py_None);
760     return Py_None;
761    
762     fail:
763     Py_XDECREF(value);
764     return NULL;
765     }
766    
767     static PyObject* l_output_helper(PyObject* target, PyObject* o) {
768     PyObject* o2;
769     if (!target) {
770     target = o;
771     } else if (target == Py_None) {
772     Py_DECREF(Py_None);
773     target = o;
774     } else {
775     if (!PyList_Check(target)) {
776     o2 = target;
777     target = PyList_New(0);
778     PyList_Append(target, o2);
779     Py_XDECREF(o2);
780     }
781     PyList_Append(target,o);
782     Py_XDECREF(o);
783     }
784     return target;
785     }
786    
787     static PyObject* t_output_helper(PyObject* target, PyObject* o) {
788     PyObject* o2;
789     PyObject* o3;
790    
791     if (!target) {
792     target = o;
793     } else if (target == Py_None) {
794     Py_DECREF(Py_None);
795     target = o;
796     } else {
797     if (!PyTuple_Check(target)) {
798     o2 = target;
799     target = PyTuple_New(1);
800     PyTuple_SetItem(target, 0, o2);
801     }
802     o3 = PyTuple_New(1);
803     PyTuple_SetItem(o3, 0, o);
804    
805     o2 = target;
806     target = PySequence_Concat(o2, o3);
807     Py_DECREF(o2);
808     Py_DECREF(o3);
809     }
810     return target;
811     }
812    
813     #define SWIG_MemoryError 1
814     #define SWIG_IOError 2
815     #define SWIG_RuntimeError 3
816     #define SWIG_IndexError 4
817     #define SWIG_TypeError 5
818     #define SWIG_DivisionByZero 6
819     #define SWIG_OverflowError 7
820     #define SWIG_SyntaxError 8
821     #define SWIG_ValueError 9
822     #define SWIG_SystemError 10
823     #define SWIG_UnknownError 99
824    
825     static void _SWIG_exception(int code, char *msg) {
826     switch(code) {
827     case SWIG_MemoryError:
828     PyErr_SetString(PyExc_MemoryError,msg);
829     break;
830     case SWIG_IOError:
831     PyErr_SetString(PyExc_IOError,msg);
832     break;
833     case SWIG_RuntimeError:
834     PyErr_SetString(PyExc_RuntimeError,msg);
835     break;
836     case SWIG_IndexError:
837     PyErr_SetString(PyExc_IndexError,msg);
838     break;
839     case SWIG_TypeError:
840     PyErr_SetString(PyExc_TypeError,msg);
841     break;
842     case SWIG_DivisionByZero:
843     PyErr_SetString(PyExc_ZeroDivisionError,msg);
844     break;
845     case SWIG_OverflowError:
846     PyErr_SetString(PyExc_OverflowError,msg);
847     break;
848     case SWIG_SyntaxError:
849     PyErr_SetString(PyExc_SyntaxError,msg);
850     break;
851     case SWIG_ValueError:
852     PyErr_SetString(PyExc_ValueError,msg);
853     break;
854     case SWIG_SystemError:
855     PyErr_SetString(PyExc_SystemError,msg);
856     break;
857     default:
858     PyErr_SetString(PyExc_RuntimeError,msg);
859     break;
860     }
861     }
862    
863     #define SWIG_exception(a,b) { _SWIG_exception(a,b); return NULL; }
864    
865     typedef struct {
866     DBFHandle handle;
867     } DBFFile;
868    
869     #define NOCHECK_delete_DBFFile
870     #define NOCHECK_DBFFile_close
871    
872     DBFFile * open_DBFFile(const char * file, const char * mode)
873     {
874     DBFFile * self = malloc(sizeof(DBFFile));
875     if (self)
876     self->handle = DBFOpen(file, mode);
877     return self;
878     }
879    
880     DBFFile * create_DBFFile(const char * file)
881     {
882     DBFFile * self = malloc(sizeof(DBFFile));
883     if (self)
884     self->handle = DBFCreate(file);
885     return self;
886     }
887     #ifdef __cplusplus
888     extern "C" {
889     #endif
890     static PyObject *_wrap_open(PyObject *self, PyObject *args) {
891     PyObject *resultobj;
892     char *arg0 ;
893     char *arg1 = "rb" ;
894     DBFFile *result ;
895    
896     if(!PyArg_ParseTuple(args,"s|s:open",&arg0,&arg1)) return NULL;
897     {
898     result = (DBFFile *)open_DBFFile((char const *)arg0,(char const *)arg1);
899     ;
900     if (!result)
901     {
902     SWIG_exception(SWIG_MemoryError, "no memory");
903     }
904     else if (!result->handle)
905     {
906     SWIG_exception(SWIG_IOError, "open_DBFFile failed");
907     }
908     }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
909     return resultobj;
910     }
911    
912    
913     static PyObject *_wrap_create(PyObject *self, PyObject *args) {
914     PyObject *resultobj;
915     char *arg0 ;
916     DBFFile *result ;
917    
918     if(!PyArg_ParseTuple(args,"s:create",&arg0)) return NULL;
919     {
920     result = (DBFFile *)create_DBFFile((char const *)arg0);
921     ;
922     if (!result)
923     {
924     SWIG_exception(SWIG_MemoryError, "no memory");
925     }
926     else if (!result->handle)
927     {
928     SWIG_exception(SWIG_IOError, "create_DBFFile failed");
929     }
930     }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
931     return resultobj;
932     }
933    
934    
935     DBFFile * new_DBFFile(char const *file,char const *mode) {
936     {
937     DBFFile * self = malloc(sizeof(DBFFile));
938     if (self)
939     self->handle = DBFOpen(file, mode);
940     return self;
941     }
942     }
943    
944    
945     static PyObject *_wrap_new_DBFFile(PyObject *self, PyObject *args) {
946     PyObject *resultobj;
947     char *arg0 ;
948     char *arg1 = "rb" ;
949     DBFFile *result ;
950    
951     if(!PyArg_ParseTuple(args,"s|s:new_DBFFile",&arg0,&arg1)) return NULL;
952     {
953     result = (DBFFile *)new_DBFFile((char const *)arg0,(char const *)arg1);
954     ;
955     if (!result)
956     {
957     SWIG_exception(SWIG_MemoryError, "no memory");
958     }
959     else if (!result->handle)
960     {
961     SWIG_exception(SWIG_IOError, "new_DBFFile failed");
962     }
963     }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
964     return resultobj;
965     }
966    
967    
968     void delete_DBFFile(DBFFile *self) {
969     {
970     if (self->handle)
971     DBFClose(self->handle);
972     free(self);
973     }
974     }
975    
976    
977     static PyObject *_wrap_delete_DBFFile(PyObject *self, PyObject *args) {
978     PyObject *resultobj;
979     DBFFile *arg0 ;
980     PyObject * argo0 =0 ;
981    
982     if(!PyArg_ParseTuple(args,"O:delete_DBFFile",&argo0)) return NULL;
983     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
984     {
985     #ifndef NOCHECK_delete_DBFFile
986     if (!arg0 || !arg0->handle)
987     SWIG_exception(SWIG_TypeError, "dbffile already closed");
988     #endif
989     }
990     delete_DBFFile(arg0);
991     Py_INCREF(Py_None);
992     resultobj = Py_None;
993     return resultobj;
994     }
995    
996    
997     void DBFFile_close(DBFFile *self) {
998     {
999     if (self->handle)
1000     DBFClose(self->handle);
1001     self->handle = NULL;
1002     }
1003     }
1004    
1005    
1006     static PyObject *_wrap_DBFFile_close(PyObject *self, PyObject *args) {
1007     PyObject *resultobj;
1008     DBFFile *arg0 ;
1009     PyObject * argo0 =0 ;
1010    
1011     if(!PyArg_ParseTuple(args,"O:DBFFile_close",&argo0)) return NULL;
1012     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1013     {
1014     #ifndef NOCHECK_DBFFile_close
1015     if (!arg0 || !arg0->handle)
1016     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1017     #endif
1018     }
1019     DBFFile_close(arg0);
1020     Py_INCREF(Py_None);
1021     resultobj = Py_None;
1022     return resultobj;
1023     }
1024    
1025    
1026     int DBFFile_field_count(DBFFile *self) {
1027     {
1028     return DBFGetFieldCount(self->handle);
1029     }
1030     }
1031    
1032    
1033     static PyObject *_wrap_DBFFile_field_count(PyObject *self, PyObject *args) {
1034     PyObject *resultobj;
1035     DBFFile *arg0 ;
1036     PyObject * argo0 =0 ;
1037     int result ;
1038    
1039     if(!PyArg_ParseTuple(args,"O:DBFFile_field_count",&argo0)) return NULL;
1040     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1041     {
1042     #ifndef NOCHECK_DBFFile_field_count
1043     if (!arg0 || !arg0->handle)
1044     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1045     #endif
1046     }
1047     result = (int )DBFFile_field_count(arg0);
1048     resultobj = PyInt_FromLong((long)result);
1049     return resultobj;
1050     }
1051    
1052    
1053     int DBFFile_record_count(DBFFile *self) {
1054     {
1055     return DBFGetRecordCount(self->handle);
1056     }
1057     }
1058    
1059    
1060     static PyObject *_wrap_DBFFile_record_count(PyObject *self, PyObject *args) {
1061     PyObject *resultobj;
1062     DBFFile *arg0 ;
1063     PyObject * argo0 =0 ;
1064     int result ;
1065    
1066     if(!PyArg_ParseTuple(args,"O:DBFFile_record_count",&argo0)) return NULL;
1067     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1068     {
1069     #ifndef NOCHECK_DBFFile_record_count
1070     if (!arg0 || !arg0->handle)
1071     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1072     #endif
1073     }
1074     result = (int )DBFFile_record_count(arg0);
1075     resultobj = PyInt_FromLong((long)result);
1076     return resultobj;
1077     }
1078    
1079    
1080     int DBFFile_field_info(DBFFile *self,int iField,char *fieldname_out,int *output_width,int *output_decimals) {
1081     {
1082     return DBFGetFieldInfo(self->handle, iField, fieldname_out,
1083     output_width, output_decimals);
1084     }
1085     }
1086    
1087    
1088     static PyObject *_wrap_DBFFile_field_info(PyObject *self, PyObject *args) {
1089     PyObject *resultobj;
1090     DBFFile *arg0 ;
1091     int arg1 ;
1092     char *arg2 ;
1093     int *arg3 ;
1094     int *arg4 ;
1095     char temp[12] ;
1096     int temp0 ;
1097     int temp1 ;
1098     PyObject * argo0 =0 ;
1099     int result ;
1100    
1101     {
1102     arg2 = temp;
1103     }
1104     {
1105     arg3 = &temp0;
1106     }
1107     {
1108     arg4 = &temp1;
1109     }
1110     if(!PyArg_ParseTuple(args,"Oi:DBFFile_field_info",&argo0,&arg1)) return NULL;
1111     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1112     {
1113     #ifndef NOCHECK_DBFFile_field_info
1114     if (!arg0 || !arg0->handle)
1115     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1116     #endif
1117     }
1118     result = (int )DBFFile_field_info(arg0,arg1,arg2,arg3,arg4);
1119     resultobj = PyInt_FromLong((long)result);
1120     {
1121     PyObject * string = PyString_FromString(arg2);
1122     resultobj = t_output_helper(resultobj,string);
1123     }
1124     {
1125     PyObject *o;
1126     o = PyInt_FromLong((long) (*arg3));
1127     resultobj = t_output_helper(resultobj, o);
1128     }
1129     {
1130     PyObject *o;
1131     o = PyInt_FromLong((long) (*arg4));
1132     resultobj = t_output_helper(resultobj, o);
1133     }
1134     return resultobj;
1135     }
1136    
1137    
1138     PyObject * DBFFile_read_record(DBFFile *self,int record) {
1139     {
1140     return DBFInfo_read_record(self->handle, record);
1141     }
1142     }
1143    
1144    
1145     static PyObject *_wrap_DBFFile_read_record(PyObject *self, PyObject *args) {
1146     PyObject *resultobj;
1147     DBFFile *arg0 ;
1148     int arg1 ;
1149     PyObject * argo0 =0 ;
1150     PyObject *result ;
1151    
1152     if(!PyArg_ParseTuple(args,"Oi:DBFFile_read_record",&argo0,&arg1)) return NULL;
1153     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1154     {
1155     #ifndef NOCHECK_DBFFile_read_record
1156     if (!arg0 || !arg0->handle)
1157     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1158     #endif
1159     }
1160     result = (PyObject *)DBFFile_read_record(arg0,arg1);
1161     {
1162     resultobj = result;
1163     }
1164     return resultobj;
1165     }
1166    
1167    
1168     int DBFFile_add_field(DBFFile *self,char const *pszFieldName,DBFFieldType eType,int nWidth,int nDecimals) {
1169     {
1170     return DBFAddField(self->handle, pszFieldName, eType, nWidth,
1171     nDecimals);
1172     }
1173     }
1174    
1175    
1176     static PyObject *_wrap_DBFFile_add_field(PyObject *self, PyObject *args) {
1177     PyObject *resultobj;
1178     DBFFile *arg0 ;
1179     char *arg1 ;
1180     int arg2 ;
1181     int arg3 ;
1182     int arg4 ;
1183     PyObject * argo0 =0 ;
1184     int result ;
1185    
1186     if(!PyArg_ParseTuple(args,"Osiii:DBFFile_add_field",&argo0,&arg1,&arg2,&arg3,&arg4)) return NULL;
1187     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1188     {
1189     #ifndef NOCHECK_DBFFile_add_field
1190     if (!arg0 || !arg0->handle)
1191     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1192     #endif
1193     }
1194     result = (int )DBFFile_add_field(arg0,(char const *)arg1,(DBFFieldType )arg2,arg3,arg4);
1195     resultobj = PyInt_FromLong((long)result);
1196     return resultobj;
1197     }
1198    
1199    
1200     PyObject * DBFFile_write_record(DBFFile *self,int record,PyObject *dict_or_sequence) {
1201     {
1202     return DBFInfo_write_record(self->handle, record,
1203     dict_or_sequence);
1204     }
1205     }
1206    
1207    
1208     static PyObject *_wrap_DBFFile_write_record(PyObject *self, PyObject *args) {
1209     PyObject *resultobj;
1210     DBFFile *arg0 ;
1211     int arg1 ;
1212     PyObject *arg2 ;
1213     PyObject * argo0 =0 ;
1214     PyObject * obj2 = 0 ;
1215     PyObject *result ;
1216    
1217     if(!PyArg_ParseTuple(args,"OiO:DBFFile_write_record",&argo0,&arg1,&obj2)) return NULL;
1218     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1219     {
1220     arg2 = obj2;
1221     }
1222     {
1223     #ifndef NOCHECK_DBFFile_write_record
1224     if (!arg0 || !arg0->handle)
1225     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1226     #endif
1227     }
1228     result = (PyObject *)DBFFile_write_record(arg0,arg1,arg2);
1229     {
1230     resultobj = result;
1231     }
1232     return resultobj;
1233     }
1234    
1235    
1236     int DBFFile_commit(DBFFile *self) {
1237     {
1238     return DBFCommit(self->handle);
1239     }
1240     }
1241    
1242    
1243     static PyObject *_wrap_DBFFile_commit(PyObject *self, PyObject *args) {
1244     PyObject *resultobj;
1245     DBFFile *arg0 ;
1246     PyObject * argo0 =0 ;
1247     int result ;
1248    
1249     if(!PyArg_ParseTuple(args,"O:DBFFile_commit",&argo0)) return NULL;
1250     if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
1251     {
1252     #ifndef NOCHECK_DBFFile_commit
1253     if (!arg0 || !arg0->handle)
1254     SWIG_exception(SWIG_TypeError, "dbffile already closed");
1255     #endif
1256     }
1257     result = (int )DBFFile_commit(arg0);
1258     resultobj = PyInt_FromLong((long)result);
1259     return resultobj;
1260     }
1261    
1262    
1263     static PyMethodDef dbflibcMethods[] = {
1264     { "open", _wrap_open, METH_VARARGS },
1265     { "create", _wrap_create, METH_VARARGS },
1266     { "new_DBFFile", _wrap_new_DBFFile, METH_VARARGS },
1267     { "delete_DBFFile", _wrap_delete_DBFFile, METH_VARARGS },
1268     { "DBFFile_close", _wrap_DBFFile_close, METH_VARARGS },
1269     { "DBFFile_field_count", _wrap_DBFFile_field_count, METH_VARARGS },
1270     { "DBFFile_record_count", _wrap_DBFFile_record_count, METH_VARARGS },
1271     { "DBFFile_field_info", _wrap_DBFFile_field_info, METH_VARARGS },
1272     { "DBFFile_read_record", _wrap_DBFFile_read_record, METH_VARARGS },
1273     { "DBFFile_add_field", _wrap_DBFFile_add_field, METH_VARARGS },
1274     { "DBFFile_write_record", _wrap_DBFFile_write_record, METH_VARARGS },
1275     { "DBFFile_commit", _wrap_DBFFile_commit, METH_VARARGS },
1276     { NULL, NULL }
1277     };
1278    
1279     #ifdef __cplusplus
1280     }
1281     #endif
1282    
1283     /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
1284    
1285     static swig_type_info _swigt__p_DBFFile[] = {{"_p_DBFFile", 0, "DBFFile *"},{"_p_DBFFile"},{0}};
1286    
1287     static swig_type_info *swig_types_initial[] = {
1288     _swigt__p_DBFFile,
1289     0
1290     };
1291    
1292    
1293     /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
1294    
1295     static swig_const_info swig_const_table[] = {
1296     { SWIG_PY_INT, "FTString", (long) FTString, 0, 0, 0},
1297     { SWIG_PY_INT, "FTInteger", (long) FTInteger, 0, 0, 0},
1298     { SWIG_PY_INT, "FTDouble", (long) FTDouble, 0, 0, 0},
1299     { SWIG_PY_INT, "FTInvalid", (long) FTInvalid, 0, 0, 0},
1300     {0}};
1301    
1302     static PyObject *SWIG_globals;
1303     #ifdef __cplusplus
1304     extern "C"
1305     #endif
1306     SWIGEXPORT(void) initdbflibc(void) {
1307     PyObject *m, *d;
1308     int i;
1309     SWIG_globals = SWIG_newvarlink();
1310     m = Py_InitModule("dbflibc", dbflibcMethods);
1311     d = PyModule_GetDict(m);
1312     for (i = 0; swig_types_initial[i]; i++) {
1313     swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
1314     }
1315     SWIG_InstallConstants(d,swig_const_table);
1316     }
1317    

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26