Borland specific code
david.pont at forestresearch.co.nz
david.pont at forestresearch.co.nz
Tue Feb 22 20:41:54 EST 2000
Bill,
I have attached an excerpt from vtkDirectory.cxx that I modified and
compiled OK with Borland C++Builder 3. As you can see I use the compiler defined
macro __BORLANDC__ to allow me to include the appropriate headers and set up
macros for the data declaration and function calls that are specific to the two
WIN32 compilers. This allows one copy of the WIN32 implementation, which is a
bit nicer for maintenance. My first hack was actually just a specific
implementation for each compiler, but as the differences are very small the use
of macros makes it much tidier.
Please note that while this compiles under Borland I have not tested the code. I
leave it to you to see if MSC and UNIX compilers like this code, and if it tests
out OK.
regards
Dave Pont
I amended the _WIN32 block (from about line 40) to be:
// First windows style directory access
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __BORLANDC__ // support BORLAND specific directory access
#include <dir.h>
#define DECL_WIN32FILEDATA( data ) struct ffblk data
#define WIN32FINDFIRST( buf, data ) findfirst(buf, data, 0) // 0=ordinary files
#define WIN32FINDNEXT( srchHandle, data ) findnext(data)
#define WIN32FINDCLOSE( srchHandle ) 0 // trick to allow good return value
#else // MSC
#include <io.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define DECL_WIN32FILEDATA( data ) struct _finddata_t data
#define WIN32FINDFIRST( buf, data ) _findfirst(buf, data)
#define WIN32FINDNEXT( srchHandle, data ) _findnext(srchHandle, data)
#define WIN32FINDCLOSE( srchHandle ) _findclose(srchHandle)
#endif // MSC
int vtkDirectory::Open(const char* name)
{
char* buf;
int n = strlen(name);
if (name[n - 1] == '/')
{
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name);
}
else
{
buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name);
}
DECL_WIN32FILEDATA( data );// data of current file
// First count the number of files in the directory
long srchHandle = WIN32FINDFIRST( buf, &data );
if (srchHandle == -1)
{
cerr << "can't open directory " << buf << endl;
this->NumberOfFiles = 0;
return 0;
}
this->NumberOfFiles = 1;
while(WIN32FINDNEXT(srchHandle,&data) != -1)
{
this->NumberOfFiles++;
}
this->Files = new char*[this->NumberOfFiles];
// Now put them into the file array
srchHandle = WIN32FINDFIRST( buf, &data );
delete [] buf;
if (srchHandle == -1)
{
this->NumberOfFiles = 0;
return 0;
}
// Loop through names
int i = 0;
do
{
this->Files[i] = strcpy(new char[strlen(data.ff_name)+1], data.ff_name);
i++;
}
while (WIN32FINDNEXT( srchHandle, &data ) != -1);
this->Path = strcpy(new char[strlen(name)+1], name);
return WIN32FINDCLOSE(srchHandle) != -1;
}
#else
// Unix style directory access
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------
More information about the vtkusers
mailing list