/[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 351 - (show annotations)
Wed Oct 22 19:53:40 2014 UTC (9 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 4516 byte(s)
(Frodo) Update copyright year in all source files

1 /*
2 buffer.h - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000-2014 Frodo Looijaard <frodo@frodo.looijaard.name>
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: the second buffer is appended to the first.
73 References are updated too. Buffer extra is untouched after this and must
74 still be freed if you want to get rid 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. References are always
87 longs (psiconv_u32). */
88 extern int psiconv_buffer_add_reference(psiconv_buffer buf,int id);
89
90 /* Resolve all references and empty the reference list. */
91 extern int psiconv_buffer_resolve(psiconv_buffer buf);
92
93 /* Get a unique reference id */
94 extern psiconv_u32 psiconv_buffer_unique_id(void);
95
96 /* Extract part of a buffer and put it into a new buffer. Note that
97 references and targets are not copied; you will have to resolve them
98 beforehand (but as this function is meant for reading buffers, they
99 will usually not be used). */
100 extern int psiconv_buffer_subbuffer(psiconv_buffer *buf,
101 const psiconv_buffer org,
102 psiconv_u32 offset, psiconv_u32 length);
103
104
105
106
107 #ifdef __cplusplus
108 }
109 #endif /* __cplusplus */
110
111 #endif /* def PSICONV_BUFFER_H */

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