better arg parsing
oops in arg parse, better error messages
This commit is contained in:
parent
7f94fb3597
commit
05d31e0890
2
TODO
2
TODO
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
tiff, jpg are the obvious ones
|
tiff, jpg are the obvious ones
|
||||||
|
|
||||||
test progressive png, non-sequential png load
|
test progressive png
|
||||||
|
|
||||||
- argh
|
- argh
|
||||||
|
|
||||||
|
@ -1394,7 +1394,7 @@ vips_foreign_save_init( VipsForeignSave *object )
|
|||||||
* Loads @filename into @out using the loader recommended by
|
* Loads @filename into @out using the loader recommended by
|
||||||
* vips_foreign_find_load().
|
* vips_foreign_find_load().
|
||||||
*
|
*
|
||||||
* See also: vips_foreign_save(), vips_foreign_read_options().
|
* See also: vips_foreign_save(), vips_foreign_load_options().
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, -1 on error
|
* Returns: 0 on success, -1 on error
|
||||||
*/
|
*/
|
||||||
|
@ -122,6 +122,8 @@ vips_object_check_required( VipsObject *object, GParamSpec *pspec,
|
|||||||
VipsArgumentInstance *argument_instance,
|
VipsArgumentInstance *argument_instance,
|
||||||
void *a, void *b )
|
void *a, void *b )
|
||||||
{
|
{
|
||||||
|
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||||
|
|
||||||
int *result = (int *) a;
|
int *result = (int *) a;
|
||||||
VipsArgumentFlags *iomask = (VipsArgumentFlags *) b;
|
VipsArgumentFlags *iomask = (VipsArgumentFlags *) b;
|
||||||
|
|
||||||
@ -142,12 +144,9 @@ vips_object_check_required( VipsObject *object, GParamSpec *pspec,
|
|||||||
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
|
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
|
||||||
(argument_class->flags & *iomask) &&
|
(argument_class->flags & *iomask) &&
|
||||||
!argument_instance->assigned ) {
|
!argument_instance->assigned ) {
|
||||||
vips_error( "VipsObject",
|
vips_error( class->nickname,
|
||||||
/* used as eg. "parameter out to VipsAdd not set".
|
_( "parameter %s not set" ),
|
||||||
*/
|
g_param_spec_get_name( pspec ) );
|
||||||
_( "parameter %s to %s not set" ),
|
|
||||||
g_param_spec_get_name( pspec ),
|
|
||||||
G_OBJECT_TYPE_NAME( object ) );
|
|
||||||
*result = -1;
|
*result = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,25 +501,23 @@ vips_object_get_argument( VipsObject *object, const char *name,
|
|||||||
|
|
||||||
if( !(*pspec = g_object_class_find_property(
|
if( !(*pspec = g_object_class_find_property(
|
||||||
G_OBJECT_CLASS( class ), name )) ) {
|
G_OBJECT_CLASS( class ), name )) ) {
|
||||||
vips_error( VIPS_OBJECT_CLASS( class )->nickname,
|
vips_error( class->nickname,
|
||||||
_( "class `%s' has no property named `%s'" ),
|
_( "no property named `%s'" ), name );
|
||||||
G_OBJECT_TYPE_NAME( object ), name );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !(*argument_class = (VipsArgumentClass *)
|
if( !(*argument_class = (VipsArgumentClass *)
|
||||||
vips__argument_table_lookup( class->argument_table,
|
vips__argument_table_lookup( class->argument_table,
|
||||||
*pspec )) ) {
|
*pspec )) ) {
|
||||||
vips_error( VIPS_OBJECT_CLASS( class )->nickname,
|
vips_error( class->nickname,
|
||||||
_( "class `%s' has no vips argument named `%s'" ),
|
_( "no vips argument named `%s'" ), name );
|
||||||
G_OBJECT_TYPE_NAME( object ), name );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
if( argument_class &&
|
if( argument_class &&
|
||||||
!(*argument_instance = vips__argument_get_instance(
|
!(*argument_instance = vips__argument_get_instance(
|
||||||
*argument_class, object )) ) {
|
*argument_class, object )) ) {
|
||||||
vips_error( VIPS_OBJECT_CLASS( class )->nickname,
|
vips_error( class->nickname,
|
||||||
_( "vips argument `%s' has no instance" ), name );
|
_( "argument `%s' has no instance" ), name );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1398,6 +1395,8 @@ int
|
|||||||
vips_object_set_argument_from_string( VipsObject *object,
|
vips_object_set_argument_from_string( VipsObject *object,
|
||||||
const char *name, const char *value )
|
const char *name, const char *value )
|
||||||
{
|
{
|
||||||
|
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||||
|
|
||||||
GParamSpec *pspec;
|
GParamSpec *pspec;
|
||||||
VipsArgumentClass *argument_class;
|
VipsArgumentClass *argument_class;
|
||||||
VipsArgumentInstance *argument_instance;
|
VipsArgumentInstance *argument_instance;
|
||||||
@ -1488,11 +1487,9 @@ vips_object_set_argument_from_string( VipsObject *object,
|
|||||||
g_type_class_ref( otype ), value )) ) {
|
g_type_class_ref( otype ), value )) ) {
|
||||||
if( !(enum_value = g_enum_get_value_by_nick(
|
if( !(enum_value = g_enum_get_value_by_nick(
|
||||||
g_type_class_ref( otype ), value )) ) {
|
g_type_class_ref( otype ), value )) ) {
|
||||||
vips_error(
|
vips_error( class->nickname,
|
||||||
"vips_object_set_argument_from_string",
|
|
||||||
_( "enum '%s' has no member '%s'" ),
|
_( "enum '%s' has no member '%s'" ),
|
||||||
g_type_name( otype ),
|
g_type_name( otype ), value );
|
||||||
value );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1692,6 +1689,8 @@ vips_object_new( GType type, VipsObjectSetArguments set, void *a, void *b )
|
|||||||
static int
|
static int
|
||||||
vips_object_set_args( VipsObject *object, const char *p )
|
vips_object_set_args( VipsObject *object, const char *p )
|
||||||
{
|
{
|
||||||
|
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||||
|
|
||||||
VipsToken token;
|
VipsToken token;
|
||||||
char string[PATH_MAX];
|
char string[PATH_MAX];
|
||||||
char string2[PATH_MAX];
|
char string2[PATH_MAX];
|
||||||
@ -1729,11 +1728,11 @@ vips_object_set_args( VipsObject *object, const char *p )
|
|||||||
&pspec, &argument_class, &argument_instance ) &&
|
&pspec, &argument_class, &argument_instance ) &&
|
||||||
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
|
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
|
||||||
(argument_class->flags & VIPS_ARGUMENT_INPUT) &&
|
(argument_class->flags & VIPS_ARGUMENT_INPUT) &&
|
||||||
!argument_instance->assigned &&
|
|
||||||
G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) {
|
G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) {
|
||||||
/* The string is the name of an unassigned optional
|
/* The string is the name of an optional
|
||||||
* input boolean ... set it!
|
* input boolean ... set it!
|
||||||
*/
|
*/
|
||||||
|
if( !argument_instance->assigned )
|
||||||
g_object_set( object, string, TRUE, NULL );
|
g_object_set( object, string, TRUE, NULL );
|
||||||
}
|
}
|
||||||
else if( (pspec = vips_object_find_required( object )) ) {
|
else if( (pspec = vips_object_find_required( object )) ) {
|
||||||
@ -1742,23 +1741,22 @@ vips_object_set_args( VipsObject *object, const char *p )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vips_error( "VipsObject",
|
vips_error( class->nickname,
|
||||||
_( "no unset required arguments for %s" ),
|
_( "unable to set '%s'" ), string );
|
||||||
string );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now must be a , or a ).
|
/* Now must be a , or a ).
|
||||||
*/
|
*/
|
||||||
if( token != VIPS_TOKEN_RIGHT && token != VIPS_TOKEN_COMMA ) {
|
if( token != VIPS_TOKEN_RIGHT && token != VIPS_TOKEN_COMMA ) {
|
||||||
vips_error( "VipsObject",
|
vips_error( class->nickname,
|
||||||
"%s", _( "not , or ) after parameter" ) );
|
"%s", _( "not , or ) after parameter" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
} while( token != VIPS_TOKEN_RIGHT );
|
} while( token != VIPS_TOKEN_RIGHT );
|
||||||
|
|
||||||
if( (p = vips__token_get( p, &token, string, PATH_MAX )) ) {
|
if( (p = vips__token_get( p, &token, string, PATH_MAX )) ) {
|
||||||
vips_error( "VipsObject",
|
vips_error( class->nickname,
|
||||||
"%s", _( "extra tokens after ')'" ) );
|
"%s", _( "extra tokens after ')'" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
@ -1790,7 +1788,6 @@ vips_object_new_from_string( VipsObjectClass *object_class, const char *p )
|
|||||||
*/
|
*/
|
||||||
if( q &&
|
if( q &&
|
||||||
vips_object_set_args( object, q ) ) {
|
vips_object_set_args( object, q ) ) {
|
||||||
vips_error( "VipsObject", "%s", _( "bad object arguments" ) );
|
|
||||||
g_object_unref( object );
|
g_object_unref( object );
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
|
@ -1267,7 +1267,7 @@ vips__token_get( const char *p, VipsToken *token, char *string, int size )
|
|||||||
*token = VIPS_TOKEN_STRING;
|
*token = VIPS_TOKEN_STRING;
|
||||||
n = strcspn( p, "<[{()}]>=," );
|
n = strcspn( p, "<[{()}]>=," );
|
||||||
i = VIPS_MIN( n, size );
|
i = VIPS_MIN( n, size );
|
||||||
vips_strncpy( string, p, i );
|
vips_strncpy( string, p, i + 1 );
|
||||||
p += n;
|
p += n;
|
||||||
|
|
||||||
/* We remove leading whitespace, so we trim trailing
|
/* We remove leading whitespace, so we trim trailing
|
||||||
|
Loading…
Reference in New Issue
Block a user