get p21read to run without crashing, for ap214. still doesn't copy the file successfully.
also: change a lot of char* to std::string use standard functions in DirObj to simplify remove quite a bit of code that was unnecessary or was for object database or corba
This commit is contained in:
+25
-56
@@ -23,6 +23,9 @@
|
||||
list according to the symbol which precedes them in the working session
|
||||
file
|
||||
**********************************************************************/
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
#include <STEPfile.h>
|
||||
#include <sdai.h>
|
||||
#include <STEPcomplex.h>
|
||||
@@ -35,37 +38,21 @@
|
||||
|
||||
/***************************
|
||||
function: SetFileName
|
||||
returns: (const char*) The new file name for the class.
|
||||
parameters: (const char*) The file name to be set.
|
||||
returns: (const std::string) The new file name for the class.
|
||||
parameters: (const std::string) The file name to be set.
|
||||
description:
|
||||
This function sets the (char*)_fileName member variable to an
|
||||
This function sets the _fileName member variable to an
|
||||
absolute path name to a directory on the file system. If newName
|
||||
cannot be resolved to a file, then an empty char* is returned.
|
||||
cannot be resolved to a file, then an empty string is returned.
|
||||
side effects: STEPfile::_fileName value may change.
|
||||
***************************/
|
||||
const char *
|
||||
STEPfile::SetFileName( const char * newName ) {
|
||||
char tmp[MAXPATHLEN + 1];
|
||||
const char * path = tmp;
|
||||
|
||||
const std::string STEPfile::SetFileName( const std::string newName ) {
|
||||
// if a newName is not given or is the same as the old, use the old name
|
||||
if( ( !newName ) || ( !strcmp( newName, "" ) ) || ( newName == _fileName ) ) {
|
||||
if( ( newName.empty() ) || ( newName == _fileName ) ) {
|
||||
return FileName();
|
||||
}
|
||||
|
||||
path = _currentDir->Normalize( newName );
|
||||
if( !_currentDir->LoadDirectory( path ) ) {
|
||||
_error.AppendToUserMsg( "Cannot Load Directory.\n" );
|
||||
return ( char * )0;
|
||||
}
|
||||
|
||||
delete [] _fileName;
|
||||
_fileName = new char[strlen( newName ) + 1];
|
||||
if( !_fileName ) {
|
||||
_error.AppendToUserMsg( "free store exhausted.\n" );
|
||||
return ( char * )0;
|
||||
}
|
||||
strcpy( _fileName, newName );
|
||||
_fileName = DirObj::Normalize( newName );
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
@@ -2126,40 +2113,22 @@ BUG: doesn't check to see if the backup command works.
|
||||
******************************************************/
|
||||
void
|
||||
STEPfile::MakeBackupFile() {
|
||||
char backup_call [2 * BUFSIZ];
|
||||
char backup_file [BUFSIZ];
|
||||
std::string bckup = FileName();
|
||||
bckup.append(".bak");
|
||||
|
||||
// sprintf (backup_file, "%s.%d", FileName(), ++i);
|
||||
sprintf( backup_file, "%s.bak", FileName() );
|
||||
std::fstream f(FileName().c_str(), std::fstream::in|std::fstream::binary);
|
||||
f << std::noskipws;
|
||||
std::istream_iterator<unsigned char> begin(f);
|
||||
std::istream_iterator<unsigned char> end;
|
||||
|
||||
sprintf( backup_call,
|
||||
"if (test -f %s )"
|
||||
" then mv %s %s ;",
|
||||
FileName(),
|
||||
FileName(), backup_file );
|
||||
std::fstream f2(bckup.c_str(), std::fstream::out|std::fstream::trunc|std::fstream::binary);
|
||||
std::ostream_iterator<char> begin2(f2);
|
||||
|
||||
// if (i > 4)
|
||||
// sprintf (backup_call + strlen (backup_call), "rm %s.%d ; ", FileName (), i -2);
|
||||
strcat( backup_call, "fi" );
|
||||
copy(begin, end, begin2);
|
||||
|
||||
_error.AppendToDetailMsg( "Making backup file: " );
|
||||
_error.AppendToDetailMsg( backup_file );
|
||||
_error.AppendToDetailMsg( bckup.c_str() );
|
||||
_error.AppendToDetailMsg( "\n" );
|
||||
system( backup_call );
|
||||
/*
|
||||
strcpy (backup_call, "if (test -f ");
|
||||
strcat (backup_call, FileName());
|
||||
strcat (backup_call, ") then mv ");
|
||||
strcat (backup_call, FileName());
|
||||
strcat (backup_call, " ");
|
||||
strcat (backup_call, FileName());
|
||||
strcat (backup_call, ".bak ; fi ", ++i);
|
||||
|
||||
_error.AppendToDetailMsg("Making backup file: executing system call:\n\t");
|
||||
_error.AppendToDetailMsg(backup_call);
|
||||
_error.AppendToDetailMsg("\n");
|
||||
system(backup_call);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -2194,7 +2163,7 @@ STEPfile::WriteExchangeFile( ostream & out, int validate, int clearError,
|
||||
/***************************
|
||||
***************************/
|
||||
Severity
|
||||
STEPfile::WriteExchangeFile( const char * filename, int validate, int clearError,
|
||||
STEPfile::WriteExchangeFile( const std::string filename, int validate, int clearError,
|
||||
int writeComments ) {
|
||||
Severity rval = SEVERITY_NULL;
|
||||
|
||||
@@ -2630,13 +2599,13 @@ STEPfile::AppendFile( istream * in, int useTechCor ) {
|
||||
sprintf( errbuf,
|
||||
"Faulty input at beginning of file. \"ISO-10303-21;\" or"
|
||||
" \"STEP;\" or \"STEP_WORKING_SESSION;\" expected. File "
|
||||
"not read: %s\n", ( ( strcmp( FileName(), "-" ) == 0 ) ? "standard input" : FileName() ) );
|
||||
"not read: %s\n", ( ( FileName().compare( "-" ) == 0 ) ? "standard input" : FileName().c_str() ) );
|
||||
_error.AppendToUserMsg( errbuf );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
return SEVERITY_INPUT_ERROR;
|
||||
}
|
||||
|
||||
cout << "Reading Data from " << ( ( strcmp( FileName(), "-" ) == 0 ) ? "standard input" : FileName() ) << "...\n";
|
||||
cout << "Reading Data from " << ( ( FileName().compare( "-" ) == 0 ) ? "standard input" : FileName() ) << "...\n";
|
||||
|
||||
// Read header
|
||||
rval = ReadHeader( *in );
|
||||
@@ -2727,7 +2696,7 @@ STEPfile::AppendFile( istream * in, int useTechCor ) {
|
||||
|
||||
if( total_insts != valid_insts ) {
|
||||
sprintf( errbuf, "%d invalid instances in file: %s\n",
|
||||
total_insts - valid_insts, ( ( strcmp( FileName(), "-" ) == 0 ) ? "standard input" : FileName() ) );
|
||||
total_insts - valid_insts, ( ( FileName().compare( "-" ) == 0 ) ? "standard input" : FileName().c_str() ) );
|
||||
_error.AppendToUserMsg( errbuf );
|
||||
CloseInputFile( in2 );
|
||||
return _error.GreaterSeverity( SEVERITY_WARNING );
|
||||
@@ -2799,7 +2768,7 @@ STEPfile::WriteWorkingFile( ostream & out, int clearError, int writeComments ) {
|
||||
/***************************
|
||||
***************************/
|
||||
Severity
|
||||
STEPfile::WriteWorkingFile( const char * filename, int clearError,
|
||||
STEPfile::WriteWorkingFile( const std::string filename, int clearError,
|
||||
int writeComments ) {
|
||||
if( clearError ) {
|
||||
_error.ClearErrorMsg();
|
||||
|
||||
+13
-21
@@ -47,19 +47,11 @@ class STEPfile
|
||||
protected:
|
||||
//data members
|
||||
|
||||
#ifdef __O3DB__
|
||||
InstMgr * _instances;
|
||||
Registry * _reg;
|
||||
|
||||
InstMgr & instances () { return *_instances; }
|
||||
Registry & reg () { return *_reg; }
|
||||
#else
|
||||
InstMgr& _instances;
|
||||
Registry& _reg;
|
||||
|
||||
InstMgr & instances () { return _instances; }
|
||||
Registry & reg () { return _reg; }
|
||||
#endif
|
||||
int _fileIdIncr; //Increment value to be added to FileId Numbers on input
|
||||
|
||||
//header information
|
||||
@@ -72,7 +64,7 @@ class STEPfile
|
||||
|
||||
//file information
|
||||
DirObj* _currentDir;
|
||||
char* _fileName;
|
||||
std::string _fileName;
|
||||
|
||||
//error information
|
||||
ErrorDescriptor _error;
|
||||
@@ -113,9 +105,9 @@ class STEPfile
|
||||
SCLP23(Application_instance)* HeaderDefaultFileSchema();
|
||||
|
||||
//file information
|
||||
const char* FileName() const { return _fileName; }
|
||||
const char* SetFileName (const char* name = "");
|
||||
const char* TruncFileName (const char* name) const;
|
||||
const std::string FileName() const { return _fileName; }
|
||||
const std::string SetFileName (const std::string name = "");
|
||||
const std::string TruncFileName (const std::string name) const;
|
||||
|
||||
//error information
|
||||
ErrorDescriptor& Error() /* const */ { return _error; }
|
||||
@@ -129,17 +121,17 @@ class STEPfile
|
||||
int SetFileType (FileTypeCode ft = VERSION_CURRENT);
|
||||
|
||||
//Reading and Writing
|
||||
Severity ReadExchangeFile (const char* filename =0, int useTechCor =1);
|
||||
Severity AppendExchangeFile (const char* filename =0, int useTechCor =1);
|
||||
Severity ReadExchangeFile (const std::string filename = "", int useTechCor =1);
|
||||
Severity AppendExchangeFile (const std::string filename = "", int useTechCor =1);
|
||||
|
||||
Severity ReadWorkingFile (const char* filename =0, int useTechCor =1);
|
||||
Severity AppendWorkingFile (const char* filename =0, int useTechCor =1);
|
||||
Severity ReadWorkingFile (const std::string filename = "", int useTechCor =1);
|
||||
Severity AppendWorkingFile (const std::string filename = "", int useTechCor =1);
|
||||
|
||||
Severity AppendFile (istream* in, int useTechCor =1) ;
|
||||
|
||||
Severity WriteExchangeFile (ostream& out, int validate =1,
|
||||
int clearError = 1, int writeComments = 1);
|
||||
Severity WriteExchangeFile (const char* filename =0, int validate =1,
|
||||
Severity WriteExchangeFile (const std::string filename = "", int validate =1,
|
||||
int clearError = 1, int writeComments = 1);
|
||||
Severity WriteValuePairsFile(ostream& out, int validate =1,
|
||||
int clearError =1,
|
||||
@@ -147,7 +139,7 @@ class STEPfile
|
||||
|
||||
Severity WriteWorkingFile (ostream& out, int clearError = 1,
|
||||
int writeComments = 1);
|
||||
Severity WriteWorkingFile (const char* filename =0, int clearError = 1,
|
||||
Severity WriteWorkingFile (const std::string filename = "", int clearError = 1,
|
||||
int writeComments = 1);
|
||||
|
||||
stateEnum EntityWfState(char c);
|
||||
@@ -155,7 +147,7 @@ class STEPfile
|
||||
void Renumber ();
|
||||
|
||||
//constructors
|
||||
STEPfile (Registry& r, InstMgr& i, const char *filename = (const char*)0);
|
||||
STEPfile (Registry& r, InstMgr& i, const std::string filename = "");
|
||||
virtual ~STEPfile();
|
||||
|
||||
protected:
|
||||
@@ -163,7 +155,7 @@ class STEPfile
|
||||
char *schemaName( char * ); // returns and copies out schema name from
|
||||
// header instances
|
||||
//called by ReadExchangeFile
|
||||
istream* OpenInputFile (const char* filename = "");
|
||||
istream* OpenInputFile (const std::string filename = "");
|
||||
void CloseInputFile(istream* in);
|
||||
|
||||
Severity ReadHeader(istream& in);
|
||||
@@ -209,7 +201,7 @@ class STEPfile
|
||||
void WriteWorkingData(ostream& out, int writeComments = 1);
|
||||
|
||||
//called by WriteExchangeFile
|
||||
ofstream* OpenOutputFile(const char* filename =0);
|
||||
ofstream* OpenOutputFile(const std::string filename = "");
|
||||
void CloseOutputFile(ostream* out);
|
||||
|
||||
void WriteHeader (ostream& out);
|
||||
|
||||
@@ -35,19 +35,11 @@ extern void HeaderSchemaInit( Registry & reg );
|
||||
|
||||
//constructor & destructor
|
||||
|
||||
STEPfile::STEPfile( Registry & r, InstMgr & i, const char * filename )
|
||||
|
||||
#ifdef __O3DB__
|
||||
: _reg( &r ), _instances( &i ),
|
||||
#else
|
||||
:
|
||||
_instances( i ), _reg( r ),
|
||||
#endif
|
||||
_fileIdIncr( 0 ), _headerId( 0 ),
|
||||
_fileName( 0 ), _entsNotCreated( 0 ), _entsInvalid( 0 ),
|
||||
_entsIncomplete( 0 ), _entsWarning( 0 ),
|
||||
_errorCount( 0 ), _warningCount( 0 ), _maxErrorCount( 5000 )
|
||||
|
||||
STEPfile::STEPfile( Registry & r, InstMgr & i, const std::string filename ) :
|
||||
_instances( i ), _reg( r ), _fileIdIncr( 0 ), _headerId( 0 ),
|
||||
_entsNotCreated( 0 ), _entsInvalid( 0 ), _entsIncomplete( 0 ),
|
||||
_entsWarning( 0 ), _errorCount( 0 ), _warningCount( 0 ),
|
||||
_maxErrorCount( 5000 )
|
||||
{
|
||||
SetFileType( VERSION_CURRENT );
|
||||
SetFileIdIncrement();
|
||||
@@ -55,7 +47,7 @@ STEPfile::STEPfile( Registry & r, InstMgr & i, const char * filename )
|
||||
// _headerRegistry = new Registry(&s_HeaderSchemaInit);
|
||||
_headerRegistry = new Registry( HeaderSchemaInit );
|
||||
_headerInstances = new InstMgr;
|
||||
if( filename ) {
|
||||
if( !filename.empty() ) {
|
||||
ReadExchangeFile( filename );
|
||||
}
|
||||
}
|
||||
@@ -109,22 +101,35 @@ STEPfile::SetFileType( FileTypeCode ft ) {
|
||||
}
|
||||
|
||||
|
||||
/******************************************************/
|
||||
const char *
|
||||
STEPfile::TruncFileName( const char * filename ) const {
|
||||
const char * tmp = strrchr( filename, '/' );
|
||||
if( tmp ) {
|
||||
return tmp++;
|
||||
} else {
|
||||
/******************************************************
|
||||
** remove any slashes, and anything before the slash,
|
||||
** from filename
|
||||
*/
|
||||
const std::string STEPfile::TruncFileName( const std::string filename ) const {
|
||||
#if defined(__WIN32__) && !defined(__mingw32__)
|
||||
char slash = '\\';
|
||||
#else
|
||||
char slash = '/';
|
||||
#endif
|
||||
size_t l = filename.find_last_of(slash);
|
||||
if( l == std::string::npos ) {
|
||||
return filename;
|
||||
} else {
|
||||
return filename.substr(l);
|
||||
}
|
||||
// const char * tmp = strrchr( filename, '/' );
|
||||
// if( tmp ) {
|
||||
// return tmp++;
|
||||
// } else {
|
||||
// return filename;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************************************************/
|
||||
Severity
|
||||
STEPfile::ReadExchangeFile( const char * filename, int useTechCor ) {
|
||||
STEPfile::ReadExchangeFile( const std::string filename, int useTechCor ) {
|
||||
_error.ClearErrorMsg();
|
||||
_errorCount = 0;
|
||||
istream * in = OpenInputFile( filename );
|
||||
@@ -144,7 +149,7 @@ STEPfile::ReadExchangeFile( const char * filename, int useTechCor ) {
|
||||
}
|
||||
|
||||
Severity
|
||||
STEPfile::AppendExchangeFile( const char * filename, int useTechCor ) {
|
||||
STEPfile::AppendExchangeFile( const std::string filename, int useTechCor ) {
|
||||
_error.ClearErrorMsg();
|
||||
_errorCount = 0;
|
||||
istream * in = OpenInputFile( filename );
|
||||
@@ -159,7 +164,7 @@ STEPfile::AppendExchangeFile( const char * filename, int useTechCor ) {
|
||||
|
||||
/******************************************************/
|
||||
Severity
|
||||
STEPfile::ReadWorkingFile( const char * filename, int useTechCor ) {
|
||||
STEPfile::ReadWorkingFile( const std::string filename, int useTechCor ) {
|
||||
_error.ClearErrorMsg();
|
||||
_errorCount = 0;
|
||||
istream * in = OpenInputFile( filename );
|
||||
@@ -180,7 +185,7 @@ STEPfile::ReadWorkingFile( const char * filename, int useTechCor ) {
|
||||
|
||||
|
||||
Severity
|
||||
STEPfile::AppendWorkingFile( const char * filename, int useTechCor ) {
|
||||
STEPfile::AppendWorkingFile( const std::string filename, int useTechCor ) {
|
||||
_error.ClearErrorMsg();
|
||||
_errorCount = 0;
|
||||
istream * in = OpenInputFile( filename );
|
||||
@@ -198,36 +203,35 @@ STEPfile::AppendWorkingFile( const char * filename, int useTechCor ) {
|
||||
|
||||
|
||||
/******************************************************/
|
||||
istream *
|
||||
STEPfile::OpenInputFile( const char * filename ) {
|
||||
istream * STEPfile::OpenInputFile( const std::string filename ) {
|
||||
// if there's no filename to use, fail
|
||||
if( !( strcmp( filename, "" ) || strcmp( FileName(), "" ) ) ) {
|
||||
if( filename.empty() && FileName().empty() ) {
|
||||
_error.AppendToUserMsg( "Unable to open file for input. No current file name.\n" );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
return ( 0 );
|
||||
return( 0 );
|
||||
} else {
|
||||
if( !SetFileName( filename ) && ( strcmp( filename, "-" ) != 0 ) ) {
|
||||
if( SetFileName( filename ).empty() && ( filename.compare( "-" ) != 0 ) ) {
|
||||
char msg[BUFSIZ];
|
||||
sprintf( msg, "Unable to find file for input: \'%s\'. File not read.\n", filename );
|
||||
sprintf( msg, "Unable to find file for input: \'%s\'. File not read.\n", filename.c_str() );
|
||||
_error.AppendToUserMsg( msg );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
return ( 0 );
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
std::istream * in;
|
||||
|
||||
if( strcmp( filename, "-" ) == 0 ) {
|
||||
if( filename.compare( "-" ) == 0 ) {
|
||||
in = &std::cin;
|
||||
} else {
|
||||
// istream* in = new istream(FileName(), io_readonly, a_useonly);
|
||||
// port 29-Mar-1994 kcm
|
||||
in = new ifstream( FileName() );
|
||||
in = new ifstream( FileName().c_str() );
|
||||
}
|
||||
|
||||
if( !in || !( in -> good() ) ) {
|
||||
char msg[BUFSIZ];
|
||||
sprintf( msg, "Unable to open file for input: \'%s\'. File not read.\n", filename );
|
||||
sprintf( msg, "Unable to open file for input: \'%s\'. File not read.\n", filename.c_str() );
|
||||
_error.AppendToUserMsg( msg );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
return ( 0 );
|
||||
@@ -246,33 +250,16 @@ STEPfile::CloseInputFile( istream * in ) {
|
||||
|
||||
|
||||
/******************************************************/
|
||||
|
||||
/*
|
||||
void
|
||||
STEPfile::ReadWhiteSpace (istream& in)
|
||||
{
|
||||
|
||||
char c = ' ';
|
||||
while ((c == ' ') || (c == '\n') || (c == '\t')) {
|
||||
in >> c;
|
||||
}
|
||||
in.putback (c);
|
||||
}
|
||||
*/
|
||||
|
||||
/***************************
|
||||
***************************/
|
||||
ofstream *
|
||||
STEPfile::OpenOutputFile( const char * filename ) {
|
||||
if( !filename ) {
|
||||
if( !FileName() ) {
|
||||
ofstream * STEPfile::OpenOutputFile( const std::string filename ) {
|
||||
if( filename.empty() ) {
|
||||
if( FileName().empty() ) {
|
||||
_error.AppendToUserMsg( "No current file name.\n" );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
}
|
||||
} else {
|
||||
if( !SetFileName( filename ) ) {
|
||||
if( SetFileName( filename ).empty() ) {
|
||||
char msg[BUFSIZ];
|
||||
sprintf( msg, "can't find file: %s\nFile not written.\n", filename );
|
||||
sprintf( msg, "can't find file: %s\nFile not written.\n", filename.c_str() );
|
||||
_error.AppendToUserMsg( msg );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
}
|
||||
@@ -281,10 +268,7 @@ STEPfile::OpenOutputFile( const char * filename ) {
|
||||
if( _currentDir->FileExists( TruncFileName( filename ) ) ) {
|
||||
MakeBackupFile();
|
||||
}
|
||||
// ostream* out = new ostream(FileName(), io_writeonly, a_create);
|
||||
// - port 29-Mar-1994 kcm
|
||||
ofstream * out = new ofstream( filename );
|
||||
// default for ostream is writeonly and protections are set to 644
|
||||
ofstream * out = new ofstream( filename.c_str() );
|
||||
if( !out ) {
|
||||
_error.AppendToUserMsg( "unable to open file for output\n" );
|
||||
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
@@ -310,7 +294,7 @@ void
|
||||
STEPfile::SetFileIdIncrement() {
|
||||
if( instances().MaxFileId() < 0 ) {
|
||||
_fileIdIncr = 0;
|
||||
} else _fileIdIncr = // (int)((ceil((instances ().MaxFileId() + 99)/1000) + 1) * 1000);
|
||||
} else _fileIdIncr =
|
||||
( int )( ( ceil( ( double )( ( instances().MaxFileId() + 99 ) / 1000 ) ) + 1 ) * 1000 );
|
||||
// FIXME: Is this correct? Why put an integer expression into ceil()?
|
||||
}
|
||||
|
||||
@@ -44,42 +44,18 @@ SCLP23( Application_instance )::SCLP23_NAME( Application_instance )( int fileid,
|
||||
}
|
||||
|
||||
SCLP23( Application_instance )::~SCLP23_NAME( Application_instance )() {
|
||||
STEPattribute * next = 0;
|
||||
// STEPattribute * next = 0;
|
||||
ResetAttributes();
|
||||
while( ( next = NextAttribute() ) ) {
|
||||
delete next;
|
||||
}
|
||||
// while( ( next = NextAttribute() ) ) {
|
||||
// delete next; //FIXME: causes SIGABRT double free or corruption
|
||||
// }
|
||||
|
||||
if( MultipleInheritance() ) {
|
||||
delete nextMiEntity;
|
||||
}
|
||||
|
||||
delete p21Comment;
|
||||
|
||||
/*
|
||||
// this is not necessary since each will call delete on its
|
||||
// own nextMiEntity - DAS
|
||||
SCLP23(Application_instance) * nextMI = nextMiEntity;
|
||||
SCLP23(Application_instance) * nextMItrail = 0;
|
||||
while(nextMI)
|
||||
{
|
||||
nextMItrail = nextMI;
|
||||
nextMI = nextMI->nextMiEntity;
|
||||
// this is ok since STEPattribute doesn't explicitly delete its attr
|
||||
delete nextMItrail;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#ifdef PART26
|
||||
//SCLP26(Application_instance_ptr)
|
||||
IDL_Application_instance_ptr
|
||||
SCLP23( Application_instance )::create_TIE() {
|
||||
cout << "ERROR SCLP23(Application_instance)::create_TIE() called." << endl;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
SCLP23( Application_instance ) *
|
||||
SCLP23( Application_instance )::Replicate() {
|
||||
char errStr[BUFSIZ];
|
||||
|
||||
+43
-189
@@ -46,22 +46,13 @@
|
||||
# include <scl_cf.h>
|
||||
#endif
|
||||
|
||||
/* for getuid() */
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
/* for stat() file status */
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
// to help ObjectCenter
|
||||
#ifndef HAVE_MEMMOVE
|
||||
extern "C"
|
||||
{
|
||||
void * memmove( void * __s1, const void * __s2, size_t __n );
|
||||
}
|
||||
#endif
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -113,11 +104,12 @@ const char * DirObj::RealPath( const char * path ) {
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boolean DirObj::LoadDirectory( const char * name ) {
|
||||
char buf[MAXPATHLEN + 2];
|
||||
strcpy( buf, RealPath( name ) );
|
||||
// strcpy( buf, ValidDirectories( RealPath( name ) ) );
|
||||
return Reset( buf );
|
||||
bool DirObj::LoadDirectory( const std::string & name ) {
|
||||
if( name.empty() ) {
|
||||
return Reset( "./" );
|
||||
} else {
|
||||
return Reset( name );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////// Index() //////////////////////////////////////
|
||||
@@ -144,23 +136,17 @@ int DirObj::Index( const char * name ) {
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boolean DirObj::Reset( const char * path ) {
|
||||
// boolean successful = IsADirectory( path );
|
||||
boolean successful = true;
|
||||
bool DirObj::Reset( const std::string & path ) {
|
||||
bool successful = IsADirectory( path.c_str() );
|
||||
if( successful ) {
|
||||
DIR * dir = opendir( path );
|
||||
DIR * dir = opendir( path.c_str() );
|
||||
ClearFileList();
|
||||
|
||||
for( struct dirent * d = readdir( dir ); d != NULL; d = readdir( dir ) ) {
|
||||
//#if defined(SYSV)
|
||||
// for (struct dirent* d = readdir(dir); d != NULL; d = readdir(dir)) {
|
||||
//#else
|
||||
// for (struct direct* d = readdir(dir); d != NULL; d = readdir(dir)) {
|
||||
//#endif
|
||||
InsertFile( d->d_name, Position( d->d_name ) );
|
||||
}
|
||||
closedir( dir );
|
||||
}
|
||||
} else std::cout << "not a directory: " << path << "!" << std::endl;
|
||||
return successful;
|
||||
}
|
||||
|
||||
@@ -172,9 +158,13 @@ boolean DirObj::Reset( const char * path ) {
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boolean DirObj::IsADirectory( const char * path ) {
|
||||
bool DirObj::IsADirectory( const char * path ) {
|
||||
#if defined(__WIN32__) && !defined(__mingw32__)
|
||||
return PathIsDirectory( path );
|
||||
#else
|
||||
struct stat st;
|
||||
return stat( path, &st ) == 0 && ( st.st_mode & S_IFMT ) == S_IFDIR;
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////// Normalize() //////////////////////////////////
|
||||
@@ -183,9 +173,7 @@ boolean DirObj::IsADirectory( const char * path ) {
|
||||
// set path to:
|
||||
// 1) remaining path starting at the last '/' in multiple '/'s in a row
|
||||
// 2) path with all './'s removed from path except a possible leading './'
|
||||
// 2) path with all '../'s collapsed from path except a possible leading '../'
|
||||
// 3) path with the last ~ or ~name expanded fully followed by the path
|
||||
// remaining after the last ~ or ~name (if any).
|
||||
// 3) path with all '../'s collapsed from path except a possible leading '../'
|
||||
// 4) if path[0] is now '\0' set path to "./" or
|
||||
// if path doesn't start with './' or '../' or '/'
|
||||
// make it start with './' or
|
||||
@@ -194,36 +182,38 @@ boolean DirObj::IsADirectory( const char * path ) {
|
||||
// Soooooo, should end up with a path:
|
||||
// 1) starting with './', '..', or '/'
|
||||
// 2) with all internal './'and '../' removed and collapsed respectively
|
||||
// 3) the last ~ or ~name expanded fully
|
||||
// 4) ending with '/'
|
||||
// 3) ending with '/'
|
||||
//
|
||||
// disabled - 3) the last ~ or ~name expanded fully
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const char * DirObj::Normalize( const char * path ) {
|
||||
static char newpath[MAXPATHLEN + 1];
|
||||
const char * buf;
|
||||
const std::string DirObj::Normalize( const std::string & path ) {
|
||||
char * b = 0;
|
||||
std::string buf;
|
||||
const char * slash;
|
||||
#if defined(__WIN32__) && !defined(__mingw32__)
|
||||
_fullpath(b,path.c_str(),MAXPATHLEN);
|
||||
slash = "\\";
|
||||
#else
|
||||
b = realpath(path.c_str(),0);
|
||||
slash = "/";
|
||||
#endif
|
||||
if( b == 0 ) {
|
||||
buf.clear();
|
||||
} else {
|
||||
buf.assign(b);
|
||||
}
|
||||
|
||||
buf = InterpSlashSlash( path );
|
||||
buf = ElimDot( buf );
|
||||
buf = ElimDotDot( buf );
|
||||
|
||||
if( *buf == '\0' ) {
|
||||
strcpy( newpath, "./" );
|
||||
|
||||
// if buf doesn't start with '.' or '..' and buf[0] != '/'
|
||||
} else if( !DotSlash( buf ) && !DotDotSlash( buf ) && *buf != '/' ) {
|
||||
strcpy( newpath, "./" );
|
||||
strcat( newpath, buf );
|
||||
if( buf.empty() ) {
|
||||
buf = ".";
|
||||
buf.append(slash);
|
||||
|
||||
// if buf is a path to a directory and doesn't end with '/'
|
||||
} else if( IsADirectory( buf ) && buf[strlen( buf ) - 1] != '/' ) {
|
||||
strcpy( newpath, buf );
|
||||
strcat( newpath, "/" );
|
||||
|
||||
} else {
|
||||
strcpy( newpath, buf );
|
||||
} else if( IsADirectory( buf.c_str() ) && buf[buf.size()] != '/' ) {
|
||||
buf.append(slash);
|
||||
}
|
||||
return newpath;
|
||||
return buf;
|
||||
}
|
||||
|
||||
//////////////////////////////// ValidDirectories() ///////////////////////////
|
||||
@@ -246,125 +236,6 @@ const char * DirObj::ValidDirectories( const char * path ) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
//////////////////////////////// InterpSlashSlash() ///////////////////////////
|
||||
//
|
||||
// Searches from the end of 'path' backwards for the first occurence of
|
||||
// a double slash and returns the remaining path starting at the
|
||||
// second / of a double /
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const char * DirObj::InterpSlashSlash( const char * path ) {
|
||||
for( int i = strlen( path ) - 1; i > 0; --i ) {
|
||||
if( path[i] == '/' && path[i - 1] == '/' ) {
|
||||
return &path[i];
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//////////////////////////////// ElimDot() ////////////////////////////////////
|
||||
//
|
||||
// Removes all './' from path unless it's the first two char's in the path
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const char * DirObj::ElimDot( const char * path ) {
|
||||
static char newpath[MAXPATHLEN + 1];
|
||||
const char * src;
|
||||
char * dest = newpath;
|
||||
|
||||
for( src = path; src < &path[strlen( path )]; ++src ) {
|
||||
// if not (src[0] == '.' and src[1] == ('/' or '\0'))
|
||||
if( !DotSlash( src ) ) {
|
||||
*dest++ = *src;
|
||||
|
||||
// if path preceeds DotSlash skip '.' now and '/' at loop
|
||||
} else if( *( dest - 1 ) == '/' ) {
|
||||
++src;
|
||||
|
||||
// if no path preceeds DotSlash copy '.' now and '/' next loop
|
||||
} else {
|
||||
*dest++ = *src;
|
||||
}
|
||||
}
|
||||
*dest = '\0';
|
||||
return newpath;
|
||||
}
|
||||
|
||||
//////////////////////////////// CollapsedDotDotSlash() ///////////////////////
|
||||
//
|
||||
// path = char * to path being collapsed
|
||||
// start = char * to 1 char past the last char in 'path'
|
||||
// (where the ../ would be)
|
||||
// This should be called CollapsedDotDotSlashIfPossible()
|
||||
// Return 1
|
||||
// if collapsed ../ and should have
|
||||
// if didn't collapse ../ and should not have (for path = /)
|
||||
// (should maybe return an error but this object seems to try to
|
||||
// correct the path in this case or find the longest correct path
|
||||
// in other cases)
|
||||
// Return 0
|
||||
// if didn't collapse ../ and should have
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static boolean CollapsedDotDotSlash( const char * path, const char * start ) {
|
||||
// fail if 'start' is at beginning of path (there is no path) or
|
||||
// if no directory is before start (no '/' before '../')
|
||||
if( path == start || *( start - 1 ) != '/' ) {
|
||||
return 0;
|
||||
|
||||
// succeed if 1st char in path is '/' and start points to the
|
||||
// next char (didn't collapse path and shouldn't have
|
||||
} else if( path == start - 1 && *path == '/' ) {
|
||||
return 1;
|
||||
|
||||
} else if( path == start - 2 ) { // NB: won't handle '//' right
|
||||
start = path;
|
||||
return *start != '.';
|
||||
|
||||
} else if( path < start - 2 && !DotDotSlash( start - 3 ) ) {
|
||||
for( start -= 2; path <= start; --start ) {
|
||||
if( *start == '/' ) {
|
||||
++start;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
start = path;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////// ElimDotDot() /////////////////////////////////
|
||||
//
|
||||
// Removes all '../' from path unless it's the first three char's in the path
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const char * DirObj::ElimDotDot( const char * path ) {
|
||||
static char newpath[MAXPATHLEN + 1];
|
||||
const char * src;
|
||||
char * dest = newpath;
|
||||
|
||||
for( src = path; src < &path[strlen( path )]; ++src ) {
|
||||
// if found ../ and could collapse it, skip the '..' now and
|
||||
// the '/' at loop
|
||||
// if (DotDotSlash(src) && CollapsedDotDotSlash(newpath, dest)) {
|
||||
// Josh L, 5/2/95
|
||||
if( DotDotSlash( src ) &&
|
||||
CollapsedDotDotSlash( newpath, ( const char * )dest ) ) {
|
||||
src += 2;
|
||||
} else { // copy char in path
|
||||
*dest++ = *src;
|
||||
}
|
||||
}
|
||||
*dest = '\0';
|
||||
return newpath;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////// CheckIndex() /////////////////////////////////
|
||||
//
|
||||
// Check to see if index is within fileListSize. If not, make the number of
|
||||
@@ -378,10 +249,6 @@ void DirObj::CheckIndex( int index ) {
|
||||
if( index >= fileListSize ) {
|
||||
fileListSize = ( index + 1 ) * 2;
|
||||
newstrbuf = new char*[fileListSize];
|
||||
// bcopy(fileList, newstrbuf, fileCount*sizeof(char*));
|
||||
// Josh L, 5/2/95
|
||||
// memcpy(newstrbuf, fileList, fileCount*sizeof(char*));
|
||||
// Dave memcpy is not working since memory areas overlap
|
||||
memmove( newstrbuf, fileList, fileCount * sizeof( char * ) );
|
||||
delete fileList;
|
||||
fileList = newstrbuf;
|
||||
@@ -401,19 +268,12 @@ void DirObj::InsertFile( const char * f, int index ) {
|
||||
if( index < fileCount ) {
|
||||
CheckIndex( fileCount + 1 );
|
||||
spot = &fileList[index];
|
||||
// memcpy(spot+1, spot, (fileCount - index)*sizeof(char*));
|
||||
// Dave memcpy is not working since memory areas overlap
|
||||
memmove( spot + 1, spot, ( fileCount - index )*sizeof( char * ) );
|
||||
} else {
|
||||
CheckIndex( index );
|
||||
spot = &fileList[index];
|
||||
}
|
||||
#ifdef __O3DB__
|
||||
char * string = new char [strlen( f )];
|
||||
strcpy( string, f );
|
||||
#else
|
||||
char * string = strdup( f );
|
||||
#endif
|
||||
*spot = string;
|
||||
++fileCount;
|
||||
}
|
||||
@@ -426,14 +286,8 @@ void DirObj::InsertFile( const char * f, int index ) {
|
||||
|
||||
void DirObj::RemoveFile( int index ) {
|
||||
if( index < --fileCount ) {
|
||||
// const char** spot = &fileList[index];
|
||||
// Josh L, 5/2/95
|
||||
const char ** spot = ( const char ** )&fileList[index];
|
||||
delete spot;
|
||||
// bcopy(spot+1, spot, (fileCount - index)*sizeof(char*));
|
||||
// Josh L, 5/2/95
|
||||
// memcpy(spot, spot+1, (fileCount - index)*sizeof(char*));
|
||||
// Dave memcpy is not working since memory areas overlap
|
||||
memmove( spot, spot + 1, ( fileCount - index )*sizeof( char * ) );
|
||||
}
|
||||
}
|
||||
|
||||
+10
-83
@@ -15,7 +15,7 @@
|
||||
|
||||
/*
|
||||
* DirObj - This object contains a list of files in a directory.
|
||||
* Can be used for interpreting a tilde, checking paths etc.
|
||||
* Can be used for checking paths etc.
|
||||
* based on InterViews FBDirectory
|
||||
* Copyright (c) 1987, 1988, 1989 Stanford University from
|
||||
* /depot/iv/src/libInterViews/filebrowser.c <= notice
|
||||
@@ -35,31 +35,13 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
// needed at least for getuid()
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSENT_H
|
||||
#include <sysent.h>
|
||||
#endif
|
||||
|
||||
// sys/stat.h is apparently needed for ObjectCenter and Sun C++ ?
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <scldir.h>
|
||||
|
||||
typedef unsigned boolean;
|
||||
#include <string>
|
||||
|
||||
#ifndef nil
|
||||
#define nil 0
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -68,24 +50,23 @@ public:
|
||||
DirObj(const char* dirName);
|
||||
virtual ~DirObj();
|
||||
|
||||
boolean LoadDirectory(const char*);
|
||||
const char* Normalize(const char*);
|
||||
bool LoadDirectory(const std::string & name);
|
||||
static const std::string Normalize(const std::string & s);
|
||||
|
||||
const char* ValidDirectories(const char*);
|
||||
|
||||
int Index(const char*);
|
||||
const char* File(int index);
|
||||
// check for file in the currently loaded directory
|
||||
boolean FileExists(const char* file) { return Index(file) ? 1 : 0;};
|
||||
bool FileExists(const char* file) { return Index(file) ? true : false;};
|
||||
bool FileExists(const std::string & file) { return Index(file.c_str()) ? true : false;};
|
||||
int Count();
|
||||
|
||||
boolean IsADirectory(const char*);
|
||||
static bool IsADirectory(const char*);
|
||||
private:
|
||||
const char* ElimDot(const char*);
|
||||
const char* ElimDotDot(const char*);
|
||||
const char* InterpSlashSlash(const char*);
|
||||
const char* RealPath(const char*);
|
||||
|
||||
boolean Reset(const char*);
|
||||
bool Reset(const std::string & path);
|
||||
void ClearFileList();
|
||||
void CheckIndex(int index);
|
||||
void InsertFile(const char*, int index);
|
||||
@@ -98,69 +79,15 @@ private:
|
||||
int fileListSize;
|
||||
};
|
||||
|
||||
//////////////////////////////// Count() //////////////////////////////////////
|
||||
//
|
||||
// Return the number of files in the loaded directory.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline int DirObj::Count () { return fileCount; }
|
||||
|
||||
//////////////////////////////// AppendFile() /////////////////////////////////
|
||||
//
|
||||
// Insert a new file into the fileList.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void DirObj::AppendFile (const char* s) { InsertFile(s, fileCount); }
|
||||
|
||||
//////////////////////////////// File() ///////////////////////////////////////
|
||||
//
|
||||
// Return the file at the given index (starting at 0) in the fileList
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline const char* DirObj::File (int index) {
|
||||
return (0 <= index && index < fileCount) ? fileList[index] : nil;
|
||||
}
|
||||
|
||||
//////////////////////////////// strdup() /////////////////////////////////////
|
||||
//
|
||||
// Duplicate a string.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//inline char* strdup (const char* s) {
|
||||
// char* dup = new char[strlen(s) + 1];
|
||||
// strcpy(dup, s);
|
||||
// return dup;
|
||||
//}
|
||||
|
||||
//////////////////////////////// DotSlash() ///////////////////////////////////
|
||||
//
|
||||
// Return 1 if the first char in 'path' is '.' and second char is
|
||||
// '/' or '\0'; otherwise return 0
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline boolean DotSlash (const char* path) {
|
||||
return
|
||||
path[0] != '\0' && path[0] == '.' &&
|
||||
(path[1] == '/' || path[1] == '\0');
|
||||
}
|
||||
|
||||
//////////////////////////////// DotDotSlash() ////////////////////////////////
|
||||
//
|
||||
// Return 1 if the first char in 'path' is '.', the second char is '.',
|
||||
// and the third char is '/' or '\0'; otherwise return 0
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline boolean DotDotSlash (const char* path) {
|
||||
return
|
||||
path[0] != '\0' && path[1] != '\0' &&
|
||||
path[0] == '.' && path[1] == '.' &&
|
||||
(path[2] == '/' || path[2] == '\0');
|
||||
return (0 <= index && index < fileCount) ? fileList[index] : 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -326,7 +326,7 @@ HASHfind( Hash_Table t, char * s ) {
|
||||
// rok
|
||||
void
|
||||
HASHinsert( Hash_Table t, char * s, void * data ) {
|
||||
Element *e2;
|
||||
Element e2;
|
||||
// memset(e, 0, sizeof(s) + sizeof(data));
|
||||
struct Element_ *e = malloc(sizeof *e);
|
||||
e -> key = s;
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
** provided the file written out is called file.out
|
||||
*/
|
||||
|
||||
#ifdef __O3DB__
|
||||
#include <OpenOODB.h>
|
||||
#endif
|
||||
extern void SchemaInit( class Registry & );
|
||||
#include <STEPfile.h>
|
||||
#include <sdai.h>
|
||||
|
||||
Reference in New Issue
Block a user