diff options
Diffstat (limited to 'docs/doxygen/nel/path_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/path_8cpp-source.html | 1280 |
1 files changed, 1280 insertions, 0 deletions
diff --git a/docs/doxygen/nel/path_8cpp-source.html b/docs/doxygen/nel/path_8cpp-source.html new file mode 100644 index 00000000..11cf9330 --- /dev/null +++ b/docs/doxygen/nel/path_8cpp-source.html @@ -0,0 +1,1280 @@ +<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<HTML> +<HEAD> + <TITLE>nevrax.org : docs</TITLE> + <LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css"> + <link href="doxygen.css" rel="stylesheet" type="text/css"> +</HEAD> +<BODY MARGINHEIGHT="0" MARGINWIDTH="0"> + +<!-- uplinks --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD> + </TR> +</TABLE> + +<!-- banner Nevrax --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%> + <TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR> +</TABLE> + +<!-- main table --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + + <!------ Begin Box ------> + <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black> + <FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF> + <TABLE cellspacing=0 cellpadding=1 border=0> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr> + </TABLE> + </TD></TR></TABLE></TD></TR></TABLE> + <!------ End Box ------> + + </TD> + <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + +<!-- title --> +<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td> +<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A> +</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT=""> +</td></tr></table> + + +<!-- block --> +<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD> + <TD><B>Documentation</B></TD> + <TD ALIGN=RIGHT> </td> +</tr></table> +<!-- Generated by Doxygen 1.2.14 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center> +<hr><h1>path.cpp</h1><a href="path_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2000, 2001 Nevrax Ltd.</font> +00008 <font class="comment"> *</font> +00009 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00013 <font class="comment"> * any later version.</font> +00014 <font class="comment"></font> +00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"></font> +00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00023 <font class="comment"> * MA 02111-1307, USA.</font> +00024 <font class="comment"> */</font> +00025 +00026 +00027 <font class="preprocessor">#include "<a class="code" href="stdmisc_8h.html">stdmisc.h</a>"</font> +00028 +00029 <font class="preprocessor">#include <fstream></font> +00030 +00031 <font class="preprocessor">#include "<a class="code" href="big__file_8h.html">nel/misc/big_file.h</a>"</font> +00032 <font class="preprocessor">#include "<a class="code" href="path_8h.html">nel/misc/path.h</a>"</font> +00033 <font class="preprocessor">#include "<a class="code" href="hierarchical__timer_8h.html">nel/misc/hierarchical_timer.h</a>"</font> +00034 +00035 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00036 <font class="preprocessor"></font><font class="preprocessor"># include <windows.h></font> +00037 <font class="preprocessor"># include <sys/types.h></font> +00038 <font class="preprocessor"># include <sys/stat.h></font> +00039 <font class="preprocessor"># include <direct.h></font> +00040 <font class="preprocessor"># include <io.h></font> +00041 <font class="preprocessor"># include <fcntl.h></font> +00042 <font class="preprocessor"># include <sys/types.h></font> +00043 <font class="preprocessor"># include <sys/stat.h></font> +00044 <font class="preprocessor">#else</font> +00045 <font class="preprocessor"></font><font class="preprocessor"># include <sys/types.h></font> +00046 <font class="preprocessor"># include <sys/stat.h></font> +00047 <font class="preprocessor"># include <dirent.h></font> +00048 <font class="preprocessor"># include <<a class="code" href="unistd_8h.html">unistd.h</a>></font> +00049 <font class="preprocessor"># include <errno.h></font> +00050 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +00051 <font class="preprocessor"></font> +00052 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00053 +00054 <font class="keyword">namespace </font>NLMISC { +00055 +00056 <font class="comment">//</font> +00057 <font class="comment">// Macros</font> +00058 <font class="comment">//</font> +00059 +00060 <font class="comment">// Use this define if you want to display info about the CPath.</font> +00061 <font class="comment">//#define NL_DEBUG_PATH</font> +00062 +00063 <font class="preprocessor">#ifdef NL_DEBUG_PATH</font> +00064 <font class="preprocessor"></font><font class="preprocessor">#define NL_DISPLAY_PATH nlinfo</font> +00065 <font class="preprocessor"></font><font class="preprocessor">#else </font> +00066 <font class="preprocessor"></font><font class="preprocessor">#ifdef __GNUC__</font> +00067 <font class="preprocessor"></font><font class="preprocessor">#define NL_DISPLAY_PATH(format, args...)</font> +00068 <font class="preprocessor"></font><font class="preprocessor">#else // __GNUC__</font> +<a name="l00069"></a><a class="code" href="path_8cpp.html#a0">00069</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_DISPLAY_PATH if(false)</font> +00070 <font class="preprocessor"></font><font class="preprocessor">#endif // __GNUC__</font> +00071 <font class="preprocessor"></font><font class="preprocessor">#endif</font> +00072 <font class="preprocessor"></font> +00073 +00074 <font class="comment">//</font> +00075 <font class="comment">// Variables</font> +00076 <font class="comment">//</font> +00077 +<a name="l00078"></a><a class="code" href="classNLMISC_1_1CPath.html#r0">00078</a> CPath *CPath::_Instance = NULL; +00079 +00080 +00081 <font class="comment">//</font> +00082 <font class="comment">// Functions</font> +00083 <font class="comment">//</font> +00084 +<a name="l00085"></a><a class="code" href="classNLMISC_1_1CPath.html#d16">00085</a> <font class="keywordtype">void</font> CPath::getFileList(<font class="keyword">const</font> std::string &extension, std::vector<std::string> &filenames) +00086 { +00087 std::map<std::string, CFileEntry>::iterator first(<a class="code" href="classNLMISC_1_1CPath.html#f0">getInstance</a>()-><a class="code" href="classNLMISC_1_1CPath.html#o1">_Files</a>.begin()), last(<a class="code" href="classNLMISC_1_1CPath.html#f0">getInstance</a>()-><a class="code" href="classNLMISC_1_1CPath.html#o1">_Files</a>.end()); +00088 +00089 <font class="keywordflow">for</font> (; first != last; ++ first) +00090 { +00091 <font class="keywordflow">if</font> (first->second.Extension == extension) +00092 { +00093 filenames.push_back(first->first); +00094 } +00095 } +00096 } +00097 +<a name="l00098"></a><a class="code" href="classNLMISC_1_1CPath.html#f0">00098</a> CPath *CPath::getInstance () +00099 { +00100 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CPath.html#r0">_Instance</a> == NULL) +00101 { +00102 <a class="code" href="classNLMISC_1_1CPath.html#r0">_Instance</a> = <font class="keyword">new</font> CPath; +00103 } +00104 <font class="keywordflow">return</font> <a class="code" href="classNLMISC_1_1CPath.html#r0">_Instance</a>; +00105 } +00106 +<a name="l00107"></a><a class="code" href="classNLMISC_1_1CPath.html#d8">00107</a> <font class="keywordtype">void</font> CPath::clearMap () +00108 { +00109 CPath *inst = CPath::getInstance(); +00110 inst->_Files.clear (); +00111 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::clearMap(): map directory cleared"</font>); +00112 } +00113 +<a name="l00114"></a><a class="code" href="classNLMISC_1_1CPath.html#c0">00114</a> sint CPath::findExtension (<font class="keyword">const</font> string &ext1, <font class="keyword">const</font> string &ext2) +00115 { +00116 CPath *inst = CPath::getInstance(); +00117 <font class="keywordflow">for</font> (uint i = 0; i < inst->_Extensions.size (); i++) +00118 { +00119 <font class="keywordflow">if</font> (inst->_Extensions[i].first == ext1 && inst->_Extensions[i].second == ext2) +00120 { +00121 <font class="keywordflow">return</font> i; +00122 } +00123 } +00124 <font class="keywordflow">return</font> -1; +00125 } +00126 +<a name="l00127"></a><a class="code" href="classNLMISC_1_1CPath.html#d9">00127</a> <font class="keywordtype">void</font> CPath::remapExtension (<font class="keyword">const</font> string &ext1, <font class="keyword">const</font> string &ext2, <font class="keywordtype">bool</font> substitute) +00128 { +00129 CPath *inst = CPath::getInstance(); +00130 +00131 string ext1lwr = <a class="code" href="namespaceNLMISC.html#a229">strlwr</a> (ext1); +00132 string ext2lwr = <a class="code" href="namespaceNLMISC.html#a229">strlwr</a> (ext2); +00133 +00134 <font class="keywordflow">if</font> (ext1lwr.empty() || ext2lwr.empty()) +00135 { +00136 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::remapExtension(%s, %s, %d): can't remap empty extension"</font>, ext1lwr.c_str(), ext2lwr.c_str(), substitute); +00137 } +00138 +00139 <font class="keywordflow">if</font> (ext1lwr == <font class="stringliteral">"bnp"</font> || ext2lwr == <font class="stringliteral">"bnp"</font>) +00140 { +00141 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::remapExtension(%s, %s, %d): you can't remap a big file"</font>, ext1lwr.c_str(), ext2lwr.c_str(), substitute); +00142 } +00143 +00144 <font class="keywordflow">if</font> (!substitute) +00145 { +00146 <font class="comment">// remove the mapping from the mapping list</font> +00147 sint n = inst->findExtension (ext1lwr, ext2lwr); +00148 <a class="code" href="debug_8h.html#a6">nlassert</a> (n != -1); +00149 inst->_Extensions.erase (inst->_Extensions.begin() + n); +00150 +00151 <font class="comment">// remove mapping in the map</font> +00152 map<string, CFileEntry>::iterator it = inst->_Files.begin(); +00153 map<string, CFileEntry>::iterator nit = it; +00154 <font class="keywordflow">while</font> (it != inst->_Files.end ()) +00155 { +00156 nit++; +00157 <font class="keywordflow">if</font> ((*it).second.Remapped && (*it).second.Extension == ext2lwr) +00158 { +00159 inst->_Files.erase (it); +00160 } +00161 it = nit; +00162 } +00163 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::remapExtension(%s, %s, %d): extension removed"</font>, ext1lwr.c_str(), ext2lwr.c_str(), substitute); +00164 } +00165 <font class="keywordflow">else</font> +00166 { +00167 sint n = inst->findExtension (ext1lwr, ext2lwr); +00168 <font class="keywordflow">if</font> (n != -1) +00169 { +00170 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::remapExtension(%s, %s, %d): remapping already set"</font>, ext1lwr.c_str(), ext2lwr.c_str(), substitute); +00171 <font class="keywordflow">return</font>; +00172 } +00173 +00174 <font class="comment">// adding mapping into the mapping list</font> +00175 inst->_Extensions.push_back (make_pair (ext1lwr, ext2lwr)); +00176 +00177 <font class="comment">// adding mapping into the map</font> +00178 vector<string> newFiles; +00179 map<string, CFileEntry>::iterator it = inst->_Files.begin(); +00180 <font class="keywordflow">while</font> (it != inst->_Files.end ()) +00181 { +00182 <font class="keywordflow">if</font> (!(*it).second.Remapped && (*it).second.Extension == ext1lwr) +00183 { +00184 <font class="comment">// find if already exist</font> +00185 uint32 pos = (*it).first.find_last_of (<font class="stringliteral">"."</font>); +00186 <font class="keywordflow">if</font> (pos != string::npos) +00187 { +00188 string <a class="code" href="cf__lexical_8cpp.html#a95">file</a> = (*it).first.substr (0, pos + 1); +00189 <a class="code" href="cf__lexical_8cpp.html#a95">file</a> += ext2lwr; +00190 +00191 <font class="comment">// TODO perhaps a problem because I insert in the current map that i parcours</font> +00192 <a class="code" href="classNLMISC_1_1CPath.html#f1">insertFileInMap</a> (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, (*it).second.Path, <font class="keyword">true</font>, ext2lwr); +00193 } +00194 } +00195 it++; +00196 } +00197 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::remapExtension(%s, %s, %d): extension added"</font>, ext1lwr.c_str(), ext2lwr.c_str(), substitute); +00198 } +00199 } +00200 +<a name="l00201"></a><a class="code" href="classNLMISC_1_1CPath.html#d6">00201</a> string CPath::lookup (<font class="keyword">const</font> string &filename, <font class="keywordtype">bool</font> throwException, <font class="keywordtype">bool</font> displayWarning, <font class="keywordtype">bool</font> lookupInLocalDirectory) +00202 { +00203 <font class="comment">// Try to find in the current directory</font> +00204 <font class="keywordflow">if</font> ( lookupInLocalDirectory && CFile::fileExists(filename) ) +00205 { +00206 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::lookup(%s): found in the current directory: '%s'"</font>, filename.c_str(), filename.c_str()); +00207 <font class="keywordflow">return</font> filename; +00208 } +00209 +00210 <font class="comment">// If the file already contains a @, it means that a lookup already proceed and returning a big file, do nothing</font> +00211 <font class="keywordflow">if</font> (filename.find (<font class="stringliteral">"@"</font>) != string::npos) +00212 { +00213 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::lookup(%s): already found"</font>, filename.c_str()); +00214 <font class="keywordflow">return</font> filename; +00215 } +00216 +00217 <font class="comment">// Try to find in the map directories</font> +00218 CPath *inst = CPath::getInstance(); +00219 string str = <a class="code" href="namespaceNLMISC.html#a229">strlwr</a> (filename); +00220 +00221 <font class="comment">// Remove end spaces</font> +00222 <font class="keywordflow">while</font> ((!str.empty()) && (str[str.size()-1] == <font class="charliteral">' '</font>)) +00223 { +00224 str.resize (str.size()-1); +00225 } +00226 +00227 map<string, CFileEntry>::iterator it = inst->_Files.find (str); +00228 <font class="comment">// If found in the map, returns it</font> +00229 <font class="keywordflow">if</font> (it != inst->_Files.end()) +00230 { +00231 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::lookup(%s): found in the map directory: '%s'"</font>, filename.c_str(), (*it).second.Path.c_str()); +00232 <font class="keywordflow">return</font> (*it).second.Path; +00233 } +00234 +00235 +00236 <font class="comment">// Try to find in the alternative directories</font> +00237 <font class="keywordflow">for</font> (uint i = 0; i < inst->_AlternativePaths.size(); i++) +00238 { +00239 string <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> = inst->_AlternativePaths[i] + filename; +00240 <font class="keywordflow">if</font> ( CFile::fileExists(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>) ) +00241 { +00242 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::lookup(%s): found in the alternative directory: '%s'"</font>, filename.c_str(), <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.c_str()); +00243 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>; +00244 } +00245 +00246 <font class="comment">// try with the remapping</font> +00247 <font class="keywordflow">for</font> (uint j = 0; j < inst->_Extensions.size(); j++) +00248 { +00249 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(CFile::getExtension (filename)) == inst->_Extensions[j].second) +00250 { +00251 string rs = inst->_AlternativePaths[i] + CFile::getFilenameWithoutExtension (filename) + <font class="stringliteral">"."</font> + inst->_Extensions[j].first; +00252 <font class="keywordflow">if</font> ( CFile::fileExists(rs) ) +00253 { +00254 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::lookup(%s): found in the alternative directory: '%s'"</font>, filename.c_str(), rs.c_str()); +00255 <font class="keywordflow">return</font> rs; +00256 } +00257 } +00258 } +00259 } +00260 +00261 +00262 <font class="comment">// Not found</font> +00263 <font class="keywordflow">if</font> (displayWarning) +00264 { +00265 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::lookup(%s): file not found"</font>, filename.c_str()); +00266 } +00267 +00268 <font class="keywordflow">if</font> (throwException) +00269 <font class="keywordflow">throw</font> EPathNotFound (filename); +00270 +00271 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; +00272 } +00273 +<a name="l00274"></a><a class="code" href="classNLMISC_1_1CPath.html#d7">00274</a> <font class="keywordtype">bool</font> CPath::exists (<font class="keyword">const</font> std::string &filename) +00275 { +00276 <font class="comment">// Try to find in the map directories</font> +00277 CPath *inst = CPath::getInstance(); +00278 string str = <a class="code" href="namespaceNLMISC.html#a229">strlwr</a> (filename); +00279 +00280 <font class="comment">// Remove end spaces</font> +00281 <font class="keywordflow">while</font> ((!str.empty()) && (str[str.size()-1] == <font class="charliteral">' '</font>)) +00282 { +00283 str.resize (str.size()-1); +00284 } +00285 +00286 map<string, CFileEntry>::iterator it = inst->_Files.find (str); +00287 <font class="comment">// If found in the map, returns it</font> +00288 <font class="keywordflow">if</font> (it != inst->_Files.end()) +00289 { +00290 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00291 } +00292 +00293 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00294 } +00295 +<a name="l00296"></a><a class="code" href="classNLMISC_1_1CPath.html#d11">00296</a> string CPath::standardizePath (<font class="keyword">const</font> string &path, <font class="keywordtype">bool</font> addFinalSlash) +00297 { +00298 string newPath; +00299 +00300 <font class="comment">// check empty path</font> +00301 <font class="keywordflow">if</font> (path.empty()) <font class="keywordflow">return</font> <font class="stringliteral">""</font>; +00302 +00303 <font class="comment">// don't transform the first \\ for windows network path</font> +00304 <font class="comment">/* if (path.size() >= 2 && path[0] == '\\' && path[1] == '\\')</font> +00305 <font class="comment"> {</font> +00306 <font class="comment"> newPath += "\\\\";</font> +00307 <font class="comment"> i = 2;</font> +00308 <font class="comment"> }</font> +00309 <font class="comment">*/</font> +00310 <font class="keywordflow">for</font> (uint i = 0; i < path.size(); i++) +00311 { +00312 <font class="comment">// don't transform the first \\ for windows network path</font> +00313 <font class="keywordflow">if</font> (path[i] == <font class="charliteral">'\\'</font>) +00314 newPath += <font class="charliteral">'/'</font>; +00315 <font class="keywordflow">else</font> +00316 newPath += path[i]; +00317 } +00318 +00319 <font class="comment">// add terminal slash</font> +00320 <font class="keywordflow">if</font> (addFinalSlash && newPath[path.size()-1] != <font class="charliteral">'/'</font>) +00321 newPath += <font class="charliteral">'/'</font>; +00322 +00323 <font class="keywordflow">return</font> newPath; +00324 } +00325 +00326 <font class="comment">// remplace / wiht \ and put all in lower case</font> +<a name="l00327"></a><a class="code" href="classNLMISC_1_1CPath.html#d12">00327</a> std::string CPath::standardizeDosPath (<font class="keyword">const</font> std::string &path) +00328 { +00329 string newPath; +00330 +00331 <font class="keywordflow">for</font> (uint i = 0; i < path.size(); i++) +00332 { +00333 <font class="keywordflow">if</font> (path[i] == <font class="charliteral">'/'</font>) +00334 newPath += <font class="charliteral">'\\'</font>; +00335 <font class="comment">// Yoyo: supress toLower. Not usefull!?!</font> +00336 <font class="comment">/*else if (isupper(path[i]))</font> +00337 <font class="comment"> newPath += tolower(path[i]);*/</font> +00338 <font class="keywordflow">else</font> +00339 newPath += path[i]; +00340 } +00341 +00342 <font class="keywordflow">if</font> (CFile::isExists(path) && CFile::isDirectory(path) && newPath[newPath.size()-1] != <font class="charliteral">'\\'</font>) +00343 newPath += <font class="charliteral">'\\'</font>; +00344 +00345 <font class="keywordflow">return</font> newPath; +00346 } +00347 +00348 +<a name="l00349"></a><a class="code" href="classNLMISC_1_1CPath.html#d15">00349</a> std::string CPath::getCurrentPath () +00350 { +00351 <font class="keywordtype">char</font> buffer [10000]; +00352 +00353 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00354 <font class="preprocessor"></font> <font class="keywordflow">return</font> _getcwd(buffer, 10000); +00355 <font class="preprocessor">#else</font> +00356 <font class="preprocessor"></font> <font class="keywordflow">return</font> getcwd(buffer, 10000); +00357 <font class="preprocessor">#endif</font> +00358 <font class="preprocessor"></font>} +00359 +<a name="l00360"></a><a class="code" href="classNLMISC_1_1CPath.html#d14">00360</a> std::string CPath::getFullPath (<font class="keyword">const</font> std::string &path, <font class="keywordtype">bool</font> addFinalSlash) +00361 { +00362 string currentPath = <a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a> (<a class="code" href="classNLMISC_1_1CPath.html#d15">getCurrentPath</a> ()); +00363 string sPath = <a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a> (path, addFinalSlash); +00364 +00365 <font class="comment">// current path</font> +00366 <font class="keywordflow">if</font> (path.empty()) +00367 { +00368 <font class="keywordflow">return</font> currentPath; +00369 } +00370 +00371 <font class="comment">// windows full path</font> +00372 <font class="keywordflow">if</font> (path.size() >= 2 && path[1] == <font class="charliteral">':'</font>) +00373 { +00374 <font class="keywordflow">return</font> sPath; +00375 } +00376 +00377 <font class="keywordflow">if</font> (path.size() >= 2 && (path[0] == <font class="charliteral">'/'</font> || path[0] == <font class="charliteral">'\\'</font>) && (path[1] == <font class="charliteral">'/'</font> || path[1] == <font class="charliteral">'\\'</font>)) +00378 { +00379 <font class="keywordflow">return</font> sPath; +00380 } +00381 +00382 +00383 <font class="comment">// from root</font> +00384 <font class="keywordflow">if</font> (path [0] == <font class="charliteral">'/'</font> || path[0] == <font class="charliteral">'\\'</font>) +00385 { +00386 <font class="keywordflow">if</font> (currentPath.size() > 2 && currentPath[1] == <font class="charliteral">':'</font>) +00387 { +00388 <font class="keywordflow">return</font> currentPath.substr(0,3) + sPath.substr(1); +00389 } +00390 <font class="keywordflow">else</font> +00391 { +00392 <font class="keywordflow">return</font> sPath; +00393 } +00394 } +00395 +00396 <font class="comment">// default case</font> +00397 <font class="keywordflow">return</font> currentPath + sPath; +00398 } +00399 +00400 +00401 +00402 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00403 <font class="preprocessor"></font><font class="preprocessor"># define dirent WIN32_FIND_DATA</font> +00404 <font class="preprocessor"></font><font class="preprocessor"># define DIR void</font> +00405 <font class="preprocessor"></font> +00406 <font class="keyword">static</font> string sDir; +00407 <font class="keyword">static</font> <font class="keywordtype">char</font> sDirBackup[512]; +00408 <font class="keyword">static</font> WIN32_FIND_DATA findData; +00409 <font class="keyword">static</font> HANDLE hFind; +00410 +00411 DIR *opendir (<font class="keyword">const</font> <font class="keywordtype">char</font> *path) +00412 { +00413 <a class="code" href="debug_8h.html#a6">nlassert</a> (path != NULL); +00414 <a class="code" href="debug_8h.html#a6">nlassert</a> (path[0] != <font class="charliteral">'\0'</font>); +00415 +00416 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] == <font class="charliteral">'\0'</font>); +00417 <font class="keywordflow">if</font> (GetCurrentDirectory (512, sDirBackup) == 0) +00418 { +00419 <font class="comment">// failed</font> +00420 sDirBackup[0] = 0; +00421 <font class="keywordflow">return</font> NULL; +00422 } +00423 +00424 +00425 <font class="keywordflow">if</font> (!CFile::isDirectory(path)) +00426 { +00427 <font class="comment">// failed</font> +00428 sDirBackup[0] = 0; +00429 <font class="keywordflow">return</font> NULL; +00430 } +00431 +00432 sDir = path; +00433 +00434 hFind = NULL; +00435 +00436 <font class="keywordflow">return</font> (<font class="keywordtype">void</font> *)1; +00437 } +00438 +00439 <font class="keywordtype">int</font> closedir (DIR *dir) +00440 { +00441 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] != <font class="charliteral">'\0'</font>); +00442 FindClose(hFind); +00443 sDirBackup[0] = <font class="charliteral">'\0'</font>; +00444 <font class="keywordflow">return</font> 0; +00445 } +00446 +00447 dirent *readdir (DIR *dir) +00448 { +00449 <font class="comment">// set the current path</font> +00450 <a class="code" href="debug_8h.html#a6">nlassert</a> (!sDir.empty()); +00451 <font class="keywordflow">if</font> (SetCurrentDirectory (sDir.c_str()) == 0) +00452 { +00453 <font class="comment">// failed</font> +00454 <font class="keywordflow">return</font> NULL; +00455 } +00456 +00457 <font class="keywordflow">if</font> (hFind == NULL) +00458 { +00459 hFind = FindFirstFile (<font class="stringliteral">"*"</font>, &findData); +00460 } +00461 <font class="keywordflow">else</font> +00462 { +00463 <font class="keywordflow">if</font> (!FindNextFile (hFind, &findData)) +00464 { +00465 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] != <font class="charliteral">'\0'</font>); +00466 SetCurrentDirectory (sDirBackup); +00467 <font class="keywordflow">return</font> NULL; +00468 } +00469 } +00470 +00471 <font class="comment">// restore the current path</font> +00472 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] != <font class="charliteral">'\0'</font>); +00473 SetCurrentDirectory (sDirBackup); +00474 +00475 <font class="keywordflow">return</font> &findData; +00476 } +00477 +00478 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +00479 <font class="preprocessor"></font> +00480 <font class="preprocessor">#ifndef NL_OS_WINDOWS</font> +00481 <font class="preprocessor"></font>string <a class="code" href="namespaceNLMISC.html#a197">BasePathgetPathContent</a>; +00482 <font class="preprocessor">#endif</font> +00483 <font class="preprocessor"></font> +00484 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a305">isdirectory</a> (dirent *de) +00485 { +00486 <a class="code" href="debug_8h.html#a6">nlassert</a> (de != NULL); +00487 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00488 <font class="preprocessor"></font> <font class="keywordflow">return</font> ((de->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) && ((de->dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) == 0); +00489 <font class="preprocessor">#else</font> +00490 <font class="preprocessor"></font> <font class="comment">//nlinfo ("isdirectory filename %s -> 0x%08x", de->d_name, de->d_type);</font> +00491 <font class="comment">// we can't use "de->d_type & DT_DIR" because it s always NULL on libc2.1</font> +00492 <font class="comment">//return (de->d_type & DT_DIR) != 0;</font> +00493 +00494 <font class="keywordflow">return</font> CFile::isDirectory (<a class="code" href="namespaceNLMISC.html#a197">BasePathgetPathContent</a> + de->d_name); +00495 +00496 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +00497 <font class="preprocessor"></font>} +00498 +00499 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a306">isfile</a> (dirent *de) +00500 { +00501 <a class="code" href="debug_8h.html#a6">nlassert</a> (de != NULL); +00502 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00503 <font class="preprocessor"></font> <font class="keywordflow">return</font> ((de->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) && ((de->dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) == 0); +00504 <font class="preprocessor">#else</font> +00505 <font class="preprocessor"></font> <font class="comment">// we can't use "de->d_type & DT_DIR" because it s always NULL on libc2.1</font> +00506 <font class="comment">//return (de->d_type & DT_DIR) == 0;</font> +00507 +00508 <font class="keywordflow">return</font> !CFile::isDirectory (<a class="code" href="namespaceNLMISC.html#a197">BasePathgetPathContent</a> + de->d_name); +00509 +00510 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +00511 <font class="preprocessor"></font>} +00512 +00513 string <a class="code" href="namespaceNLMISC.html#a307">getname</a> (dirent *de) +00514 { +00515 <a class="code" href="debug_8h.html#a6">nlassert</a> (de != NULL); +00516 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00517 <font class="preprocessor"></font> <font class="keywordflow">return</font> de->cFileName; +00518 <font class="preprocessor">#else</font> +00519 <font class="preprocessor"></font> <font class="keywordflow">return</font> de->d_name; +00520 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +00521 <font class="preprocessor"></font>} +00522 +<a name="l00523"></a><a class="code" href="classNLMISC_1_1CPath.html#d13">00523</a> <font class="keywordtype">void</font> CPath::getPathContent (<font class="keyword">const</font> string &path, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> wantDir, <font class="keywordtype">bool</font> wantFile, vector<string> &result) +00524 { +00525 <font class="preprocessor">#ifndef NL_OS_WINDOWS</font> +00526 <font class="preprocessor"></font> <a class="code" href="namespaceNLMISC.html#a197">BasePathgetPathContent</a> = CPath::standardizePath (path); +00527 <font class="preprocessor">#endif</font> +00528 <font class="preprocessor"></font> +00529 DIR *dir = opendir (path.c_str()); +00530 +00531 <font class="keywordflow">if</font> (dir == NULL) +00532 { +00533 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): could not open the directory"</font>, path.c_str(), recurse, wantDir, wantFile); +00534 <font class="keywordflow">return</font>; +00535 } +00536 +00537 <font class="comment">// contains path that we have to recurs into</font> +00538 vector<string> recursPath; +00539 +00540 <font class="keywordflow">while</font> (true) +00541 { +00542 dirent *de = readdir(dir); +00543 <font class="keywordflow">if</font> (de == NULL) +00544 { +00545 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): end of directory"</font>, path.c_str(), recurse, wantDir, wantFile); +00546 <font class="keywordflow">break</font>; +00547 } +00548 +00549 string fn = <a class="code" href="namespaceNLMISC.html#a307">getname</a> (de); +00550 +00551 <font class="comment">// skip . and ..</font> +00552 <font class="keywordflow">if</font> (fn == <font class="stringliteral">"."</font> || fn == <font class="stringliteral">".."</font>) +00553 <font class="keywordflow">continue</font>; +00554 +00555 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a305">isdirectory</a>(de)) +00556 { +00557 <font class="comment">// skip CVS directory</font> +00558 <font class="keywordflow">if</font> (fn == <font class="stringliteral">"CVS"</font>) +00559 { +00560 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): skip CVS directory"</font>, path.c_str(), recurse, wantDir, wantFile); +00561 <font class="keywordflow">continue</font>; +00562 } +00563 +00564 string stdName = <a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a>(<a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a>(path) + fn); +00565 <font class="keywordflow">if</font> (recurse) +00566 { +00567 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): need to recurse into '%s'"</font>, path.c_str(), recurse, wantDir, wantFile, stdName.c_str()); +00568 recursPath.push_back (stdName); +00569 } +00570 +00571 <font class="keywordflow">if</font> (wantDir) +00572 { +00573 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): adding path '%s'"</font>, path.c_str(), recurse, wantDir, wantFile, stdName.c_str()); +00574 result.push_back (stdName); +00575 } +00576 } +00577 <font class="keywordflow">if</font> (wantFile && <a class="code" href="namespaceNLMISC.html#a306">isfile</a>(de)) +00578 { +00579 <font class="keywordflow">if</font> (fn.size() >= 4 && fn.substr (fn.size()-4) == <font class="stringliteral">".log"</font>) +00580 { +00581 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): skip *.log files (%s)"</font>, path.c_str(), recurse, wantDir, wantFile, fn.c_str()); +00582 <font class="keywordflow">continue</font>; +00583 } +00584 +00585 <font class="comment">/* int lastSep = CFile::getLastSeparator(path);</font> +00586 <font class="comment"> #ifdef NL_OS_WINDOWS</font> +00587 <font class="comment"> char sep = lastSep == std::string::npos ? '\\'</font> +00588 <font class="comment"> : path[lastSep];</font> +00589 <font class="comment"> #else</font> +00590 <font class="comment"> char sep = lastSep == std::string::npos ? '/'</font> +00591 <font class="comment"> : path[lastSep];</font> +00592 <font class="comment"> #endif</font> +00593 <font class="comment">*/</font> +00594 string stdName = <a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a>(path) + <a class="code" href="namespaceNLMISC.html#a307">getname</a>(de); +00595 +00596 +00597 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::getPathContent(%s, %d, %d, %d): adding file '%s'"</font>, path.c_str(), recurse, wantDir, wantFile, stdName.c_str()); +00598 result.push_back (stdName); +00599 } +00600 } +00601 +00602 closedir (dir); +00603 +00604 <font class="preprocessor">#ifndef NL_OS_WINDOWS</font> +00605 <font class="preprocessor"></font> <a class="code" href="namespaceNLMISC.html#a197">BasePathgetPathContent</a> = <font class="stringliteral">""</font>; +00606 <font class="preprocessor">#endif</font> +00607 <font class="preprocessor"></font> +00608 <font class="comment">// let s recurse</font> +00609 <font class="keywordflow">for</font> (uint i = 0; i < recursPath.size (); i++) +00610 { +00611 <a class="code" href="classNLMISC_1_1CPath.html#d13">getPathContent</a> (recursPath[i], recurse, wantDir, wantFile, result); +00612 } +00613 } +00614 +<a name="l00615"></a><a class="code" href="classNLMISC_1_1CPath.html#d5">00615</a> <font class="keywordtype">void</font> CPath::removeAllAlternativeSearchPath () +00616 { +00617 CPath *inst = CPath::getInstance(); +00618 inst->_AlternativePaths.clear (); +00619 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::RemoveAllAternativeSearchPath(): removed"</font>); +00620 } +00621 +00622 +<a name="l00623"></a><a class="code" href="classNLMISC_1_1CPath.html#d0">00623</a> <font class="keywordtype">void</font> CPath::addSearchPath (<font class="keyword">const</font> string &path, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> alternative) +00624 { +00625 <a class="code" href="hierarchical__timer_8h.html#a5">H_AUTO_INST</a>(<a class="code" href="classNLMISC_1_1CPath.html#d0">addSearchPath</a>); +00626 +00627 CPath *inst = CPath::getInstance(); +00628 +00629 <font class="comment">// check empty directory</font> +00630 <font class="keywordflow">if</font> (path.empty()) +00631 { +00632 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): can't add empty directory, skip it"</font>, path.c_str(), recurse, alternative); +00633 <font class="keywordflow">return</font>; +00634 } +00635 +00636 <font class="comment">// check if it s a directory</font> +00637 <font class="keywordflow">if</font> (!CFile::isDirectory (path)) +00638 { +00639 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): '%s' is not a directory, I'll call addSearchFile()"</font>, path.c_str(), recurse, alternative, path.c_str()); +00640 <a class="code" href="classNLMISC_1_1CPath.html#d2">addSearchFile</a> (path); +00641 <font class="keywordflow">return</font>; +00642 } +00643 +00644 string newPath = <a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a>(path); +00645 +00646 <font class="comment">// check if it s a directory</font> +00647 <font class="keywordflow">if</font> (!CFile::isExists (newPath)) +00648 { +00649 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): '%s' is not found, skip it"</font>, path.c_str(), recurse, alternative, newPath.c_str()); +00650 <font class="keywordflow">return</font>; +00651 } +00652 +00653 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): adding the path '%s'"</font>, path.c_str(), recurse, alternative, newPath.c_str()); +00654 +00655 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): try to add '%s'"</font>, path.c_str(), recurse, alternative, newPath.c_str()); +00656 +00657 <font class="keywordflow">if</font> (alternative) +00658 { +00659 vector<string> pathsToProcess; +00660 +00661 <font class="comment">// add the current path</font> +00662 pathsToProcess.push_back (newPath); +00663 +00664 <font class="keywordflow">if</font> (recurse) +00665 { +00666 <font class="comment">// find all path and subpath</font> +00667 <a class="code" href="classNLMISC_1_1CPath.html#d13">getPathContent</a> (newPath, recurse, <font class="keyword">true</font>, <font class="keyword">false</font>, pathsToProcess); +00668 } +00669 +00670 <font class="keywordflow">for</font> (uint p = 0; p < pathsToProcess.size(); p++) +00671 { +00672 <font class="comment">// check if the path not already in the vector</font> +00673 uint i; +00674 <font class="keywordflow">for</font> (i = 0; i < inst->_AlternativePaths.size(); i++) +00675 { +00676 <font class="keywordflow">if</font> (inst->_AlternativePaths[i] == pathsToProcess[p]) +00677 <font class="keywordflow">break</font>; +00678 } +00679 <font class="keywordflow">if</font> (i == inst->_AlternativePaths.size()) +00680 { +00681 <font class="comment">// add them in the alternative directory</font> +00682 inst->_AlternativePaths.push_back (pathsToProcess[p]); +00683 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): path '%s' added"</font>, newPath.c_str(), recurse, alternative, pathsToProcess[p].c_str()); +00684 } +00685 <font class="keywordflow">else</font> +00686 { +00687 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchPath(%s, %d, %d): path '%s' already added"</font>, newPath.c_str(), recurse, alternative, pathsToProcess[p].c_str()); +00688 } +00689 } +00690 } +00691 <font class="keywordflow">else</font> +00692 { +00693 vector<string> filesToProcess; +00694 <font class="comment">// find all files in the path and subpaths</font> +00695 <a class="code" href="classNLMISC_1_1CPath.html#d13">getPathContent</a> (newPath, recurse, <font class="keyword">false</font>, <font class="keyword">true</font>, filesToProcess); +00696 +00697 <font class="comment">// add them in the map</font> +00698 <font class="keywordflow">for</font> (uint f = 0; f < filesToProcess.size(); f++) +00699 { +00700 string filename = CFile::getFilename (filesToProcess[f]); +00701 string filepath = CFile::getPath (filesToProcess[f]); +00702 <font class="comment">// insertFileInMap (filename, filepath, false, CFile::getExtension(filename));</font> +00703 <a class="code" href="classNLMISC_1_1CPath.html#d2">addSearchFile</a> (filesToProcess[f]); +00704 } +00705 } +00706 } +00707 +<a name="l00708"></a><a class="code" href="classNLMISC_1_1CPath.html#d2">00708</a> <font class="keywordtype">void</font> CPath::addSearchFile (<font class="keyword">const</font> string &<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="keywordtype">bool</font> remap, <font class="keyword">const</font> string &virtual_ext) +00709 { +00710 CPath *inst = CPath::getInstance(); +00711 string newFile = <a class="code" href="classNLMISC_1_1CPath.html#d11">standardizePath</a>(<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="keyword">false</font>); +00712 +00713 <font class="comment">// check empty file</font> +00714 <font class="keywordflow">if</font> (newFile.empty()) +00715 { +00716 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchFile(%s, %d, %s): can't add empty file, skip it"</font>, <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), remap, virtual_ext.c_str()); +00717 <font class="keywordflow">return</font>; +00718 } +00719 +00720 <font class="comment">// check if the file exists</font> +00721 <font class="keywordflow">if</font> (!CFile::isExists (newFile)) +00722 { +00723 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchFile(%s, %d, %s): '%s' is not found, skip it"</font>, <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), remap, virtual_ext.c_str(), newFile.c_str()); +00724 <font class="keywordflow">return</font>; +00725 } +00726 +00727 <font class="comment">// check if it s a file</font> +00728 <font class="keywordflow">if</font> (CFile::isDirectory (newFile)) +00729 { +00730 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchFile(%s, %d, %s): '%s' is not a file, skip it"</font>, <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), remap, virtual_ext.c_str(), newFile.c_str()); +00731 <font class="keywordflow">return</font>; +00732 } +00733 +00734 <font class="comment">// check if it s a big file</font> +00735 <font class="keywordflow">if</font> (CFile::getExtension(newFile) == <font class="stringliteral">"bnp"</font>) +00736 { +00737 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a> (<font class="stringliteral">"CPath::addSearchFile(%s, %d, %s): '%s' is a big file, add it"</font>, <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), remap, virtual_ext.c_str(), newFile.c_str()); +00738 <a class="code" href="classNLMISC_1_1CPath.html#d4">addSearchBigFile</a>(<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="keyword">false</font>, <font class="keyword">false</font>); +00739 <font class="keywordflow">return</font>; +00740 } +00741 +00742 string filenamewoext = CFile::getFilenameWithoutExtension (newFile); +00743 string filename, ext; +00744 +00745 <font class="keywordflow">if</font> (virtual_ext.empty()) +00746 { +00747 filename = CFile::getFilename (newFile); +00748 ext = CFile::getExtension (filename); +00749 } +00750 <font class="keywordflow">else</font> +00751 { +00752 filename = filenamewoext + <font class="stringliteral">"."</font> + virtual_ext; +00753 ext = virtual_ext; +00754 } +00755 +00756 <a class="code" href="classNLMISC_1_1CPath.html#f1">insertFileInMap</a> (filename, newFile, remap, ext); +00757 +00758 <font class="keywordflow">if</font> (!remap && !ext.empty()) +00759 { +00760 <font class="comment">// now, we have to see extension and insert in the map the remapped files</font> +00761 <font class="keywordflow">for</font> (uint i = 0; i < inst->_Extensions.size (); i++) +00762 { +00763 <font class="keywordflow">if</font> (inst->_Extensions[i].first == <a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(ext)) +00764 { +00765 <font class="comment">// need to remap</font> +00766 <a class="code" href="classNLMISC_1_1CPath.html#d2">addSearchFile</a> (newFile, <font class="keyword">true</font>, inst->_Extensions[i].second); +00767 } +00768 } +00769 } +00770 } +00771 +<a name="l00772"></a><a class="code" href="classNLMISC_1_1CPath.html#d3">00772</a> <font class="keywordtype">void</font> CPath::addSearchListFile (<font class="keyword">const</font> string &filename, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> alternative) +00773 { +00774 <font class="comment">// check empty file</font> +00775 <font class="keywordflow">if</font> (filename.empty()) +00776 { +00777 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchListFile(%s, %d, %d): can't add empty file, skip it"</font>, filename.c_str(), recurse, alternative); +00778 <font class="keywordflow">return</font>; +00779 } +00780 +00781 <font class="comment">// check if the file exists</font> +00782 <font class="keywordflow">if</font> (!CFile::isExists (filename)) +00783 { +00784 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchListFile(%s, %d, %d): '%s' is not found, skip it"</font>, filename.c_str(), recurse, alternative, filename.c_str()); +00785 <font class="keywordflow">return</font>; +00786 } +00787 +00788 <font class="comment">// check if it s a file</font> +00789 <font class="keywordflow">if</font> (CFile::isDirectory (filename)) +00790 { +00791 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchListFile(%s, %d, %d): '%s' is not a file, skip it"</font>, filename.c_str(), recurse, alternative, filename.c_str()); +00792 <font class="keywordflow">return</font>; +00793 } +00794 +00795 <font class="comment">// TODO lire le fichier et ajouter les fichiers qui sont dedans</font> +00796 +00797 } +00798 +00799 <font class="comment">// WARNING : recurse is not used</font> +<a name="l00800"></a><a class="code" href="classNLMISC_1_1CPath.html#d4">00800</a> <font class="keywordtype">void</font> CPath::addSearchBigFile (<font class="keyword">const</font> string &sBigFilename, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> alternative) +00801 { +00802 <font class="comment">// Check if filename is not empty</font> +00803 <font class="keywordflow">if</font> (sBigFilename.empty()) +00804 { +00805 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchBigFile(%s, %d, %d): can't add empty file, skip it"</font>, sBigFilename.c_str(), recurse, alternative); +00806 <font class="keywordflow">return</font>; +00807 } +00808 <font class="comment">// Check if the file exists</font> +00809 <font class="keywordflow">if</font> (!CFile::isExists (sBigFilename)) +00810 { +00811 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchBigFile(%s, %d, %d): '%s' is not found, skip it"</font>, sBigFilename.c_str(), recurse, alternative, sBigFilename.c_str()); +00812 <font class="keywordflow">return</font>; +00813 } +00814 <font class="comment">// Check if it s a file</font> +00815 <font class="keywordflow">if</font> (CFile::isDirectory (sBigFilename)) +00816 { +00817 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchBigFile(%s, %d, %d): '%s' is not a file, skip it"</font>, sBigFilename.c_str(), recurse, alternative, sBigFilename.c_str()); +00818 <font class="keywordflow">return</font>; +00819 } +00820 <font class="comment">// Open and read the big file header</font> +00821 CPath *inst = CPath::getInstance(); +00822 +00823 FILE *Handle = fopen (sBigFilename.c_str(), <font class="stringliteral">"rb"</font>); +00824 <font class="keywordflow">if</font> (Handle == NULL) +00825 { +00826 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it"</font>, sBigFilename.c_str(), recurse, alternative); +00827 <font class="keywordflow">return</font>; +00828 } +00829 +00830 <font class="comment">// add the link with the CBigFile singleton</font> +00831 CBigFile::getInstance().add (sBigFilename, <a class="code" href="namespaceNLMISC.html#a0">BF_ALWAYS_OPENED</a> | <a class="code" href="namespaceNLMISC.html#a1">BF_CACHE_FILE_ON_OPEN</a>); +00832 +00833 <font class="comment">// parse the big file to add file in the map</font> +00834 fseek (Handle, 0, SEEK_END); +00835 uint32 nFileSize = ftell (Handle); +00836 fseek (Handle, nFileSize-4, SEEK_SET); +00837 uint32 nOffsetFromBegining; +00838 fread (&nOffsetFromBegining, <font class="keyword">sizeof</font>(uint32), 1, Handle); +00839 fseek (Handle, nOffsetFromBegining, SEEK_SET); +00840 uint32 nNbFile; +00841 fread (&nNbFile, <font class="keyword">sizeof</font>(uint32), 1, Handle); +00842 <font class="keywordflow">for</font> (uint32 i = 0; i < nNbFile; ++i) +00843 { +00844 <font class="keywordtype">char</font> FileName[256]; +00845 uint8 nStringSize; +00846 fread (&nStringSize, 1, 1, Handle); +00847 fread (FileName, 1, nStringSize, Handle); +00848 FileName[nStringSize] = 0; +00849 uint32 nFileSize; +00850 fread (&nFileSize, <font class="keyword">sizeof</font>(uint32), 1, Handle); +00851 uint32 nFilePos; +00852 fread (&nFilePos, <font class="keyword">sizeof</font>(uint32), 1, Handle); +00853 string sTmp = <a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(string(FileName)); +00854 <font class="keywordflow">if</font> (sTmp.empty()) +00855 { +00856 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::addSearchBigFile(%s, %d, %d): can't add empty file, skip it"</font>, sBigFilename.c_str(), recurse, alternative); +00857 <font class="keywordflow">continue</font>; +00858 } +00859 string bigfilenamealone = CFile::getFilename (sBigFilename); +00860 string filenamewoext = CFile::getFilenameWithoutExtension (sTmp); +00861 string ext = <a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(CFile::getExtension(sTmp)); +00862 +00863 <a class="code" href="classNLMISC_1_1CPath.html#f1">insertFileInMap</a> (sTmp, bigfilenamealone + <font class="stringliteral">"@"</font> + sTmp, <font class="keyword">false</font>, ext); +00864 +00865 <font class="keywordflow">for</font> (uint j = 0; j < inst->_Extensions.size (); j++) +00866 { +00867 <font class="keywordflow">if</font> (inst->_Extensions[j].first == ext) +00868 { +00869 <font class="comment">// need to remap</font> +00870 <a class="code" href="classNLMISC_1_1CPath.html#f1">insertFileInMap</a> (filenamewoext+<font class="stringliteral">"."</font>+inst->_Extensions[j].second, +00871 bigfilenamealone + <font class="stringliteral">"@"</font> + sTmp, +00872 <font class="keyword">true</font>, +00873 inst->_Extensions[j].second); +00874 } +00875 } +00876 +00877 } +00878 fclose (Handle); +00879 } +00880 +<a name="l00881"></a><a class="code" href="classNLMISC_1_1CPath.html#f1">00881</a> <font class="keywordtype">void</font> CPath::insertFileInMap (<font class="keyword">const</font> string &filename, <font class="keyword">const</font> string &filepath, <font class="keywordtype">bool</font> remap, <font class="keyword">const</font> string &extension) +00882 { +00883 CPath *inst = CPath::getInstance(); +00884 +00885 <font class="comment">// find if the file already exist</font> +00886 map<string, CFileEntry>::iterator it = inst->_Files.find (<a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(filename)); +00887 <font class="keywordflow">if</font> (it != inst->_Files.end ()) +00888 { +00889 <font class="keywordflow">if</font> ((*it).second.Path.find(<font class="stringliteral">"@"</font>) != string::npos && filepath.find(<font class="stringliteral">"@"</font>) == string::npos) +00890 { +00891 <font class="comment">// if there's a file in a big file and a file in a path, the file in path wins</font> +00892 <font class="comment">// remplace with the new one</font> +00893 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"CPath::insertFileInMap(%s, %s, %d, %s): already inserted from '%s' but special case so overide it"</font>, filename.c_str(), filepath.c_str(), remap, extension.c_str(), (*it).second.Path.c_str()); +00894 (*it).second.Path = filepath; +00895 (*it).second.Remapped = remap; +00896 (*it).second.Extension = extension; +00897 } +00898 <font class="keywordflow">else</font> +00899 { +00900 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CPath::insertFileInMap(%s, %s, %d, %s): already inserted from '%s', skip it"</font>, filename.c_str(), filepath.c_str(), remap, extension.c_str(), (*it).second.Path.c_str()); +00901 } +00902 } +00903 <font class="keywordflow">else</font> +00904 { +00905 inst->_Files.insert (make_pair (<a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(filename), CFileEntry (filepath, remap, <a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(extension)))); +00906 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CPath::insertFileInMap(%s, %s, %d, %s): added"</font>, <a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(filename).c_str(), filepath.c_str(), remap, <a class="code" href="namespaceNLMISC.html#a229">strlwr</a>(extension).c_str()); +00907 } +00908 } +00909 +<a name="l00910"></a><a class="code" href="classNLMISC_1_1CPath.html#d10">00910</a> <font class="keywordtype">void</font> CPath::display () +00911 { +00912 CPath *inst = CPath::getInstance (); +00913 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Contents of the map:"</font>); +00914 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"%-25s %-5s %-5s %s"</font>, <font class="stringliteral">"filename"</font>, <font class="stringliteral">"ext"</font>, <font class="stringliteral">"remap"</font>, <font class="stringliteral">"full path"</font>); +00915 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"----------------------------------------------------"</font>); +00916 <font class="keywordflow">for</font> (map<string, CFileEntry>::iterator it = inst->_Files.begin(); it != inst->_Files.end (); it++) +00917 { +00918 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"%-25s %-5s %-5d %s"</font>, (*it).first.c_str(), (*it).second.Extension.c_str(), (*it).second.Remapped, (*it).second.Path.c_str()); +00919 } +00920 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">""</font>); +00921 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Contents of the alternative directory:"</font>); +00922 <font class="keywordflow">for</font> (uint i = 0; i < inst->_AlternativePaths.size(); i++) +00923 { +00924 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"'%s'"</font>, inst->_AlternativePaths[i].c_str ()); +00925 } +00926 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">""</font>); +00927 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Contents of the remapped entension table:"</font>); +00928 <font class="keywordflow">for</font> (uint j = 0; j < inst->_Extensions.size(); j++) +00929 { +00930 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"'%s' -> '%s'"</font>, inst->_Extensions[j].first.c_str (), inst->_Extensions[j].second.c_str ()); +00931 } +00932 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"End of display"</font>); +00933 } +00934 +00940 +<a name="l00941"></a><a class="code" href="structNLMISC_1_1CFile.html#d6">00941</a> <font class="keywordtype">int</font> CFile::getLastSeparator (<font class="keyword">const</font> string &filename) +00942 { +00943 uint32 pos = filename.find_last_of (<font class="charliteral">'/'</font>); +00944 <font class="keywordflow">if</font> (pos == string::npos) +00945 { +00946 pos = filename.find_last_of (<font class="charliteral">'\\'</font>); +00947 <font class="keywordflow">if</font> (pos == string::npos) +00948 { +00949 pos = filename.find_last_of (<font class="charliteral">'@'</font>); +00950 } +00951 } +00952 <font class="keywordflow">return</font> pos; +00953 } +00954 +<a name="l00955"></a><a class="code" href="structNLMISC_1_1CFile.html#d0">00955</a> string CFile::getFilename (<font class="keyword">const</font> string &filename) +00956 { +00957 uint32 pos = CFile::getLastSeparator(filename); +00958 <font class="keywordflow">if</font> (pos != string::npos) +00959 <font class="keywordflow">return</font> filename.substr (pos + 1); +00960 <font class="keywordflow">else</font> +00961 <font class="keywordflow">return</font> filename; +00962 } +00963 +<a name="l00964"></a><a class="code" href="structNLMISC_1_1CFile.html#d7">00964</a> string CFile::getFilenameWithoutExtension (<font class="keyword">const</font> string &filename) +00965 { +00966 string filename2 = <a class="code" href="structNLMISC_1_1CFile.html#d0">getFilename</a> (filename); +00967 uint32 pos = filename2.find_last_of (<font class="charliteral">'.'</font>); +00968 <font class="keywordflow">if</font> (pos == string::npos) +00969 <font class="keywordflow">return</font> filename2; +00970 <font class="keywordflow">else</font> +00971 <font class="keywordflow">return</font> filename2.substr (0, pos); +00972 } +00973 +<a name="l00974"></a><a class="code" href="structNLMISC_1_1CFile.html#d8">00974</a> string CFile::getExtension (<font class="keyword">const</font> string &filename) +00975 { +00976 uint32 pos = filename.find_last_of (<font class="charliteral">'.'</font>); +00977 <font class="keywordflow">if</font> (pos == string::npos) +00978 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; +00979 <font class="keywordflow">else</font> +00980 <font class="keywordflow">return</font> filename.substr (pos + 1); +00981 } +00982 +<a name="l00983"></a><a class="code" href="structNLMISC_1_1CFile.html#d1">00983</a> string CFile::getPath (<font class="keyword">const</font> string &filename) +00984 { +00985 uint32 pos = CFile::getLastSeparator(filename); +00986 <font class="keywordflow">if</font> (pos != string::npos) +00987 <font class="keywordflow">return</font> filename.substr (0, pos + 1); +00988 <font class="keywordflow">else</font> +00989 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; +00990 } +00991 +<a name="l00992"></a><a class="code" href="structNLMISC_1_1CFile.html#d2">00992</a> <font class="keywordtype">bool</font> CFile::isDirectory (<font class="keyword">const</font> string &filename) +00993 { +00994 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00995 <font class="preprocessor"></font> DWORD <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = GetFileAttributes(filename.c_str()); +00996 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> == -1) +00997 { +00998 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"%s is not a valid file / directory name"</font>, filename); +00999 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01000 } +01001 <font class="keywordflow">return</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> & FILE_ATTRIBUTE_DIRECTORY) != 0; +01002 <font class="preprocessor">#else // NL_OS_WINDOWS</font> +01003 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf; +01004 <font class="keywordtype">int</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = stat (filename.c_str (), &buf); +01005 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> == -1) +01006 { +01007 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"can't stat '%s' error %d '%s'"</font>, filename.c_str(), errno, strerror(errno)); +01008 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01009 } +01010 <font class="keywordflow">return</font> (buf.st_mode & S_IFDIR) != 0; +01011 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +01012 <font class="preprocessor"></font>} +01013 +<a name="l01014"></a><a class="code" href="structNLMISC_1_1CFile.html#d4">01014</a> <font class="keywordtype">bool</font> CFile::isExists (<font class="keyword">const</font> string &filename) +01015 { +01016 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +01017 <font class="preprocessor"></font> <font class="keywordflow">return</font> (GetFileAttributes(filename.c_str()) != -1); +01018 <font class="preprocessor">#else // NL_OS_WINDOWS</font> +01019 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf; +01020 <font class="keywordflow">return</font> stat (filename.c_str (), &buf) == 0; +01021 <font class="preprocessor">#endif // NL_OS_WINDOWS</font> +01022 <font class="preprocessor"></font>} +01023 +<a name="l01024"></a><a class="code" href="structNLMISC_1_1CFile.html#d3">01024</a> <font class="keywordtype">bool</font> CFile::fileExists (<font class="keyword">const</font> string& filename) +01025 { +01026 <font class="keywordflow">return</font> ! ! fstream( filename.c_str(), ios::in ); +01027 } +01028 +01029 +<a name="l01030"></a><a class="code" href="structNLMISC_1_1CFile.html#d5">01030</a> string CFile::findNewFile (<font class="keyword">const</font> string &filename) +01031 { +01032 uint32 pos = filename.find_last_of (<font class="charliteral">'.'</font>); +01033 <font class="keywordflow">if</font> (pos == string::npos) +01034 <font class="keywordflow">return</font> filename; +01035 +01036 string start = filename.substr (0, pos); +01037 string end = filename.substr (pos); +01038 +01039 uint <a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a> = 0; +01040 <font class="keywordtype">char</font> numchar[4]; +01041 string npath; +01042 <font class="keywordflow">do</font> +01043 { +01044 npath = start; +01045 <a class="code" href="namespaceNLMISC.html#a211">smprintf</a>(numchar,4,<font class="stringliteral">"%03d"</font>,<a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a>++); +01046 npath += numchar; +01047 npath += end; +01048 <font class="keywordflow">if</font> (!CFile::fileExists(npath)) <font class="keywordflow">break</font>; +01049 } +01050 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a><999); +01051 <font class="keywordflow">return</font> npath; +01052 } +01053 +01054 <font class="comment">// \warning doesn't work with big file</font> +<a name="l01055"></a><a class="code" href="structNLMISC_1_1CFile.html#d9">01055</a> uint32 CFile::getFileSize (<font class="keyword">const</font> std::string &filename) +01056 { +01057 <font class="comment">/* FILE *fp = fopen (filename.c_str(), "rb");</font> +01058 <font class="comment"> if (fp == NULL) return 0;</font> +01059 <font class="comment"> fseek (fp, 0, SEEK_END);</font> +01060 <font class="comment"> uint32 size = ftell (fp);</font> +01061 <font class="comment"> fclose (fp);</font> +01062 <font class="comment"> return size;*/</font> +01063 +01064 <font class="comment">/* const char *s = filename.c_str();</font> +01065 <font class="comment"> int h = _open (s, _O_RDONLY | _O_BINARY);</font> +01066 <font class="comment"> _lseek (h, 0, SEEK_END);</font> +01067 <font class="comment"> uint32 size = _tell (h);</font> +01068 <font class="comment"> _close (h);</font> +01069 <font class="comment"> return size;</font> +01070 <font class="comment">*/</font> +01071 +01072 <font class="preprocessor">#if defined (NL_OS_WINDOWS)</font> +01073 <font class="preprocessor"></font> <font class="keyword">struct </font>_stat buf; +01074 <font class="keywordtype">int</font> result = _stat (filename.c_str (), &buf); +01075 <font class="preprocessor">#elif defined (NL_OS_UNIX)</font> +01076 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf; +01077 <font class="keywordtype">int</font> result = stat (filename.c_str (), &buf); +01078 <font class="preprocessor">#endif</font> +01079 <font class="preprocessor"></font> <font class="keywordflow">if</font> (result != 0) <font class="keywordflow">return</font> 0; +01080 <font class="keywordflow">else</font> <font class="keywordflow">return</font> buf.st_size; +01081 +01082 } +01083 +<a name="l01084"></a><a class="code" href="structNLMISC_1_1CFile.html#d10">01084</a> uint32 CFile::getFileModificationDate(<font class="keyword">const</font> std::string &filename) +01085 { +01086 uint pos; +01087 string fn; +01088 <font class="keywordflow">if</font> ((pos=filename.find(<font class="charliteral">'@'</font>)) != string::npos) +01089 { +01090 fn = filename.substr (0, pos); +01091 } +01092 <font class="keywordflow">else</font> +01093 { +01094 fn = filename; +01095 } +01096 +01097 <font class="preprocessor">#if defined (NL_OS_WINDOWS)</font> +01098 <font class="preprocessor"></font> <font class="keyword">struct </font>_stat buf; +01099 <font class="keywordtype">int</font> result = _stat (fn.c_str (), &buf); +01100 <font class="preprocessor">#elif defined (NL_OS_UNIX)</font> +01101 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf; +01102 <font class="keywordtype">int</font> result = stat (fn.c_str (), &buf); +01103 <font class="preprocessor">#endif</font> +01104 <font class="preprocessor"></font> +01105 <font class="keywordflow">if</font> (result != 0) <font class="keywordflow">return</font> 0; +01106 <font class="keywordflow">else</font> <font class="keywordflow">return</font> buf.st_mtime; +01107 } +01108 +01109 +<a name="l01110"></a><a class="code" href="structNLMISC_1_1CFile.html#d11">01110</a> uint32 CFile::getFileCreationDate(<font class="keyword">const</font> std::string &filename) +01111 { +01112 uint pos; +01113 string fn; +01114 <font class="keywordflow">if</font> ((pos=filename.find(<font class="charliteral">'@'</font>)) != string::npos) +01115 { +01116 fn = filename.substr (0, pos); +01117 } +01118 <font class="keywordflow">else</font> +01119 { +01120 fn = filename; +01121 } +01122 +01123 <font class="preprocessor">#if defined (NL_OS_WINDOWS)</font> +01124 <font class="preprocessor"></font> <font class="keyword">struct </font>_stat buf; +01125 <font class="keywordtype">int</font> result = _stat (fn.c_str (), &buf); +01126 <font class="preprocessor">#elif defined (NL_OS_UNIX)</font> +01127 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf; +01128 <font class="keywordtype">int</font> result = stat (fn.c_str (), &buf); +01129 <font class="preprocessor">#endif</font> +01130 <font class="preprocessor"></font> +01131 <font class="keywordflow">if</font> (result != 0) <font class="keywordflow">return</font> 0; +01132 <font class="keywordflow">else</font> <font class="keywordflow">return</font> buf.st_ctime; +01133 } +01134 +<a name="l01135"></a><a class="code" href="structNLMISC_1_1CFileEntry.html">01135</a> <font class="keyword">struct </font>CFileEntry +01136 { +<a name="l01137"></a><a class="code" href="structNLMISC_1_1CFileEntry.html#a0">01137</a> <a class="code" href="structNLMISC_1_1CFileEntry.html#a0">CFileEntry</a> (<font class="keyword">const</font> string &filename, <font class="keywordtype">void</font> (*callback)(<font class="keyword">const</font> string &filename)) : <a class="code" href="structNLMISC_1_1CFileEntry.html#m0">FileName</a> (filename), <a class="code" href="structNLMISC_1_1CFileEntry.html#m1">Callback</a> (callback) +01138 { +01139 <a class="code" href="structNLMISC_1_1CFileEntry.html#m2">LastModified</a> = CFile::getFileModificationDate(filename); +01140 } +<a name="l01141"></a><a class="code" href="structNLMISC_1_1CFileEntry.html#m0">01141</a> string <a class="code" href="structNLMISC_1_1CFileEntry.html#m0">FileName</a>; +01142 <a class="code" href="driver__opengl__extension__def_8h.html#a424">void</a> (*<a class="code" href="structNLMISC_1_1CFileEntry.html#m1">Callback</a>)(<font class="keyword">const</font> string &filename); +<a name="l01143"></a><a class="code" href="structNLMISC_1_1CFileEntry.html#m2">01143</a> uint32 <a class="code" href="structNLMISC_1_1CFileEntry.html#m2">LastModified</a>; +01144 }; +01145 +01146 <font class="keyword">static</font> vector <CFileEntry> <a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>; +01147 +01148 +<a name="l01149"></a><a class="code" href="structNLMISC_1_1CFile.html#d12">01149</a> <font class="keywordtype">void</font> CFile::addFileChangeCallback (<font class="keyword">const</font> std::string &filename, <font class="keywordtype">void</font> (*cb)(<font class="keyword">const</font> string &filename)) +01150 { +01151 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"CFile::addFileChangeCallback: I'll check the modification date for this file '%s'"</font>, CPath::lookup(filename).c_str()); +01152 <a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>.push_back(CFileEntry(CPath::lookup(filename), cb)); +01153 } +01154 +<a name="l01155"></a><a class="code" href="structNLMISC_1_1CFile.html#d13">01155</a> <font class="keywordtype">void</font> CFile::checkFileChange (<a class="code" href="namespaceNLMISC.html#a183">TTime</a> frequency) +01156 { +01157 <font class="keyword">static</font> <a class="code" href="namespaceNLMISC.html#a183">TTime</a> lastChecked = CTime::getLocalTime(); +01158 +01159 <font class="keywordflow">if</font> (CTime::getLocalTime() > lastChecked + frequency) +01160 { +01161 <font class="keywordflow">for</font> (uint i = 0; i < <a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>.size(); i++) +01162 { +01163 <font class="keywordflow">if</font>(CFile::getFileModificationDate(<a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].FileName) != <a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].LastModified) +01164 { +01165 <font class="comment">// need to reload it</font> +01166 <font class="keywordflow">if</font>(<a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].Callback != NULL) +01167 <a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].Callback(<a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].FileName); +01168 +01169 <a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].LastModified = CFile::getFileModificationDate(<a class="code" href="namespaceNLMISC.html#a198">FileToCheck</a>[i].FileName); +01170 } +01171 } +01172 +01173 lastChecked = CTime::getLocalTime(); +01174 } +01175 } +01176 +01177 +01178 <font class="keyword">static</font> <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a308">CopyMoveFile</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *dest, <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <font class="keywordtype">bool</font> copyFile, <font class="keywordtype">bool</font> failIfExists = <font class="keyword">false</font>) +01179 { +01180 <font class="keywordflow">if</font> (!dest || !<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>) <font class="keywordflow">return</font> <font class="keyword">false</font>; +01181 <font class="keywordflow">if</font> (!strlen(dest) || !strlen(<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>)) <font class="keywordflow">return</font> <font class="keyword">false</font>; +01182 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +01183 <font class="preprocessor"></font> std::string dosdest = CPath::standardizeDosPath(dest); +01184 std::string dossrc = CPath::standardizeDosPath(<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>); +01185 +01186 <font class="keywordflow">return</font> copyFile ? CopyFile(dossrc.c_str(), dosdest.c_str(), failIfExists) != FALSE +01187 : MoveFile(dossrc.c_str(), dosdest.c_str()) != FALSE; +01188 <font class="preprocessor">#else</font> +01189 <font class="preprocessor"></font> <a class="code" href="debug_8h.html#a12">nlstop</a>; <font class="comment">// not implemented yet</font> +01190 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01191 <font class="preprocessor">#endif </font> +01192 <font class="preprocessor"></font>} +01193 +<a name="l01194"></a><a class="code" href="structNLMISC_1_1CFile.html#d14">01194</a> <font class="keywordtype">bool</font> CFile::copyFile(<font class="keyword">const</font> <font class="keywordtype">char</font> *dest, <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <font class="keywordtype">bool</font> failIfExists <font class="comment">/*=false*/</font>) +01195 { +01196 <font class="keywordflow">return</font> <a class="code" href="namespaceNLMISC.html#a308">CopyMoveFile</a>(dest, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <font class="keyword">true</font>, failIfExists); +01197 } +01198 +<a name="l01199"></a><a class="code" href="structNLMISC_1_1CFile.html#d15">01199</a> <font class="keywordtype">bool</font> CFile::moveFile(<font class="keyword">const</font> <font class="keywordtype">char</font> *dest,<font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>) +01200 { +01201 <font class="keywordflow">return</font> <a class="code" href="namespaceNLMISC.html#a308">CopyMoveFile</a>(dest, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <font class="keyword">false</font>); +01202 } +01203 +01204 +<a name="l01205"></a><a class="code" href="structNLMISC_1_1CFile.html#d16">01205</a> <font class="keywordtype">bool</font> CFile::createDirectory(<font class="keyword">const</font> std::string &filename) +01206 { +01207 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +01208 <font class="preprocessor"></font> <font class="keywordflow">return</font> _mkdir(filename.c_str())==0; +01209 <font class="preprocessor">#else</font> +01210 <font class="preprocessor"></font> <font class="comment">// Set full permissions....</font> +01211 <font class="keywordflow">return</font> mkdir(filename.c_str(), 0xFFFF)==0; +01212 <font class="preprocessor">#endif</font> +01213 <font class="preprocessor"></font>} +01214 +01215 +01216 } <font class="comment">// NLMISC</font> +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </FONT> +</TD> +<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD> +</TR> +</TABLE> +</BODY> +</HTML> |