1#ifndef __PARADOX_H__ 2#define __PARADOX_H__ 3 4#define PX_USE_RECODE @PX_HAVE_RECODE@ 5#define PX_USE_ICONV @PX_HAVE_ICONV@ 6 7#include <stdio.h> 8#if PX_USE_RECODE 9#include <recode.h> 10#else 11#if PX_USE_ICONV 12#include <iconv.h> 13#endif 14#endif 15 16#ifdef WIN32 17 18#define PXLIB_CALL __cdecl 19 20#ifdef PXLIB_EXPORTS 21#define PXLIB_API __declspec(dllexport) /* prepare a DLL (internal use only) */ 22#elif defined(PXLIB_DLL) 23#define PXLIB_API __declspec(dllimport) /* PXlib clients: import PXlib DLL */ 24#else /* !PXLIB_DLL */ 25#define PXLIB_API /* */ /* default: generate or use static library */ 26 27#endif /* !PXLIB_DLL */ 28 29#endif /* !WIN32 */ 30 31#ifndef PXLIB_CALL 32#define PXLIB_CALL 33#endif 34#ifndef PXLIB_API 35#define PXLIB_API 36#endif 37 38#define px_true 1 39#define px_false 0 40 41/* Error codes */ 42#define PX_MemoryError 1 43#define PX_IOError 2 44#define PX_RuntimeError 3 45#define PX_Warning 100 46 47/* IO Stream types */ 48#define pxfIOFile 1 49/* pxfIOGsf is defined as 2 in paradox-gsf.h */ 50#define pxfIOStream 3 51 52/* Field types */ 53#define pxfAlpha 0x01 54#define pxfDate 0x02 55#define pxfShort 0x03 56#define pxfLong 0x04 57#define pxfCurrency 0x05 58#define pxfNumber 0x06 59#define pxfLogical 0x09 60#define pxfMemoBLOb 0x0C 61#define pxfBLOb 0x0D 62#define pxfFmtMemoBLOb 0x0E 63#define pxfOLE 0x0F 64#define pxfGraphic 0x10 65#define pxfTime 0x14 66#define pxfTimestamp 0x15 67#define pxfAutoInc 0x16 68#define pxfBCD 0x17 69#define pxfBytes 0x18 70#define pxfNumTypes 0x18 71 72/* File types */ 73#define pxfFileTypIndexDB 0 /* .DB */ 74#define pxfFileTypPrimIndex 1 /* .PX */ 75#define pxfFileTypNonIndexDB 2 /* .DB */ 76#define pxfFileTypNonIncSecIndex 3 /* .Xnn */ 77#define pxfFileTypSecIndex 4 /* .Ynn */ 78#define pxfFileTypIncSecIndex 5 /* .Xnn */ 79#define pxfFileTypNonIncSecIndexG 6 /* .XGn */ 80#define pxfFileTypSecIndexG 7 /* .YGn */ 81#define pxfFileTypIncSecIndexG 8 /* .XGn */ 82 83/* File modes */ 84#define pxfFileRead 0x1 85#define pxfFileWrite 0x2 86 87struct px_field { 88 char *px_fname; 89 char px_ftype; 90 int px_flen; 91 int px_fdc; 92}; 93 94struct px_val { 95 char isnull; 96 int type; 97 union { 98 long lval; 99 double dval; 100 struct { 101 char *val; 102 int len; 103 } str; 104 } value; 105}; 106 107struct px_head { 108 char *px_tablename; 109 int px_recordsize; 110 char px_filetype; 111 int px_fileversion; 112 int px_numrecords; // number of records as in header 113 int px_theonumrecords; // number of records that fit in data blocks 114 int px_numfields; 115 int px_maxtablesize; 116 int px_headersize; 117 unsigned int px_fileblocks; 118 unsigned int px_firstblock; // block number of first block 119 unsigned int px_lastblock; // block number of last block 120 int px_indexfieldnumber; 121 int px_indexroot; // number of root index block (only px files) 122 int px_numindexlevels; // number of index levels (only px files) 123 int px_writeprotected; 124 int px_doscodepage; 125 int px_primarykeyfields; 126 char px_modifiedflags1; 127 char px_modifiedflags2; 128 char px_sortorder; 129 int px_autoinc; 130 int px_fileupdatetime; 131 char px_refintegrity; 132 struct px_field *px_fields; 133 unsigned long px_encryption; 134}; 135 136typedef struct px_doc pxdoc_t; 137typedef struct px_datablockinfo pxdatablockinfo_t; 138typedef struct px_blob pxblob_t; 139typedef struct px_head pxhead_t; 140typedef struct px_field pxfield_t; 141typedef struct px_pindex pxpindex_t; 142typedef struct px_stream pxstream_t; 143typedef struct px_val pxval_t; 144typedef struct mb_head mbhead_t; 145 146struct px_stream { 147 int type; /* set to pxfIOFile | pxfIOGsf | pxfIOStream*/ 148 int mode; /* set to pxfFileRead | pxfFileWrite */ 149 int close; /* set to true if stream must be closed */ 150 union { 151 FILE *fp; 152 void *stream; 153#if HAVE_GSF 154 GsfInput *gsfin; 155 GsfOutput *gsfout; 156#endif 157 } s; 158 size_t (*read)(pxdoc_t *p, pxstream_t *stream, size_t numbytes, void *buffer); 159 int (*seek)(pxdoc_t *p, pxstream_t *stream, long offset, int whence); 160 long (*tell)(pxdoc_t *p, pxstream_t *stream); 161 size_t (*write)(pxdoc_t *p, pxstream_t *stream, size_t numbytes, void *buffer); 162}; 163 164struct px_doc { 165 /* database file */ 166// FILE *px_fp; /* File pointer of file */ 167 pxstream_t *px_stream; /* input stream to read file from */ 168 char *px_name; /* Name of file */ 169 int px_close_fp; /* set to true if file pointer must be closed, deprecated */ 170// int px_filemode; /* set to pxfFileRead|pxfFileWrite */ 171 pxhead_t *px_head; /* Pointer to header of file */ 172 void *px_data; /* Pointer to data of file (used in prim. index for 173 * index data, used in db files for an self build 174 * index) */ 175 int px_datalen; /* length of data field in number of units */ 176 void *px_indexdata;/* Pointer to index data */ 177 int px_indexdatalen; /* number of index data records */ 178 179 /* primary index file */ 180 pxdoc_t *px_pindex; 181 182 /* blob file */ 183 pxblob_t *px_blob; 184 185 /* record accounting */ 186 int last_position; /* Position (starting at 0) where last record was put. */ 187 188 int warnings; /* Turn of/off output of warnings */ 189 190 /* output function */ 191 size_t (*writeproc)(pxdoc_t *p, void *data, size_t size); 192 193 /* error handler function */ 194 void (*errorhandler)(pxdoc_t *p, int level, const char* msg, void *data); 195 196 /* user data passed to error handler */ 197 void *errorhandler_user_data; 198 199 /* Memory allocation functions */ 200 void *(*malloc)(pxdoc_t *p, size_t size, const char *caller); 201 void *(*calloc)(pxdoc_t *p, size_t size, const char *caller); 202 void *(*realloc)(pxdoc_t *p, void *mem, size_t size, const char *caller); 203 void (*free)(pxdoc_t *p, void *mem); 204 205 /* input stream functions */ 206 size_t (*read)(pxdoc_t *p, pxstream_t *stream, size_t numbytes, void *buffer); 207 int (*seek)(pxdoc_t *p, pxstream_t *stream, long offset, int whence); 208 long (*tell)(pxdoc_t *p, pxstream_t *stream); 209 size_t (*write)(pxdoc_t *p, pxstream_t *stream, size_t numbytes, void *buffer); 210 211 char *targetencoding; 212 char *inputencoding; 213#if PX_USE_RECODE 214 RECODE_OUTER recode_outer; 215 RECODE_REQUEST out_recode_request; /* Encoding of written data */ 216 RECODE_REQUEST in_recode_request; /* Encoding of read data */ 217#else 218#if PX_USE_ICONV 219 iconv_t out_iconvcd; /* Encoding of written data */ 220 iconv_t in_iconvcd; /* Encoding of read data */ 221#endif 222#endif 223 224 long curblocknr; /* Number of current block in cache (0-n) */ 225 int curblockdirty; /* Set to px_true if the block needs to be written */ 226 unsigned char *curblock; /* Data of block in read cache */ 227}; 228 229struct px_blockcache { 230 long start; 231 size_t size; 232 unsigned char *data; 233}; 234typedef struct px_blockcache pxblockcache_t; 235 236struct px_mbblockinfo { 237 int number; 238 char type; 239 char numblobs; 240 int numblocks; 241 int allocspace; 242}; 243typedef struct px_mbblockinfo pxmbblockinfo_t; 244 245struct px_blob { 246 char *mb_name; 247 pxdoc_t *pxdoc; 248 pxstream_t *mb_stream; /* input stream to read file from */ 249 mbhead_t *mb_head; /* Pointer to header of file */ 250 int used_datablocks; 251 int subblockoffset; 252 int subblockinneroffset; 253 int subblockfree; 254 int subblockblobcount; 255 /* input stream functions */ 256 size_t (*read)(pxblob_t *p, pxstream_t *stream, size_t numbytes, void *buffer); 257 int (*seek)(pxblob_t *p, pxstream_t *stream, long offset, int whence); 258 long (*tell)(pxblob_t *p, pxstream_t *stream); 259 size_t (*write)(pxblob_t *p, pxstream_t *stream, size_t numbytes, void *buffer); 260 /* Cache for the last read block */ 261 pxblockcache_t blockcache; 262 /* Index of all blocks in the blob file */ 263 pxmbblockinfo_t *blocklist; 264 int blocklistlen; 265}; 266 267struct mb_head { 268 int modcount; 269}; 270 271struct px_datablockinfo { 272 long blockpos; /* the start of the block in the file */ 273 long recordpos; /* the start of the record in the file */ 274 int size; /* the size of the block */ 275 int recno; /* the recno with the block starting with 0 */ 276 int numrecords; /* the number of records in the block */ 277 int prev; /* the number of the previous block */ 278 int next; /* the number of the next block */ 279 int number; /* the block number count (first block is 1) */ 280}; 281 282struct px_pindex { 283 char *data; 284 int blocknumber; /* Block number of referenced block */ 285 int numrecords; 286 int dummy; 287 int myblocknumber; /* Number of block this record is stored in */ 288 int level; /* level of index block, level 1 blocks point to 289 * data block in the database file. */ 290}; 291 292#define MAKE_PXVAL(pxdoc, pxval) \ 293 (pxval) = (pxval_t *) (pxdoc)->malloc((pxdoc), sizeof(pxval_t), "Allocate memory for pxval_t"); \ 294 memset((void *) (pxval), 0, sizeof(pxval_t)); 295 296#define FREE_PXVAL(pxdoc, pxval) \ 297 (pxdoc)->free((pxdoc), (pxval)); 298 299PXLIB_API int PXLIB_CALL 300PX_get_majorversion(void); 301 302PXLIB_API int PXLIB_CALL 303PX_get_minorversion(void); 304 305PXLIB_API int PXLIB_CALL 306PX_get_subminorversion(void); 307 308PXLIB_API int PXLIB_CALL 309PX_has_recode_support(void); 310 311PXLIB_API int PXLIB_CALL 312PX_has_gsf_support(void); 313 314PXLIB_API int PXLIB_CALL 315PX_is_bigendian(void); 316 317PXLIB_API char * PXLIB_CALL 318PX_get_builddate(void); 319 320PXLIB_API void PXLIB_CALL 321PX_boot(void); 322 323PXLIB_API void PXLIB_CALL 324PX_shutdown(void); 325 326PXLIB_API pxdoc_t* PXLIB_CALL 327PX_new3(void (*errorhandler)(pxdoc_t *p, int type, const char *msg, void *data), 328 void* (*allocproc)(pxdoc_t *p, size_t size, const char *caller), 329 void* (*reallocproc)(pxdoc_t *p, void *mem, size_t size, const char *caller), 330 void (*freeproc)(pxdoc_t *p, void *mem), 331 void* errorhandler_user_data); 332 333PXLIB_API pxdoc_t* PXLIB_CALL 334PX_new2(void (*errorhandler)(pxdoc_t *p, int type, const char *msg, void *data), 335 void* (*allocproc)(pxdoc_t *p, size_t size, const char *caller), 336 void* (*reallocproc)(pxdoc_t *p, void *mem, size_t size, const char *caller), 337 void (*freeproc)(pxdoc_t *p, void *mem)); 338 339PXLIB_API pxdoc_t* PXLIB_CALL 340PX_new(void); 341 342PXLIB_API int PXLIB_CALL 343PX_open_fp(pxdoc_t *pxdoc, FILE *fp); 344 345PXLIB_API int PXLIB_CALL 346PX_open_file(pxdoc_t *pxdoc, const char *filename); 347 348PXLIB_API int PXLIB_CALL 349PX_create_file(pxdoc_t *pxdoc, pxfield_t *pxf, int numfields, const char *filename, int type); 350 351PXLIB_API int PXLIB_CALL 352PX_create_fp(pxdoc_t *pxdoc, pxfield_t *pxf, int numfields, FILE *fp, int type); 353 354PXLIB_API void* PXLIB_CALL 355PX_get_opaque(pxdoc_t *pxdoc); 356 357PXLIB_API int PXLIB_CALL 358PX_write_primary_index(pxdoc_t *pxdoc, pxdoc_t *pxindex); 359 360PXLIB_API int PXLIB_CALL 361PX_read_primary_index(pxdoc_t *pindex); 362 363PXLIB_API int PXLIB_CALL 364PX_add_primary_index(pxdoc_t *pxdoc, pxdoc_t *pindex); 365 366PXLIB_API char * PXLIB_CALL 367PX_get_record(pxdoc_t *pxdoc, int recno, char *data); 368 369PXLIB_API char * PXLIB_CALL 370PX_get_record2(pxdoc_t *pxdoc, int recno, char *data, int *deleted, pxdatablockinfo_t *pxdbinfo); 371 372PXLIB_API int PXLIB_CALL 373PX_put_recordn(pxdoc_t *pxdoc, char *data, int recpos); 374 375PXLIB_API int PXLIB_CALL 376PX_put_record(pxdoc_t *pxdoc, char *data); 377 378PXLIB_API int PXLIB_CALL 379PX_insert_record(pxdoc_t *pxdoc, pxval_t **dataptr); 380 381PXLIB_API int PXLIB_CALL 382PX_update_record(pxdoc_t *pxdoc, pxval_t **dataptr, int recno); 383 384PXLIB_API int PXLIB_CALL 385PX_delete_record(pxdoc_t *pxdoc, int recno); 386 387PXLIB_API pxval_t ** PXLIB_CALL 388PX_retrieve_record(pxdoc_t *pxdoc, int recno); 389 390PXLIB_API void PXLIB_CALL 391PX_close(pxdoc_t *pxdoc); 392 393PXLIB_API void PXLIB_CALL 394PX_delete(pxdoc_t *pxdoc); 395 396PXLIB_API int PXLIB_CALL 397PX_pack(pxdoc_t *pxdoc); 398 399PXLIB_API pxfield_t* PXLIB_CALL 400PX_get_fields(pxdoc_t *pxdoc); 401 402PXLIB_API pxfield_t* PXLIB_CALL 403PX_get_field(pxdoc_t *pxdoc, int i); 404 405PXLIB_API int PXLIB_CALL 406PX_get_num_fields(pxdoc_t *pxdoc); 407 408PXLIB_API int PXLIB_CALL 409PX_get_num_records(pxdoc_t *pxdoc); 410 411PXLIB_API int PXLIB_CALL 412PX_get_recordsize(pxdoc_t *pxdoc); 413 414PXLIB_API int PXLIB_CALL 415PX_set_parameter(pxdoc_t *pxdoc, const char *name, const char *value); 416 417PXLIB_API int PXLIB_CALL 418PX_get_parameter(pxdoc_t *pxdoc, const char *name, char **value); 419 420PXLIB_API int PXLIB_CALL 421PX_set_value(pxdoc_t *pxdoc, const char *name, float value); 422 423PXLIB_API int PXLIB_CALL 424PX_get_value(pxdoc_t *pxdoc, const char *name, float *value); 425 426PXLIB_API int PXLIB_CALL 427PX_set_targetencoding(pxdoc_t *pxdoc, const char *encoding); 428 429PXLIB_API int PXLIB_CALL 430PX_set_inputencoding(pxdoc_t *pxdoc, const char *encoding); 431 432PXLIB_API int PXLIB_CALL 433PX_set_tablename(pxdoc_t *pxdoc, const char *tablename); 434 435PXLIB_API int PXLIB_CALL 436PX_set_blob_file(pxdoc_t *pxdoc, const char *filename); 437 438PXLIB_API int PXLIB_CALL 439PX_set_blob_fp(pxdoc_t *pxdoc, FILE *fp); 440 441PXLIB_API int PXLIB_CALL 442PX_has_blob_file(pxdoc_t *pxdoc); 443 444PXLIB_API pxblob_t* PXLIB_CALL 445PX_new_blob(pxdoc_t *pxdoc); 446 447PXLIB_API int PXLIB_CALL 448PX_open_blob_fp(pxblob_t *pxdoc, FILE *fp); 449 450PXLIB_API int PXLIB_CALL 451PX_open_blob_file(pxblob_t *pxdoc, const char *filename); 452 453PXLIB_API int PXLIB_CALL 454PX_create_blob_fp(pxblob_t *pxdoc, FILE *fp); 455 456PXLIB_API int PXLIB_CALL 457PX_create_blob_file(pxblob_t *pxblob, const char *filename); 458 459PXLIB_API void PXLIB_CALL 460PX_close_blob(pxblob_t *pxdoc); 461 462PXLIB_API void PXLIB_CALL 463PX_delete_blob(pxblob_t *pxblob); 464 465PXLIB_API char* PXLIB_CALL 466PX_read_blobdata(pxblob_t *pxblob, const char *data, int len, int *mod, int *blobsize); 467 468PXLIB_API char* PXLIB_CALL 469PX_read_graphicdata(pxblob_t *pxblob, const char *data, int len, int *mod, int *blobsize); 470 471PXLIB_API char* PXLIB_CALL 472PX_read_grahicdata(pxblob_t *pxblob, const char *data, int len, int *mod, int *blobsize); 473 474/* Data conversion functions */ 475/* Functions to read data from a record */ 476PXLIB_API int PXLIB_CALL 477PX_get_data_alpha(pxdoc_t *pxdoc, char *data, int len, char **value); 478 479PXLIB_API int PXLIB_CALL 480PX_get_data_bytes(pxdoc_t *pxdoc, char *data, int len, char **value); 481 482PXLIB_API int PXLIB_CALL 483PX_get_data_double(pxdoc_t *pxdoc, char *data, int len, double *value); 484 485PXLIB_API int PXLIB_CALL 486PX_get_data_long(pxdoc_t *pxdoc, char *data, int len, long *value); 487 488PXLIB_API int PXLIB_CALL 489PX_get_data_short(pxdoc_t *pxdoc, char *data, int len, short int *value); 490 491PXLIB_API int PXLIB_CALL 492PX_get_data_byte(pxdoc_t *pxdoc, char *data, int len, char *value); 493 494PXLIB_API int PXLIB_CALL 495PX_get_data_bcd(pxdoc_t *pxdoc, unsigned char *data, int len, char **value); 496 497PXLIB_API int PXLIB_CALL 498PX_get_data_blob(pxdoc_t *pxdoc, const char *data, int len, int *mod, int *blobsize, char **value); 499 500PXLIB_API int PXLIB_CALL 501PX_get_data_graphic(pxdoc_t *pxdoc, const char *data, int len, int *mod, int *blobsize, char **value); 502 503/* Funktion to add data to a record */ 504PXLIB_API void PXLIB_CALL 505PX_put_data_alpha(pxdoc_t *pxdoc, char *data, int len, char *value); 506 507PXLIB_API void PXLIB_CALL 508PX_put_data_bytes(pxdoc_t *pxdoc, char *data, int len, char *value); 509 510PXLIB_API void PXLIB_CALL 511PX_put_data_double(pxdoc_t *pxdoc, char *data, int len, double value); 512 513PXLIB_API void PXLIB_CALL 514PX_put_data_long(pxdoc_t *pxdoc, char *data, int len, int value); 515 516PXLIB_API void PXLIB_CALL 517PX_put_data_short(pxdoc_t *pxdoc, char *data, int len, short int value); 518 519PXLIB_API void PXLIB_CALL 520PX_put_data_byte(pxdoc_t *pxdoc, char *data, int len, char value); 521 522PXLIB_API void PXLIB_CALL 523PX_put_data_bcd(pxdoc_t *pxdoc, char *data, int len, char *value); 524 525PXLIB_API int PXLIB_CALL 526PX_put_data_blob(pxdoc_t *pxdoc, char *data, int len, char *value, int valuelen); 527 528PXLIB_API void PXLIB_CALL 529PX_SdnToGregorian(long int sdn, int *pYear, int *pMonth, int *pDay); 530 531PXLIB_API long int PXLIB_CALL 532PX_GregorianToSdn(int year, int month, int day); 533 534PXLIB_API pxval_t* PXLIB_CALL 535PX_make_time(pxdoc_t *pxdoc, int hour, int minute, int second); 536 537PXLIB_API pxval_t* PXLIB_CALL 538PX_make_date(pxdoc_t *pxdoc, int year, int month, int day); 539 540PXLIB_API pxval_t* PXLIB_CALL 541PX_make_timestamp(pxdoc_t *pxdoc, int year, int month, int day, int hour, int minute, int second); 542 543PXLIB_API char * PXLIB_CALL 544PX_timestamp2string(pxdoc_t *pxdoc, double value, const char *format); 545 546PXLIB_API char * PXLIB_CALL 547PX_time2string(pxdoc_t *pxdoc, long value, const char *format); 548 549PXLIB_API char * PXLIB_CALL 550PX_date2string(pxdoc_t *pxdoc, long value, const char *format); 551 552PXLIB_API char * PXLIB_CALL 553PX_strdup(pxdoc_t *pxdoc, const char *str); 554 555#endif 556 557/* 558 * Local variables: 559 * tab-width: 4 560 * c-basic-offset: 4 561 * End: 562 * vim600: sw=4 ts=4 fdm=marker 563 * vim<600: sw=4 ts=4 564 */ 565