#include "cbf.h"
#include "cbf_alloc.h"
#include "cbf_binary.h"
#include "cbf_write.h"
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Functions | |
int | cbf_parse (void *context) |
int | cbf_make_handle (cbf_handle *handle) |
int | cbf_free_handle (cbf_handle handle) |
int | cbf_read_file (cbf_handle handle, FILE *stream, int headers) |
int | cbf_write_file (cbf_handle handle, FILE *stream, int isbuffer, int ciforcbf, int headers, int encoding) |
int | cbf_new_datablock (cbf_handle handle, const char *datablockname) |
int | cbf_force_new_datablock (cbf_handle handle, const char *datablockname) |
int | cbf_new_category (cbf_handle handle, const char *categoryname) |
int | cbf_force_new_category (cbf_handle handle, const char *categoryname) |
int | cbf_new_column (cbf_handle handle, const char *columnname) |
int | cbf_new_row (cbf_handle handle) |
int | cbf_insert_row (cbf_handle handle, const int rownumber) |
int | cbf_delete_row (cbf_handle handle, const int rownumber) |
int | cbf_set_datablockname (cbf_handle handle, const char *datablockname) |
int | cbf_reset_datablocks (cbf_handle handle) |
int | cbf_reset_datablock (cbf_handle handle) |
int | cbf_reset_category (cbf_handle handle) |
int | cbf_remove_datablock (cbf_handle handle) |
int | cbf_remove_category (cbf_handle handle) |
int | cbf_remove_column (cbf_handle handle) |
int | cbf_remove_row (cbf_handle handle) |
int | cbf_rewind_datablock (cbf_handle handle) |
int | cbf_rewind_category (cbf_handle handle) |
int | cbf_rewind_column (cbf_handle handle) |
int | cbf_rewind_row (cbf_handle handle) |
int | cbf_next_datablock (cbf_handle handle) |
int | cbf_next_category (cbf_handle handle) |
int | cbf_next_column (cbf_handle handle) |
int | cbf_next_row (cbf_handle handle) |
int | cbf_select_datablock (cbf_handle handle, unsigned int datablock) |
int | cbf_select_category (cbf_handle handle, unsigned int category) |
int | cbf_select_column (cbf_handle handle, unsigned int column) |
int | cbf_select_row (cbf_handle handle, unsigned int row) |
int | cbf_find_datablock (cbf_handle handle, const char *datablockname) |
int | cbf_find_category (cbf_handle handle, const char *categoryname) |
int | cbf_find_column (cbf_handle handle, const char *columnname) |
int | cbf_find_row (cbf_handle handle, const char *value) |
int | cbf_find_nextrow (cbf_handle handle, const char *value) |
int | cbf_count_datablocks (cbf_handle handle, unsigned int *datablocks) |
int | cbf_count_categories (cbf_handle handle, unsigned int *categories) |
int | cbf_count_columns (cbf_handle handle, unsigned int *columns) |
int | cbf_count_rows (cbf_handle handle, unsigned int *rows) |
int | cbf_datablock_name (cbf_handle handle, const char **datablockname) |
int | cbf_category_name (cbf_handle handle, const char **categoryname) |
int | cbf_column_name (cbf_handle handle, const char **columnname) |
int | cbf_row_number (cbf_handle handle, unsigned int *row) |
int | cbf_get_value (cbf_handle handle, const char **value) |
int | cbf_set_value (cbf_handle handle, const char *value) |
int | cbf_get_integervalue (cbf_handle handle, int *number) |
int | cbf_get_doublevalue (cbf_handle handle, double *number) |
int | cbf_set_integervalue (cbf_handle handle, int number) |
int | cbf_set_doublevalue (cbf_handle handle, const char *format, double number) |
int | cbf_get_integerarrayparameters (cbf_handle handle, unsigned int *compression, int *id, size_t *elsize, int *elsigned, int *elunsigned, size_t *nelem, int *minelem, int *maxelem) |
int | cbf_get_integerarray (cbf_handle handle, int *id, void *value, size_t elsize, int elsign, size_t nelem, size_t *nelem_read) |
int | cbf_set_integerarray (cbf_handle handle, unsigned int compression, int id, void *value, size_t elsize, int elsign, size_t nelem) |
void | cbf_warning (const char *message) |
void | cbf_error (const char *message) |
int cbf_category_name | ( | cbf_handle | handle, |
const char ** | categoryname | ||
) |
Definition at line 1844 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_failnez, cbf_find_parent(), cbf_get_name(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Get the name */ return cbf_get_name (categoryname, node); }
int cbf_column_name | ( | cbf_handle | handle, |
const char ** | columnname | ||
) |
Definition at line 1866 of file cbf.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_failnez, cbf_find_parent(), cbf_get_name(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the column node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_COLUMN)) /* Get the name */ return cbf_get_name (columnname, node); }
int cbf_count_categories | ( | cbf_handle | handle, |
unsigned int * | categories | ||
) |
Definition at line 1715 of file cbf.c.
References CBF_ARGUMENT, cbf_count_children(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Count the categories */ return cbf_count_children (categories, node); }
int cbf_count_columns | ( | cbf_handle | handle, |
unsigned int * | columns | ||
) |
Definition at line 1737 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_count_children(), cbf_failnez, cbf_find_parent(), and cbf_handle_struct::node.
Referenced by cbf_delete_row(), cbf_insert_row(), and cbf_new_row().
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Count the columns */ return cbf_count_children (columns, node); }
int cbf_count_datablocks | ( | cbf_handle | handle, |
unsigned int * | datablocks | ||
) |
Definition at line 1693 of file cbf.c.
References CBF_ARGUMENT, cbf_count_children(), cbf_failnez, cbf_find_parent(), CBF_ROOT, and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Count the data blocks */ return cbf_count_children (datablocks, node); }
int cbf_count_rows | ( | cbf_handle | handle, |
unsigned int * | rows | ||
) |
Definition at line 1759 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_count_children(), cbf_failnez, cbf_find_parent(), CBF_FORMAT, cbf_get_child(), and cbf_handle_struct::node.
Referenced by cbf_delete_row(), cbf_insert_row(), cbf_new_column(), and cbf_new_row().
{ cbf_node *node, *parent; unsigned int columns, column, columnrows, categoryrows; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&parent, handle->node, CBF_CATEGORY)) /* Count the columns */ cbf_failnez (cbf_count_children (&columns, parent)) /* Get the size of each column */ categoryrows = 0; for (column = 0; column < columns; column++) { /* Get the column */ cbf_failnez (cbf_get_child (&node, parent, column)) /* Count the number of rows */ cbf_failnez (cbf_count_children (&columnrows, node)) /* Is it the same size as the other columns? */ if (column == 0) categoryrows = columnrows; else if (categoryrows != columnrows) return CBF_FORMAT; } if (rows) *rows = categoryrows; /* Success */ return 0; }
int cbf_datablock_name | ( | cbf_handle | handle, |
const char ** | datablockname | ||
) |
Definition at line 1822 of file cbf.c.
References CBF_ARGUMENT, CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_get_name(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Get the name */ return cbf_get_name (datablockname, node); }
int cbf_delete_row | ( | cbf_handle | handle, |
const int | rownumber | ||
) |
Definition at line 825 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_count_columns(), cbf_count_rows(), cbf_delete_columnrow(), cbf_failnez, cbf_find_parent(), cbf_get_child(), cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by cbf_remove_row().
{ cbf_node *node, *columnnode; int errorcode [2]; unsigned int rows, columns, column; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* How many rows and columns does this category have? */ cbf_failnez (cbf_count_rows (handle, &rows)) cbf_failnez (cbf_count_columns (handle, &columns)) /* Delete a row from each column */ errorcode [0] = 0; for (column = 0; column < columns; column++) { errorcode [1] = cbf_get_child (&columnnode, node, column); if (!errorcode [1]) errorcode [1] = cbf_delete_columnrow (columnnode, rownumber); errorcode [0] |= errorcode [1]; } rows--; if (handle->row > rownumber) handle->row--; if (handle->search_row > rownumber) handle->search_row--; return errorcode [0]; }
void cbf_error | ( | const char * | message | ) |
int cbf_find_category | ( | cbf_handle | handle, |
const char * | categoryname | ||
) |
Definition at line 1552 of file cbf.c.
References CBF_ARGUMENT, CBF_DATABLOCK, cbf_failnez, cbf_find_child(), cbf_find_parent(), cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by GetCIFData(), and GetCIFHeader().
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Find the category */ cbf_failnez (cbf_find_child (&node, node, categoryname)) handle->node = node; handle->row = 0; handle->search_row = 0; /* Success */ return 0; }
int cbf_find_column | ( | cbf_handle | handle, |
const char * | columnname | ||
) |
Definition at line 1585 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_failnez, cbf_find_child(), cbf_find_parent(), and cbf_handle_struct::node.
Referenced by GetCIFData(), and GetCIFHeader().
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Find the column */ cbf_failnez (cbf_find_child (&node, node, columnname)) handle->node = node; /* Success */ return 0; }
int cbf_find_datablock | ( | cbf_handle | handle, |
const char * | datablockname | ||
) |
Definition at line 1523 of file cbf.c.
References CBF_ARGUMENT, cbf_failnez, cbf_find_child(), cbf_find_parent(), CBF_ROOT, and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Find the data block */ cbf_failnez (cbf_find_child (&node, node, datablockname)) handle->node = node; /* Success */ return 0; }
int cbf_find_nextrow | ( | cbf_handle | handle, |
const char * | value | ||
) |
Definition at line 1624 of file cbf.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_count_children(), cbf_failnez, cbf_find_parent(), cbf_get_columnrow(), cbf_is_binary(), CBF_NOTFOUND, cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by cbf_find_row(), and GetCIFHeader().
{ cbf_node *node; unsigned int row, rows; const char *text; if (!handle) return CBF_ARGUMENT; /* Find the column node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_COLUMN)) /* Count the rows */ cbf_failnez (cbf_count_children (&rows, node)) for (row = handle->search_row; row < rows; row++) { /* Is the value ascii? */ if (cbf_is_binary (node, row)) continue; /* Get the value of the current row */ cbf_failnez (cbf_get_columnrow (&text, node, row)) /* Compare the values */ if (text && value) { if (strcmp (text + 1, value)) continue; } else if (text != value) continue; /* Found a match */ handle->row = row; handle->search_row = row + 1; return 0; } /* Fail */ return CBF_NOTFOUND; }
int cbf_find_row | ( | cbf_handle | handle, |
const char * | value | ||
) |
Definition at line 1614 of file cbf.c.
References cbf_failnez, cbf_find_nextrow(), and cbf_rewind_row().
Referenced by GetCIFData().
{ cbf_failnez (cbf_rewind_row (handle)) return cbf_find_nextrow (handle, value); }
int cbf_force_new_category | ( | cbf_handle | handle, |
const char * | categoryname | ||
) |
Definition at line 567 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, CBF_CATEGORY, cbf_copy_string(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_string(), cbf_make_new_child(), and cbf_handle_struct::node.
Referenced by PutCIFHeader().
{ cbf_node *node; int errorcode; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Copy the name */ if (categoryname) { categoryname = cbf_copy_string (NULL, categoryname, 0); if (!categoryname) return CBF_ALLOC; } /* Add a category */ errorcode = cbf_make_new_child (&node, node, CBF_CATEGORY, categoryname); if (errorcode) { cbf_free_string (NULL, categoryname); return errorcode; } /* Success */ handle->node = node; return 0; }
int cbf_force_new_datablock | ( | cbf_handle | handle, |
const char * | datablockname | ||
) |
Definition at line 467 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, cbf_copy_string(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_string(), cbf_make_new_child(), CBF_ROOT, and cbf_handle_struct::node.
{ cbf_node *node; int errorcode; if (!handle) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Copy the name */ if (datablockname) { datablockname = cbf_copy_string (NULL, datablockname, 0); if (!datablockname) return CBF_ALLOC; } /* Add a datablock */ errorcode = cbf_make_new_child (&node, node, CBF_DATABLOCK, datablockname); if (errorcode) { cbf_free_string (NULL, datablockname); return errorcode; } /* Success */ handle->node = node; return 0; }
int cbf_free_handle | ( | cbf_handle | handle | ) |
Definition at line 159 of file cbf.c.
References cbf_free(), cbf_free_node(), and cbf_handle_struct::node.
Referenced by GetCIFData(), and PutCIFData().
{ int errorcode; if (handle) { errorcode = cbf_free_node (handle->node); return errorcode | cbf_free ((void **) &handle, NULL); } return 0; }
int cbf_get_doublevalue | ( | cbf_handle | handle, |
double * | number | ||
) |
Definition at line 2022 of file cbf.c.
References cbf_failnez, cbf_get_value(), and CBF_NOTFOUND.
Referenced by GetCIFHeader().
{ const char *value; /* Get the value */ cbf_failnez (cbf_get_value (handle, &value)) /* Convert it into a double */ if (!value) return CBF_NOTFOUND; if (number) *number = atof (value); /* Success */ return 0; }
int cbf_get_integerarray | ( | cbf_handle | handle, |
int * | id, | ||
void * | value, | ||
size_t | elsize, | ||
int | elsign, | ||
size_t | nelem, | ||
size_t * | nelem_read | ||
) |
Definition at line 2122 of file cbf.c.
References CBF_ARGUMENT, cbf_get_binary(), cbf_handle_struct::node, and cbf_handle_struct::row.
Referenced by GetCIFData().
{ if (!handle) return CBF_ARGUMENT; return cbf_get_binary (handle->node, handle->row, id, value, elsize, elsign, nelem, nelem_read); }
int cbf_get_integerarrayparameters | ( | cbf_handle | handle, |
unsigned int * | compression, | ||
int * | id, | ||
size_t * | elsize, | ||
int * | elsigned, | ||
int * | elunsigned, | ||
size_t * | nelem, | ||
int * | minelem, | ||
int * | maxelem | ||
) |
Definition at line 2087 of file cbf.c.
References CBF_ARGUMENT, CBF_ASCII, cbf_binary_parameters(), cbf_is_binary(), cbf_handle_struct::node, and cbf_handle_struct::row.
Referenced by GetCIFData().
{ /* Check the arguments */ if (!handle) return CBF_ARGUMENT; /* Is the value binary? */ if (!cbf_is_binary (handle->node, handle->row)) return CBF_ASCII; /* Get the parameters */ return cbf_binary_parameters (handle->node, handle->row, compression, id, NULL, elsize, elsigned, elunsigned, nelem, minelem, maxelem); }
int cbf_get_integervalue | ( | cbf_handle | handle, |
int * | number | ||
) |
Definition at line 1993 of file cbf.c.
References cbf_failnez, cbf_get_value(), and CBF_NOTFOUND.
Referenced by GetCIFHeader().
{ const char *value; /* Get the value */ cbf_failnez (cbf_get_value (handle, &value)) /* Convert it into an integer */ if (!value) return CBF_NOTFOUND; if (number) *number = atoi (value); /* Success */ return 0; }
int cbf_get_value | ( | cbf_handle | handle, |
const char ** | value | ||
) |
Definition at line 1907 of file cbf.c.
References CBF_ARGUMENT, CBF_BINARY, cbf_failnez, cbf_get_columnrow(), cbf_is_binary(), cbf_handle_struct::node, and cbf_handle_struct::row.
Referenced by cbf_get_doublevalue(), cbf_get_integervalue(), and GetCIFHeader().
{ const char *text; /* Check the arguments */ if (!handle) return CBF_ARGUMENT; /* Is the value binary? */ if (cbf_is_binary (handle->node, handle->row)) return CBF_BINARY; /* Get the value */ cbf_failnez (cbf_get_columnrow (&text, handle->node, handle->row)) if (value) if (text) *value = text + 1; else *value = NULL; /* Success */ return 0; }
int cbf_insert_row | ( | cbf_handle | handle, |
const int | rownumber | ||
) |
Definition at line 756 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_count_columns(), cbf_count_rows(), cbf_delete_columnrow(), cbf_failnez, cbf_find_parent(), cbf_get_child(), cbf_insert_columnrow(), cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
{ cbf_node *node, *columnnode; int errorcode [2]; unsigned int rows, columns, column; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* How many rows and columns does this category have? */ cbf_failnez (cbf_count_rows (handle, &rows)) cbf_failnez (cbf_count_columns (handle, &columns)) /* Insert a row into each column */ for (column = 0; column < columns; column++) { errorcode [0] = cbf_get_child (&columnnode, node, column); if (!errorcode [0]) errorcode [0] = cbf_insert_columnrow (columnnode, rownumber, NULL); if (errorcode [0]) { /* Set the columns back to the original number of rows */ while (column) { column--; errorcode [1] = cbf_get_child (&columnnode, node, column); if (!errorcode [1]) errorcode [1] |= cbf_delete_columnrow (columnnode, rownumber); errorcode [0] |= errorcode [1]; } return errorcode [0]; } } /* Success */ handle->row = rownumber; handle->search_row = rownumber; return 0; }
int cbf_make_handle | ( | cbf_handle * | handle | ) |
Definition at line 137 of file cbf.c.
References cbf_alloc(), cbf_failnez, cbf_free(), cbf_make_node(), and CBF_ROOT.
Referenced by GetCIFHeader(), and PutCIFHeader().
{ int errorcode; cbf_failnez (cbf_alloc ((void **) handle, NULL, sizeof (cbf_handle), 1)) errorcode = cbf_make_node (&(*handle)->node, CBF_ROOT, NULL, NULL); if (errorcode) return errorcode | cbf_free ((void **) handle, NULL); (*handle)->row = 0; (*handle)->search_row = 0; return 0; }
int cbf_new_category | ( | cbf_handle | handle, |
const char * | categoryname | ||
) |
Definition at line 517 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, CBF_CATEGORY, cbf_copy_string(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_string(), cbf_make_child(), and cbf_handle_struct::node.
{ cbf_node *node; int errorcode; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Copy the name */ if (categoryname) { categoryname = cbf_copy_string (NULL, categoryname, 0); if (!categoryname) return CBF_ALLOC; } /* Add a category */ errorcode = cbf_make_child (&node, node, CBF_CATEGORY, categoryname); if (errorcode) { cbf_free_string (NULL, categoryname); return errorcode; } /* Success */ handle->node = node; return 0; }
int cbf_new_column | ( | cbf_handle | handle, |
const char * | columnname | ||
) |
Definition at line 617 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, CBF_CATEGORY, CBF_COLUMN, cbf_copy_string(), cbf_count_rows(), cbf_failnez, cbf_find_parent(), cbf_free_node(), cbf_free_string(), cbf_make_child(), cbf_set_children(), cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by PutCIFHeader().
{ cbf_node *node; int errorcode; unsigned int rows; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* How many rows does this category have? */ cbf_failnez (cbf_count_rows (handle, &rows)) /* Copy the name */ if (columnname) { columnname = cbf_copy_string (NULL, columnname, 0); if (!columnname) return CBF_ALLOC; } /* Add a column */ errorcode = cbf_make_child (&node, node, CBF_COLUMN, columnname); if (errorcode) { cbf_free_string (NULL, columnname); return errorcode; } /* Set the number of rows */ errorcode = cbf_set_children (node, rows); if (errorcode) return errorcode | cbf_free_node (node); /* Success */ handle->node = node; handle->row = 0; handle->search_row = 0; return 0; }
int cbf_new_datablock | ( | cbf_handle | handle, |
const char * | datablockname | ||
) |
Definition at line 417 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, cbf_copy_string(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_string(), cbf_make_child(), CBF_ROOT, and cbf_handle_struct::node.
Referenced by PutCIFHeader().
{ cbf_node *node; int errorcode; if (!handle) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Copy the name */ if (datablockname) { datablockname = cbf_copy_string (NULL, datablockname, 0); if (!datablockname) return CBF_ALLOC; } /* Add a datablock */ errorcode = cbf_make_child (&node, node, CBF_DATABLOCK, datablockname); if (errorcode) { cbf_free_string (NULL, datablockname); return errorcode; } /* Success */ handle->node = node; return 0; }
int cbf_new_row | ( | cbf_handle | handle | ) |
Definition at line 687 of file cbf.c.
References cbf_add_columnrow(), CBF_ARGUMENT, CBF_CATEGORY, cbf_count_columns(), cbf_count_rows(), cbf_failnez, cbf_find_parent(), cbf_get_child(), cbf_set_children(), cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by PutCIFHeader().
{ cbf_node *node, *columnnode; int errorcode [2]; unsigned int rows, columns, column; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* How many rows and columns does this category have? */ cbf_failnez (cbf_count_rows (handle, &rows)) cbf_failnez (cbf_count_columns (handle, &columns)) /* Add a row to each column */ for (column = 0; column < columns; column++) { errorcode [0] = cbf_get_child (&columnnode, node, column); if (!errorcode [0]) errorcode [0] = cbf_add_columnrow (columnnode, NULL); if (errorcode [0]) { /* Set the columns back to the original number of rows */ while (column) { column--; errorcode [1] = cbf_get_child (&columnnode, node, column); if (!errorcode [1]) errorcode [1] |= cbf_set_children (columnnode, rows); errorcode [0] |= errorcode [1]; } return errorcode [0]; } } /* Success */ handle->row = rows; handle->search_row = rows; return 0; }
int cbf_next_category | ( | cbf_handle | handle | ) |
Definition at line 1280 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_child_index(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_get_child(), and cbf_handle_struct::node.
{ cbf_node *parent, *node; unsigned int index; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Find the data block node */ cbf_failnez (cbf_find_parent (&parent, node, CBF_DATABLOCK)) /* Which child is this? */ cbf_failnez (cbf_child_index (&index, node)) /* Get the next category */ cbf_failnez (cbf_get_child (&node, parent, index + 1)) handle->node = node; /* Success */ return 0; }
int cbf_next_column | ( | cbf_handle | handle | ) |
Definition at line 1321 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_child_index(), CBF_COLUMN, cbf_failnez, cbf_find_parent(), cbf_get_child(), and cbf_handle_struct::node.
{ cbf_node *parent, *node; unsigned int index; if (!handle) return CBF_ARGUMENT; /* Find the column node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_COLUMN)) /* Find the category node */ cbf_failnez (cbf_find_parent (&parent, node, CBF_CATEGORY)) /* Which child is this? */ cbf_failnez (cbf_child_index (&index, node)) /* Get the next column */ cbf_failnez (cbf_get_child (&node, parent, index + 1)) handle->node = node; /* Success */ return 0; }
int cbf_next_datablock | ( | cbf_handle | handle | ) |
Definition at line 1239 of file cbf.c.
References CBF_ARGUMENT, cbf_child_index(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_get_child(), CBF_ROOT, and cbf_handle_struct::node.
{ cbf_node *parent, *node; unsigned int index; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Find the root node */ cbf_failnez (cbf_find_parent (&parent, node, CBF_ROOT)) /* Which child is this? */ cbf_failnez (cbf_child_index (&index, node)) /* Get the next data block */ cbf_failnez (cbf_get_child (&node, parent, index + 1)) handle->node = node; /* Success */ return 0; }
int cbf_next_row | ( | cbf_handle | handle | ) |
Definition at line 1362 of file cbf.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_count_children(), cbf_failnez, cbf_find_parent(), CBF_NOTFOUND, cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by PutCIFHeader().
{ cbf_node *node; unsigned int rows; if (!handle) return CBF_ARGUMENT; /* Find the column node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_COLUMN)) cbf_failnez (cbf_count_children (&rows, node)) /* Is the row valid? */ if (handle->row >= rows) return CBF_NOTFOUND; handle->row++; handle->search_row = handle->row; /* Success */ return 0; }
int cbf_parse | ( | void * | context | ) |
Referenced by cbf_read_file().
int cbf_read_file | ( | cbf_handle | handle, |
FILE * | stream, | ||
int | headers | ||
) |
Definition at line 176 of file cbf.c.
References CBF_ARGUMENT, cbf_count_children(), cbf_delete_fileconnection(), cbf_failnez, cbf_find_parent(), cbf_free_node(), cbf_get_child(), cbf_get_name(), cbf_make_file(), CBF_NOTFOUND, cbf_parse(), CBF_ROOT, cbf_set_children(), HDR_DEFAULT, MSG_DIGEST, MSG_DIGESTNOW, MSG_NODIGEST, cbf_handle_struct::node, and cbf_file::read_headers.
Referenced by GetCIFHeader().
{ cbf_file *file; cbf_node *node; void *parse [2]; int errorcode; unsigned int children; const char *name; /* Check the arguments */ if (!handle) return CBF_ARGUMENT; if (((headers & (MSG_DIGEST | MSG_DIGESTNOW)) && (headers & MSG_NODIGEST))) return CBF_ARGUMENT; /* Delete the old datablocks */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) cbf_failnez (cbf_set_children (node, 0)) handle->node = node; /* Create the input file */ cbf_failnez (cbf_make_file (&file, stream)) /* Defaults */ if ((headers & (MSG_DIGEST | MSG_NODIGEST | MSG_DIGESTNOW)) == 0) headers |= (HDR_DEFAULT & (MSG_DIGEST | MSG_NODIGEST | MSG_DIGESTNOW)); if (headers & MSG_DIGESTNOW) headers |= MSG_DIGEST; /* Copy the flags */ file->read_headers = headers; /* Parse the file */ parse [0] = file; parse [1] = handle->node; errorcode = cbf_parse (parse); /* Delete the first datablock if it's empty */ if (!errorcode) { errorcode = cbf_get_child (&node, node, 0); if (!errorcode) { errorcode = cbf_get_name (&name, node); if (!errorcode && !name) { errorcode = cbf_count_children (&children, node); if (!errorcode && !children) errorcode = cbf_free_node (node); } } else if (errorcode == CBF_NOTFOUND) errorcode = 0; } /* Disconnect the file */ return errorcode | cbf_delete_fileconnection (&file); }
int cbf_remove_category | ( | cbf_handle | handle | ) |
Definition at line 1063 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_node(), and cbf_handle_struct::node.
{ cbf_node *node, *parent; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Find the data block node */ cbf_failnez (cbf_find_parent (&parent, node, CBF_DATABLOCK)) handle->node = parent; /* Delete the column */ return cbf_free_node (node); }
int cbf_remove_column | ( | cbf_handle | handle | ) |
Definition at line 1092 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, CBF_COLUMN, cbf_failnez, cbf_find_parent(), cbf_free_node(), and cbf_handle_struct::node.
{ cbf_node *node, *parent; if (!handle) return CBF_ARGUMENT; /* Find the column node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_COLUMN)) /* Find the category node */ cbf_failnez (cbf_find_parent (&parent, node, CBF_CATEGORY)) handle->node = parent; /* Delete the column */ return cbf_free_node (node); }
int cbf_remove_datablock | ( | cbf_handle | handle | ) |
Definition at line 1034 of file cbf.c.
References CBF_ARGUMENT, CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_node(), CBF_ROOT, and cbf_handle_struct::node.
{ cbf_node *node, *parent; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Find the root node */ cbf_failnez (cbf_find_parent (&parent, node, CBF_ROOT)) handle->node = parent; /* Delete the datablock */ return cbf_free_node (node); }
int cbf_remove_row | ( | cbf_handle | handle | ) |
Definition at line 1121 of file cbf.c.
References CBF_ARGUMENT, cbf_delete_row(), and cbf_handle_struct::row.
{ if (!handle) return CBF_ARGUMENT; return cbf_delete_row (handle, handle->row); }
int cbf_reset_category | ( | cbf_handle | handle | ) |
Definition at line 1010 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_failnez, cbf_find_parent(), cbf_set_children(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) handle->node = node; /* Delete the children */ return cbf_set_children (node, 0); }
int cbf_reset_datablock | ( | cbf_handle | handle | ) |
Definition at line 986 of file cbf.c.
References CBF_ARGUMENT, CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_set_children(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) handle->node = node; /* Delete the children */ return cbf_set_children (node, 0); }
int cbf_reset_datablocks | ( | cbf_handle | handle | ) |
Definition at line 931 of file cbf.c.
References CBF_ARGUMENT, cbf_count_children(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_get_child(), CBF_NOTFOUND, CBF_ROOT, cbf_set_children(), and cbf_handle_struct::node.
{ cbf_node *node, *datablocknode; unsigned int datablocks, datablock; int errorcode; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ errorcode = cbf_find_parent (&datablocknode, handle->node, CBF_DATABLOCK); if (errorcode && errorcode != CBF_NOTFOUND) return errorcode; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) if (errorcode) handle->node = node; else handle->node = datablocknode; /* Delete all grandchildren */ cbf_failnez (cbf_count_children (&datablocks, node)) for (datablock = 0; datablock < datablocks; datablock++) { cbf_failnez (cbf_get_child (&node, handle->node, datablock)) cbf_failnez (cbf_set_children (node, 0)) } /* Success */ return 0; }
int cbf_rewind_category | ( | cbf_handle | handle | ) |
Definition at line 1162 of file cbf.c.
References CBF_ARGUMENT, CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_get_child(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Find the first child */ cbf_failnez (cbf_get_child (&node, node, 0)) handle->node = node; /* Success */ return 0; }
int cbf_rewind_column | ( | cbf_handle | handle | ) |
Definition at line 1191 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_failnez, cbf_find_parent(), cbf_get_child(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Find the first child */ cbf_failnez (cbf_get_child (&node, node, 0)) handle->node = node; /* Success */ return 0; }
int cbf_rewind_datablock | ( | cbf_handle | handle | ) |
Definition at line 1133 of file cbf.c.
References CBF_ARGUMENT, cbf_failnez, cbf_find_parent(), cbf_get_child(), CBF_ROOT, and cbf_handle_struct::node.
Referenced by GetCIFData(), and GetCIFHeader().
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Find the first child */ cbf_failnez (cbf_get_child (&node, node, 0)) handle->node = node; /* Success */ return 0; }
int cbf_rewind_row | ( | cbf_handle | handle | ) |
Definition at line 1220 of file cbf.c.
References CBF_ARGUMENT, cbf_handle_struct::row, and cbf_handle_struct::search_row.
Referenced by cbf_find_row(), GetCIFHeader(), and PutCIFHeader().
{ if (!handle) return CBF_ARGUMENT; handle->row = 0; handle->search_row = 0; /* Success */ return 0; }
int cbf_row_number | ( | cbf_handle | handle, |
unsigned int * | row | ||
) |
Definition at line 1888 of file cbf.c.
References CBF_ARGUMENT, and cbf_handle_struct::row.
{ if (!handle) return CBF_ARGUMENT; if (row) *row = handle->row; /* Success */ return 0; }
int cbf_select_category | ( | cbf_handle | handle, |
unsigned int | category | ||
) |
Definition at line 1428 of file cbf.c.
References CBF_ARGUMENT, CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_get_child(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Select the category */ cbf_failnez (cbf_get_child (&node, node, category)) handle->node = node; /* Success */ return 0; }
int cbf_select_column | ( | cbf_handle | handle, |
unsigned int | column | ||
) |
Definition at line 1457 of file cbf.c.
References CBF_ARGUMENT, CBF_CATEGORY, cbf_failnez, cbf_find_parent(), cbf_get_child(), and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the category node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_CATEGORY)) /* Select the column */ cbf_failnez (cbf_get_child (&node, node, column)) handle->node = node; /* Success */ return 0; }
int cbf_select_datablock | ( | cbf_handle | handle, |
unsigned int | datablock | ||
) |
Definition at line 1399 of file cbf.c.
References CBF_ARGUMENT, cbf_failnez, cbf_find_parent(), cbf_get_child(), CBF_ROOT, and cbf_handle_struct::node.
{ cbf_node *node; if (!handle) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Select the data block */ cbf_failnez (cbf_get_child (&node, node, datablock)) handle->node = node; /* Success */ return 0; }
int cbf_select_row | ( | cbf_handle | handle, |
unsigned int | row | ||
) |
Definition at line 1486 of file cbf.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_count_children(), cbf_failnez, cbf_find_parent(), CBF_NOTFOUND, cbf_handle_struct::node, cbf_handle_struct::row, and cbf_handle_struct::search_row.
{ cbf_node *node; unsigned int rows; if (!handle) return CBF_ARGUMENT; /* Find the column node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_COLUMN)) cbf_failnez (cbf_count_children (&rows, node)) /* Is the row valid? */ if (row >= rows) return CBF_NOTFOUND; handle->row = row; handle->search_row = row; /* Success */ return 0; }
int cbf_set_datablockname | ( | cbf_handle | handle, |
const char * | datablockname | ||
) |
Definition at line 881 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, cbf_copy_string(), CBF_DATABLOCK, cbf_failnez, cbf_find_parent(), cbf_free_string(), cbf_name_node(), and cbf_handle_struct::node.
{ cbf_node *node; int errorcode; if (!handle) return CBF_ARGUMENT; /* Find the data block node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_DATABLOCK)) /* Copy the name */ if (datablockname) { datablockname = cbf_copy_string (NULL, datablockname, 0); if (!datablockname) return CBF_ALLOC; } /* Change the name */ errorcode = cbf_name_node (node, datablockname); if (errorcode) { cbf_free_string (NULL, datablockname); return errorcode; } /* Success */ handle->node = node; return 0; }
int cbf_set_doublevalue | ( | cbf_handle | handle, |
const char * | format, | ||
double | number | ||
) |
Definition at line 2069 of file cbf.c.
References cbf_set_value().
Referenced by PutCIFHeader().
{ char value [64]; /* Write the value */ sprintf (value, format, number); /* Save it */ return cbf_set_value (handle, value); }
int cbf_set_integerarray | ( | cbf_handle | handle, |
unsigned int | compression, | ||
int | id, | ||
void * | value, | ||
size_t | elsize, | ||
int | elsign, | ||
size_t | nelem | ||
) |
Definition at line 2141 of file cbf.c.
References CBF_ARGUMENT, cbf_set_binary(), cbf_handle_struct::node, and cbf_handle_struct::row.
Referenced by PutCIFData().
{ if (!handle) return CBF_ARGUMENT; return cbf_set_binary (handle->node, handle->row, compression, id, value, elsize, elsign, nelem); }
int cbf_set_integervalue | ( | cbf_handle | handle, |
int | number | ||
) |
Definition at line 2051 of file cbf.c.
References cbf_set_value().
Referenced by PutCIFHeader().
{ char value [64]; /* Write the value */ sprintf (value, "%d", number); /* Save it */ return cbf_set_value (handle, value); }
int cbf_set_value | ( | cbf_handle | handle, |
const char * | value | ||
) |
Definition at line 1949 of file cbf.c.
References CBF_ALLOC, CBF_ARGUMENT, cbf_copy_string(), cbf_free_string(), cbf_set_columnrow(), cbf_handle_struct::node, and cbf_handle_struct::row.
Referenced by cbf_set_doublevalue(), cbf_set_integervalue(), and PutCIFHeader().
{ int errorcode; /* Check the arguments */ if (!handle) return CBF_ARGUMENT; /* Copy the string */ if (value) { value = cbf_copy_string (NULL, value, '\200'); if (!value) return CBF_ALLOC; } /* Set the new value */ errorcode = cbf_set_columnrow (handle->node, handle->row, value, 1); if (errorcode) { cbf_free_string (NULL, value); return errorcode; } /* Success */ return 0; }
void cbf_warning | ( | const char * | message | ) |
int cbf_write_file | ( | cbf_handle | handle, |
FILE * | stream, | ||
int | isbuffer, | ||
int | ciforcbf, | ||
int | headers, | ||
int | encoding | ||
) |
Definition at line 275 of file cbf.c.
References CBF_ARGUMENT, cbf_delete_fileconnection(), cbf_failnez, cbf_find_parent(), cbf_make_file(), CBF_ROOT, cbf_write_node(), CIF, ENC_BACKWARD, ENC_BASE10, ENC_BASE16, ENC_BASE64, ENC_BASE8, ENC_CRTERM, ENC_DEFAULT, ENC_FORWARD, ENC_LFTERM, ENC_NONE, ENC_QP, HDR_DEFAULT, MIME_HEADERS, MSG_DIGEST, MSG_DIGESTNOW, MSG_NODIGEST, cbf_handle_struct::node, PLAIN_HEADERS, cbf_file::stream, cbf_file::write_encoding, and cbf_file::write_headers.
Referenced by PutCIFData().
{ cbf_file *file; cbf_node *node; int errorcode; int little; /* CIF or CBF? */ if (ciforcbf == CIF) encoding = encoding & ~ENC_NONE; else encoding = (encoding & ~(ENC_BASE8 | ENC_BASE10 | ENC_BASE16 | ENC_BASE64 | ENC_QP | ENC_FORWARD | ENC_BACKWARD)) | ENC_NONE | ENC_CRTERM | ENC_LFTERM; /* Check the arguments */ if (!handle) return CBF_ARGUMENT; if (((headers & MIME_HEADERS) && (headers & PLAIN_HEADERS)) || ((headers & MSG_DIGEST) && (headers & MSG_NODIGEST)) || ((headers & MSG_DIGEST) && (headers & PLAIN_HEADERS)) || ((headers & MSG_DIGESTNOW) && (headers & MSG_NODIGEST)) || ((headers & MSG_DIGESTNOW) && (headers & PLAIN_HEADERS)) || ((encoding & ENC_FORWARD) && (encoding & ENC_BACKWARD))) return CBF_ARGUMENT; if (((encoding & ENC_NONE) > 0) + ((encoding & ENC_BASE8) > 0) + ((encoding & ENC_BASE10) > 0) + ((encoding & ENC_BASE16) > 0) + ((encoding & ENC_BASE64) > 0) + ((encoding & ENC_QP) > 0) > 1) return CBF_ARGUMENT; /* Find the root node */ cbf_failnez (cbf_find_parent (&node, handle->node, CBF_ROOT)) /* Create the file */ cbf_failnez (cbf_make_file (&file, stream)) /* Defaults */ if (headers & (MSG_DIGEST | MSG_DIGESTNOW)) headers |= MIME_HEADERS; else if ((headers & (MIME_HEADERS | PLAIN_HEADERS)) == 0) headers |= (HDR_DEFAULT & (MIME_HEADERS | PLAIN_HEADERS)); if (headers & PLAIN_HEADERS) headers |= MSG_NODIGEST; else if ((headers & (MSG_DIGEST | MSG_NODIGEST | MSG_DIGESTNOW)) == 0) headers |= (HDR_DEFAULT & (MSG_DIGEST | MSG_NODIGEST | MSG_DIGESTNOW)); if (headers & MSG_DIGESTNOW) headers |= MSG_DIGEST; if ((encoding & (ENC_NONE | ENC_BASE8 | ENC_BASE10 | ENC_BASE16 | ENC_BASE64 | ENC_QP)) == 0) encoding |= (ENC_DEFAULT & (ENC_NONE | ENC_BASE8 | ENC_BASE10 | ENC_BASE16 | ENC_BASE64 | ENC_QP)); if ((encoding & (ENC_CRTERM | ENC_LFTERM)) == 0) encoding |= (ENC_DEFAULT & (ENC_CRTERM | ENC_LFTERM)); if ((encoding & (ENC_FORWARD | ENC_BACKWARD)) == 0) encoding |= (ENC_DEFAULT & (ENC_FORWARD | ENC_BACKWARD)); /* Copy the flags */ file->write_headers = headers; file->write_encoding = encoding; /* Write the file */ errorcode = cbf_write_node (node, file, isbuffer); /* Free the file structure but don't close the file? */ if (!isbuffer) file->stream = NULL; /* Disconnect the file */ return errorcode | cbf_delete_fileconnection (&file); }