[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bzflag-commits
Subject:    SF.net SVN: bzflag:[18475] trunk/bzwgen
From:       jwmelto () users ! sourceforge ! net
Date:       2008-08-25 5:23:25
Message-ID: E1KXUY1-0005xb-Vu () c3vjzd1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 18475
          http://bzflag.svn.sourceforge.net/bzflag/?rev=18475&view=rev
Author:   jwmelto
Date:     2008-08-25 05:23:25 +0000 (Mon, 25 Aug 2008)

Log Message:
-----------
Mostly whitespace. Changed to use new/delete instead of malloc

Modified Paths:
--------------
    trunk/bzwgen/inc/OSFile.h
    trunk/bzwgen/src/OSFile.cxx

Modified: trunk/bzwgen/inc/OSFile.h
===================================================================
--- trunk/bzwgen/inc/OSFile.h	2008-08-25 01:54:46 UTC (rev 18474)
+++ trunk/bzwgen/inc/OSFile.h	2008-08-25 05:23:25 UTC (rev 18475)
@@ -36,98 +36,98 @@
 #include <stdio.h>
 
 typedef enum 
-{
-	eFileStart,
-	eCurentPos,
-	eFileEnd
-}teFilePos;
+  {
+    eFileStart,
+    eCurentPos,
+    eFileEnd
+  } teFilePos;
 
 void SetOSFileBaseDir ( const char *szDir );
 
 class COSFile
 {
-public:
-	COSFile ();
-	COSFile ( const COSFile &r);
-	COSFile& operator = (const COSFile &r);
+ public:
+  COSFile ();
+  COSFile ( const COSFile &r);
+  COSFile& operator = (const COSFile &r);
 
-	COSFile ( const char *szName );
-	COSFile ( const char *szName, const char *szMode );
-	~COSFile();
+  COSFile ( const char *szName );
+  COSFile ( const char *szName, const char *szMode );
+  ~COSFile();
 
-	bool Open ( const char *szName, const char *szMode );
-	bool Open ( const char *szMode );
-	bool Close ( void );
+  bool Open ( const char *szName, const char *szMode );
+  bool Open ( const char *szMode );
+  bool Close ( void );
 
-	void StdName ( const char *szName );
-	void OSName ( const char *szName );
+  void StdName ( const char *szName );
+  void OSName ( const char *szName );
 
-	FILE* GetFile ( void );
+  FILE* GetFile ( void );
 
-	const char* GetStdName ( void );
-	const char* GetOSName ( void );
+  const char* GetStdName ( void );
+  const char* GetOSName ( void );
 
-	const char* GetFileTitle ( void );
+  const char* GetFileTitle ( void );
 
-	const char* GetExtension ( void );
+  const char* GetExtension ( void );
 	
-	const char* GetFullOSPath ( void );
+  const char* GetFullOSPath ( void );
 
-	bool IsOpen ( void );
+  bool IsOpen ( void );
 
-	int Read ( void* data, int size, int count = 1 );
-	unsigned char ReadChar ( void );
-	int ScanChar ( unsigned char *pChar );
-	const char* ScanStr ( void );
-	const char* ReadLine ( void );
-	int Write ( const void* data, int size );
-	void Write ( const char* data );
-	void Write ( std::string data );
-	void Flush ( void );
+  int Read ( void* data, int size, int count = 1 );
+  unsigned char ReadChar ( void );
+  int ScanChar ( unsigned char *pChar );
+  const char* ScanStr ( void );
+  const char* ReadLine ( void );
+  int Write ( const void* data, int size );
+  void Write ( const char* data );
+  void Write ( std::string data );
+  void Flush ( void );
 
-	std::vector<std::string> ParseFile ( std::string delim );
+  std::vector<std::string> ParseFile ( std::string delim );
 
-	int Seek ( teFilePos ePos, int iOffset );
-	unsigned int Size ( void );
-	unsigned int Tell ( void );
+  int Seek ( teFilePos ePos, int iOffset );
+  unsigned int Size ( void );
+  unsigned int Tell ( void );
 
-	bool GetFileText ( std::string &text );
+  bool GetFileText ( std::string &text );
 
-	void SetUseGlobalPath ( bool use = false );
-protected:
-	class COSFileInfo;
-	COSFileInfo		*info;
+  void SetUseGlobalPath ( bool use = false );
+ protected:
+  class COSFileInfo;
+  COSFileInfo		*info;
 };
 
 
 class COSDir
 {
-public:
-	COSDir();
-	COSDir( const COSDir &r);
-	COSDir& operator = (const COSDir &r);
-	explicit COSDir( const char* szDirName );
-	~COSDir();
+ public:
+  COSDir();
+  COSDir( const COSDir &r);
+  COSDir& operator = (const COSDir &r);
+  explicit COSDir( const char* szDirName );
+  ~COSDir();
 
-	void SetStdDir ( const char* szDirName );
-	void SetOSDir ( const char* szDirName );
+  void SetStdDir ( const char* szDirName );
+  void SetOSDir ( const char* szDirName );
 
-	void MakeStdDir ( const char* szDirName );
-	void MakeOSDir ( const char* szDirName );
+  void MakeStdDir ( const char* szDirName );
+  void MakeOSDir ( const char* szDirName );
 
-	bool GetNextFile ( COSFile &oFile, bool bRecursive );
-	bool GetNextFile ( COSFile &oFile, const char* fileMask, bool bRecursive );
+  bool GetNextFile ( COSFile &oFile, bool bRecursive );
+  bool GetNextFile ( COSFile &oFile, const char* fileMask, bool bRecursive );
 
-	const char* GetStdName ( void );
-	const char* GetOSName ( void );
-	const char* GetFullOSPath ( void );
+  const char* GetStdName ( void );
+  const char* GetOSName ( void );
+  const char* GetFullOSPath ( void );
 
-protected:
-	class COSDirInfo;
-	COSDirInfo		*info;
+ protected:
+  class COSDirInfo;
+  COSDirInfo		*info;
 
-	bool WindowsAddFileStack ( const char *szPathName, const char* fileMask , bool \
                bRecursive );
-	bool LinuxAddFileStack( const char *szPathName, const char* fileMask , bool \
bRecursive); +  bool WindowsAddFileStack ( const char *szPathName, const char* \
fileMask , bool bRecursive ); +  bool LinuxAddFileStack( const char *szPathName, \
const char* fileMask , bool bRecursive);  };
 
 

Modified: trunk/bzwgen/src/OSFile.cxx
===================================================================
--- trunk/bzwgen/src/OSFile.cxx	2008-08-25 01:54:46 UTC (rev 18474)
+++ trunk/bzwgen/src/OSFile.cxx	2008-08-25 05:23:25 UTC (rev 18475)
@@ -26,15 +26,15 @@
   #include <stddef.h>
 #endif
 
-void GetUperName ( char *szData )
+void GetUperName ( char* szData )
 {
 #ifdef	_WIN32
-	strupr(szData);
+  strupr(szData);
 #else
-	while(*szData) {
-		*szData = toupper(*szData);
-		szData++;
-    }
+  while(*szData) {
+    *szData = toupper(*szData);
+    szData++;
+  }
 #endif
 }
 
@@ -46,84 +46,74 @@
 // this is one place you need to add conversions to/from your OS
 
 // util functions
-void OSFileStdToOSDir ( char *dir )
+void OSFileStdToOSDir ( char* dir )
 {
 #ifndef _WIN32
-	return;
+  return;
 #else
-	char *p = dir;
+  char* p = dir;
 
-	while ( *p != NULL )
-	{
-		if (*p == '/')
-			*p = '\\';
-
-		p++;
-	}
+  while ( *p != NULL ) {
+    if (*p == '/') *p = '\\';
+    p++;
+  }
 #endif//WIN32
 }
 
-void OSFileOSToStdDir ( char *dir )
+void OSFileOSToStdDir ( char* dir )
 {
 #ifndef _WIN32
-	return;
+  return;
 #else
-	char *p = dir;
+  char *p = dir;
 
-	while ( *p != NULL )
-	{
-		if (*p == '\\')
-			*p= '/';
-
-		p++;
-	}
+  while ( *p != NULL ) {
+    if (*p == '\\') *p= '/';
+    p++;
+  }
 #endif//WIN32
 }
 
 // windows specific make path
 #ifdef _WIN32
-void WindowsMakePath(const char * path)
+void WindowsMakePath(const char* path)
 {
-	// scan the folder path and make it
-	const char *pos = strchr (path,'\\');
+  // scan the folder path and make it
+  const char* pos = strchr (path,'\\');
 
-	if (!pos) // dono maybe the screwed up
-	{
-		std::string str = "\\";
-		str += path;
-		mkdir(str.c_str());
-		return;
-	}
+  if (!pos) { // dono maybe the screwed up
+    std::string str = "\\";
+    str += path;
+    mkdir(str.c_str());
+    return;
+  }
 
-	while (pos)
-	{
-		std::string str = path;
-		str.resize(pos-path);
-		mkdir(str.c_str());
-		pos = strchr (pos+1,'\\');
-	}
+  while (pos) {
+    std::string str = path;
+    str.resize(pos-path);
+    mkdir(str.c_str());
+    pos = strchr (pos+1,'\\');
+  }
 }
 #else 
-void nixMakePath(const char * path)
+void nixMakePath(const char* path)
 {
-	// scan the folder path and make it
-	char *pos = strchr (path,'/');
+  // scan the folder path and make it
+  char *pos = strchr (path,'/');
 
-	if (!pos) // dono maybe the screwed up
-	{
-		std::string str = "//";
-		str += path;
-		mkdir(str.c_str(), 0777);
-		return;
-	}
+  if (!pos) { // dono maybe the screwed up
+    std::string str = "//";
+    str += path;
+    mkdir(str.c_str(), 0777);
+    return;
+  }
 
-	while (pos)
-	{
-		std::string str = path;
-		str.resize(pos-path);
-		mkdir(str.c_str(), 0777);
-		pos = strchr (pos+1,'/');
-	}
+  while (pos) {
+    std::string str = path;
+    str.resize(pos-path);
+    mkdir(str.c_str(), 0777);
+    pos = strchr (pos+1,'/');
+  }
 }
 #endif // windows
 
@@ -132,9 +122,9 @@
 void OSMakePath(const char * path)
 {
 #ifdef _WIN32
-	WindowsMakePath(path);
+  WindowsMakePath(path);
 #else
-	nixMakePath(path);
+  nixMakePath(path);
 #endif // win32	
 }
 
@@ -145,633 +135,597 @@
 
 void SetOSFileBaseDir ( const char *dir )
 {
-	stdBaseDir = dir;
-	if (!dir)
-		osBaseDir.empty();
-	else
-	{
-		osBaseDir = stdBaseDir;
-		OSFileStdToOSDir((char*)osBaseDir.c_str());
-	}
+  stdBaseDir = dir;
+  if (!dir) {
+    osBaseDir.empty();
+  } else {
+    osBaseDir = stdBaseDir;
+    OSFileStdToOSDir((char*)osBaseDir.c_str());
+  }
 }
 
 // OSFileClass
 class COSFile::COSFileInfo
 {
-	public:
-		COSFileInfo();
-		COSFileInfo( const COSFile::COSFileInfo &r);
-		std::string		stdName;
-		std::string		osName;
-		std::string		title;
-		bool			useGlobalPath;
-		FILE			*fp;
+public:
+  COSFileInfo();
+  COSFileInfo( const COSFile::COSFileInfo &r);
+  std::string		stdName;
+  std::string		osName;
+  std::string		title;
+  bool			useGlobalPath;
+  FILE			*fp;
 };
 
 COSFile::COSFileInfo::COSFileInfo ( void )
+  : useGlobalPath(true), fp(NULL)
 {
-	fp = NULL;
-	osName = "";
-	stdName = "";
-	title = "";
-	useGlobalPath = true;
 }
 
 COSFile::COSFileInfo::COSFileInfo( const COSFile::COSFileInfo &r)
+  : stdName(r.stdName)
+  , osName(r.osName)
+  , title(r.title)
+  , useGlobalPath(r.useGlobalPath)
+  , fp(NULL)			// never copy the file
 {
-	// never copy the file
-	fp = NULL;
-	osName = r.osName;
-	stdName = r.stdName;
-	title =  r.title;
-	useGlobalPath = r.useGlobalPath;
 }
 
 void COSFile::SetUseGlobalPath ( bool use )
 {
-	info->useGlobalPath = use;
+  info->useGlobalPath = use;
 }
 
 COSFile::COSFile ()
+  : info(new COSFileInfo)
 {
-	info = new COSFileInfo;
 }
 
 COSFile::COSFile ( const char *name )
+  : info(new COSFileInfo)
 {
-	info = new COSFileInfo;
-	StdName(name);
+  StdName(name);
 }
 
 COSFile::COSFile ( const COSFile &r)
 {
-	if (this == &r)
-		return;
+  if (this == &r)
+    return;
 
-	info = new COSFileInfo(*r.info);
+  info = new COSFileInfo(*r.info);
 }
 
 COSFile& COSFile::operator = (const COSFile &r)
 {
-	if (this == &r)
-		return *this;
+  if (this == &r)
+    return *this;
 
-	if (info)
-		delete (info);
-
-	info = new COSFileInfo(*r.info);
-	return *this;
+  delete info;
+  info = new COSFileInfo(*r.info);
+  return *this;
 }
 
 COSFile::COSFile ( const char *name, const char *mode   )
+  : info(new COSFileInfo)
 {
-	info = new COSFileInfo;
-	Open(name,mode);
+  Open(name,mode);
 }
 
 COSFile::~COSFile()
 {
-	Close();
-	if (info)
-		delete (info);
+  Close();
+  delete info;
 }
 
 bool COSFile::Open ( const char *name, const char *mode  )
 {
-	Close();
+  Close();
 
-	StdName(name);
+  StdName(name);
 
-	return Open(mode);
+  return Open(mode);
 }
 
 bool COSFile::Open ( const char *mode )
 {
-	Close();
+  Close();
 
-	char	modeToUse[32];
+  char	modeToUse[32];
 
-	if (!mode)
-		sprintf(modeToUse,"rb");
-	else
-		strcpy(modeToUse,mode);
+  if (!mode)
+    sprintf(modeToUse,"rb");
+  else
+    strcpy(modeToUse,mode);
 
-	std::string	fileName;
+  std::string	fileName;
 	
-	if (info->useGlobalPath)
-		fileName = osBaseDir;
-	fileName += info->osName;
+  if (info->useGlobalPath)
+    fileName = osBaseDir;
+  fileName += info->osName;
 
-	info->fp = fopen(fileName.c_str(),mode);
+  info->fp = fopen(fileName.c_str(),mode);
 
-	// we may need to make the file path to the file, if we are writing then lets get \
                on with it.
-	if (!info->fp && strchr(mode,'w'))
-	{
-		OSMakePath(fileName.c_str());
-		info->fp = fopen(fileName.c_str(),mode);
-	}
+  // we may need to make the file path to the file, if we are writing
+  // then lets get on with it.
+  if (!info->fp && strchr(mode,'w')) {
+    OSMakePath(fileName.c_str());
+    info->fp = fopen(fileName.c_str(),mode);
+  }
 
-	return IsOpen();
+  return IsOpen();
 }
 
 bool COSFile::Close ( void )
 {
-	if (info->fp)
-		fclose(info->fp);
+  if (info->fp)
+    fclose(info->fp);
 
-	info->fp = NULL;
+  info->fp = NULL;
 
-	return (!IsOpen());
+  return (!IsOpen());
 }
 
 int COSFile::Read ( void* data, int size, int count )
 {
-	if (!IsOpen())
-		return 0;
+  if (!IsOpen())
+    return 0;
 
-	return (int)fread(data,size,count,info->fp);
+  return (int)fread(data,size,count,info->fp);
 }
 
 unsigned char  COSFile::ReadChar ( void )
 {
-	if (!IsOpen())
-		return 0;
+  if (!IsOpen())
+    return 0;
 
-	char c = 0;
+  char c = 0;
 
-	if (fscanf(info->fp,"%c",&c) != 1)
-		return 0;
-	return c;
+  if (fscanf(info->fp,"%c",&c) != 1)
+    return 0;
+  return c;
 }
 
 const char* COSFile::ReadLine ( void )
 {
-	static std::string line;
+  static std::string line;
 	
-	line = "";
-	char c = ReadChar();
-	while (c != 0 && c != '\n' && c != 10)
-	{
-		line += c;
-		c = ReadChar();
-	}
-	return line.c_str();
+  line = "";
+  char c = ReadChar();
+  while (c != 0 && c != '\n' && c != 10)
+    {
+      line += c;
+      c = ReadChar();
+    }
+  return line.c_str();
 }
 
 int COSFile::ScanChar ( unsigned char *pChar )
 {
-	if (!pChar || !IsOpen())
-		return 0;
+  if (!pChar || !IsOpen())
+    return 0;
 
-	return fscanf(info->fp,"%c",pChar);
+  return fscanf(info->fp,"%c",pChar);
 }
 
 const char* COSFile::ScanStr ( void )
 {
-	if (!IsOpen())
-		return 0;
+  if (!IsOpen())
+    return 0;
 	
-	static char temp[1024] = {0};
-	if (fscanf(info->fp,"%s",temp)!=1)
-		return NULL;
-	return temp;
+  static char temp[1024] = {0};
+  if (fscanf(info->fp,"%s",temp)!=1)
+    return NULL;
+  return temp;
 }
 
 int  COSFile::Write ( const void* data, int size )
 {
-	if (!IsOpen())
-		return 0;
+  if (!IsOpen())
+    return 0;
 
-	return (int)fwrite(data,size,1,info->fp);
+  return (int)fwrite(data,size,1,info->fp);
 }
 
 void COSFile::Write ( const char* data )
 {
-	if (!IsOpen())
-		return;
+  if (!IsOpen())
+    return;
 
-	fprintf(info->fp,"%s",data);
+  fprintf(info->fp,"%s",data);
 }
 
 void COSFile::Write ( std::string data )
 {
-	Write(data.c_str(),(int)data.size());
+  Write(data.c_str(),(int)data.size());
 }
 
 void COSFile::Flush ( void )
 {
-	fflush(info->fp);
+  fflush(info->fp);
 }
 
 std::vector<std::string> COSFile::ParseFile ( std::string delim )
 {
-	std::vector<std::string>	fileSegments;
-	if (!IsOpen())
-		return fileSegments;
+  std::vector<std::string>	fileSegments;
+  if (!IsOpen())
+    return fileSegments;
 
-	int pos = Tell();
-	int size = Size();
-	char *data = (char*)malloc(size+1);
-	data[size] = 0;
-	Read(data,size);
-	Seek(eFileStart,pos);
+  int pos = Tell();
+  int size = Size();
+  char *data = new char [size+1];
+  data[size] = 0;
+  Read(data,size);
+  Seek(eFileStart,pos);
 
-	std::string dataStr = data;
-	free(data);
+  std::string dataStr = data;
+  delete[] data;
 
-	fileSegments = TextUtils::tokenize(dataStr,delim,0,true);
-	return fileSegments; 
+  fileSegments = TextUtils::tokenize(dataStr,delim,0,true);
+  return fileSegments; 
 }
 
 int COSFile::Seek ( teFilePos ePos, int iOffset )
 {
-	if (!IsOpen())
-		return 0;
+  if (!IsOpen())
+    return 0;
 
-	long iMode;
-	switch(ePos)
-	{
-		case eFileStart:
-			iMode = SEEK_SET;
-			break;
+  long iMode;
+  switch(ePos) {
+  case eFileStart:
+    iMode = SEEK_SET;
+    break;
 
-		case eFileEnd:
-			iMode = SEEK_END ;
-			break;
+  case eFileEnd:
+    iMode = SEEK_END ;
+    break;
 
-		case eCurentPos:
-		default:
-			iMode = SEEK_CUR ;
-			break;
-	}
+  case eCurentPos:
+  default:
+    iMode = SEEK_CUR ;
+    break;
+  }
 
-	return fseek(info->fp,iOffset,iMode);
+  return fseek(info->fp,iOffset,iMode);
 }
 
 unsigned int COSFile::Size ( void )
 {
-	if (!IsOpen())
-		return 0;
+  if (!IsOpen())
+    return 0;
 
-	unsigned int pos = ftell(info->fp);
-	fseek(info->fp,0,SEEK_END);
-	unsigned int len = ftell(info->fp);
-	fseek(info->fp,pos, SEEK_SET);
+  unsigned int pos = ftell(info->fp);
+  fseek(info->fp,0,SEEK_END);
+  unsigned int len = ftell(info->fp);
+  fseek(info->fp,pos, SEEK_SET);
 	
-	return len;
+  return len;
 }
 
 unsigned int COSFile::Tell ( void )
 {
-	if (!IsOpen())
-		return 0;
-	return ftell(info->fp);
+  if (!IsOpen())
+    return 0;
+  return ftell(info->fp);
 }
 
 bool  COSFile::GetFileText ( std::string &text )
 {
-	bool opened = false;
+  bool opened = false;
 
-	if ( !IsOpen() )
-	{
-		if (!Open("r"))
-			return false;
-		opened = true;
-	}
+  if ( !IsOpen() ) {
+    if (!Open("r"))
+      return false;
+    opened = true;
+  }
 
-	unsigned int pos = Tell();
-	Seek(eFileStart,0);
-	unsigned int size = Size();
-	unsigned char *p = (unsigned char *)malloc(size+1);
-	Read(p,size,1);
-	p[size] = 0;
-	text = (char*)p;
-	free(p);
+  unsigned int pos = Tell();
+  Seek(eFileStart,0);
+  unsigned int size = Size();
+  unsigned char *p = new unsigned char [size+1];
+  Read(p,size,1);
+  p[size] = 0;
+  text = (char*)p;
+  delete[] p;
 
-	if ( !opened )
-		Seek(eFileStart,pos);
-	else
-		Close();
+  if ( !opened )
+    Seek(eFileStart,pos);
+  else
+    Close();
 
-	return true;
+  return true;
 }
 
 void COSFile::StdName ( const char *name )
 {
-	info->stdName = name;
-	info->osName = name;
-	OSFileStdToOSDir((char*)info->osName.c_str());
+  info->stdName = name;
+  info->osName = name;
+  OSFileStdToOSDir((char*)info->osName.c_str());
 }
 
 void COSFile::OSName ( const char *name )
 {
-	info->stdName = name;
-	info->osName = name;
-	OSFileOSToStdDir((char*)info->stdName.c_str());
+  info->stdName = name;
+  info->osName = name;
+  OSFileOSToStdDir((char*)info->stdName.c_str());
 }
 
 const char* COSFile::GetFileTitle ( void )
 {
-	if (info->stdName.size()== 0)
-		return NULL;
+  if (info->stdName.size()== 0)
+    return NULL;
 
-	// yes I know this part is horible, put it in the pimple
-	static std::string title;
-	const char	*path = strrchr(info->stdName.c_str(),'/');
+  // yes I know this part is horible, put it in the pimple
+  static std::string title;
+  const char	*path = strrchr(info->stdName.c_str(),'/');
 
-	if (path)
-		path++;
-	else
-		path = (char*)info->stdName.c_str();
+  if (path)
+    path++;
+  else
+    path = (char*)info->stdName.c_str();
 
-	title = path;
+  title = path;
 
-    // if no ext then we just give them the raw, as it may not have an extension
-	const char *ext = GetExtension();
-    if (ext)
-	  title.resize(title.size() - strlen(ext) - 1);
+  // if no ext then we just give them the raw, as it may not have an extension
+  const char *ext = GetExtension();
+  if (ext)
+    title.resize(title.size() - strlen(ext) - 1);
     
-	return title.c_str();
+  return title.c_str();
 }
 
 // this CAN return null, cus the file may not have an extenstion, if it just happens \
to end in a '.' then well, your really wierd Mr. File.  const char* \
COSFile::GetExtension ( void )  {
-	if (info->stdName.size()== 0)
-		return NULL;
+  if (info->stdName.size()== 0)
+    return NULL;
 
-	const char	*pEnd = strrchr(info->stdName.c_str(),'.');
+  const char	*pEnd = strrchr(info->stdName.c_str(),'.');
 
-	if (pEnd)
-		pEnd++;
+  if (pEnd)
+    pEnd++;
 
-	return pEnd;
+  return pEnd;
 }
 
 const char* COSFile::GetFullOSPath ( void )
 {
-	static std::string	szPath;
+  static std::string	szPath;
 	
-	szPath.empty();
-	szPath = osBaseDir;
-	szPath += info->osName;
-	return szPath.c_str();
+  szPath.empty();
+  szPath = osBaseDir;
+  szPath += info->osName;
+  return szPath.c_str();
 }
 
 FILE* COSFile::GetFile ( void )
 {
-	return info->fp;
+  return info->fp;
 }
 
 const char* COSFile::GetStdName ( void )
 {
-	return info->stdName.c_str();
+  return info->stdName.c_str();
 }
 
 const char* COSFile::GetOSName ( void )
 {
-	return info->osName.c_str();
+  return info->osName.c_str();
 }
 
 bool COSFile::IsOpen ( void )
 {
-	return info->fp != NULL;
+  return info->fp != NULL;
 }
 
 // OS Dir classes
 class COSDir::COSDirInfo
 {
 public:
-	COSDirInfo();
-	COSDirInfo(const COSDir::COSDirInfo &r);
+  COSDirInfo();
 
-	std::string		baseStdDir;
-	std::string		baseOSDir;
-	tvFileNameList	nameList;
-	unsigned int	namePos;
+  std::string		baseStdDir;
+  std::string		baseOSDir;
+  tvFileNameList	nameList;
+  unsigned int		namePos;
 };
 
 COSDir::COSDirInfo::COSDirInfo ( void )
+  : namePos(0xFFFFFFFF)
 {
-	namePos = 0xFFFFFFFF;
 }
 
-COSDir::COSDirInfo::COSDirInfo ( const COSDir::COSDirInfo &r )
-{
-	if (this == &r)
-		return;
-
-	baseStdDir = r.baseStdDir;
-	baseOSDir = r.baseOSDir;
-	nameList = r.nameList;
-	namePos = r.namePos;
-}
-
 COSDir::COSDir()
+  : info(new COSDirInfo)
 {
-	info = new COSDirInfo;
 }
 
 COSDir::COSDir( const COSDir& r)
 {
-	info = new COSDirInfo(*r.info);
+  if (this == &r)
+    return;
+
+  info = new COSDirInfo(*r.info);
 }
 
 COSDir& COSDir::operator = (const COSDir& r)
 {
-	if (this == &r)
-		return *this;
+  if (this == &r)
+    return *this;
 
-	if (info)
-		delete(info);
+  delete(info);
+  info = new COSDirInfo(*r.info);
 
-	info = new COSDirInfo(*r.info);
-
-	return *this;
+  return *this;
 }
 
 COSDir::COSDir( const char* szDirName )
+  : info(new COSDirInfo)
 {
-	info = new COSDirInfo;
-	SetStdDir(szDirName);
+  SetStdDir(szDirName);
 }
 
 COSDir::~COSDir()
 {
-	if (info)
-	{
-		info->nameList.clear();
-		delete(info);
-	}
-	info = NULL;
+  delete(info);
 }
 
 void COSDir::SetStdDir ( const char* szDirName )
 {
-	info->baseStdDir = szDirName;
-	info->baseOSDir = szDirName;
-	OSFileStdToOSDir((char*)info->baseOSDir.c_str());
+  info->baseStdDir = szDirName;
+  info->baseOSDir = szDirName;
+  OSFileStdToOSDir((char*)info->baseOSDir.c_str());
 }
 
 void COSDir::SetOSDir ( const char* szDirName )
 {
-	info->baseStdDir = szDirName;
-	info->baseOSDir = szDirName;
-	OSFileOSToStdDir((char*)info->baseStdDir.c_str());
+  info->baseStdDir = szDirName;
+  info->baseOSDir = szDirName;
+  OSFileOSToStdDir((char*)info->baseStdDir.c_str());
 }
 
 void COSDir::MakeStdDir ( const char* szDirName )
 {
-	SetStdDir(szDirName);
+  SetStdDir(szDirName);
 #ifdef _WIN32
-	mkdir(info->baseOSDir.c_str());
+  mkdir(info->baseOSDir.c_str());
 #else
-	mkdir(info->baseOSDir.c_str(), 0777);
+  mkdir(info->baseOSDir.c_str(), 0777);
 #endif
 }
 
 void COSDir::MakeOSDir ( const char* szDirName )
 {
-	SetOSDir(szDirName);
+  SetOSDir(szDirName);
 #ifdef _WIN32
-	mkdir(info->baseOSDir.c_str());
+  mkdir(info->baseOSDir.c_str());
 #else
-	mkdir(info->baseOSDir.c_str(), 0777);
+  mkdir(info->baseOSDir.c_str(), 0777);
 #endif
 }
 
 const char* COSDir::GetStdName ( void )
 {
-	return info->baseStdDir.c_str();
+  return info->baseStdDir.c_str();
 }
 
 const char* COSDir::GetOSName ( void )
 {
-	return info->baseOSDir.c_str();
+  return info->baseOSDir.c_str();
 }
 
 const char* COSDir::GetFullOSPath ( void )
 {
-	static std::string	szFilePath;
+  static std::string	szFilePath;
 
-	szFilePath.empty();
-	szFilePath = osBaseDir; 
+  szFilePath.empty();
+  szFilePath = osBaseDir; 
 
-	szFilePath += info->baseOSDir;
-	return szFilePath.c_str();
+  szFilePath += info->baseOSDir;
+  return szFilePath.c_str();
 }
 
 bool COSDir::GetNextFile ( COSFile &oFile, bool bRecursive )
 {
-	return GetNextFile(oFile,NULL,bRecursive);
+  return GetNextFile(oFile,NULL,bRecursive);
 }
 
 bool COSDir::GetNextFile ( COSFile &oFile, const char* fileMask, bool bRecursive )
 {
 #ifdef _WIN32
-	std::string realMask = "*.*";	//FIXME -- could this also be just '*' ?
+  std::string realMask = "*.*";	//FIXME -- could this also be just '*' ?
 #else
-	std::string realMask = "*";
+  std::string realMask = "*";
 #endif
-	if (fileMask)
-		realMask = fileMask;
+  if (fileMask)
+    realMask = fileMask;
 
-	GetUperName((char*)realMask.c_str());
+  GetUperName((char*)realMask.c_str());
 	
-	std::string theFileExt;
-	if (info->namePos == 0xFFFFFFFF)
-	{
-		info->nameList.clear();
-        //FIXME -- just do the #ifdef'ing here?
-		WindowsAddFileStack(GetFullOSPath(),realMask.c_str(),bRecursive);
-		LinuxAddFileStack(GetFullOSPath(),realMask.c_str(),bRecursive);
+  std::string theFileExt;
+  if (info->namePos == 0xFFFFFFFF) {
+    info->nameList.clear();
+    //FIXME -- just do the #ifdef'ing here?
+    WindowsAddFileStack(GetFullOSPath(),realMask.c_str(),bRecursive);
+    LinuxAddFileStack(GetFullOSPath(),realMask.c_str(),bRecursive);
 
-		info->namePos = 0;
-	}
+    info->namePos = 0;
+  }
 	
-	unsigned int size = (int)info->nameList.size();
-	if (info->namePos >= size)
-	{
-		info->namePos = 0xFFFFFFFF;
-		return false;
-	}
+  unsigned int size = (int)info->nameList.size();
+  if (info->namePos >= size) {
+    info->namePos = 0xFFFFFFFF;
+    return false;
+  }
 
-	std::string	fileName = info->nameList[info->namePos];
+  std::string	fileName = info->nameList[info->namePos];
 
-	if (osBaseDir.size()>1)
-	{
-		std::string temp = &(fileName.c_str()[osBaseDir.size()]);
-		fileName = temp;
-	}
+  if (osBaseDir.size()>1) {
+    std::string temp = &(fileName.c_str()[osBaseDir.size()]);
+    fileName = temp;
+  }
 
-	oFile.OSName(fileName.c_str());
-	info->namePos++;
+  oFile.OSName(fileName.c_str());
+  info->namePos++;
 
-	return true;
+  return true;
 }
 
 bool COSDir::WindowsAddFileStack ( const char *szPathName, const char* fileMask, \
bool bRecursive   )  {
 #ifdef _WIN32
-	struct _finddata_t fileInfo;
+  struct _finddata_t fileInfo;
 	
-	long		hFile;
-	std::string searchstr;
+  long		hFile;
+  std::string searchstr;
 
-	std::string FilePath;
+  std::string FilePath;
 
-	bool	bDone = false;
+  bool	bDone = false;
 
-	searchstr = szPathName;
-	searchstr += "\\";
-	if (bRecursive)
-		searchstr += "*.*";
-	else if (fileMask)
-		searchstr += fileMask;
-	else
-		searchstr += "*.*";
+  searchstr = szPathName;
+  searchstr += "\\";
+  if (bRecursive)
+    searchstr += "*.*";
+  else if (fileMask)
+    searchstr += fileMask;
+  else
+    searchstr += "*.*";
 
-	std::string extenstionSearch;
+  std::string extenstionSearch;
 
-	if ( fileMask && strchr(fileMask,'.'))
-		extenstionSearch = strchr(fileMask,'.')+1;
+  if ( fileMask && strchr(fileMask,'.'))
+    extenstionSearch = strchr(fileMask,'.')+1;
 
-	hFile = (long)_findfirst(searchstr.c_str(),&fileInfo);
+  hFile = (long)_findfirst(searchstr.c_str(),&fileInfo);
 
-	if (hFile != -1)
-	{
-		while (!bDone)
-		{
-			if ((strlen(fileInfo.name) >0) && (strcmp(fileInfo.name,".") != 0) && 
-                (strcmp(fileInfo.name,"..") != 0))
-			{
-				FilePath = szPathName;
-				FilePath += "\\";
-				FilePath += fileInfo.name;
+  if (hFile != -1) {
+    while (!bDone) {
+      if ((strlen(fileInfo.name) >0) && (strcmp(fileInfo.name,".") != 0) && 
+	  (strcmp(fileInfo.name,"..") != 0)) {
+	FilePath = szPathName;
+	FilePath += "\\";
+	FilePath += fileInfo.name;
 
-				if ( (fileInfo.attrib & _A_SUBDIR ) && bRecursive)
-					WindowsAddFileStack(FilePath.c_str(),fileMask,bRecursive);
-				else if (!(fileInfo.attrib & _A_SUBDIR) )
-				{
-					if (bRecursive && fileMask)	// if we are recusive we need to check extension \
                manualy, so we get dirs and stuf
-					{
-						if (strrchr(FilePath.c_str(),'.'))
-						{
-							if ( stricmp(strrchr(FilePath.c_str(),'.')+1, extenstionSearch.c_str() ) == 0 \
                )
-								info->nameList.push_back(FilePath);
-						}
-					}
-					else
-						info->nameList.push_back(FilePath);
-				}
-			}
-			if (_findnext(hFile,&fileInfo) == -1)
-				bDone = true;
-		}
+	if ( (fileInfo.attrib & _A_SUBDIR ) && bRecursive) {
+	  WindowsAddFileStack(FilePath.c_str(),fileMask,bRecursive);
+	} else if (!(fileInfo.attrib & _A_SUBDIR) ) {
+	  if (bRecursive && fileMask) {	// if we are recusive we need to check extension \
manualy, so we get dirs and stuf +	    if (strrchr(FilePath.c_str(),'.')) {
+	      if ( stricmp(strrchr(FilePath.c_str(),'.')+1, extenstionSearch.c_str() ) == 0 \
) +		info->nameList.push_back(FilePath);
+	    }
+	  } else {
+	    info->nameList.push_back(FilePath);
+	  }
 	}
-	return true;
+      }
+      if (_findnext(hFile,&fileInfo) == -1)
+	bDone = true;
+    }
+  }
+  return true;
 #else
-	return false;
+  return false;
 #endif 
 }
 
@@ -780,140 +734,133 @@
 #ifndef _WIN32
 static int match_multi (const char **mask, const char **string)
 {
-	const char *msk;
-	const char *str;
-	const char *msktop;
-	const char *strtop;
+  const char *msk;
+  const char *str;
+  const char *msktop;
+  const char *strtop;
 
-	msk = *mask;
-	str = *string;
+  msk = *mask;
+  str = *string;
 
-	while ((*msk != '\0') && (*msk == '*'))
-		msk++;                      /* get rid of multiple '*'s */
+  while ((*msk != '\0') && (*msk == '*'))
+    msk++;                      /* get rid of multiple '*'s */
 
-	if (*msk == '\0')				/* '*' was last, auto-match */
-		return +1;
+  if (*msk == '\0')				/* '*' was last, auto-match */
+    return +1;
 
-	msktop = msk;
-	strtop = str;
+  msktop = msk;
+  strtop = str;
 
-	while (*msk != '\0')
-	{
-		if (*msk == '*')
-		{
-			*mask = msk;
-			*string = str;
-			return 0;                 /* matched this segment */
-		}
-		else if (*str == '\0')
-			return -1;                /* can't match */
-		else
-		{
-			if ((*msk == '?') || (*msk == *str))
-			{
-				msk++;
-				str++;
-				if ((*msk == '\0') && (*str != '\0'))	/* advanced check */
-				{										
-					str++;
-					strtop++;
-					str = strtop;
-					msk = msktop;
-				}
-			}
-			else
-			{
-				str++;
-				strtop++;
-				str = strtop;
-				msk = msktop;
-			}
-		}
+  while (*msk != '\0') {
+    if (*msk == '*') {
+      *mask = msk;
+      *string = str;
+      return 0;                 /* matched this segment */
+    } else if (*str == '\0') {
+      return -1;                /* can't match */
+    } else {
+      if ((*msk == '?') || (*msk == *str)) {
+	msk++;
+	str++;
+	if ((*msk == '\0') && (*str != '\0')) {	/* advanced check */
+	  str++;
+	  strtop++;
+	  str = strtop;
+	  msk = msktop;
 	}
+      } else {
+	str++;
+	strtop++;
+	str = strtop;
+	msk = msktop;
+      }
+    }
+  }
 
-	*mask = msk;
-	*string = str;
-	return +1;											 /* full match */
+  *mask = msk;
+  *string = str;
+  return +1;			/* full match */
 }
 
 static int match_mask (const char *mask, const char *string)
 { 
-	if (mask == NULL)
-		return 0;
+  if (mask == NULL)
+    return 0;
 
-	if (string == NULL)
-		return 0;
+  if (string == NULL)
+    return 0;
 
-	if ((mask[0] == '*') && (mask[1] == '\0'))
-		return 1;									/* instant match */
+  if ((mask[0] == '*') && (mask[1] == '\0'))
+    return 1;									/* instant match */
 
-	while (*mask != '\0')
-	{
-		if (*mask == '*')
-		{
-			mask++;
-			switch (match_multi (&mask, &string))
-			{
-				case +1:
-					return 1;
-				case -1:
-					return 0;
-			}
-		}
-		else if (*string == '\0')
-			return 0;
-		else if ((*mask == '?') || (*mask == *string))
-		{
-			mask++;
-			string++;
-		}
-		else
-			return 0;
-	}
+  while (*mask != '\0') {
+    if (*mask == '*') {
+      mask++;
+      switch (match_multi (&mask, &string)) {
+      case +1:
+	return 1;
+      case -1:
+	return 0;
+      }
+    } else if (*string == '\0') {
+      return 0;
+    } else if ((*mask == '?') || (*mask == *string)) {
+      mask++;
+      string++;
+    } else {
+      return 0;
+    }
+  }
 
-	if (*string == '\0')
-		return 1;
-	else
-		return 0;
+  if (*string == '\0')
+    return 1;
+  else
+    return 0;
 }
 #endif
 
 bool COSDir::LinuxAddFileStack (  const char *szPathName, const char* fileMask, bool \
bRecursive  )  {
 #ifdef _WIN32
-	return false;//WIN32
+  return false;//WIN32
 #else
-	DIR	*directory;
-	dirent	*fileInfo;
-	struct stat	statbuf;
-	char	searchstr[1024];
-	std::string	FilePath;
+  DIR	*directory;
+  dirent	*fileInfo;
+  struct stat	statbuf;
+  char	searchstr[1024];
+  std::string	FilePath;
 
-	strcpy(searchstr, szPathName);
-	if (searchstr[strlen(searchstr) - 1] != '/')
-		strcat(searchstr, "/");
-	directory = opendir(searchstr);
-	if (!directory)
-		return false;
+  strcpy(searchstr, szPathName);
+  if (searchstr[strlen(searchstr) - 1] != '/')
+    strcat(searchstr, "/");
+  directory = opendir(searchstr);
+  if (!directory)
+    return false;
 
-	// TODO: make it use the filemask
-	while ((fileInfo = readdir(directory)))
-	{
-		if (!((strcmp(fileInfo->d_name, ".") == 0) || (strcmp(fileInfo->d_name, "..") == \
                0)))
-		{
-			FilePath = searchstr;
-			FilePath += fileInfo->d_name;
-			GetUperName(fileInfo->d_name);
+  // TODO: make it use the filemask
+  while ((fileInfo = readdir(directory))) {
+    if (!((strcmp(fileInfo->d_name, ".") == 0) || (strcmp(fileInfo->d_name, "..") == \
0))) { +      FilePath = searchstr;
+      FilePath += fileInfo->d_name;
+      GetUperName(fileInfo->d_name);
 
-			stat(FilePath.c_str(), &statbuf);
+      stat(FilePath.c_str(), &statbuf);
 
-			if (S_ISDIR(statbuf.st_mode) && bRecursive)
-				LinuxAddFileStack(FilePath.c_str(),fileMask,bRecursive);
-			else if (match_mask (fileMask, fileInfo->d_name))
-				info->nameList.push_back(FilePath);
-		}
-	}
-	closedir(directory);
-	return true;
+      if (S_ISDIR(statbuf.st_mode) && bRecursive)
+	LinuxAddFileStack(FilePath.c_str(),fileMask,bRecursive);
+      else if (match_mask (fileMask, fileInfo->d_name))
+	info->nameList.push_back(FilePath);
+    }
+  }
+  closedir(directory);
+  return true;
 #endif// !Win32
 }
+
+// Local Variables: ***
+// mode:C++ ***
+// tab-width: 8 ***
+// c-basic-offset: 2 ***
+// indent-tabs-mode: t ***
+// End: ***
+// ex: shiftwidth=2 tabstop=8


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
BZFlag-commits mailing list
BZFlag-commits@lists.SourceForge.net
https://lists.SourceForge.net/lists/listinfo/bzflag-commits
irc: #BZFlag @ irc.freenode.net


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic