# include "filesys.h"
# include "pathsys.h"
# include "strings.h"
-# include "newstr.h"
+# include "object.h"
# ifdef OS_NT
* file_dirscan() - scan a directory for files
*/
-void file_dirscan( char * dir, scanback func, void * closure )
+void file_dirscan( OBJECT * dir, scanback func, void * closure )
{
PROFILE_ENTER( FILE_DIRSCAN );
file_info_t * d = 0;
- dir = short_path_to_long_path( dir );
-
/* First enter directory itself */
d = file_query( dir );
if ( !d || !d->is_dir )
{
+ object_free( dir );
PROFILE_EXIT( FILE_DIRSCAN );
return;
}
int ret;
struct _finddata_t finfo[ 1 ];
LIST * files = L0;
- int d_length = strlen( d->name );
+ int d_length;
+
+ dir = short_path_to_long_path( dir );
+
+ d_length = strlen( object_str( dir ) );
memset( (char *)&f, '\0', sizeof( f ) );
- f.f_dir.ptr = d->name;
+ f.f_dir.ptr = object_str( dir );
f.f_dir.len = d_length;
/* Now enter contents of directory */
* its trailing path separator or otherwise we would not support the
* Windows root folder specified without its drive letter, i.e. '\'.
*/
- char trailingChar = d->name[ d_length - 1 ] ;
- string_copy( filespec, d->name );
+ char trailingChar = object_str( dir )[ d_length - 1 ] ;
+ string_copy( filespec, object_str( dir ) );
if ( ( trailingChar != '\\' ) && ( trailingChar != '/' ) )
string_append( filespec, "\\" );
string_append( filespec, "*" );
if ( ret = findfirst( filespec->value, finfo, FA_NORMAL | FA_DIREC ) )
{
string_free( filespec );
+ object_free( dir );
PROFILE_EXIT( FILE_DIRSCAN );
return;
}
string_truncate( filename, 0 );
path_build( &f, filename );
- files = list_new( files, newstr(filename->value) );
+ files = list_push_back( files, object_new(filename->value) );
ff = file_info( filename->value );
ff->is_file = finfo->ff_attrib & FA_DIREC ? 0 : 1;
ff->is_dir = finfo->ff_attrib & FA_DIREC ? 1 : 0;
if ( ret = ( handle < 0L ) )
{
string_free( filespec );
+ object_free( dir );
PROFILE_EXIT( FILE_DIRSCAN );
return;
}
string_new( filename );
while ( !ret )
{
+ OBJECT * filename_obj;
file_info_t * ff = 0;
f.f_base.ptr = finfo->name;
string_truncate( filename, 0 );
path_build( &f, filename, 0 );
- files = list_new( files, newstr( filename->value ) );
- ff = file_info( filename->value );
+ filename_obj = object_new( filename->value );
+ path_add_key( filename_obj );
+ files = list_push_back( files, filename_obj );
+ ff = file_info( filename_obj );
ff->is_file = finfo->attrib & _A_SUBDIR ? 0 : 1;
ff->is_dir = finfo->attrib & _A_SUBDIR ? 1 : 0;
ff->size = finfo->size;
# endif
string_free( filename );
string_free( filespec );
+ object_free( dir );
d->files = files;
}
/* Special case \ or d:\ : enter it */
{
- unsigned long len = strlen(d->name);
- if ( len == 1 && d->name[0] == '\\' )
- (*func)( closure, d->name, 1 /* stat()'ed */, d->time );
- else if ( len == 3 && d->name[1] == ':' ) {
- (*func)( closure, d->name, 1 /* stat()'ed */, d->time );
+ unsigned long len = strlen( object_str( d->name ) );
+ if ( len == 1 && object_str( d->name )[0] == '\\' )
+ {
+ OBJECT * dir = short_path_to_long_path( d->name );
+ (*func)( closure, dir, 1 /* stat()'ed */, d->time );
+ object_free( dir );
+ }
+ else if ( len == 3 && object_str( d->name )[1] == ':' )
+ {
+ char buf[4];
+ OBJECT * dir1 = short_path_to_long_path( d->name );
+ OBJECT * dir2;
+ (*func)( closure, dir1, 1 /* stat()'ed */, d->time );
/* We've just entered 3-letter drive name spelling (with trailing
slash), into the hash table. Now enter two-letter variant,
without trailing slash, so that if we try to check whether
There will be no trailing slash in $(p), but there will be one
in $(p2). But, that seems rather fragile.
*/
- d->name[2] = 0;
- (*func)( closure, d->name, 1 /* stat()'ed */, d->time );
+ strcpy( buf, object_str( dir1 ) );
+ buf[2] = 0;
+ dir2 = object_new( buf );
+ (*func)( closure, dir2, 1 /* stat()'ed */, d->time );
+ object_free( dir2 );
+ object_free( dir1 );
}
}
/* Now enter contents of directory */
- if ( d->files )
+ if ( !list_empty( d->files ) )
{
LIST * files = d->files;
- while ( files )
+ LISTITER iter = list_begin( files ), end = list_end( files );
+ for ( ; iter != end; iter = list_next( iter ) )
{
- file_info_t * ff = file_info( files->string );
- (*func)( closure, ff->name, 1 /* stat()'ed */, ff->time );
- files = list_next( files );
+ file_info_t * ff = file_info( list_item( iter ) );
+ (*func)( closure, list_item( iter ), 1 /* stat()'ed */, ff->time );
}
}
PROFILE_EXIT( FILE_DIRSCAN );
}
-file_info_t * file_query( char * filename )
+file_info_t * file_query( OBJECT * filename )
{
file_info_t * ff = file_info( filename );
if ( ! ff->time )
{
struct stat statbuf;
- if ( stat( *filename ? filename : ".", &statbuf ) < 0 )
+ if ( stat( *object_str( filename ) ? object_str( filename ) : ".", &statbuf ) < 0 )
return 0;
ff->is_file = statbuf.st_mode & S_IFREG ? 1 : 0;
int
file_time(
- char *filename,
- time_t *time )
+ OBJECT * filename,
+ time_t * time )
{
file_info_t * ff = file_query( filename );
if ( !ff ) return -1;
return 0;
}
-int file_is_file(char* filename)
+int file_is_file( OBJECT * filename )
{
file_info_t * ff = file_query( filename );
if ( !ff ) return -1;
return ff->is_file;
}
-int file_mkdir(char *pathname)
+int file_mkdir( const char * pathname )
{
return _mkdir(pathname);
}
void
file_archscan(
- char *archive,
- scanback func,
- void *closure )
+ const char * archive,
+ scanback func,
+ void * closure )
{
struct ar_hdr ar_hdr;
char *string_table = 0;
{
long lar_date;
long lar_size;
- char *name = 0;
- char *endname;
- char *c;
+ char * name = 0;
+ char * endname;
+ char * c;
+ OBJECT * member;
sscanf( ar_hdr.ar_date, "%ld", &lar_date );
sscanf( ar_hdr.ar_size, "%ld", &lar_size );
name = c + 1;
sprintf( buf, "%s(%.*s)", archive, endname - name, name );
- (*func)( closure, buf, 1 /* time valid */, (time_t)lar_date );
+ member = object_new( buf );
+ (*func)( closure, member, 1 /* time valid */, (time_t)lar_date );
+ object_free( member );
offset += SARHDR + lar_size;
lseek( fd, offset, 0 );