From 3f8259e390fe5519812640a2097567f6bec94135 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 24 Jun 2010 16:02:00 +0000 Subject: [PATCH] vips.exe is less chatty --- ChangeLog | 1 + TODO | 46 ----------------------------------------- libvips/iofuncs/error.c | 22 ++++++++++++++------ tools/iofuncs/vips.c | 32 ++++++++++++++++++---------- 4 files changed, 38 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e007872..e110126c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ - constant ops clip to target range - oops, moreconst and moreeqconst were the same - better buffer handling in sinkdisc for single-line images +- less chatty errors from "vips" 12/5/10 started 7.22.0 - bump and rename diff --git a/TODO b/TODO index 0b05ab99..97f8b9dc 100644 --- a/TODO +++ b/TODO @@ -2,52 +2,6 @@ I guess this causes nip2 problems as well? or we call the full name I guess -- change vips error reporting - - what we have now: - - $ vips im_copy - usage: vips im_copy in out - where: - in is of type "image" - out is of type "image" - copy image, from package "conversion" - flags: (PIO function) (no coordinate transformation) (area operation) (result can be cached) - vips: error calling function - im_run_command: too few arguments - - $ vips im_copy ~/pics/babe.jpg /dev/poop.v - usage: vips im_copy in out - where: - in is of type "image" - out is of type "image" - copy image, from package "conversion" - flags: (PIO function) (no coordinate transformation) (area operation) (result can be cached) - vips: error calling function - im_setupout: unable to write to "/dev/poop.v" - - should be: - - $ vips im_copy - usage: vips im_copy in out - where: - in is of type "image" - out is of type "image" - copy image, from package "conversion" - flags: (PIO function) (no coordinate transformation) (area operation) (result can be cached) - - ie. no "error calling function" message - - and - - $ vips im_copy ~/pics/babe.jpg /dev/poop.v - im_setupout: unable to write to "/dev/poop.v" - - ie. no usage message, no "error calling function" message - - - - - lcms2 needs testing diff --git a/libvips/iofuncs/error.c b/libvips/iofuncs/error.c index 9a9ef052..27bd7640 100644 --- a/libvips/iofuncs/error.c +++ b/libvips/iofuncs/error.c @@ -12,6 +12,8 @@ * 2/10/09 * - error_exit() moved here * - gtkdoc comments + * 24/6/10 + * - fmt to error_exit() may be NULL */ /* @@ -363,19 +365,27 @@ im_warn( const char *domain, const char *fmt, ... ) * * Sends a formatted error message to stderr, then sends the contents of the * error buffer, if any, then terminates the program with an error code. + * + * @fmt may be %NULL, in which case only the error buffer is printed before + * exiting. + * + * See also: im_error(). */ void error_exit( const char *fmt, ... ) { - va_list ap; + if( fmt ) { + va_list ap; - fprintf( stderr, "%s: ", g_get_prgname() ); + fprintf( stderr, "%s: ", g_get_prgname() ); - va_start( ap, fmt ); - (void) vfprintf( stderr, fmt, ap ); - va_end( ap ); + va_start( ap, fmt ); + (void) vfprintf( stderr, fmt, ap ); + va_end( ap ); + + fprintf( stderr, "\n" ); + } - fprintf( stderr, "\n" ); fprintf( stderr, "%s", im_error_buffer() ); exit( 1 ); diff --git a/tools/iofuncs/vips.c b/tools/iofuncs/vips.c index e73a7991..2d484850 100644 --- a/tools/iofuncs/vips.c +++ b/tools/iofuncs/vips.c @@ -32,6 +32,8 @@ * - and now we just have --list packages/classes/package-name * 13/11/09 * - drop _f postfixes, drop many postfixes + * 24/6/10 + * - less chatty error messages */ /* @@ -884,7 +886,7 @@ main( int argc, char **argv ) int i, j; if( im_init_world( argv[0] ) ) - error_exit( "unable to start VIPS" ); + error_exit( NULL ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); @@ -920,8 +922,7 @@ main( int argc, char **argv ) if( main_option_plugin ) { if( !im_load_plugin( main_option_plugin ) ) - error_exit( "unable to load plugin %s", - main_option_plugin ); + error_exit( NULL ); } if( main_option_cpph ) print_cppdecls( main_option_cpph ); @@ -933,7 +934,7 @@ main( int argc, char **argv ) print_list( main_option_list ); if( main_option_usage ) { if( !(fn = im_find_function( main_option_usage )) ) - error_exit( "unknown operation %s", main_option_usage ); + error_exit( NULL ); usage( fn ); } if( main_option_version ) @@ -971,24 +972,33 @@ main( int argc, char **argv ) name[strlen( name ) - 4] = '\0'; if( !(fn = im_find_function( name )) ) - error_exit( "unknown function" ); + error_exit( NULL ); } /* Execute it! */ if( im_run_command( name, argc - 1, argv + 1 ) ) { - usage( fn ); - error_exit( "error calling function" ); + /* If there are no arguments and the operation failed, + * show usage. There are no-arg operations, so we have + * to try running it. + */ + if( argc == 1 ) + usage( fn ); + else + error_exit( NULL ); } } else if( argc > 1 ) { /* Nope ... run the first arg instead. */ + if( !(fn = im_find_function( argv[1] )) ) + error_exit( NULL ); + if( im_run_command( argv[1], argc - 2, argv + 2 ) ) { - if( !(fn = im_find_function( argv[1] )) ) - error_exit( "unknown function" ); - usage( fn ); - error_exit( "error calling function" ); + if( argc == 2 ) + usage( fn ); + else + error_exit( NULL ); } }