Modifiche alla formattazione

git-svn-id: svn://10.65.10.50/trunk@312 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1994-10-04 16:03:54 +00:00
parent a0cf576daf
commit 85f5697a82

View File

@ -105,7 +105,7 @@
#if defined( AL_BUILDING_DLL ) #if defined( AL_BUILDING_DLL )
void AL_DLL_FAR * AL_PROTO ALFile::operator new( size_t size ) void AL_DLL_FAR * AL_PROTO ALFile::operator new( size_t size )
{ {
return ::new char[ size ]; return ::new char[ size ];
} }
#endif #endif
@ -149,11 +149,11 @@ void AL_DLL_FAR * AL_PROTO ALFile::operator new( size_t size )
// //
AL_PROTO ALFile::ALFile( const char AL_DLL_FAR *file_name /* = "" */, AL_PROTO ALFile::ALFile( const char AL_DLL_FAR *file_name /* = "" */,
int buffer_size /* = 4096 */, int buffer_size /* = 4096 */,
ALCase name_case /* = AL_LOWER */) ALCase name_case /* = AL_LOWER */)
// Note: if non-msdos, change case parameter to AL_MIXED // Note: if non-msdos, change case parameter to AL_MIXED
: ALStorage( file_name, buffer_size, AL_FILE_OBJECT, name_case ) { : ALStorage( file_name, buffer_size, AL_FILE_OBJECT, name_case ) {
miHandle = -1; miHandle = -1;
} }
// //
@ -186,9 +186,9 @@ AL_PROTO ALFile::ALFile( const char AL_DLL_FAR *file_name /* = "" */,
AL_PROTO ALFile::~ALFile() AL_PROTO ALFile::~ALFile()
{ {
AL_ASSERT( GoodTag(), "~ALFile: attempting to delete invalid object" ); AL_ASSERT( GoodTag(), "~ALFile: attempting to delete invalid object" );
if ( miHandle != -1 ) if ( miHandle != -1 )
Close(); Close();
} }
// //
@ -233,31 +233,31 @@ AL_PROTO ALFile::~ALFile()
int AL_PROTO ALFile::LoadBuffer( long address ) int AL_PROTO ALFile::LoadBuffer( long address )
{ {
if ( mStatus < AL_SUCCESS ) if ( mStatus < AL_SUCCESS )
return mStatus; return mStatus;
if ( mlFilePointer != address ) { if ( mlFilePointer != address ) {
long result = lseek( miHandle, address, SEEK_SET ); long result = lseek( miHandle, address, SEEK_SET );
if ( result == -1L ) if ( result == -1L )
return mStatus.SetError( AL_SEEK_ERROR, return mStatus.SetError( AL_SEEK_ERROR,
"Seek failure on %s. errno = %d", "Seek failure on %s. errno = %d",
mName.GetName(), mName.GetName(),
errno ); errno );
} }
int result = read( miHandle, mpcBuffer, muBufferSize ); int result = read( miHandle, mpcBuffer, muBufferSize );
if ( result == 0 ) if ( result == 0 )
return AL_END_OF_FILE; return AL_END_OF_FILE;
if ( result < 0 ) if ( result < 0 )
return mStatus.SetError( AL_READ_ERROR, return mStatus.SetError( AL_READ_ERROR,
"Read failure on %s. errno = %d", "Read failure on %s. errno = %d",
mName.GetName(), mName.GetName(),
errno ); errno );
if ( miUpdateCrcFlag ) if ( miUpdateCrcFlag )
UpdateCrc( result ); UpdateCrc( result );
muReadIndex = 0; //Reading can resume at this location in the I/O buffer muReadIndex = 0; //Reading can resume at this location in the I/O buffer
mlFilePointer += result; mlFilePointer += result;
muBufferValidData = result; muBufferValidData = result;
YieldTime(); YieldTime();
return result; return result;
} }
// //
@ -296,24 +296,24 @@ int AL_PROTO ALFile::LoadBuffer( long address )
int AL_PROTO ALFile::FlushBuffer() int AL_PROTO ALFile::FlushBuffer()
{ {
if ( mStatus < 0 ) if ( mStatus < 0 )
return mStatus; return mStatus;
if ( muWriteIndex != 0 ) { if ( muWriteIndex != 0 ) {
if ( miUpdateCrcFlag ) if ( miUpdateCrcFlag )
UpdateCrc( muWriteIndex ); UpdateCrc( muWriteIndex );
int result = write( miHandle, mpcBuffer, muWriteIndex ); int result = write( miHandle, mpcBuffer, muWriteIndex );
muWriteIndex = 0; muWriteIndex = 0;
if ( result == -1L ) if ( result == -1L )
return mStatus.SetError( AL_WRITE_ERROR, return mStatus.SetError( AL_WRITE_ERROR,
"Write failure on %s. errno = %d", "Write failure on %s. errno = %d",
mName.GetName(), mName.GetName(),
errno ); errno );
mlFilePointer += result; mlFilePointer += result;
} }
muReadIndex = 0; muReadIndex = 0;
muBufferValidData = 0; muBufferValidData = 0;
YieldTime(); YieldTime();
return AL_SUCCESS; return AL_SUCCESS;
} }
// //
@ -347,19 +347,19 @@ int AL_PROTO ALFile::FlushBuffer()
int AL_PROTO ALFile::Seek( long address ) int AL_PROTO ALFile::Seek( long address )
{ {
FlushBuffer(); FlushBuffer();
if ( mStatus < 0 ) if ( mStatus < 0 )
return mStatus; return mStatus;
if ( mlFilePointer != address ) { if ( mlFilePointer != address ) {
long result = lseek( miHandle, address, SEEK_SET ); long result = lseek( miHandle, address, SEEK_SET );
if ( result == -1L ) if ( result == -1L )
return mStatus.SetError( AL_SEEK_ERROR, return mStatus.SetError( AL_SEEK_ERROR,
"Seek failure on %s. errno = %d", "Seek failure on %s. errno = %d",
mName.GetName(), mName.GetName(),
errno ); errno );
} }
mlFilePointer = address; mlFilePointer = address;
return AL_SUCCESS; return AL_SUCCESS;
} }
// //
@ -398,56 +398,56 @@ int AL_PROTO ALFile::Seek( long address )
int AL_PROTO ALFile::Open() int AL_PROTO ALFile::Open()
{ {
if ( mStatus < AL_SUCCESS ) if ( mStatus < AL_SUCCESS )
return mStatus; return mStatus;
miHandle = open( mName, O_BINARY | O_RDWR ); miHandle = open( mName, O_BINARY | O_RDWR );
if ( miHandle == -1 && errno == EACCES ) if ( miHandle == -1 && errno == EACCES )
miHandle = open( mName, O_BINARY | O_RDONLY ); miHandle = open( mName, O_BINARY | O_RDONLY );
if ( miHandle == -1 ) if ( miHandle == -1 )
return mStatus.SetError( AL_CANT_OPEN_FILE, return mStatus.SetError( AL_CANT_OPEN_FILE,
"File open failure. Open of %s returned " "File open failure. Open of %s returned "
"errno = %d", "errno = %d",
mName.GetName(), mName.GetName(),
errno ); errno );
ALStorage::Open(); ALStorage::Open();
struct stat buf; struct stat buf;
struct tm *tblock; struct tm *tblock;
if ( stat( mName, &buf ) == -1 ) if ( stat( mName, &buf ) == -1 )
return mStatus.SetError( AL_CANT_OPEN_FILE, return mStatus.SetError( AL_CANT_OPEN_FILE,
"Couldn't get time, date, and size " "Couldn't get time, date, and size "
"information for %s. errno = %d.", "information for %s. errno = %d.",
mName.GetName(), mName.GetName(),
errno ); errno );
mlSize = buf.st_size; mlSize = buf.st_size;
tblock = localtime( &buf.st_mtime ); tblock = localtime( &buf.st_mtime );
mTimeDate.SetTimeDate( tblock ); mTimeDate.SetTimeDate( tblock );
#if XVT_OS == XVT_OS_SCOUNIX #if XVT_OS == XVT_OS_SCOUNIX
// TBI code for UNIX attributes // TBI code for UNIX attributes
// stat s; // stat s;
// mAttributes = SetFromUnixMode(stat.st_mode) // mAttributes = SetFromUnixMode(stat.st_mode)
#else #else
#if defined( AL_WIN32S ) #if defined( AL_WIN32S )
DWORD attributes = GetFileAttributes( mName ); DWORD attributes = GetFileAttributes( mName );
if ( attributes == 0xFFFFFFFF ) if ( attributes == 0xFFFFFFFF )
return mStatus.SetError( AL_CANT_OPEN_FILE, return mStatus.SetError( AL_CANT_OPEN_FILE,
"Couldn't get Win32 file attribute " "Couldn't get Win32 file attribute "
"information for %s. GetLastError = %d.", "information for %s. GetLastError = %d.",
mName.GetName(), mName.GetName(),
GetLastError() ); GetLastError() );
mAttributes.SetFromWin32Attributes( attributes ); mAttributes.SetFromWin32Attributes( attributes );
#else #else
unsigned attributes; unsigned attributes;
if ( _dos_getfileattr( mName, &attributes ) != 0 ) if ( _dos_getfileattr( mName, &attributes ) != 0 )
return mStatus.SetError( AL_CANT_OPEN_FILE, return mStatus.SetError( AL_CANT_OPEN_FILE,
"Couldn't get DOS attribute " "Couldn't get DOS attribute "
"information for %s. errno = %d.", "information for %s. errno = %d.",
mName.GetName(), mName.GetName(),
errno ); errno );
mAttributes.SetFromDosAttributes( attributes ); mAttributes.SetFromDosAttributes( attributes );
#endif #endif
#endif #endif
return AL_SUCCESS; return AL_SUCCESS;
} }
// //
@ -482,10 +482,10 @@ int AL_PROTO ALFile::Open()
void AL_PROTO ALFile::MakeTempName( int i ) void AL_PROTO ALFile::MakeTempName( int i )
{ {
char name[ 21 ]; char name[ 21 ];
sprintf( name, "~al~%03d.tmp", i ); sprintf( name, "~al~%03d.tmp", i );
mName = name; mName = name;
} }
// //
@ -526,48 +526,48 @@ void AL_PROTO ALFile::MakeTempName( int i )
int AL_PROTO ALFile::Create() int AL_PROTO ALFile::Create()
{ {
ALStorage::Create(); ALStorage::Create();
if ( mStatus < AL_SUCCESS ) if ( mStatus < AL_SUCCESS )
return mStatus; return mStatus;
if ( (char *) mName == 0 || strlen( mName ) == 0 ) { if ( (char *) mName == 0 || strlen( mName ) == 0 ) {
for ( int i = 0 ; i < 999 ; i++ ) { for ( int i = 0 ; i < 999 ; i++ ) {
MakeTempName( i ); MakeTempName( i );
miHandle = open( mName, miHandle = open( mName,
O_CREAT | O_RDWR | O_BINARY | O_EXCL, O_CREAT | O_RDWR | O_BINARY | O_EXCL,
S_IREAD | S_IWRITE ); S_IREAD | S_IWRITE );
if ( miHandle != -1 ) if ( miHandle != -1 )
break; break;
else if ( errno != EEXIST && errno != EACCES ) { else if ( errno != EEXIST && errno != EACCES ) {
mStatus.SetError( AL_CANT_OPEN_FILE, mStatus.SetError( AL_CANT_OPEN_FILE,
"Temporary file creation failure. " "Temporary file creation failure. "
"Open of %s returned errno = %d", "Open of %s returned errno = %d",
mName.GetName(), mName.GetName(),
errno ); errno );
mName = ""; mName = "";
return AL_CANT_OPEN_FILE; return AL_CANT_OPEN_FILE;
} }
}
if ( i == 1000 ) {
mStatus.SetError( AL_CANT_OPEN_FILE,
"Temporary file creation failure. "
"Tried 1000 times to open %s "
"(or a name something like that).",
mName.GetName() );
mName = "";
return AL_CANT_OPEN_FILE;
}
} else {
miHandle = open( mName,
O_CREAT | O_RDWR | O_BINARY | O_TRUNC,
S_IREAD | S_IWRITE );
} }
if ( miHandle == -1 ) if ( i == 1000 ) {
return mStatus.SetError( AL_CANT_OPEN_FILE, mStatus.SetError( AL_CANT_OPEN_FILE,
"File creation failure. " "Temporary file creation failure. "
"Open of %s returned errno = %d", "Tried 1000 times to open %s "
mName.GetName(), "(or a name something like that).",
errno ); mName.GetName() );
return AL_SUCCESS; mName = "";
return AL_CANT_OPEN_FILE;
}
} else {
miHandle = open( mName,
O_CREAT | O_RDWR | O_BINARY | O_TRUNC,
S_IREAD | S_IWRITE );
}
if ( miHandle == -1 )
return mStatus.SetError( AL_CANT_OPEN_FILE,
"File creation failure. "
"Open of %s returned errno = %d",
mName.GetName(),
errno );
return AL_SUCCESS;
} }
// //
@ -597,32 +597,32 @@ int AL_PROTO ALFile::Create()
int AL_PROTO ALFile::Close() int AL_PROTO ALFile::Close()
{ {
if ( miHandle == -1 ) if ( miHandle == -1 )
return mStatus; return mStatus;
FlushBuffer(); FlushBuffer();
mlSize = filelength( miHandle ); mlSize = filelength( miHandle );
if ( miCreated && mTimeDate.Valid() ) { if ( miCreated && mTimeDate.Valid() ) {
#if defined( AL_WIN32S ) #if defined( AL_WIN32S )
// Can you do this under NT? I don't know how. // Can you do this under NT? I don't know how.
#else #else
_dos_setftime( miHandle, mTimeDate.GetDosDate(), mTimeDate.GetDosTime() ); _dos_setftime( miHandle, mTimeDate.GetDosDate(), mTimeDate.GetDosTime() );
#endif #endif
} }
close( miHandle ); close( miHandle );
miHandle = -1; miHandle = -1;
ALStorage::Close(); ALStorage::Close();
if ( miCreated && mTimeDate.Valid() ) { if ( miCreated && mTimeDate.Valid() ) {
#if XVT_OS == XVT_OS_SCOUNIX #if XVT_OS == XVT_OS_SCOUNIX
// TBI code for setting UNIX attributes // TBI code for setting UNIX attributes
#else #else
#if defined( AL_WIN32S ) #if defined( AL_WIN32S )
SetFileAttributes( mName, mAttributes.GetWin32Attributes() ); SetFileAttributes( mName, mAttributes.GetWin32Attributes() );
#else #else
_dos_setfileattr( mName, mAttributes.GetDosAttributes() ); _dos_setfileattr( mName, mAttributes.GetDosAttributes() );
#endif #endif
#endif #endif
} }
return mStatus; return mStatus;
} }
// //
@ -656,8 +656,8 @@ int AL_PROTO ALFile::Close()
int AL_PROTO ALFile::RenameToBackup( int delete_on_clash /* = 1 */ ) int AL_PROTO ALFile::RenameToBackup( int delete_on_clash /* = 1 */ )
{ {
mName.ChangeExtension(); mName.ChangeExtension();
return Rename( 0, delete_on_clash ); return Rename( 0, delete_on_clash );
} }
// //
@ -700,61 +700,61 @@ int AL_PROTO ALFile::RenameToBackup( int delete_on_clash /* = 1 */ )
// //
int AL_PROTO ALFile::Rename( const char AL_DLL_FAR *new_name /* = 0 */, int AL_PROTO ALFile::Rename( const char AL_DLL_FAR *new_name /* = 0 */,
int delete_on_clash /* = 1 */ ) int delete_on_clash /* = 1 */ )
{ {
AL_ASSERT( miHandle == -1, "Rename: attempting to rename open file" ); AL_ASSERT( miHandle == -1, "Rename: attempting to rename open file" );
AL_ASSERT( mName.GetName() != 0, "Rename: attempting to rename file with null name" ); AL_ASSERT( mName.GetName() != 0, "Rename: attempting to rename file with null name" );
AL_ASSERT( strlen( mName ) > 0, "Rename: attempting to rename file with 0 length name" ); AL_ASSERT( strlen( mName ) > 0, "Rename: attempting to rename file with 0 length name" );
int status; int status;
const char *real_old_name; const char *real_old_name;
const char *real_new_name; const char *real_new_name;
if ( new_name ) { if ( new_name ) {
real_old_name = mName.GetSafeName(); real_old_name = mName.GetSafeName();
real_new_name = new_name; real_new_name = new_name;
} else { } else {
real_old_name = mName.GetSafeOldName(); real_old_name = mName.GetSafeOldName();
real_new_name = mName.GetSafeName(); real_new_name = mName.GetSafeName();
} }
#if !defined( AL_WIN32S ) #if !defined( AL_WIN32S )
const char *p = strchr( real_new_name, '.' ); const char *p = strchr( real_new_name, '.' );
if ( p && strlen( p ) > 4 ) if ( p && strlen( p ) > 4 )
return mStatus.SetError( AL_RENAME_ERROR, return mStatus.SetError( AL_RENAME_ERROR,
"Error trying to rename %s. It has a long " "Error trying to rename %s. It has a long "
"extension, which could lead to inadvertent " "extension, which could lead to inadvertent "
"deletion of a file when trying to rename.", "deletion of a file when trying to rename.",
real_old_name ); real_old_name );
#endif #endif
if ( delete_on_clash ) { if ( delete_on_clash ) {
if ( mName.mCase == AL_MIXED ) if ( mName.mCase == AL_MIXED )
status = strcmp( real_new_name, real_old_name ); status = strcmp( real_new_name, real_old_name );
else else
status = stricmp( real_new_name, real_old_name ); status = stricmp( real_new_name, real_old_name );
if ( status == 0 ) if ( status == 0 )
return mStatus.SetError( AL_RENAME_ERROR, return mStatus.SetError( AL_RENAME_ERROR,
"Error attempting to rename %s to %s. " "Error attempting to rename %s to %s. "
"Can't rename to the same name!", "Can't rename to the same name!",
real_new_name, real_new_name,
real_old_name ); real_old_name );
status = unlink( real_new_name ); status = unlink( real_new_name );
if ( status != 0 && errno != ENOENT ) if ( status != 0 && errno != ENOENT )
return mStatus.SetError( AL_RENAME_ERROR, return mStatus.SetError( AL_RENAME_ERROR,
"Error deleting %s before renaming %s. " "Error deleting %s before renaming %s. "
"errno = %d", "errno = %d",
real_new_name, real_new_name,
real_old_name, real_old_name,
errno ); errno );
} }
status = rename( real_old_name, real_new_name ); status = rename( real_old_name, real_new_name );
if ( status != 0 ) if ( status != 0 )
return mStatus.SetError( AL_RENAME_ERROR, return mStatus.SetError( AL_RENAME_ERROR,
"Error renaming %s to %s. errno = %d", "Error renaming %s to %s. errno = %d",
real_old_name, real_old_name,
real_new_name, real_new_name,
errno ); errno );
if ( new_name != 0 ) if ( new_name != 0 )
mName = new_name; mName = new_name;
return AL_SUCCESS; return AL_SUCCESS;
} }
// //
@ -790,33 +790,33 @@ int AL_PROTO ALFile::Rename( const char AL_DLL_FAR *new_name /* = 0 */,
int AL_PROTO ALFile::UnRename( int delete_on_clash /* = 1 */ ) int AL_PROTO ALFile::UnRename( int delete_on_clash /* = 1 */ )
{ {
AL_ASSERT( miHandle == -1, "UnRename: attempting to rename open file" ); AL_ASSERT( miHandle == -1, "UnRename: attempting to rename open file" );
AL_ASSERT( mName.GetName() != 0, "UnRename: attempting to rename file with null name" ); AL_ASSERT( mName.GetName() != 0, "UnRename: attempting to rename file with null name" );
AL_ASSERT( mName.GetOldName() != 0, "UnRename: attempting to rename file with null old name" ); AL_ASSERT( mName.GetOldName() != 0, "UnRename: attempting to rename file with null old name" );
AL_ASSERT( strlen( mName ) > 0, "UnRename: attempting to rename file with 0 length name" ); AL_ASSERT( strlen( mName ) > 0, "UnRename: attempting to rename file with 0 length name" );
AL_ASSERT( strlen( mName.GetOldName() ) > 0, "UnRename: attempting to rename file with 0 length old name" ); AL_ASSERT( strlen( mName.GetOldName() ) > 0, "UnRename: attempting to rename file with 0 length old name" );
int status; int status;
if ( delete_on_clash ) { if ( delete_on_clash ) {
status = unlink( mName.GetOldName() ); status = unlink( mName.GetOldName() );
if ( status != 0 && errno != ENOENT )
return mStatus.SetError( AL_RENAME_ERROR,
"Error deleting %s before renaming %s. "
"errno = %d",
mName.GetOldName(),
mName.GetName(),
errno );
}
status = rename( mName, mName.GetOldName() );
if ( status != 0 && errno != ENOENT ) if ( status != 0 && errno != ENOENT )
return mStatus.SetError( AL_RENAME_ERROR, return mStatus.SetError( AL_RENAME_ERROR,
"Error renaming %s to %s. errno = %d", "Error deleting %s before renaming %s. "
mName.GetName(), "errno = %d",
mName.GetOldName(), mName.GetOldName(),
errno ); mName.GetName(),
ALStorage::mName = mName.GetOldName(); errno );
return AL_SUCCESS; }
status = rename( mName, mName.GetOldName() );
if ( status != 0 && errno != ENOENT )
return mStatus.SetError( AL_RENAME_ERROR,
"Error renaming %s to %s. errno = %d",
mName.GetName(),
mName.GetOldName(),
errno );
ALStorage::mName = mName.GetOldName();
return AL_SUCCESS;
} }
// //
@ -843,17 +843,17 @@ int AL_PROTO ALFile::UnRename( int delete_on_clash /* = 1 */ )
int AL_PROTO ALFile::Delete() int AL_PROTO ALFile::Delete()
{ {
AL_ASSERT( miHandle == -1, "Delete: attempting to delete open file" ); AL_ASSERT( miHandle == -1, "Delete: attempting to delete open file" );
AL_ASSERT( mName.GetName() != 0, "Delete: attempting to delete file with null name" ); AL_ASSERT( mName.GetName() != 0, "Delete: attempting to delete file with null name" );
AL_ASSERT( strlen( mName ) > 0, "Delete: attempting to delete file with 0 length name" ); AL_ASSERT( strlen( mName ) > 0, "Delete: attempting to delete file with 0 length name" );
int status = unlink( mName ); int status = unlink( mName );
if ( status != 0 ) if ( status != 0 )
return mStatus.SetError( AL_DELETE_ERROR, return mStatus.SetError( AL_DELETE_ERROR,
"Error deleting file %s, errno = %d ", "Error deleting file %s, errno = %d ",
mName.GetName(), mName.GetName(),
errno ); errno );
return AL_SUCCESS; return AL_SUCCESS;
} }