move some junk to deprecated/

This commit is contained in:
John Cupitt 2014-05-06 22:01:20 +01:00
parent c8d6aac98d
commit 1a3c62851e
7 changed files with 228 additions and 203 deletions

10
TODO
View File

@ -1,17 +1,7 @@
- vips_filename_suffix_match() is used by
vips_foreign_load_new_from_foreign_sub(), but it splits on ':' ... argh!
deprecate this thing and stop ':' split
- can we use postbuild elsewhere? look at use of "preclose" / "written", etc.
- why is cache in nip2 so slow? its awful
investigate again

View File

@ -43,6 +43,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <vips/vips.h>
#include <vips/internal.h>
@ -50,6 +51,192 @@
#include <vips/vector.h>
#include <vips/transform.h>
/* Split filename into name / mode components. name and mode should both be
* FILENAME_MAX chars.
*
* We look for the ':' splitting the name and mode by searching for the
* rightmost occurence of the regexp ".[A-Za-z0-9]+:". Example: consider the
* horror that is
*
* c:\silly:dir:name\fr:ed.tif:jpeg:95,,,,c:\icc\srgb.icc
*
*/
void
im_filename_split( const char *path, char *name, char *mode )
{
char *p;
vips_strncpy( name, path, FILENAME_MAX );
/* Search back towards start stopping at each ':' char.
*/
for( p = name + strlen( name ) - 1; p > name; p -= 1 )
if( *p == ':' ) {
char *q;
for( q = p - 1; isalnum( *q ) && q > name; q -= 1 )
;
if( *q == '.' )
break;
}
if( *p == ':' ) {
vips_strncpy( mode, p + 1, FILENAME_MAX );
*p = '\0';
}
else
strcpy( mode, "" );
}
/* Skip any leading path stuff. Horrible: if this is a filename which came
* from win32 and we're a *nix machine, it'll have '\\' not '/' as the
* separator :-(
*
* Try to fudge this ... if the file doesn't contain any of our native
* separators, look for the opposite one as well. If there are none of those
* either, just return the filename.
*/
const char *
im_skip_dir( const char *path )
{
char name[FILENAME_MAX];
char mode[FILENAME_MAX];
const char *p;
const char *q;
const char native_dir_sep = G_DIR_SEPARATOR;
const char non_native_dir_sep = native_dir_sep == '/' ? '\\' : '/';
/* Remove any trailing save modifiers: we don't want '/' or '\' in the
* modifier confusing us.
*/
im_filename_split( path, name, mode );
/* The '\0' char at the end of the string.
*/
p = name + strlen( name );
/* Search back for the first native dir sep, or failing that, the first
* non-native dir sep.
*/
for( q = p; q > name && q[-1] != native_dir_sep; q-- )
;
if( q == name )
for( q = p; q > name && q[-1] != non_native_dir_sep; q-- )
;
return( path + (q - name) );
}
/* Extract suffix from filename, ignoring any mode string. Suffix should be
* FILENAME_MAX chars. Include the "." character, if any.
*/
void
im_filename_suffix( const char *path, char *suffix )
{
char name[FILENAME_MAX];
char mode[FILENAME_MAX];
char *p;
im_filename_split( path, name, mode );
if( (p = strrchr( name, '.' )) )
strcpy( suffix, p );
else
strcpy( suffix, "" );
}
/* Does a filename have one of a set of suffixes. Ignore case.
*/
int
im_filename_suffix_match( const char *path, const char *suffixes[] )
{
char suffix[FILENAME_MAX];
const char **p;
im_filename_suffix( path, suffix );
for( p = suffixes; *p; p++ )
if( g_ascii_strcasecmp( suffix, *p ) == 0 )
return( 1 );
return( 0 );
}
/* p points to the start of a buffer ... move it on through the buffer (ready
* for the next call), and return the current option (or NULL for option
* missing). ',' characters inside options can be escaped with a '\'.
*/
char *
im_getnextoption( char **in )
{
char *p;
char *q;
p = *in;
q = p;
if( !p || !*p )
return( NULL );
/* Find the next ',' not prefixed with a '\'. If the first character
* of p is ',', there can't be a previous escape character.
*/
for(;;) {
if( !(p = strchr( p, ',' )) )
break;
if( p == q )
break;
if( p[-1] != '\\' )
break;
p += 1;
}
if( p ) {
/* Another option follows this one .. set up to pick that out
* next time.
*/
*p = '\0';
*in = p + 1;
}
else {
/* This is the last one.
*/
*in = NULL;
}
if( strlen( q ) > 0 )
return( q );
else
return( NULL );
}
/* Get a suboption string, or NULL.
*/
char *
im_getsuboption( const char *buf )
{
char *p, *q, *r;
if( !(p = strchr( buf, ':' )) )
/* No suboption.
*/
return( NULL );
/* Step over the ':'.
*/
p += 1;
/* Need to unescape any \, pairs. Shift stuff down one if we find one.
*/
for( q = p; *q; q++ )
if( q[0] == '\\' && q[1] == ',' )
for( r = q; *r; r++ )
r[0] = r[1];
return( p );
}
VipsImage *
im_open( const char *filename, const char *mode )
{

View File

@ -192,12 +192,7 @@ int vips_vsnprintf( char *str, size_t size, const char *format, va_list ap );
int vips_snprintf( char *str, size_t size, const char *format, ... )
__attribute__((format(printf, 3, 4)));
void vips_filename_split( const char *path, char *name, char *mode );
const char *vips_skip_dir( const char *filename );
void vips_filename_suffix( const char *path, char *suffix );
int vips_filename_suffix_match( const char *path, const char *suffixes[] );
char *vips_getnextoption( char **in );
char *vips_getsuboption( const char *buf );
gint64 vips_file_length( int fd );
int vips__write( int fd, const void *buf, size_t count );

View File

@ -548,12 +548,6 @@ size_t im_ref_string_get_length( const GValue *value );
#define im_break_token vips_break_token
#define im_vsnprintf vips_vsnprintf
#define im_snprintf vips_snprintf
#define im_filename_split vips_filename_split
#define im_skip_dir vips_skip_dir
#define im_filename_suffix vips_filename_suffix
#define im_filename_suffix_match vips_filename_suffix_match
#define im_getnextoption vips_getnextoption
#define im_getsuboption vips_getsuboption
#define im_file_length vips_file_length
#define im__write vips__write
#define im__file_open_read vips__file_open_read
@ -1033,6 +1027,13 @@ int im_read_point( VipsImage *image, int x, int y, VipsPel *ink );
int im_draw_smudge( VipsImage *image,
int left, int top, int width, int height );
void im_filename_split( const char *path, char *name, char *mode );
const char *im_skip_dir( const char *filename );
void im_filename_suffix( const char *path, char *suffix );
int im_filename_suffix_match( const char *path, const char *suffixes[] );
char *im_getnextoption( char **in );
char *im_getsuboption( const char *buf );
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -804,7 +804,7 @@ const char *
vips_guess_prefix( const char *argv0, const char *env_name )
{
const char *prefix;
const char *p;
char *dirname;
char name[VIPS_PATH_MAX];
/* Already set?
@ -819,18 +819,20 @@ vips_guess_prefix( const char *argv0, const char *env_name )
/* Get the program name from argv0.
*/
p = vips_skip_dir( argv0 );
dirname = g_path_get_dirname( argv0 );
/* Add the exe suffix, if it's missing.
*/
if( strlen( VIPS_EXEEXT ) > 0 ) {
const char *olds[] = { VIPS_EXEEXT };
vips__change_suffix( p, name,
vips__change_suffix( dirname, name,
VIPS_PATH_MAX, VIPS_EXEEXT, olds, 1 );
}
else
vips_strncpy( name, p, VIPS_PATH_MAX );
vips_strncpy( name, dirname, VIPS_PATH_MAX );
g_free( dirname );
#ifdef DEBUG
printf( "vips_guess_prefix: argv0 = %s\n", argv0 );

View File

@ -118,10 +118,6 @@ vips_system_build( VipsObject *object )
char cmd[VIPS_PATH_MAX];
FILE *fp;
char line[VIPS_PATH_MAX];
char txt[VIPS_PATH_MAX];
VipsBuf buf = VIPS_BUF_STATIC( txt );
char *p;
char *std_output;
char *std_error;

View File

@ -448,190 +448,44 @@ vips_snprintf( char *str, size_t size, const char *format, ... )
return( n );
}
/* Split filename into name / mode components. name and mode should both be
* FILENAME_MAX chars.
*
* We look for the ':' splitting the name and mode by searching for the
* rightmost occurence of the regexp ".[A-Za-z0-9]+:". Example: consider the
* horror that is
*
* c:\silly:dir:name\fr:ed.tif:jpeg:95,,,,c:\icc\srgb.icc
*
*/
void
vips_filename_split( const char *path, char *name, char *mode )
{
char *p;
vips_strncpy( name, path, FILENAME_MAX );
/* Search back towards start stopping at each ':' char.
*/
for( p = name + strlen( name ) - 1; p > name; p -= 1 )
if( *p == ':' ) {
char *q;
for( q = p - 1; isalnum( *q ) && q > name; q -= 1 )
;
if( *q == '.' )
break;
}
if( *p == ':' ) {
vips_strncpy( mode, p + 1, FILENAME_MAX );
*p = '\0';
}
else
strcpy( mode, "" );
}
/* Skip any leading path stuff. Horrible: if this is a filename which came
* from win32 and we're a *nix machine, it'll have '\\' not '/' as the
* separator :-(
*
* Try to fudge this ... if the file doesn't contain any of our native
* separators, look for the opposite one as well. If there are none of those
* either, just return the filename.
*/
const char *
vips_skip_dir( const char *path )
{
char name[FILENAME_MAX];
char mode[FILENAME_MAX];
const char *p;
const char *q;
const char native_dir_sep = G_DIR_SEPARATOR;
const char non_native_dir_sep = native_dir_sep == '/' ? '\\' : '/';
/* Remove any trailing save modifiers: we don't want '/' or '\' in the
* modifier confusing us.
*/
vips_filename_split( path, name, mode );
/* The '\0' char at the end of the string.
*/
p = name + strlen( name );
/* Search back for the first native dir sep, or failing that, the first
* non-native dir sep.
*/
for( q = p; q > name && q[-1] != native_dir_sep; q-- )
;
if( q == name )
for( q = p; q > name && q[-1] != non_native_dir_sep; q-- )
;
return( path + (q - name) );
}
/* Extract suffix from filename, ignoring any mode string. Suffix should be
* FILENAME_MAX chars. Include the "." character, if any.
*/
void
vips_filename_suffix( const char *path, char *suffix )
{
char name[FILENAME_MAX];
char mode[FILENAME_MAX];
char *p;
vips_filename_split( path, name, mode );
if( (p = strrchr( name, '.' )) )
strcpy( suffix, p );
else
strcpy( suffix, "" );
}
/* Does a filename have one of a set of suffixes. Ignore case.
/* Does a filename have one of a set of suffixes. Ignore case and any trailing
* options.
*/
int
vips_filename_suffix_match( const char *path, const char *suffixes[] )
{
char suffix[FILENAME_MAX];
const char **p;
vips_filename_suffix( path, suffix );
for( p = suffixes; *p; p++ )
if( g_ascii_strcasecmp( suffix, *p ) == 0 )
return( 1 );
return( 0 );
}
/* p points to the start of a buffer ... move it on through the buffer (ready
* for the next call), and return the current option (or NULL for option
* missing). ',' characters inside options can be escaped with a '\'.
*/
char *
vips_getnextoption( char **in )
{
char *p;
char *basename;
char *suffix;
char *q;
const char **p;
int result;
p = *in;
q = p;
if( !p || !*p )
return( NULL );
/* Find the next ',' not prefixed with a '\'. If the first character
* of p is ',', there can't be a previous escape character.
/* Drop any directory components, we want ignore any '.' in there.
*/
for(;;) {
if( !(p = strchr( p, ',' )) )
break;
if( p == q )
break;
if( p[-1] != '\\' )
break;
basename = g_path_get_basename( path );
p += 1;
}
if( p ) {
/* Another option follows this one .. set up to pick that out
* next time.
/* Zap any trailing options.
*/
*p = '\0';
*in = p + 1;
}
else {
/* This is the last one.
*/
*in = NULL;
}
if( (q = (char *) vips__find_rightmost_brackets( basename )) )
*q = '\0';
if( strlen( q ) > 0 )
return( q );
/* And select just the '.' and to the right.
*/
if( (q = strrchr( basename, '.' )) )
suffix = q;
else
return( NULL );
suffix = basename;
result = 0;
for( p = suffixes; *p; p++ )
if( g_ascii_strcasecmp( suffix, *p ) == 0 ) {
result = 1;
break;
}
/* Get a suboption string, or NULL.
*/
char *
vips_getsuboption( const char *buf )
{
char *p, *q, *r;
g_free( basename );
if( !(p = strchr( buf, ':' )) )
/* No suboption.
*/
return( NULL );
/* Step over the ':'.
*/
p += 1;
/* Need to unescape any \, pairs. Shift stuff down one if we find one.
*/
for( q = p; *q; q++ )
if( q[0] == '\\' && q[1] == ',' )
for( r = q; *r; r++ )
r[0] = r[1];
return( p );
return( result );
}
/* Get file length ... 64-bitally. -1 for error.