00001
00002 #ifndef CBF_H
00003 #define CBF_H
00004
00005 #ifdef __cplusplus
00006
00007 extern "C" {
00008
00009 #endif
00010
00011 #include "cbf_tree.h"
00012
00013 #include <stdlib.h>
00014 #include <limits.h>
00015
00016
00017
00018
00019 #if UINT_MAX / 65535U < 65535U
00020 #error cbflib assumes int is at least 32 bits
00021 #endif
00022
00023
00024
00025
00026 #define CBF_LINELENGTH 80
00027
00028
00029
00030
00031 #define CBF_FORMAT 0x00000001
00032 #define CBF_ALLOC 0x00000002
00033 #define CBF_ARGUMENT 0x00000004
00034 #define CBF_ASCII 0x00000008
00035 #define CBF_BINARY 0x00000010
00036 #define CBF_BITCOUNT 0x00000020
00037 #define CBF_ENDOFDATA 0x00000040
00038 #define CBF_FILECLOSE 0x00000080
00039 #define CBF_FILEOPEN 0x00000100
00040 #define CBF_FILEREAD 0x00000200
00041 #define CBF_FILESEEK 0x00000400
00042 #define CBF_FILETELL 0x00000800
00043 #define CBF_FILEWRITE 0x00001000
00044 #define CBF_IDENTICAL 0x00002000
00045 #define CBF_NOTFOUND 0x00004000
00046 #define CBF_OVERFLOW 0x00008000
00047
00048
00049
00050
00051 #define CBF_TOKEN_NULL '\377'
00052 #define CBF_TOKEN_WORD '\300'
00053 #define CBF_TOKEN_SQSTRING '\301'
00054 #define CBF_TOKEN_DQSTRING '\302'
00055 #define CBF_TOKEN_SCSTRING '\303'
00056 #define CBF_TOKEN_BIN '\304'
00057 #define CBF_TOKEN_MIME_BIN '\305'
00058 #define CBF_TOKEN_TMP_BIN '\306'
00059
00060
00061
00062
00063 #define CBF_INTEGER 0x0010
00064 #define CBF_FLOAT 0x0020
00065 #define CBF_CANONICAL 0x0050
00066 #define CBF_PACKED 0x0060
00067 #define CBF_BYTE_OFFSET 0x0070
00068 #define CBF_PREDICTOR 0x0080
00069 #define CBF_NONE 0x0040
00070
00071
00072
00073
00074 #define PLAIN_HEADERS 0x0001
00075 #define MIME_HEADERS 0x0002
00076 #define MSG_NODIGEST 0x0004
00077 #define MSG_DIGEST 0x0008
00078 #define MSG_DIGESTNOW 0x0010
00079
00080 #define HDR_DEFAULT (MIME_HEADERS | MSG_NODIGEST)
00081
00082 #define MIME_NOHEADERS PLAIN_HEADERS
00083
00084
00085
00086
00087 #define CBF 0x0000
00088 #define CIF 0x0001
00089
00090
00091
00092
00093 #define ENC_NONE 0x0001
00094 #define ENC_BASE64 0x0002
00095 #define ENC_QP 0x0004
00096 #define ENC_BASE10 0x0008
00097 #define ENC_BASE16 0x0010
00098 #define ENC_BASE8 0x0020
00099 #define ENC_FORWARD 0x0040
00100 #define ENC_BACKWARD 0x0080
00101 #define ENC_CRTERM 0x0100
00102 #define ENC_LFTERM 0x0200
00103
00104 #define ENC_DEFAULT (ENC_BASE64 | ENC_LFTERM | ENC_FORWARD)
00105
00106
00107
00108
00109 #ifdef CBFDEBUG
00110
00111 #define cbf_failnez(x) {int err; err = (x); if (err) { fprintf (stderr, \
00112 "\nCBFlib error %d in \"x\"\n", err); return err; }}
00113
00114 #define cbf_onfailnez(x,c) {int err; err = (x); if (err) { fprintf (stderr, \
00115 "\nCBFlib error %d in \"x\"\n", err); \
00116 { c; } return err; }}
00117
00118 #else
00119
00120 #define cbf_failnez(f) { int err; err = (f); if (err) return err; }
00121
00122 #define cbf_onfailnez(f,c) { int err; err = (f); if (err) {{ c; } return err; }}
00123
00124 #endif
00125
00126
00127
00128
00129 typedef struct
00130 {
00131 cbf_node *node;
00132
00133 int row, search_row;
00134 }
00135 cbf_handle_struct;
00136
00137 typedef cbf_handle_struct *cbf_handle;
00138
00139
00140
00141
00142
00143
00144 int cbf_make_handle (cbf_handle *handle);
00145
00146
00147
00148
00149 int cbf_free_handle (cbf_handle handle);
00150
00151
00152
00153
00154 int cbf_read_file (cbf_handle handle, FILE *stream, int headers);
00155
00156
00157
00158
00159 int cbf_write_file (cbf_handle handle, FILE *stream, int isbuffer,
00160 int ciforcbf,
00161 int headers,
00162 int encoding);
00163
00164
00165
00166
00167 int cbf_new_datablock (cbf_handle handle, const char *datablockname);
00168
00169
00170
00171
00172 int cbf_force_new_datablock (cbf_handle handle, const char *datablockname);
00173
00174
00175
00176
00177 int cbf_new_category (cbf_handle handle, const char *categoryname);
00178
00179
00180
00181
00182 int cbf_force_new_category (cbf_handle handle, const char *categoryname);
00183
00184
00185
00186
00187 int cbf_new_column (cbf_handle handle, const char *columnname);
00188
00189
00190
00191
00192 int cbf_new_row (cbf_handle handle);
00193
00194
00195
00196
00197 int cbf_insert_row (cbf_handle handle, const int rownumber);
00198
00199
00200
00201
00202 int cbf_delete_row (cbf_handle handle, const int rownumber);
00203
00204
00205
00206
00207 int cbf_set_datablockname (cbf_handle handle, const char *datablockname);
00208
00209
00210
00211
00212 int cbf_reset_datablocks (cbf_handle handle);
00213
00214
00215
00216
00217 int cbf_reset_datablock (cbf_handle handle);
00218
00219
00220
00221
00222 int cbf_reset_category (cbf_handle handle);
00223
00224
00225
00226
00227 int cbf_remove_datablock (cbf_handle handle);
00228
00229
00230
00231
00232 int cbf_remove_category (cbf_handle handle);
00233
00234
00235
00236
00237 int cbf_remove_column (cbf_handle handle);
00238
00239
00240
00241
00242 int cbf_remove_row (cbf_handle handle);
00243
00244
00245
00246
00247 int cbf_rewind_datablock (cbf_handle handle);
00248
00249
00250
00251
00252 int cbf_rewind_category (cbf_handle handle);
00253
00254
00255
00256
00257 int cbf_rewind_column (cbf_handle handle);
00258
00259
00260
00261
00262 int cbf_rewind_row (cbf_handle handle);
00263
00264
00265
00266
00267 int cbf_next_datablock (cbf_handle handle);
00268
00269
00270
00271
00272 int cbf_next_category (cbf_handle handle);
00273
00274
00275
00276
00277 int cbf_next_column (cbf_handle handle);
00278
00279
00280
00281
00282 int cbf_next_row (cbf_handle handle);
00283
00284
00285
00286
00287 int cbf_find_datablock (cbf_handle handle, const char *datablockname);
00288
00289
00290
00291
00292 int cbf_find_category (cbf_handle handle, const char *categoryname);
00293
00294
00295
00296
00297 int cbf_find_column (cbf_handle handle, const char *columnname);
00298
00299
00300
00301
00302 int cbf_find_row (cbf_handle handle, const char *value);
00303
00304
00305
00306
00307 int cbf_find_nextrow (cbf_handle handle, const char *value);
00308
00309
00310
00311
00312 int cbf_count_datablocks (cbf_handle handle, unsigned int *datablocks);
00313
00314
00315
00316
00317 int cbf_count_categories (cbf_handle handle, unsigned int *categories);
00318
00319
00320
00321
00322 int cbf_count_columns (cbf_handle handle, unsigned int *columns);
00323
00324
00325
00326
00327 int cbf_count_rows (cbf_handle handle, unsigned int *rows);
00328
00329
00330
00331
00332 int cbf_select_datablock (cbf_handle handle, unsigned int datablock);
00333
00334
00335
00336
00337 int cbf_select_category (cbf_handle handle, unsigned int category);
00338
00339
00340
00341
00342 int cbf_select_column (cbf_handle handle, unsigned int column);
00343
00344
00345
00346
00347 int cbf_select_row (cbf_handle handle, unsigned int row);
00348
00349
00350
00351
00352 int cbf_datablock_name (cbf_handle handle, const char **datablockname);
00353
00354
00355
00356
00357 int cbf_category_name (cbf_handle handle, const char **categoryname);
00358
00359
00360
00361
00362 int cbf_column_name (cbf_handle handle, const char **columnname);
00363
00364
00365
00366
00367 int cbf_row_number (cbf_handle handle, unsigned int *row);
00368
00369
00370
00371
00372 int cbf_get_value (cbf_handle handle, const char **value);
00373
00374
00375
00376
00377 int cbf_set_value (cbf_handle handle, const char *value);
00378
00379
00380
00381
00382 int cbf_get_integervalue (cbf_handle handle, int *number);
00383
00384
00385
00386
00387 int cbf_get_doublevalue (cbf_handle handle, double *number);
00388
00389
00390
00391
00392 int cbf_set_integervalue (cbf_handle handle, int number);
00393
00394
00395
00396
00397 int cbf_set_doublevalue (cbf_handle handle, const char *format, double number);
00398
00399
00400
00401
00402 int cbf_get_integerarrayparameters (cbf_handle handle,
00403 unsigned int *compression,
00404 int *id,
00405 size_t *elsize,
00406 int *elsigned,
00407 int *elunsigned,
00408 size_t *nelem,
00409 int *minelem,
00410 int *maxelem);
00411
00412
00413
00414
00415 int cbf_get_integerarray (cbf_handle handle,
00416 int *id,
00417 void *value,
00418 size_t elsize,
00419 int elsign,
00420 size_t nelem,
00421 size_t *nelem_read);
00422
00423
00424
00425
00426 int cbf_set_integerarray (cbf_handle handle,
00427 unsigned int compression,
00428 int id,
00429 void *value,
00430 size_t elsize,
00431 int elsign,
00432 size_t nelem);
00433
00434
00435 #ifdef __cplusplus
00436
00437 }
00438
00439 #endif
00440
00441 #endif
00442