/[public]/psiconv/trunk/lib/psiconv/buffer.h
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/buffer.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 79 Revision 80
18*/ 18*/
19 19
20#ifndef PSICONV_BUFFER_H 20#ifndef PSICONV_BUFFER_H
21#define PSICONV_BUFFER_H 21#define PSICONV_BUFFER_H
22 22
23/* A psiconv_buffer is a buffer of raw byte data. It is used when parsing
24 or generating a Psion file. You can use references within it that
25 are resolved at a later time. */
26
23#include <psiconv/general.h> 27#include <psiconv/general.h>
24 28
25#ifdef __cplusplus 29#ifdef __cplusplus
26extern "C" { 30extern "C" {
27#endif /* __cplusplus */ 31#endif /* __cplusplus */
28 32
33
29/* Always use psiconv_buffer, never struct psiconv_buffer_s */ 34/* Always use psiconv_buffer, never struct psiconv_buffer_s */
30/* No need to export the actual internal format */ 35/* No need to export the actual internal format */
31typedef struct psiconv_buffer_s *psiconv_buffer; 36typedef struct psiconv_buffer_s *psiconv_buffer;
32 37
38/* Allocate a new buffer. Returns NULL when not enough memory is available.
39 All other functions assume you have called this function first! */
33extern psiconv_buffer psiconv_buffer_new(psiconv_u32 base_offset); 40extern psiconv_buffer psiconv_buffer_new(void);
41
42/* Free a buffer and reclaim its memory. Never use a buffer again after
43 calling this (unless you do a psiconv_buffer_new on it first) */
34extern void psiconv_buffer_free(psiconv_buffer buf); 44extern void psiconv_buffer_free(psiconv_buffer buf);
35extern psiconv_u32 psiconv_buffer_base_offset(const psiconv_buffer buf); 45
46/* Get the length of the data */
36extern psiconv_u32 psiconv_buffer_length(const psiconv_buffer buf); 47extern psiconv_u32 psiconv_buffer_length(const psiconv_buffer buf);
48
49/* Get one byte of data. Returns NULL if you are trying to read past
50 the end of the buffer. Do not use this; instead use psiconv_read_u8
51 and friends */
37extern psiconv_u8 *psiconv_buffer_get(const psiconv_buffer buf, 52extern psiconv_u8 *psiconv_buffer_get(const psiconv_buffer buf,
38 psiconv_u32 off); 53 psiconv_u32 off);
54
55/* Add one byte of data to the end. Returns 0 on success, and an error
56 code on failure. Do not use this; instead use psiconv_write_u8 and
57 friends */
39extern int psiconv_buffer_add(psiconv_buffer buf,psiconv_u8 data); 58extern int psiconv_buffer_add(psiconv_buffer buf,psiconv_u8 data);
59
60/* Do an fread to the buffer. Returns the number of read bytes. See
61 fread(3) for more information. */
40extern size_t psiconv_buffer_fread(psiconv_buffer buf,size_t size, FILE *f); 62extern size_t psiconv_buffer_fread(psiconv_buffer buf,size_t size, FILE *f);
63
64/* Read a complete file to the buffer. Returns 0 on success, and an
65 error code on failure. */
41extern int psiconv_buffer_fread_all(psiconv_buffer buf, FILE *f); 66extern int psiconv_buffer_fread_all(psiconv_buffer buf, FILE *f);
67
68/* Write a complete buffer to file. Returns 0 on success, and an
69 error code on failure. */
42extern int psiconv_buffer_fwrite_all(const psiconv_buffer buf, FILE *f); 70extern int psiconv_buffer_fwrite_all(const psiconv_buffer buf, FILE *f);
71
72/* Concatenate two buffers. References are updated too. Buffer extra is
73 untouched after this and must still be freed if you want to get rid
74 of it. */
43extern int psiconv_buffer_concat(psiconv_buffer buf, 75extern int psiconv_buffer_concat(psiconv_buffer buf,
44 const psiconv_buffer extra); 76 const psiconv_buffer extra);
77
78/* Add a target to the reference list. This does not really change the
79 buffer data in any way. The id needs to be unique. The target is
80 added at the current end of the buffer. */
81extern int psiconv_buffer_add_target(psiconv_buffer buf, int id);
82
83/* Add a reference to a target to the reference list. The id does not
84 need to be defined already, though it must be by the time you call
85 psiconv_buffer_resolve. The reference is added to the current end
86 of the buffer, and space is allocated for it. */
87extern int psiconv_buffer_add_reference(psiconv_buffer buf,int id);
88
89/* Resolve all references and empty the reference list. */
90extern int psiconv_buffer_resolve(psiconv_buffer buf);
91
92/* Get a unique reference id */
93extern psiconv_u32 psiconv_buffer_unique_id(void);
45 94
46 95
47#ifdef __cplusplus 96#ifdef __cplusplus
48} 97}
49#endif /* __cplusplus */ 98#endif /* __cplusplus */

Legend:
Removed from v.79  
changed lines
  Added in v.80

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26