cbf_file.h

Go to the documentation of this file.
00001 
00002 #ifndef CBF_FILE_H
00003 #define CBF_FILE_H
00004 
00005 #ifdef __cplusplus
00006 
00007 extern "C" {
00008 
00009 #endif
00010 
00011 #include <stdio.h>
00012 #include "global.h"
00013 #include "md5.h"
00014 
00015 
00016   /* File structure */
00017 
00018 typedef struct
00019 {
00020   FILE        *stream;            /* File pointer                           */
00021   unsigned int connections;       /* Number of pointers to this structure   */
00022   int          bits [2];          /* Buffer for bitwise reads and writes    */
00023   char         characters [64];   /* Buffer for character writes            */
00024   size_t       characters_used;   /* Characters in the character buffer     */
00025   int          last_read;         /* The last character read                */
00026   unsigned int line;              /* Current line                           */
00027   unsigned int column;            /* Current column                         */
00028   char        *buffer;            /* Buffer                                 */
00029   size_t       buffer_size;       /* Size of the buffer                     */
00030   size_t       buffer_used;       /* Number in use                          */
00031   int          read_headers;      /* message digest control (read)          */
00032   int          write_headers;     /* message digest and header type (write) */
00033   int          write_encoding;    /* encoding and line terminations (write) */
00034   MD5_CTX     *digest;            /* message digest context                 */
00035 }
00036 cbf_file;
00037 
00038 
00039   /* Create and initialise a file */
00040 
00041 int cbf_make_file (cbf_file **file, FILE *stream);
00042 
00043 
00044   /* Free a file */
00045 
00046 int cbf_free_file (cbf_file **file);
00047 
00048 
00049   /* Add a file connection */
00050 
00051 int cbf_add_fileconnection (cbf_file **file, FILE *stream);
00052 
00053 
00054   /* Remove a connection */
00055 
00056 int cbf_delete_fileconnection (cbf_file **file);
00057 
00058                     
00059   /* Count the connections */
00060 
00061 int cbf_file_connections (cbf_file *file);
00062 
00063                     
00064   /* Set the size of the buffer */
00065 
00066 int cbf_set_buffersize (cbf_file *file, size_t size);
00067 
00068 
00069   /* Empty the buffer */
00070 
00071 int cbf_reset_buffer (cbf_file *file);
00072 
00073 
00074   /* Add a character to the buffer */
00075 
00076 int cbf_save_character (cbf_file *file, int c);
00077 
00078 
00079   /* Retrieve the buffer */
00080 
00081 int cbf_get_buffer (cbf_file *file, const char **buffer, 
00082                                          size_t *buffer_size);
00083 
00084 
00085   /* Get the file coordinates */
00086 
00087 int cbf_get_filecoordinates (cbf_file *file, unsigned int *line,
00088                                              unsigned int *column);
00089                                              
00090 
00091   /* Set the file coordinates */
00092 
00093 int cbf_set_filecoordinates (cbf_file *file, unsigned int line,
00094                                              unsigned int column);
00095                                              
00096 
00097   /* Read the next bit */
00098 
00099 int cbf_get_bit (cbf_file *file);
00100 
00101 
00102   /* Read the next bits (signed) */
00103 
00104 int cbf_get_bits (cbf_file *file, int *bitslist, int bitcount);
00105 
00106 
00107   /* Write bits */
00108 
00109 int cbf_put_bits (cbf_file *file, int *bitslist, int bitcount);
00110 
00111 
00112   /* Read an integer as a series of bits */
00113 
00114 int cbf_get_integer (cbf_file *file, int *val, int valsign, int bitcount);
00115 
00116 
00117   /* Write an integer as a series of bits */
00118 
00119 int cbf_put_integer (cbf_file *file, int val, int valsign, int bitcount);
00120 
00121 
00122   /* Initialize a message digest */
00123   
00124 int cbf_start_digest (cbf_file *file);
00125 
00126 
00127   /* Get the message digest */
00128   
00129 int cbf_end_digest (cbf_file *file, char *digest);
00130 
00131 
00132   /* Discard any bits in the buffers */
00133 
00134 int cbf_reset_bits (cbf_file *file);
00135 
00136 
00137   /* Discard any characters in the character buffers */
00138 
00139 int cbf_reset_characters (cbf_file *file);
00140 
00141 
00142   /* Flush any remaining bits (write) */
00143 
00144 int cbf_flush_bits (cbf_file *file);
00145 
00146 
00147   /* Flush the character buffer (write) */
00148 
00149 int cbf_flush_characters (cbf_file *file);
00150 
00151 
00152   /* Get the next character */
00153 
00154 int cbf_get_character (cbf_file *file);
00155 
00156 
00157   /* Read the next character (convert end-of-line and update line and column) */
00158 
00159 int cbf_read_character (cbf_file *file);
00160 
00161 
00162   /* Put the next character */
00163 
00164 int cbf_put_character (cbf_file *file, int c);
00165 
00166 
00167   /* Write the next character (convert end-of-line and update line and column) */
00168 
00169 int cbf_write_character (cbf_file *file, int c);
00170 
00171 
00172   /* Put a string */
00173 
00174 int cbf_put_string (cbf_file *file, const char *string);
00175 
00176 
00177   /* Write a string (convert end-of-line and update line and column) */
00178 
00179 int cbf_write_string (cbf_file *file, const char *string);
00180 
00181 
00182   /* Read a (CR/LF)-terminated line into the buffer */
00183 
00184 int cbf_read_line (cbf_file *file, const char **line);
00185 
00186 
00187   /* Read nelem characters into the buffer */
00188 
00189 int cbf_get_block (cbf_file *file, size_t nelem);
00190 
00191 
00192   /* Write nelem characters from the buffer */
00193 
00194 int cbf_put_block (cbf_file *file, size_t nelem);
00195 
00196 
00197   /* Copy characters between files */
00198 
00199 int cbf_copy_file (cbf_file *destination, cbf_file *source, size_t nelem);
00200 
00201 
00202   /* Get the file position */
00203 
00204 int cbf_get_fileposition (cbf_file *file, long int *position);
00205                                              
00206 
00207   /* Set the file position */
00208 
00209 int cbf_set_fileposition (cbf_file *file, long int position, int whence);
00210                                              
00211 
00212 #ifdef __cplusplus
00213 
00214 }
00215 
00216 #endif
00217 
00218 #endif /* CBF_FILE_H */
00219