-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.pl
More file actions
311 lines (222 loc) · 7.74 KB
/
generate.pl
File metadata and controls
311 lines (222 loc) · 7.74 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
if( /LIBSPECTRUM_DEFINE_TYPES/ ) {
$_ = << "CODE";
#include <stdint.h>
typedef uint8_t libspectrum_byte;
typedef int8_t libspectrum_signed_byte;
typedef uint16_t libspectrum_word;
typedef int16_t libspectrum_signed_word;
typedef uint32_t libspectrum_dword;
typedef int32_t libspectrum_signed_dword;
typedef uint64_t libspectrum_qword;
typedef int64_t libspectrum_signed_qword;
CODE
}
if( /LIBSPECTRUM_GLIB_REPLACEMENT/ ) {
$_ = << "CODE";
#define LIBSPECTRUM_HAS_GLIB_REPLACEMENT 1
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
typedef char gchar;
typedef int gint;
typedef long glong;
typedef gint gboolean;
typedef unsigned int guint;
typedef unsigned long gulong;
typedef const void * gconstpointer;
typedef void * gpointer;
typedef struct _GSList GSList;
struct _GSList {
gpointer data;
GSList *next;
};
typedef void (*GFunc) (gpointer data,
gpointer user_data);
typedef gint (*GCompareFunc) (gconstpointer a,
gconstpointer b);
typedef void (*GDestroyNotify) (gpointer data);
typedef void (*GFreeFunc) (gpointer data);
WIN32_DLL GSList *g_slist_insert_sorted (GSList *list,
gpointer data,
GCompareFunc func);
WIN32_DLL GSList *g_slist_insert (GSList *list,
gpointer data,
gint position);
WIN32_DLL GSList *g_slist_append (GSList *list,
gpointer data);
WIN32_DLL GSList *g_slist_prepend (GSList *list,
gpointer data);
WIN32_DLL GSList *g_slist_remove (GSList *list,
gconstpointer data);
WIN32_DLL GSList *g_slist_last (GSList *list);
WIN32_DLL GSList *g_slist_reverse (GSList *list);
WIN32_DLL GSList *g_slist_delete_link (GSList *list,
GSList *link);
WIN32_DLL guint g_slist_length (GSList *list);
WIN32_DLL void g_slist_foreach (GSList *list,
GFunc func,
gpointer user_data);
WIN32_DLL void g_slist_free (GSList *list);
WIN32_DLL GSList *g_slist_nth (GSList *list,
guint n);
WIN32_DLL GSList *g_slist_find_custom (GSList *list,
gconstpointer data,
GCompareFunc func );
WIN32_DLL gint g_slist_position (GSList *list,
GSList *llink);
typedef struct _GHashTable GHashTable;
typedef guint (*GHashFunc) (gconstpointer key);
typedef void (*GHFunc) (gpointer key,
gpointer value,
gpointer user_data);
typedef gboolean (*GHRFunc) (gpointer key,
gpointer value,
gpointer user_data);
WIN32_DLL gint g_int_equal (gconstpointer v,
gconstpointer v2);
WIN32_DLL guint g_int_hash (gconstpointer v);
WIN32_DLL gint g_str_equal (gconstpointer v,
gconstpointer v2);
WIN32_DLL guint g_str_hash (gconstpointer v);
WIN32_DLL GHashTable *g_hash_table_new (GHashFunc hash_func,
GCompareFunc key_compare_func);
WIN32_DLL GHashTable *g_hash_table_new_full (GHashFunc hash_func,
GCompareFunc key_equal_func,
GDestroyNotify key_destroy_func,
GDestroyNotify value_destroy_func);
WIN32_DLL void g_hash_table_destroy (GHashTable *hash_table);
WIN32_DLL void g_hash_table_insert (GHashTable *hash_table,
gpointer key,
gpointer value);
WIN32_DLL gpointer g_hash_table_lookup (GHashTable *hash_table,
gconstpointer key);
WIN32_DLL void g_hash_table_foreach (GHashTable *hash_table,
GHFunc func,
gpointer user_data);
WIN32_DLL guint g_hash_table_foreach_remove (GHashTable *hash_table,
GHRFunc func,
gpointer user_data);
WIN32_DLL guint g_hash_table_size (GHashTable *hash_table);
typedef struct _GArray GArray;
struct _GArray {
/* Public */
gchar *data;
guint len;
/* Private */
guint element_size;
guint allocated;
};
WIN32_DLL GArray* g_array_new( gboolean zero_terminated, gboolean clear,
guint element_size );
WIN32_DLL GArray* g_array_sized_new( gboolean zero_terminated, gboolean clear,
guint element_size, guint reserved_size );
#define g_array_append_val(a,v) g_array_append_vals( a, &(v), 1 );
WIN32_DLL GArray* g_array_append_vals( GArray *array, gconstpointer data, guint len );
#define g_array_index(a,t,i) (*(((t*)a->data)+i))
WIN32_DLL GArray* g_array_set_size( GArray *array, guint length );
WIN32_DLL GArray* g_array_remove_index_fast( GArray *array, guint index );
WIN32_DLL gchar* g_array_free( GArray *array, gboolean free_segment );
#include <TargetConditionals.h>
#ifdef TARGET_RT_64_BIT
#define GINT_TO_POINTER(i) ((gpointer) (glong)(i))
#define GPOINTER_TO_INT(p) ((gint) (glong)(p))
#define GPOINTER_TO_UINT(p) ((guint) (gulong)(p))
#else
#define GINT_TO_POINTER(i) ((gpointer) (i))
#define GPOINTER_TO_INT(p) ((gint) (p))
#define GPOINTER_TO_UINT(p) ((guint) (p))
#endif
CODE
}
if( /LIBSPECTRUM_INCLUDE_GCRYPT/ ) {
$_ = '';
}
if( /LIBSPECTRUM_SIGNATURE_PARAMETERS/ ) {
$_ = "/* Signature parameters not stored as libgcrypt is not present */
";
}
if( /LIBSPECTRUM_CAPABILITIES/ ) {
$_ = << "CODE";
/* we support snapshots etc. requiring zlib (e.g. compressed szx) */
#define LIBSPECTRUM_SUPPORTS_ZLIB_COMPRESSION (1)
/* zlib (de)compression routines */
WIN32_DLL libspectrum_error
libspectrum_zlib_inflate( const libspectrum_byte *gzptr, size_t gzlength,
libspectrum_byte **outptr, size_t *outlength );
WIN32_DLL libspectrum_error
libspectrum_zlib_compress( const libspectrum_byte *data, size_t length,
libspectrum_byte **gzptr, size_t *gzlength );
CODE
}
if( /LIBSPECTRUM_AUTOGEN_WARNING/ ) {
$_ = << "CODE";
/* NB: This file is autogenerated from libspectrum.h.in. Do not edit
unless you know what you're doing */
CODE
}
if( /LIBSPECTRUM_SNAP_ACCESSORS/ ) {
open( DATAFILE, '<' . "$ENV{SRCROOT}/libspectrum/snap_accessors.txt" ) or die "Couldn't open `$ENV{SRCROOT}/libspectrum/snap_accessors.txt': $!";
$_ = '';
while( <DATAFILE> ) {
# Blank lines
next if /^\s*$/;
# Perl comments
next if /^\s*#/;
# Leading C comments
next if /^\s*\/\*/;
# Trailing C comments
s/\/\*(.*)\*\///;
my( $type, $name, $indexed ) = split;
my $return_type;
if( $type =~ /^(.*)\*/ ) {
$return_type = "WIN32_DLL $1 *";
} else {
$return_type = "WIN32_DLL $type";
}
if( $indexed ) {
print << "CODE";
$return_type libspectrum_snap_$name( libspectrum_snap *snap, int idx );
WIN32_DLL void libspectrum_snap_set_$name( libspectrum_snap *snap, int idx, $type $name );
CODE
} else {
print << "CODE";
$return_type libspectrum_snap_$name( libspectrum_snap *snap );
WIN32_DLL void libspectrum_snap_set_$name( libspectrum_snap *snap, $type $name );
CODE
}
}
}
if( /LIBSPECTRUM_TAPE_ACCESSORS/ ) {
open( DATAFILE, '<' . "$ENV{SRCROOT}/libspectrum/tape_accessors.txt" )
or die "Couldn't open `$ENV{SRCROOT}/libspectrum/tape_accessors.txt': $!";
$_ = '';
while( <DATAFILE> ) {
# Remove comments and blank lines
s/#.*//;
next if /^\s*$/;
# Skip which block types each accessor applies to
next if /^\s/;
my( $type, $name, $indexed, undef ) = split;
my $return_type;
if( $type =~ /^(.*)\*/ ) {
$return_type = "WIN32_DLL $1 *";
} else {
$return_type = "WIN32_DLL $type";
}
if( $indexed ) {
print << "CODE";
$return_type libspectrum_tape_block_$name( libspectrum_tape_block *block, size_t idx );
WIN32_DLL libspectrum_error libspectrum_tape_block_set_$name( libspectrum_tape_block *block, $type \*$name );
CODE
} else {
print << "CODE";
$return_type libspectrum_tape_block_$name( libspectrum_tape_block *block );
WIN32_DLL libspectrum_error libspectrum_tape_block_set_$name( libspectrum_tape_block *block, $type $name );
CODE
}
}
close DATAFILE or die "Couldn't close `$ENV{SRCROOT}/libspectrum/tape_accessors.txt': $!";
}