/* It'd be great to be able to write a generic string->array function, but * it doesn't seem possible. */ static void transform_g_string_array_double( const GValue *src_value, GValue *dest_value ) { char *str; int n; char *p, *q; int i; double *array; /* Walk the string to get the number of elements. * We need a copy of the string, since we insert \0 during * scan. * * We can't allow ',' as a separator, since some locales use it as a * decimal point. */ str = g_value_dup_string( src_value ); n = 0; for( p = str; (q = vips_break_token( p, "\t; " )); p = q ) n += 1; g_free( str ); vips_value_set_array( dest_value, n, G_TYPE_DOUBLE, sizeof( double ) ); array = (double *) vips_value_get_array( dest_value, NULL, NULL, NULL ); str = g_value_dup_string( src_value ); i = 0; for( p = str; (q = vips_break_token( p, "\t; " )); p = q ) array[i++] = atof( p ); g_free( str ); }
static void transform_g_string_array_image( const GValue *src_value, GValue *dest_value ) { char *str; int n; char *p, *q; int i; GObject **array; /* We need a copy of the string, since we insert \0 during * scan. */ str = g_value_dup_string( src_value ); n = 0; for( p = str; (q = vips_break_token( p, " " )); p = q ) n += 1; g_free( str ); vips_value_set_array_object( dest_value, n ); array = vips_value_get_array_object( dest_value, NULL ); str = g_value_dup_string( src_value ); for( i = 0, p = str; (q = vips_break_token( p, " " )); i++, p = q ) if( !(array[i] = G_OBJECT( vips_image_new_from_file( p ) )) ) { /* Set the dest to length zero to indicate error. */ vips_value_set_array_object( dest_value, 0 ); g_free( str ); return; } g_free( str ); }
/* Search a path for a file ... we overwrite the PATH string passed in. */ static char * scan_path( char *path, const char *name ) { char *p, *q; char *prefix; for( p = path; (q = vips_break_token( p, G_SEARCHPATH_SEPARATOR_S )); p = q ) { char str[PATH_MAX]; /* Form complete path. */ vips_snprintf( str, PATH_MAX, "%s" G_DIR_SEPARATOR_S "%s", p, name ); #ifdef DEBUG printf( "scan_path: looking in \"%s\" for \"%s\"\n", p, name ); #endif /*DEBUG*/ if( vips_existsf( "%s", str ) && (prefix = extract_prefix( str, name )) ) { return( prefix ); } } return( NULL ); }