Menu

[f9e13c]: / make-perl.c  Maximize  Restore  History

Download this file

350 lines (296 with data), 11.1 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* make-perl.c: Generate a perl script to create the libspectrum_* typedefs
Copyright (c) 2002-2003,2015 Philip Kendall, Darren Salt
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <stdio.h>
int main(void)
{
/*
* Define the integer types
*/
printf( "if( /LIBSPECTRUM_DEFINE_TYPES/ ) {\n\n $_ = << \"CODE\";\n" );
#ifdef HAVE_STDINT_H
printf( "#include <stdint.h>\n\n" );
printf( "typedef uint8_t libspectrum_byte;\n" );
printf( "typedef int8_t libspectrum_signed_byte;\n" );
printf( "typedef uint16_t libspectrum_word;\n" );
printf( "typedef int16_t libspectrum_signed_word;\n" );
printf( "typedef uint32_t libspectrum_dword;\n" );
printf( "typedef int32_t libspectrum_signed_dword;\n" );
printf( "typedef uint64_t libspectrum_qword;\n" );
printf( "typedef int64_t libspectrum_signed_qword;\n" );
#else /* #ifdef HAVE_STDINT_H */
if( sizeof( char ) == 1 ) {
printf( "typedef unsigned char libspectrum_byte;\n" );
printf( "typedef signed char libspectrum_signed_byte;\n" );
} else if( sizeof( short ) == 1 ) {
printf( "typedef unsigned short libspectrum_byte;\n" );
printf( "typedef signed short libspectrum_signed_byte;\n" );
} else {
fprintf( stderr, "No plausible 8 bit types found\n" );
return 1;
}
if( sizeof( short ) == 2 ) {
printf( "typedef unsigned short libspectrum_word;\n" );
printf( "typedef signed short libspectrum_signed_word;\n" );
} else if( sizeof( int ) == 2 ) {
printf( "typedef unsigned int libspectrum_word;\n" );
printf( "typedef signed int libspectrum_signed_word;\n" );
} else {
fprintf( stderr, "No plausible 16 bit types found\n" );
return 1;
}
if( sizeof( int ) == 4 ) {
printf( "typedef unsigned int libspectrum_dword;\n" );
printf( "typedef signed int libspectrum_signed_dword;\n" );
} else if( sizeof( long ) == 4 ) {
printf( "typedef unsigned long libspectrum_dword;\n" );
printf( "typedef signed long libspectrum_signed_dword;\n" );
} else {
fprintf( stderr, "No plausible 32 bit types found\n" );
return 1;
}
if( sizeof( long ) == 8 ) {
printf( "typedef unsigned long libspectrum_qword;\n" );
printf( "typedef signed long libspectrum_signed_qword;\n" );
#if defined(_MSC_VER) && _MSC_VER <= 1200
} else {
printf( "typedef unsigned __int64 libspectrum_qword;\n" );
printf( "typedef signed __int64 libspectrum_signed_qword;\n" );
#else
} else if( sizeof( long long ) == 8 ) {
printf( "typedef unsigned long long libspectrum_qword;\n" );
printf( "typedef signed long long libspectrum_signed_qword;\n" );
} else {
fprintf( stderr, "No plausible 64 bit types found\n" );
return 1;
#endif
}
#endif /* #ifdef HAVE_STDINT_H */
printf( "CODE\n}\n\n" );
/*
* Get glib or our replacement for it
*/
printf( "if( /LIBSPECTRUM_GLIB_REPLACEMENT/ ) {\n\n" );
#ifdef HAVE_LIB_GLIB /* #ifdef HAVE_LIB_GLIB */
printf( " $_ = \"#define LIBSPECTRUM_HAS_GLIB_REPLACEMENT 0\\n\"\n" );
#else /* #ifdef HAVE_LIB_GLIB */
printf( " $_ = << \"CODE\";\n"
"#define LIBSPECTRUM_HAS_GLIB_REPLACEMENT 1\n"
"\n"
"#ifndef FALSE\n"
"#define FALSE (0)\n"
"#endif\n"
"\n"
"#ifndef TRUE\n"
"#define TRUE (!FALSE)\n"
"#endif\n"
"\n"
"typedef char gchar;\n"
"typedef int gint;\n"
"typedef long glong;\n"
"typedef gint gboolean;\n"
"typedef unsigned int guint;\n"
"typedef unsigned long gulong;\n"
"typedef const void * gconstpointer;\n"
"typedef void * gpointer;\n"
"\n"
"typedef struct _GSList GSList;\n"
"\n"
"struct _GSList {\n"
" gpointer data;\n"
" GSList *next;\n"
"};\n"
"\n"
"typedef void (*GFunc) (gpointer data,\n"
" gpointer user_data);\n"
"\n"
"typedef gint (*GCompareFunc) (gconstpointer a,\n"
" gconstpointer b);\n"
"\n"
"typedef void (*GDestroyNotify) (gpointer data);\n"
"\n"
"typedef void (*GFreeFunc) (gpointer data);\n"
"\n"
"\n"
"WIN32_DLL GSList *g_slist_insert_sorted (GSList *list,\n"
" gpointer data,\n"
" GCompareFunc func);\n"
"\n"
"WIN32_DLL GSList *g_slist_insert (GSList *list,\n"
" gpointer data,\n"
" gint position);\n"
"\n"
"WIN32_DLL GSList *g_slist_append (GSList *list,\n"
" gpointer data);\n"
"\n"
"WIN32_DLL GSList *g_slist_prepend (GSList *list,\n"
" gpointer data);\n"
"\n"
"WIN32_DLL GSList *g_slist_remove (GSList *list,\n"
" gconstpointer data);\n"
"\n"
"WIN32_DLL GSList *g_slist_last (GSList *list);\n"
"\n"
"WIN32_DLL GSList *g_slist_reverse (GSList *list);\n"
"\n"
"WIN32_DLL GSList *g_slist_delete_link (GSList *list,\n"
" GSList *link);\n"
"\n"
"WIN32_DLL guint g_slist_length (GSList *list);\n"
"\n"
"WIN32_DLL void g_slist_foreach (GSList *list,\n"
" GFunc func,\n"
" gpointer user_data);\n"
"\n"
"WIN32_DLL void g_slist_free (GSList *list);\n"
"\n"
"WIN32_DLL GSList *g_slist_nth (GSList *list,\n"
" guint n);\n"
"\n"
"WIN32_DLL GSList *g_slist_find_custom (GSList *list,\n"
" gconstpointer data,\n"
" GCompareFunc func );\n"
"\n"
"WIN32_DLL gint g_slist_position (GSList *list,\n"
" GSList *llink);\n"
"\n"
"typedef struct _GHashTable GHashTable;\n"
"\n"
"typedef guint (*GHashFunc) (gconstpointer key);\n"
"\n"
"typedef void (*GHFunc) (gpointer key,\n"
" gpointer value,\n"
" gpointer user_data);\n"
"\n"
"typedef gboolean (*GHRFunc) (gpointer key,\n"
" gpointer value,\n"
" gpointer user_data);\n"
"\n"
"WIN32_DLL gint g_int_equal (gconstpointer v,\n"
" gconstpointer v2);\n"
"WIN32_DLL guint g_int_hash (gconstpointer v);\n"
"\n"
"WIN32_DLL gint g_str_equal (gconstpointer v,\n"
" gconstpointer v2);\n"
"WIN32_DLL guint g_str_hash (gconstpointer v);\n"
"\n"
"WIN32_DLL GHashTable *g_hash_table_new (GHashFunc hash_func,\n"
" GCompareFunc key_compare_func);\n"
"\n"
"WIN32_DLL GHashTable *g_hash_table_new_full (GHashFunc hash_func,\n"
" GCompareFunc key_equal_func,\n"
" GDestroyNotify key_destroy_func,\n"
" GDestroyNotify value_destroy_func);\n"
"\n"
"WIN32_DLL void g_hash_table_destroy (GHashTable *hash_table);\n"
"\n"
"WIN32_DLL void g_hash_table_insert (GHashTable *hash_table,\n"
" gpointer key,\n"
" gpointer value);\n"
"\n"
"WIN32_DLL gpointer g_hash_table_lookup (GHashTable *hash_table,\n"
" gconstpointer key);\n"
"\n"
"WIN32_DLL void g_hash_table_foreach (GHashTable *hash_table,\n"
" GHFunc func,\n"
" gpointer user_data);\n"
"\n"
"WIN32_DLL guint g_hash_table_foreach_remove (GHashTable *hash_table,\n"
" GHRFunc func,\n"
" gpointer user_data);\n"
"\n"
"WIN32_DLL guint g_hash_table_size (GHashTable *hash_table);\n"
"\n"
"typedef struct _GArray GArray;\n"
"\n"
"struct _GArray {\n"
" /* Public */\n"
" gchar *data;\n"
" size_t len;\n"
"\n"
" /* Private */\n"
" guint element_size;\n"
" size_t allocated;\n"
"};\n"
"\n"
"WIN32_DLL GArray* g_array_new( gboolean zero_terminated, gboolean clear,\n"
" guint element_size );\n"
"WIN32_DLL GArray* g_array_sized_new( gboolean zero_terminated, gboolean clear,\n"
" guint element_size, guint reserved_size );\n"
"#define g_array_append_val(a,v) g_array_append_vals( a, &(v), 1 );\n"
"WIN32_DLL GArray* g_array_append_vals( GArray *array, gconstpointer data, guint len );\n"
"#define g_array_index(a,t,i) (*(((t*)a->data)+i))\n"
"WIN32_DLL GArray* g_array_set_size( GArray *array, guint length );\n"
"WIN32_DLL GArray* g_array_remove_index_fast( GArray *array, guint index );\n"
"WIN32_DLL gchar* g_array_free( GArray *array, gboolean free_segment );\n"
"\n" );
if( sizeof( void* ) == sizeof( int ) ) {
printf( "#define GINT_TO_POINTER(i) ((gpointer) (i))\n" );
printf( "#define GPOINTER_TO_INT(p) ((gint) (p))\n" );
printf( "#define GPOINTER_TO_UINT(p) ((guint) (p))\n" );
} else if( sizeof( void* ) == sizeof( long ) ) {
printf( "#define GINT_TO_POINTER(i) ((gpointer) (glong)(i))\n" );
printf( "#define GPOINTER_TO_INT(p) ((gint) (glong)(p))\n" );
printf( "#define GPOINTER_TO_UINT(p) ((guint) (gulong)(p))\n" );
} else {
fprintf( stderr, "No plausible int to pointer cast found\n" );
return 1;
}
printf( "CODE\n" );
#endif /* #ifdef HAVE_LIB_GLIB */
printf( "}\n\n" );
/*
* If we have libgcrypt, include the header file and store the signature
* parameters
*/
printf( "if( /LIBSPECTRUM_INCLUDE_GCRYPT/ ) {\n\n" );
#ifdef HAVE_GCRYPT_H
printf( " $_ = \"#include <gcrypt.h>\\n\";\n\n" );
#else
printf( " $_ = '';\n\n" );
#endif
printf( "}\n\n" );
printf( "if( /LIBSPECTRUM_SIGNATURE_PARAMETERS/ ) {\n\n" );
#ifdef HAVE_GCRYPT_H
printf( " $_ = \" /* The DSA signature parameters 'r' and 's' */\\n gcry_mpi_t r, s;\\n\";\n\n" );
#else
printf( " $_ = \"/* Signature parameters not stored as libgcrypt is not present */\n\";\n\n" );
#endif
printf( "}\n\n" );
printf( "if( /LIBSPECTRUM_CAPABILITIES/ ) {\n\n $_ = << \"CODE\";\n" );
#ifdef HAVE_ZLIB_H
printf( "\n/* we support snapshots etc. requiring zlib (e.g. compressed szx) */\n" );
printf( "#define LIBSPECTRUM_SUPPORTS_ZLIB_COMPRESSION (1)\n\n" );
printf( "/* zlib (de)compression routines */\n\n" );
printf( "WIN32_DLL libspectrum_error\n" );
printf( "libspectrum_zlib_inflate( const libspectrum_byte *gzptr, size_t gzlength,\n" );
printf( " libspectrum_byte **outptr, size_t *outlength );\n\n" );
printf( "WIN32_DLL libspectrum_error\n" );
printf( "libspectrum_zlib_compress( const libspectrum_byte *data, size_t length,\n" );
printf( " libspectrum_byte **gzptr, size_t *gzlength );\n\n" );
#endif /* #ifdef HAVE_ZLIB_H */
#ifdef HAVE_LIBBZ2
printf( "\n/* we support files compressed with bz2 */\n" );
printf( "#define LIBSPECTRUM_SUPPORTS_BZ2_COMPRESSION (1)\n\n" );
#endif /* #ifdef HAVE_LIBBZ2 */
#ifdef HAVE_LIB_AUDIOFILE
printf( "\n/* we support wav files */\n" );
printf( "#define LIBSPECTRUM_SUPPORTS_AUDIOFILE (1)\n\n" );
#endif /* #ifdef HAVE_LIB_AUDIOFILE */
printf( "CODE\n}\n\n" );
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.