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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 80 - (show annotations)
Wed Dec 27 02:12:23 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 3962 byte(s)
(Frodo) Many changes. Layout sections now work!

* Added list_empty, list_replace
* Added relocation to buffers, removed base address
* Added buffer_resolve, buffer_add_reference, buffer_add_target,
  psiconv_unique_id functions
* Modifified other buffer functions to work with references
* Added comments to buffer.h
* Added write_offset function
* Added reference support in functions where needed
* Corrected extra/rewrite error message
* Corrected numerous bugs to make layouts work.

1 /*
2 buffer.h - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef PSICONV_BUFFER_H
21 #define PSICONV_BUFFER_H
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
27 #include <psiconv/general.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32
33
34 /* Always use psiconv_buffer, never struct psiconv_buffer_s */
35 /* No need to export the actual internal format */
36 typedef struct psiconv_buffer_s *psiconv_buffer;
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! */
40 extern 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) */
44 extern void psiconv_buffer_free(psiconv_buffer buf);
45
46 /* Get the length of the data */
47 extern 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 */
52 extern psiconv_u8 *psiconv_buffer_get(const psiconv_buffer buf,
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 */
58 extern 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. */
62 extern 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. */
66 extern 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. */
70 extern 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. */
75 extern int psiconv_buffer_concat(psiconv_buffer buf,
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. */
81 extern 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. */
87 extern int psiconv_buffer_add_reference(psiconv_buffer buf,int id);
88
89 /* Resolve all references and empty the reference list. */
90 extern int psiconv_buffer_resolve(psiconv_buffer buf);
91
92 /* Get a unique reference id */
93 extern psiconv_u32 psiconv_buffer_unique_id(void);
94
95
96 #ifdef __cplusplus
97 }
98 #endif /* __cplusplus */
99
100 #endif /* def PSICONV_BUFFER_H */

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