diff options
Diffstat (limited to 'tools/build/v2/engine/filent.c')
-rw-r--r-- | tools/build/v2/engine/filent.c | 96 |
1 files changed, 60 insertions, 36 deletions
diff --git a/tools/build/v2/engine/filent.c b/tools/build/v2/engine/filent.c index ab18957677..b448cd03f7 100644 --- a/tools/build/v2/engine/filent.c +++ b/tools/build/v2/engine/filent.c @@ -16,7 +16,7 @@ # include "filesys.h" # include "pathsys.h" # include "strings.h" -# include "newstr.h" +# include "object.h" # ifdef OS_NT @@ -57,20 +57,19 @@ * 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; } @@ -84,11 +83,15 @@ void file_dirscan( char * dir, scanback func, void * closure ) 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 */ @@ -103,8 +106,8 @@ void file_dirscan( char * dir, scanback func, void * closure ) * 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, "*" ); @@ -117,6 +120,7 @@ void file_dirscan( char * dir, scanback func, void * closure ) if ( ret = findfirst( filespec->value, finfo, FA_NORMAL | FA_DIREC ) ) { string_free( filespec ); + object_free( dir ); PROFILE_EXIT( FILE_DIRSCAN ); return; } @@ -132,7 +136,7 @@ void file_dirscan( char * dir, scanback func, void * closure ) 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; @@ -147,6 +151,7 @@ void file_dirscan( char * dir, scanback func, void * closure ) if ( ret = ( handle < 0L ) ) { string_free( filespec ); + object_free( dir ); PROFILE_EXIT( FILE_DIRSCAN ); return; } @@ -154,6 +159,7 @@ void file_dirscan( char * dir, scanback func, void * closure ) string_new( filename ); while ( !ret ) { + OBJECT * filename_obj; file_info_t * ff = 0; f.f_base.ptr = finfo->name; @@ -162,8 +168,10 @@ void file_dirscan( char * dir, scanback func, void * closure ) 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; @@ -176,17 +184,26 @@ void file_dirscan( char * dir, scanback func, void * closure ) # 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 @@ -199,34 +216,38 @@ void file_dirscan( char * dir, scanback func, void * closure ) 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; @@ -243,8 +264,8 @@ file_info_t * file_query( char * filename ) int file_time( - char *filename, - time_t *time ) + OBJECT * filename, + time_t * time ) { file_info_t * ff = file_query( filename ); if ( !ff ) return -1; @@ -252,14 +273,14 @@ file_time( 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); } @@ -290,9 +311,9 @@ struct ar_hdr { 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; @@ -320,9 +341,10 @@ file_archscan( { 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 ); @@ -375,7 +397,9 @@ file_archscan( 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 ); |