|
From: <pst...@us...> - 2008-03-30 03:03:42
|
Revision: 355
http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=355&view=rev
Author: pstieber
Date: 2008-03-29 20:03:40 -0700 (Sat, 29 Mar 2008)
Log Message:
-----------
1. Changed to take a const wxString&.
2. Fixed incorrect JAZZ environment variable test.
3. Only print debug info if the file is found.
4. Removed compiled path code.
5. Updated comment header.
Modified Paths:
--------------
trunk/jazz/src/FindFile.cpp
trunk/jazz/src/FindFile.h
Modified: trunk/jazz/src/FindFile.cpp
===================================================================
--- trunk/jazz/src/FindFile.cpp 2008-03-30 00:21:03 UTC (rev 354)
+++ trunk/jazz/src/FindFile.cpp 2008-03-30 03:03:40 UTC (rev 355)
@@ -21,6 +21,7 @@
//*****************************************************************************
#include "WxWidgets.h"
+#include <wx/filename.h>
#include <iostream>
@@ -28,65 +29,64 @@
//*****************************************************************************
// Description:
-// Find a file, looking in
-// 1. where the HOME environment var is pointing
-// 2. where the JAZZ environment var is pointing
-// 3. where the jazz executable was started
+// This function attempts to find a file. It checks for the existence of
+// the file by
//
-// This function was converted to use wxString instead of char* because it is
-// safe to return localy allocated wxStrings because of reference counting.
+// 1. using the passed file name
+// 2. appending the passed file name to the path specified by the HOME
+// environment variable, if it exists
+// 3. appending the passed file name to the path specified by the JAZZ
+// environment variable, if it exists
+// 4. appending the passed file name to the location of the jazz executable
+//
+// Returns:
+// wxString:
+// A complete path and file name for the found file or wxEmptyString if
+// the file was not found.
//*****************************************************************************
-wxString FindFile(const char* pFileName)
+wxString FindFile(const wxString& FileName)
{
- wxString buf;
-
- if (wxFileExists((char *)pFileName))
+ if (wxFileExists(FileName))
{
- cout << "imediate hit " << pFileName << endl;
- return pFileName;
+ cout << "imediate hit " << FileName << endl;
+ return FileName;
}
- wxString home;
+ wxString FoundFileName;
+
+ wxString Home;
if (getenv("HOME") != 0)
{
- home = getenv("HOME");
- buf << home << "/" << pFileName;
- cout << "home " << buf <<endl;
- if (wxFileExists(buf))
+ Home = getenv("HOME");
+ FoundFileName << Home << wxFileName::GetPathSeparator() << FileName;
+ if (wxFileExists(FoundFileName))
{
- return buf;
+ cout << "home " << FoundFileName << endl;
+ return FoundFileName;
}
}
- if (getenv("HOME") != 0)
+
+ if (getenv("JAZZ") != 0)
{
- buf = "";
- home = getenv("JAZZ");
- buf << home << "/" << pFileName;
- cout << "jazz " << buf <<endl;
- if (wxFileExists(buf))
+ FoundFileName = "";
+ Home = getenv("JAZZ");
+ FoundFileName << Home << wxFileName::GetPathSeparator() << FileName;
+ if (wxFileExists(FoundFileName))
{
- return buf;
+ cout << "jazz " << FoundFileName <<endl;
+ return FoundFileName;
}
}
- // look where the executable was started
- home = wxPathOnly((const char *)wxTheApp->argv[0]);
- buf = "";
- buf << home << "/" << pFileName;
- cout <<"startup " << buf <<endl;
- if (wxFileExists(buf))
+ // Look where the executable was started.
+ FoundFileName = "";
+ Home = wxPathOnly((const char *)wxTheApp->argv[0]);
+ FoundFileName << Home << wxFileName::GetPathSeparator() << FileName;
+ if (wxFileExists(FoundFileName))
{
- return buf;
+ cout << "startup " << FoundFileName << endl;
+ return FoundFileName;
}
- // look in the compiled-in path
-// buf = "";
-// buf << JAZZ_DATADIR << "/" << pFileName;
-// cout << "compiled in path " << buf << " " << wxFileExists(buf) << endl;
-// if (wxFileExists(buf))
-// {
-// return buf;
-// }
-
return wxEmptyString;
}
Modified: trunk/jazz/src/FindFile.h
===================================================================
--- trunk/jazz/src/FindFile.h 2008-03-30 00:21:03 UTC (rev 354)
+++ trunk/jazz/src/FindFile.h 2008-03-30 03:03:40 UTC (rev 355)
@@ -23,6 +23,23 @@
#ifndef JZ_FINDFILE_H
#define JZ_FINDFILE_H
-wxString FindFile(const char* pFileName);
+//*****************************************************************************
+// Description:
+// This function attempts to find a file. It checks for the existence of
+// the file by
+//
+// 1. using the passed file name
+// 2. appending the passed file name to the path specified by the HOME
+// environment variable, if it exists
+// 3. appending the passed file name to the path specified by the JAZZ
+// environment variable, if it exists
+// 4. appending the passed file name to the location of the jazz executable
+//
+// Returns:
+// wxString:
+// A complete path and file name for the found file or wxEmptyString if
+// the file was not found.
+//*****************************************************************************
+wxString FindFile(const wxString& pFileName);
#endif // !defined(JZ_FINDFILE_H)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|