cbf.h

Go to the documentation of this file.
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   /* Currently the cbf library assumes a 32-bit or larger integer */
00018 
00019 #if UINT_MAX / 65535U < 65535U
00020 #error cbflib assumes int is at least 32 bits
00021 #endif
00022 
00023 
00024   /* Maximum line length */
00025 
00026 #define CBF_LINELENGTH 80
00027 
00028 
00029   /* Error codes */
00030 
00031 #define CBF_FORMAT           0x00000001  /*     1 */
00032 #define CBF_ALLOC            0x00000002  /*     2 */
00033 #define CBF_ARGUMENT         0x00000004  /*     4 */
00034 #define CBF_ASCII            0x00000008  /*     8 */
00035 #define CBF_BINARY           0x00000010  /*    16 */
00036 #define CBF_BITCOUNT         0x00000020  /*    32 */
00037 #define CBF_ENDOFDATA        0x00000040  /*    64 */
00038 #define CBF_FILECLOSE        0x00000080  /*   128 */
00039 #define CBF_FILEOPEN         0x00000100  /*   256 */
00040 #define CBF_FILEREAD         0x00000200  /*   512 */
00041 #define CBF_FILESEEK         0x00000400  /*  1024 */
00042 #define CBF_FILETELL         0x00000800  /*  2048 */
00043 #define CBF_FILEWRITE        0x00001000  /*  4096 */
00044 #define CBF_IDENTICAL        0x00002000  /*  8192 */
00045 #define CBF_NOTFOUND         0x00004000  /* 16384 */
00046 #define CBF_OVERFLOW         0x00008000  /* 32768 */
00047 
00048 
00049   /* Token Type Strings */
00050   
00051 #define CBF_TOKEN_NULL       '\377'
00052 #define CBF_TOKEN_WORD       '\300'     /* Simple word                 */
00053 #define CBF_TOKEN_SQSTRING   '\301'     /* Single-quoted string        */
00054 #define CBF_TOKEN_DQSTRING   '\302'     /* Double-quoted string        */
00055 #define CBF_TOKEN_SCSTRING   '\303'     /* Semicolon-delimited string  */
00056 #define CBF_TOKEN_BIN        '\304'     /* Binary section              */
00057 #define CBF_TOKEN_MIME_BIN   '\305'     /* Mime-encoded binary section */
00058 #define CBF_TOKEN_TMP_BIN    '\306'     /* Temporary binary section    */
00059 
00060 
00061   /* Constants used for compression */
00062 
00063 #define CBF_INTEGER     0x0010  /* Uncompressed integer               */
00064 #define CBF_FLOAT       0x0020  /* Uncompressed IEEE floating-point   */
00065 #define CBF_CANONICAL   0x0050  /* Canonical compression              */
00066 #define CBF_PACKED      0x0060  /* Packed compression                 */
00067 #define CBF_BYTE_OFFSET 0x0070  /* Byte Offset Compression            */
00068 #define CBF_PREDICTOR   0x0080  /* Predictor_Huffman Compression      */
00069 #define CBF_NONE        0x0040  /* No compression flag                */
00070 
00071 
00072   /* Constants used for headers */
00073 
00074 #define PLAIN_HEADERS   0x0001  /* Use plain ASCII headers            */
00075 #define MIME_HEADERS    0x0002  /* Use MIME headers                   */
00076 #define MSG_NODIGEST    0x0004  /* Do not check message digests       */
00077 #define MSG_DIGEST      0x0008  /* Check message digests              */
00078 #define MSG_DIGESTNOW   0x0010  /* Check message digests immediately  */
00079 
00080 #define HDR_DEFAULT (MIME_HEADERS | MSG_NODIGEST)
00081 
00082 #define MIME_NOHEADERS  PLAIN_HEADERS
00083 
00084 
00085   /* CBF vs CIF */
00086 
00087 #define CBF             0x0000  /* Use simple binary sections         */
00088 #define CIF             0x0001  /* Use MIME-encoded binary sections   */
00089 
00090 
00091   /* Constants used for encoding */
00092 
00093 #define ENC_NONE        0x0001  /* Use BINARY encoding                 */
00094 #define ENC_BASE64      0x0002  /* Use BASE64 encoding                 */
00095 #define ENC_QP          0x0004  /* Use QUOTED-PRINTABLE encoding       */
00096 #define ENC_BASE10      0x0008  /* Use BASE10 encoding                 */
00097 #define ENC_BASE16      0x0010  /* Use BASE16 encoding                 */
00098 #define ENC_BASE8       0x0020  /* Use BASE8  encoding                 */
00099 #define ENC_FORWARD     0x0040  /* Map bytes to words forward (1234)   */
00100 #define ENC_BACKWARD    0x0080  /* Map bytes to words backward (4321)  */
00101 #define ENC_CRTERM      0x0100  /* Terminate lines with CR             */
00102 #define ENC_LFTERM      0x0200  /* Terminate lines with LF             */
00103 
00104 #define ENC_DEFAULT (ENC_BASE64 | ENC_LFTERM | ENC_FORWARD)
00105 
00106 
00107   /* Convenience definitions for functions returning error codes */
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   /* cbf handle */
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   /* Prototypes */
00141 
00142   /* Create a handle */
00143 
00144 int cbf_make_handle (cbf_handle *handle);
00145 
00146 
00147   /* Free a handle */
00148 
00149 int cbf_free_handle (cbf_handle handle);
00150 
00151 
00152   /* Read a file */
00153 
00154 int cbf_read_file (cbf_handle handle, FILE *stream, int headers);
00155 
00156 
00157   /* Write a file */
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   /* Add a data block */
00166 
00167 int cbf_new_datablock (cbf_handle handle, const char *datablockname);
00168 
00169 
00170   /* Add a data block, allowing for duplicates */
00171 
00172 int cbf_force_new_datablock (cbf_handle handle, const char *datablockname);
00173 
00174 
00175   /* Add a category to the current data block */
00176 
00177 int cbf_new_category (cbf_handle handle, const char *categoryname);
00178 
00179 
00180   /* Add a category to the current data block, allowing for duplicates */
00181 
00182 int cbf_force_new_category (cbf_handle handle, const char *categoryname);
00183 
00184 
00185   /* Add a column to the current category */
00186   
00187 int cbf_new_column (cbf_handle handle, const char *columnname);
00188 
00189 
00190   /* Add a row to the current category */
00191 
00192 int cbf_new_row (cbf_handle handle);
00193 
00194 
00195   /* Insert a row in the current category */
00196 
00197 int cbf_insert_row (cbf_handle handle, const int rownumber);
00198 
00199 
00200   /* Delete a row from the current category */
00201 
00202 int cbf_delete_row (cbf_handle handle, const int rownumber);
00203 
00204 
00205   /* Change the name of the current data block */
00206 
00207 int cbf_set_datablockname (cbf_handle handle, const char *datablockname);
00208 
00209 
00210   /* Delete all categories from all the data blocks */
00211 
00212 int cbf_reset_datablocks (cbf_handle handle);
00213 
00214 
00215   /* Delete all categories from the current data block */
00216 
00217 int cbf_reset_datablock (cbf_handle handle);
00218 
00219 
00220   /* Delete all columns and rows from the current category */
00221 
00222 int cbf_reset_category (cbf_handle handle);
00223 
00224 
00225   /* Delete the current data block */
00226 
00227 int cbf_remove_datablock (cbf_handle handle);
00228 
00229 
00230   /* Delete the current category */
00231 
00232 int cbf_remove_category (cbf_handle handle);
00233 
00234 
00235   /* Delete the current column */
00236 
00237 int cbf_remove_column (cbf_handle handle);
00238 
00239 
00240   /* Delete the current row */
00241 
00242 int cbf_remove_row (cbf_handle handle);
00243 
00244 
00245   /* Make the first data block the current data block */
00246 
00247 int cbf_rewind_datablock (cbf_handle handle);
00248 
00249 
00250   /* Make the first category in the current data block the current category */
00251 
00252 int cbf_rewind_category (cbf_handle handle);
00253 
00254 
00255   /* Make the first column in the current category the current column */
00256 
00257 int cbf_rewind_column (cbf_handle handle);
00258 
00259 
00260   /* Make the first row in the current category the current row */
00261 
00262 int cbf_rewind_row (cbf_handle handle);
00263 
00264 
00265   /* Make the next data block the current data block */
00266 
00267 int cbf_next_datablock (cbf_handle handle);
00268 
00269 
00270   /* Make the next category in the current data block the current category */
00271 
00272 int cbf_next_category (cbf_handle handle);
00273 
00274 
00275   /* Make the next column in the current category the current column */
00276 
00277 int cbf_next_column (cbf_handle handle);
00278 
00279 
00280   /* Make the next row in the current category the current row */
00281 
00282 int cbf_next_row (cbf_handle handle);
00283 
00284 
00285   /* Make the named data block the current data block */
00286 
00287 int cbf_find_datablock (cbf_handle handle, const char *datablockname);
00288 
00289 
00290   /* Make the named category in the current data block the current category */
00291 
00292 int cbf_find_category (cbf_handle handle, const char *categoryname);
00293 
00294 
00295   /* Make the named column in the current category the current column */
00296 
00297 int cbf_find_column (cbf_handle handle, const char *columnname);
00298 
00299 
00300   /* Make the first row with matching value the current row */
00301 
00302 int cbf_find_row (cbf_handle handle, const char *value);
00303 
00304 
00305   /* Make the next row with matching value the current row */
00306 
00307 int cbf_find_nextrow (cbf_handle handle, const char *value);
00308 
00309 
00310   /* Count the data blocks */
00311 
00312 int cbf_count_datablocks (cbf_handle handle, unsigned int *datablocks);
00313 
00314 
00315   /* Count the categories in the current data block */
00316 
00317 int cbf_count_categories (cbf_handle handle, unsigned int *categories);
00318 
00319 
00320   /* Count the columns in the current category */
00321 
00322 int cbf_count_columns (cbf_handle handle, unsigned int *columns);
00323 
00324 
00325   /* Count the rows in the current category */
00326 
00327 int cbf_count_rows (cbf_handle handle, unsigned int *rows);
00328 
00329 
00330   /* Make the specified data block the current data block */
00331 
00332 int cbf_select_datablock (cbf_handle handle, unsigned int datablock);
00333 
00334 
00335   /* Make the specified category the current category */
00336 
00337 int cbf_select_category (cbf_handle handle, unsigned int category);
00338 
00339 
00340   /* Make the specified column the current column */
00341 
00342 int cbf_select_column (cbf_handle handle, unsigned int column);
00343 
00344 
00345   /* Make the specified row the current row */
00346 
00347 int cbf_select_row (cbf_handle handle, unsigned int row);
00348 
00349 
00350   /* Get the name of the current data block */
00351   
00352 int cbf_datablock_name (cbf_handle handle, const char **datablockname);
00353 
00354 
00355   /* Get the name of the current category */
00356   
00357 int cbf_category_name (cbf_handle handle, const char **categoryname);
00358 
00359 
00360   /* Get the name of the current column */
00361   
00362 int cbf_column_name (cbf_handle handle, const char **columnname);
00363 
00364 
00365   /* Get the number of the current row */
00366   
00367 int cbf_row_number (cbf_handle handle, unsigned int *row);
00368 
00369 
00370   /* Get the ascii value of the current (row, column) entry */
00371   
00372 int cbf_get_value (cbf_handle handle, const char **value);
00373 
00374 
00375   /* Set the ascii value of the current (row, column) entry */
00376   
00377 int cbf_set_value (cbf_handle handle, const char *value);
00378 
00379 
00380   /* Get the (int) numeric value of the current (row, column) entry */
00381   
00382 int cbf_get_integervalue (cbf_handle handle, int *number);
00383 
00384 
00385   /* Get the (double) numeric value of the current (row, column) entry */
00386   
00387 int cbf_get_doublevalue (cbf_handle handle, double *number);
00388 
00389 
00390   /* Set the ascii value of the current (row, column) entry from an int */
00391   
00392 int cbf_set_integervalue (cbf_handle handle, int number);
00393 
00394 
00395   /* Set the ascii value of the current (row, column) entry from a double */
00396   
00397 int cbf_set_doublevalue (cbf_handle handle, const char *format, double number);
00398 
00399 
00400   /* Get the parameters of the current (row, column) array entry */
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   /* Get the value of the current (row, column) array entry */
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   /* Set the value of the current (row, column) array entry */
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 /* CBF_H */
00442