1
0
mirror of https://git.code.sf.net/p/fuse-emulator/fuse-utils synced 2025-08-09 00:42:13 +03:00

Put libspectrum version into creator information, and ensure that

libspectrum_init is called by all programs which use libspectrum functions.

Legacy-ID: 1707
This commit is contained in:
Philip Kendall
2003-10-13 15:42:26 +00:00
parent bacedc25e7
commit d24f07675c
9 changed files with 47 additions and 7 deletions

View File

@@ -49,3 +49,6 @@
20031007 tapeconv.c: remove double-free bug if tape reading fails. 20031007 tapeconv.c: remove double-free bug if tape reading fails.
20031009 utils.c: add information from uname() into creator custom data. 20031009 utils.c: add information from uname() into creator custom data.
20031010 utils.c: on Solaris, uname() returns 1 to indicate success. 20031010 utils.c: on Solaris, uname() returns 1 to indicate success.
20031013 Put libspectrum version into creator information, and ensure that
libspectrum_init is called by all programs which use libspectrum
functions.

View File

@@ -74,6 +74,8 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
error = init_libspectrum(); if( error ) return error;
error = mmap_file( argv[1], &buffer, &length ); if( error ) return error; error = mmap_file( argv[1], &buffer, &length ); if( error ) return error;
error = libspectrum_identify_file( &type, argv[1], buffer, length ); error = libspectrum_identify_file( &type, argv[1], buffer, length );

View File

@@ -57,7 +57,7 @@ main( int argc, char **argv )
progname = argv[0]; progname = argv[0];
if( libspectrum_init() ) return 16; if( init_libspectrum() ) return 16;
if( argc < 2 ) { if( argc < 2 ) {
fprintf( stderr, "%s: usage: %s <rzxfile>\n", progname, progname ); fprintf( stderr, "%s: usage: %s <rzxfile>\n", progname, progname );

View File

@@ -65,6 +65,7 @@ main( int argc, char **argv )
{ {
unsigned char *buffer; size_t length; unsigned char *buffer; size_t length;
unsigned char *snap_buffer; size_t snap_length; unsigned char *snap_buffer; size_t snap_length;
int error;
libspectrum_rzx *rzx; libspectrum_rzx *rzx;
libspectrum_snap *snap = NULL; libspectrum_snap *snap = NULL;
@@ -74,7 +75,7 @@ main( int argc, char **argv )
progname = argv[0]; progname = argv[0];
if( libspectrum_init() ) return 1; error = init_libspectrum(); if( error ) return error;
init_options( &options ); init_options( &options );
if( parse_options( argc, argv, &options ) ) return 1; if( parse_options( argc, argv, &options ) ) return 1;

View File

@@ -59,6 +59,8 @@ main( int argc, char **argv )
return 1; return 1;
} }
error = init_libspectrum(); if( error ) return error;
error = libspectrum_snap_alloc( &snap ); if( error ) return error; error = libspectrum_snap_alloc( &snap ); if( error ) return error;
if( mmap_file( argv[1], &buffer, &length ) ) { if( mmap_file( argv[1], &buffer, &length ) ) {

View File

@@ -46,13 +46,15 @@ char *progname;
int int
main( int argc, char **argv ) main( int argc, char **argv )
{ {
int c; int c, error;
char *input_type_string = NULL; libspectrum_id_t input_type; char *input_type_string = NULL; libspectrum_id_t input_type;
char *output_type_string = NULL; libspectrum_id_t output_type; char *output_type_string = NULL; libspectrum_id_t output_type;
libspectrum_tape *tzx; libspectrum_tape *tzx;
progname = argv[0]; progname = argv[0];
error = init_libspectrum(); if( error ) return error;
/* Don't screw up people's terminals */ /* Don't screw up people's terminals */
if( isatty( STDOUT_FILENO ) ) { if( isatty( STDOUT_FILENO ) ) {
fprintf( stderr, "%s: won't output binary data to a terminal\n", fprintf( stderr, "%s: won't output binary data to a terminal\n",

View File

@@ -282,6 +282,7 @@ main( int argc, char **argv )
{ {
int ret = 0; int ret = 0;
int arg = 0; int arg = 0;
int error;
progname = argv[0]; progname = argv[0];
@@ -290,6 +291,8 @@ main( int argc, char **argv )
return 1; return 1;
} }
error = init_libspectrum(); if( error ) return error;
while( ++arg < argc ) while( ++arg < argc )
ret |= process_tzx( argv[arg] ); ret |= process_tzx( argv[arg] );

34
utils.c
View File

@@ -40,12 +40,31 @@
extern char *progname; extern char *progname;
/* The minimum version of libspectrum we need */
static const char *LIBSPECTRUM_MIN_VERSION = "0.2.0";
int
init_libspectrum( void )
{
if( libspectrum_check_version( LIBSPECTRUM_MIN_VERSION ) ) {
if( libspectrum_init() ) return 1;
} else {
fprintf( stderr, "libspectrum version %s found, but %s required",
libspectrum_version(), LIBSPECTRUM_MIN_VERSION );
return 1;
}
return 0;
}
int int
get_creator( libspectrum_creator **creator, const char *program ) get_creator( libspectrum_creator **creator, const char *program )
{ {
char *custom; char *custom;
int version[4] = { 0, 0, 0, 0 };
struct utsname buf; struct utsname buf;
libspectrum_error error; int sys_error; libspectrum_error error; int sys_error;
size_t i;
sys_error = uname( &buf ); sys_error = uname( &buf );
if( sys_error == -1 ) { if( sys_error == -1 ) {
@@ -60,10 +79,16 @@ get_creator( libspectrum_creator **creator, const char *program )
error = libspectrum_creator_set_program( *creator, program ); error = libspectrum_creator_set_program( *creator, program );
if( error ) { libspectrum_creator_free( *creator ); return error; } if( error ) { libspectrum_creator_free( *creator ); return error; }
error = libspectrum_creator_set_major( *creator, 0x0006 ); sscanf( VERSION, "%u.%u.%u.%u",
&version[0], &version[1], &version[2], &version[3] );
for( i=0; i<4; i++ ) if( version[i] > 0xff ) version[i] = 0xff;
error = libspectrum_creator_set_major( *creator,
version[0] * 0x100 + version[1] );
if( error ) { libspectrum_creator_free( *creator ); return error; } if( error ) { libspectrum_creator_free( *creator ); return error; }
error = libspectrum_creator_set_minor( *creator, 0x0100 ); error = libspectrum_creator_set_minor( *creator,
version[2] * 0x100 + version[3] );
if( error ) { libspectrum_creator_free( *creator ); return error; } if( error ) { libspectrum_creator_free( *creator ); return error; }
custom = malloc( 256 ); custom = malloc( 256 );
@@ -74,8 +99,9 @@ get_creator( libspectrum_creator **creator, const char *program )
return 1; return 1;
} }
snprintf( custom, 256, "uname: %s %s %s\n", buf.sysname, buf.machine, snprintf( custom, 256, "libspectrum: %s\nuname: %s %s %s\n",
buf.release ); libspectrum_version(),
buf.sysname, buf.machine, buf.release );
error = libspectrum_creator_set_custom( *creator, error = libspectrum_creator_set_custom( *creator,
custom, strlen( custom ) ); custom, strlen( custom ) );

View File

@@ -29,6 +29,7 @@
#include <libspectrum.h> #include <libspectrum.h>
int init_libspectrum( void );
int get_creator( libspectrum_creator **creator, const char *program ); int get_creator( libspectrum_creator **creator, const char *program );
int mmap_file( const char *filename, unsigned char **buffer, size_t *length ); int mmap_file( const char *filename, unsigned char **buffer, size_t *length );