diff --git a/hacking/ChangeLog b/hacking/ChangeLog index 939cc76..e6842ee 100644 --- a/hacking/ChangeLog +++ b/hacking/ChangeLog @@ -49,3 +49,6 @@ 20031007 tapeconv.c: remove double-free bug if tape reading fails. 20031009 utils.c: add information from uname() into creator custom data. 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. diff --git a/listbasic.c b/listbasic.c index d1989ac..899b048 100644 --- a/listbasic.c +++ b/listbasic.c @@ -74,6 +74,8 @@ int main(int argc, char* argv[]) return 1; } + error = init_libspectrum(); if( error ) return error; + error = mmap_file( argv[1], &buffer, &length ); if( error ) return error; error = libspectrum_identify_file( &type, argv[1], buffer, length ); diff --git a/rzxcheck.c b/rzxcheck.c index cee74e9..72c9a8b 100644 --- a/rzxcheck.c +++ b/rzxcheck.c @@ -57,7 +57,7 @@ main( int argc, char **argv ) progname = argv[0]; - if( libspectrum_init() ) return 16; + if( init_libspectrum() ) return 16; if( argc < 2 ) { fprintf( stderr, "%s: usage: %s \n", progname, progname ); diff --git a/rzxtool.c b/rzxtool.c index 94d8cea..1106f49 100644 --- a/rzxtool.c +++ b/rzxtool.c @@ -65,6 +65,7 @@ main( int argc, char **argv ) { unsigned char *buffer; size_t length; unsigned char *snap_buffer; size_t snap_length; + int error; libspectrum_rzx *rzx; libspectrum_snap *snap = NULL; @@ -74,7 +75,7 @@ main( int argc, char **argv ) progname = argv[0]; - if( libspectrum_init() ) return 1; + error = init_libspectrum(); if( error ) return error; init_options( &options ); if( parse_options( argc, argv, &options ) ) return 1; diff --git a/snapconv.c b/snapconv.c index d039888..1383492 100644 --- a/snapconv.c +++ b/snapconv.c @@ -59,6 +59,8 @@ main( int argc, char **argv ) return 1; } + error = init_libspectrum(); if( error ) return error; + error = libspectrum_snap_alloc( &snap ); if( error ) return error; if( mmap_file( argv[1], &buffer, &length ) ) { diff --git a/tapeconv.c b/tapeconv.c index 49d2865..463e5f4 100644 --- a/tapeconv.c +++ b/tapeconv.c @@ -46,13 +46,15 @@ char *progname; int main( int argc, char **argv ) { - int c; + int c, error; char *input_type_string = NULL; libspectrum_id_t input_type; char *output_type_string = NULL; libspectrum_id_t output_type; libspectrum_tape *tzx; progname = argv[0]; + error = init_libspectrum(); if( error ) return error; + /* Don't screw up people's terminals */ if( isatty( STDOUT_FILENO ) ) { fprintf( stderr, "%s: won't output binary data to a terminal\n", diff --git a/tzxlist.c b/tzxlist.c index 68f3324..8066f68 100644 --- a/tzxlist.c +++ b/tzxlist.c @@ -282,6 +282,7 @@ main( int argc, char **argv ) { int ret = 0; int arg = 0; + int error; progname = argv[0]; @@ -290,6 +291,8 @@ main( int argc, char **argv ) return 1; } + error = init_libspectrum(); if( error ) return error; + while( ++arg < argc ) ret |= process_tzx( argv[arg] ); diff --git a/utils.c b/utils.c index b532fe2..ad23a35 100644 --- a/utils.c +++ b/utils.c @@ -40,12 +40,31 @@ 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 get_creator( libspectrum_creator **creator, const char *program ) { char *custom; + int version[4] = { 0, 0, 0, 0 }; struct utsname buf; libspectrum_error error; int sys_error; + size_t i; sys_error = uname( &buf ); if( sys_error == -1 ) { @@ -60,10 +79,16 @@ get_creator( libspectrum_creator **creator, const char *program ) error = libspectrum_creator_set_program( *creator, program ); 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; } - 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; } custom = malloc( 256 ); @@ -74,8 +99,9 @@ get_creator( libspectrum_creator **creator, const char *program ) return 1; } - snprintf( custom, 256, "uname: %s %s %s\n", buf.sysname, buf.machine, - buf.release ); + snprintf( custom, 256, "libspectrum: %s\nuname: %s %s %s\n", + libspectrum_version(), + buf.sysname, buf.machine, buf.release ); error = libspectrum_creator_set_custom( *creator, custom, strlen( custom ) ); diff --git a/utils.h b/utils.h index 3dfbbf1..6408e33 100644 --- a/utils.h +++ b/utils.h @@ -29,6 +29,7 @@ #include +int init_libspectrum( void ); int get_creator( libspectrum_creator **creator, const char *program ); int mmap_file( const char *filename, unsigned char **buffer, size_t *length );