1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/* Copyright (C) 2001-2018 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
Refer to licensing information at http://www.artifex.com or contact
Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
CA 94945, U.S.A., +1(415)492-9861, for further information.
*/
/* DataSource definitions */
#ifndef gsdsrc_INCLUDED
# define gsdsrc_INCLUDED
#include "gsstruct.h"
#include "scommon.h"
/* ---------------- Types and structures ---------------- */
/*
* A gs_data_source_t represents the data source for various constructs. It
* can be a string (either a gs_string or a byte-type object), a
* positionable, non-procedure-based stream, or an array of floats. An
* ordinary positionable file stream will do, as long as the client doesn't
* attempt to read past the EOF.
*
* The handling of floats is anomalous, but we don't see a good alternative
* at the moment.
*/
/*
* Prepare to access a block of data from a source. buf must be a client-
* supplied buffer of at least length bytes. If ptr == 0, always copy the
* data into buf. If ptr != 0, either copy the data into buf and set *ptr =
* buf, or set *ptr to point to the data (which might be invalidated by the
* next call). Note that this procedure may or may not do bounds checking.
*/
#define data_source_proc_access(proc)\
int proc(const gs_data_source_t *psrc, ulong start, uint length,\
byte *buf, const byte **ptr)
typedef enum {
data_source_type_string,
data_source_type_bytes,
data_source_type_floats,
data_source_type_stream
} gs_data_source_type_t;
typedef struct gs_data_source_s gs_data_source_t;
struct gs_data_source_s {
data_source_proc_access((*access));
gs_data_source_type_t type;
union d_ {
gs_const_string str; /* also used for byte objects */
stream *strm;
} data;
};
#define data_source_access_only(psrc, start, length, buf, ptr)\
(*(psrc)->access)(psrc, (ulong)(start), length, buf, ptr)
#define data_source_access(psrc, start, length, buf, ptr)\
BEGIN\
int code_ = data_source_access_only(psrc, start, length, buf, ptr);\
if ( code_ < 0 ) return code_;\
END
#define data_source_copy_only(psrc, start, length, buf)\
data_source_access_only(psrc, start, length, buf, (const byte **)0)
#define data_source_copy(psrc, start, length, buf)\
data_source_access(psrc, start, length, buf, (const byte **)0)
/*
* Data sources are always embedded in other structures, but they do have
* pointers that need to be traced and relocated, so they do have a GC
* structure type.
*/
extern_st(st_data_source);
#define public_st_data_source() /* in gsdsrc.c */\
gs_public_st_composite(st_data_source, gs_data_source_t, "gs_data_source_t",\
data_source_enum_ptrs, data_source_reloc_ptrs)
#define st_data_source_max_ptrs 1
/* ---------------- Procedures ---------------- */
/* Initialize a data source of the various known types. */
data_source_proc_access(data_source_access_string);
#define data_source_init_string(psrc, strg)\
((psrc)->type = data_source_type_string,\
(psrc)->data.str = strg, (psrc)->access = data_source_access_string)
#define data_source_init_string2(psrc, bytes, len)\
((psrc)->type = data_source_type_string,\
(psrc)->data.str.data = bytes, (psrc)->data.str.size = len,\
(psrc)->access = data_source_access_string)
data_source_proc_access(data_source_access_bytes);
#define data_source_init_bytes(psrc, bytes, len)\
((psrc)->type = data_source_type_bytes,\
(psrc)->data.str.data = bytes, (psrc)->data.str.size = len,\
(psrc)->access = data_source_access_bytes)
#define data_source_init_floats(psrc, floats, count)\
((psrc)->type = data_source_type_floats,\
(psrc)->data.str.data = (byte *)floats,\
(psrc)->data.str.size = (count) * sizeof(float),\
(psrc)->access = data_source_access_bytes)
data_source_proc_access(data_source_access_stream);
#define data_source_init_stream(psrc, s)\
((psrc)->type = data_source_type_stream,\
(psrc)->data.strm = s, (psrc)->access = data_source_access_stream)
#define data_source_is_stream(dsource)\
((dsource).type == data_source_type_stream)
#define data_source_is_array(dsource)\
((dsource).type == data_source_type_floats)
#endif /* gsdsrc_INCLUDED */
|