1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
|
<!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="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><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="/inc/img/black_banner.jpg"><A HREF=""><IMG SRC="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="/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="/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="/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="/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:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>new_path.cpp</h1><a href="new__path_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="preprocessor">#if 0</font>
00002 <font class="preprocessor"></font>
00008 <font class="comment">/* Copyright, 2000, 2001 Nevrax Ltd.</font>
00009 <font class="comment"> *</font>
00010 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00011 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00012 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00013 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00014 <font class="comment"> * any later version.</font>
00015 <font class="comment"></font>
00016 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00017 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00018 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00019 <font class="comment"> * General Public License for more details.</font>
00020 <font class="comment"></font>
00021 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00022 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00023 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00024 <font class="comment"> * MA 02111-1307, USA.</font>
00025 <font class="comment"> */</font>
00026
00027 <font class="preprocessor">#include <fstream></font>
00028
00029 <font class="preprocessor">#include "<a class="code" href="debug_8h.html">nel/misc/debug.h</a>"</font>
00030
00031 <font class="preprocessor">#include "<a class="code" href="new__path_8h.html">nel/misc/new_path.h</a>"</font>
00032
00033 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00034 <font class="preprocessor"></font><font class="preprocessor"># include <windows.h></font>
00035 <font class="preprocessor">#else</font>
00036 <font class="preprocessor"></font><font class="preprocessor"># include <sys/types.h></font>
00037 <font class="preprocessor"># include <sys/stat.h></font>
00038 <font class="preprocessor"># include <dirent.h></font>
00039 <font class="preprocessor"># include <<a class="code" href="unistd_8h.html">unistd.h</a>></font>
00040 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00041 <font class="preprocessor"></font>
00042 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00043
00044 <font class="keyword">namespace </font>NLMISC {
00045
00046 <font class="comment">//</font>
00047 <font class="comment">// Macros</font>
00048 <font class="comment">//</font>
00049
00050 <font class="comment">// Use this define if you want to display info about the CPath.</font>
00051 <font class="preprocessor">#define NL_DEBUG_PATH</font>
00052 <font class="preprocessor"></font>
00053 <font class="preprocessor">#ifdef NL_DEBUG_PATH</font>
00054 <font class="preprocessor"></font><font class="preprocessor">#define NL_DISPLAY_PATH nlinfo</font>
00055 <font class="preprocessor"></font><font class="preprocessor">#else </font>
00056 <font class="preprocessor"></font><font class="preprocessor">#define NL_DISPLAY_PATH if(false)</font>
00057 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00058 <font class="preprocessor"></font>
00059
00060 <font class="comment">//</font>
00061 <font class="comment">// Variables</font>
00062 <font class="comment">//</font>
00063
00064 CNewPath *CNewPath::_Instance = NULL;
00065
00066
00067 <font class="comment">//</font>
00068 <font class="comment">// Functions</font>
00069 <font class="comment">//</font>
00070
00071 CNewPath *CNewPath::getInstance ()
00072 {
00073 <font class="keywordflow">if</font> (_Instance == NULL)
00074 {
00075 _Instance = <font class="keyword">new</font> CNewPath;
00076 }
00077 <font class="keywordflow">return</font> _Instance;
00078 }
00079
00080 <font class="keywordtype">void</font> CNewPath::clearMap ()
00081 {
00082 CNewPath *inst = CNewPath::getInstance();
00083 inst->_Files.clear ();
00084 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::clearMap(): map directory cleared"</font>);
00085 }
00086
00087 <a class="code" href="types__nl_8h.html#a13">sint</a> CNewPath::findExtension (<font class="keyword">const</font> string &ext1, <font class="keyword">const</font> string &ext2)
00088 {
00089 CNewPath *inst = CNewPath::getInstance();
00090 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i = 0; i < inst->_Extensions.size (); i++)
00091 {
00092 <font class="keywordflow">if</font> (inst->_Extensions[i].first == ext1 && inst->_Extensions[i].second == ext2)
00093 {
00094 <font class="keywordflow">return</font> i;
00095 }
00096 }
00097 <font class="keywordflow">return</font> -1;
00098 }
00099
00100 <font class="keywordtype">void</font> CNewPath::remapExtension (<font class="keyword">const</font> string &ext1, <font class="keyword">const</font> string &ext2, <font class="keywordtype">bool</font> substitute)
00101 {
00102 CNewPath *inst = CNewPath::getInstance();
00103
00104 <font class="keywordflow">if</font> (ext1.empty() || ext2.empty())
00105 {
00106 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::remapExtension(%s, %s, %d): can't remap empty extension"</font>, ext1.c_str(), ext2.c_str(), substitute);
00107 }
00108
00109 <font class="keywordflow">if</font> (!substitute)
00110 {
00111 <font class="comment">// remove the mapping from the mapping list</font>
00112 <a class="code" href="types__nl_8h.html#a13">sint</a> n = inst->findExtension (ext1, ext2);
00113 <a class="code" href="debug_8h.html#a6">nlassert</a> (n != -1);
00114 inst->_Extensions.erase (inst->_Extensions.begin() + n);
00115
00116 <font class="comment">// remove mapping in the map</font>
00117 map<string, CNewFileEntry>::iterator it = inst->_Files.begin();
00118 map<string, CNewFileEntry>::iterator nit = it;
00119 <font class="keywordflow">while</font> (it != inst->_Files.end ())
00120 {
00121 nit++;
00122 <font class="keywordflow">if</font> ((*it).second.Remapped && (*it).second.Extension == ext2)
00123 {
00124 inst->_Files.erase (it);
00125 }
00126 it = nit;
00127 }
00128 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::remapExtension(%s, %s, %d): extension removed"</font>, ext1.c_str(), ext2.c_str(), substitute);
00129 }
00130 <font class="keywordflow">else</font>
00131 {
00132 <a class="code" href="types__nl_8h.html#a13">sint</a> n = inst->findExtension (ext1, ext2);
00133 <font class="keywordflow">if</font> (n != -1)
00134 {
00135 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::remapExtension(%s, %s, %d): remapping already set"</font>, ext1.c_str(), ext2.c_str(), substitute);
00136 <font class="keywordflow">return</font>;
00137 }
00138
00139 <font class="comment">// adding mapping into the mapping list</font>
00140 inst->_Extensions.push_back (make_pair (ext1, ext2));
00141
00142 <font class="comment">// adding mapping into the map</font>
00143 vector<string> newFiles;
00144 map<string, CNewFileEntry>::iterator it = inst->_Files.begin();
00145 <font class="keywordflow">while</font> (it != inst->_Files.end ())
00146 {
00147 <font class="keywordflow">if</font> (!(*it).second.Remapped && (*it).second.Extension == ext1)
00148 {
00149 <font class="comment">// find if already exist</font>
00150 <a class="code" href="types__nl_8h.html#a13">sint</a> pos = (*it).first.find_last_of (<font class="stringliteral">"."</font>);
00151 <font class="keywordflow">if</font> (pos != string::npos)
00152 {
00153 string <a class="code" href="cf__lexical_8cpp.html#a95">file</a> = (*it).first.substr (0, pos + 1);
00154 <a class="code" href="cf__lexical_8cpp.html#a95">file</a> += ext2;
00155
00156 map<string, CNewFileEntry>::iterator nit = inst->_Files.find (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>);
00157 <font class="keywordflow">if</font> (nit != inst->_Files.end())
00158 {
00159 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::remapExtension(%s, %s): The file '%s' is in conflict with the remapping file '%s', skip it"</font>, ext1.c_str(), ext2.c_str(), <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), (*it).first.c_str());
00160 }
00161 <font class="keywordflow">else</font>
00162 {
00163 <font class="comment">// TODO perhaps a problem because I insert in the current map that i parcours</font>
00164 insertFileInMap (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, (*it).second.Path, <font class="keyword">true</font>, ext2);
00165 }
00166 }
00167 }
00168 it++;
00169 }
00170 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::remapExtension(%s, %s, %d): extension added"</font>, ext1.c_str(), ext2.c_str(), substitute);
00171 }
00172 }
00173
00174 string CNewPath::lookup (<font class="keyword">const</font> string &filename)
00175 {
00176 <font class="comment">// Try to find in the map directories</font>
00177 CNewPath *inst = CNewPath::getInstance();
00178 map<string, CNewFileEntry>::iterator it = inst->_Files.find (filename);
00179 <font class="comment">// If found in the map, returns it</font>
00180 <font class="keywordflow">if</font> (it != inst->_Files.end())
00181 {
00182 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::lookup(%s): found in the map directory: '%s'"</font>, filename.c_str(), (*it).second.Path.c_str());
00183 <font class="keywordflow">return</font> (*it).second.Path;
00184 }
00185
00186 <font class="comment">// Try to find in the alternative directories</font>
00187 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i = 0; i < inst->_AlternativePaths.size(); i++)
00188 {
00189 string <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> = inst->_AlternativePaths[i] + filename;
00190 <font class="keywordflow">if</font> ( CNewFile::fileExists(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>) )
00191 {
00192 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::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());
00193 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00194 }
00195
00196 <font class="comment">// try with the remapping</font>
00197 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> j = 0; j < inst->_Extensions.size(); j++)
00198 {
00199 string rs = inst->_AlternativePaths[i] + CNewFile::getFilenameWithoutExtension (filename) + <font class="stringliteral">"."</font> + inst->_Extensions[j].first;
00200 <font class="keywordflow">if</font> ( CNewFile::fileExists(rs) )
00201 {
00202 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::lookup(%s): found in the alternative directory: '%s'"</font>, filename.c_str(), rs.c_str());
00203 <font class="keywordflow">return</font> rs;
00204 }
00205 }
00206 }
00207
00208 <font class="comment">// Not found</font>
00209 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::lookup(%s): file not found"</font>, filename.c_str());
00210 <font class="keywordflow">return</font> <font class="stringliteral">""</font>;
00211 }
00212
00213 string CNewPath::standardizePath (<font class="keyword">const</font> string &path, <font class="keywordtype">bool</font> addFinalSlash)
00214 {
00215 string newPath;
00216
00217 <font class="comment">// check empty path</font>
00218 <font class="keywordflow">if</font> (path.empty()) <font class="keywordflow">return</font> <font class="stringliteral">""</font>;
00219
00220 <font class="comment">// don't transform the first \\ for windows network path</font>
00221 <font class="comment">/* if (path.size() >= 2 && path[0] == '\\' && path[1] == '\\')</font>
00222 <font class="comment"> {</font>
00223 <font class="comment"> newPath += "\\\\";</font>
00224 <font class="comment"> i = 2;</font>
00225 <font class="comment"> }</font>
00226 <font class="comment">*/</font>
00227 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i = 0; i < path.size(); i++)
00228 {
00229 <font class="comment">// don't transform the first \\ for windows network path</font>
00230 <font class="keywordflow">if</font> (path[i] == <font class="charliteral">'\\'</font>)
00231 newPath += <font class="charliteral">'/'</font>;
00232 <font class="keywordflow">else</font>
00233 newPath += path[i];
00234 }
00235
00236 <font class="comment">// add terminal slash</font>
00237 <font class="keywordflow">if</font> (addFinalSlash && newPath[path.size()-1] != <font class="charliteral">'/'</font>)
00238 newPath += <font class="charliteral">'/'</font>;
00239
00240 <font class="keywordflow">return</font> newPath;
00241 }
00242
00243 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00244 <font class="preprocessor"></font><font class="preprocessor"># define dirent WIN32_FIND_DATA</font>
00245 <font class="preprocessor"></font><font class="preprocessor"># define DIR void</font>
00246 <font class="preprocessor"></font>
00247 <font class="keyword">static</font> string sDir;
00248 <font class="keyword">static</font> <font class="keywordtype">char</font> sDirBackup[512];
00249 <font class="keyword">static</font> WIN32_FIND_DATA findData;
00250 <font class="keyword">static</font> HANDLE hFind;
00251
00252 DIR *opendir (<font class="keyword">const</font> <font class="keywordtype">char</font> *path)
00253 {
00254 <a class="code" href="debug_8h.html#a6">nlassert</a> (path != NULL);
00255 <a class="code" href="debug_8h.html#a6">nlassert</a> (path[0] != <font class="charliteral">'\0'</font>);
00256
00257 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] == <font class="charliteral">'\0'</font>);
00258 <font class="keywordflow">if</font> (GetCurrentDirectory (512, sDirBackup) == 0)
00259 {
00260 <font class="comment">// failed</font>
00261 <font class="keywordflow">return</font> NULL;
00262 }
00263
00264 <font class="keywordflow">if</font> (!CNewFile::isDirectory(path))
00265 {
00266 <font class="comment">// failed</font>
00267 <font class="keywordflow">return</font> NULL;
00268 }
00269
00270 sDir = path;
00271
00272 hFind = NULL;
00273
00274 <font class="keywordflow">return</font> (<font class="keywordtype">void</font> *)1;
00275 }
00276
00277 <font class="keywordtype">int</font> closedir (DIR *dir)
00278 {
00279 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] != <font class="charliteral">'\0'</font>);
00280 sDirBackup[0] = <font class="charliteral">'\0'</font>;
00281 <font class="keywordflow">return</font> 0;
00282 }
00283
00284 dirent *readdir (DIR *dir)
00285 {
00286 <font class="comment">// set the current path</font>
00287 <a class="code" href="debug_8h.html#a6">nlassert</a> (!sDir.empty());
00288 <font class="keywordflow">if</font> (SetCurrentDirectory (sDir.c_str()) == 0)
00289 {
00290 <font class="comment">// failed</font>
00291 <font class="keywordflow">return</font> NULL;
00292 }
00293
00294 <font class="keywordflow">if</font> (hFind == NULL)
00295 {
00296 hFind = FindFirstFile (<font class="stringliteral">"*"</font>, &findData);
00297 }
00298 <font class="keywordflow">else</font>
00299 {
00300 <font class="keywordflow">if</font> (!FindNextFile (hFind, &findData))
00301 {
00302 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] != <font class="charliteral">'\0'</font>);
00303 SetCurrentDirectory (sDirBackup);
00304 <font class="keywordflow">return</font> NULL;
00305 }
00306 }
00307
00308 <font class="comment">// restore the current path</font>
00309 <a class="code" href="debug_8h.html#a6">nlassert</a> (sDirBackup[0] != <font class="charliteral">'\0'</font>);
00310 SetCurrentDirectory (sDirBackup);
00311
00312 <font class="keywordflow">return</font> &findData;
00313 }
00314
00315 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00316 <font class="preprocessor"></font>
00317 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a288">isdirectory</a> (dirent *de)
00318 {
00319 <a class="code" href="debug_8h.html#a6">nlassert</a> (de != NULL);
00320 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00321 <font class="preprocessor"></font> <font class="keywordflow">return</font> (de->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
00322 <font class="preprocessor">#else</font>
00323 <font class="preprocessor"></font> <font class="keywordflow">return</font> (de->d_type & DT_DIR) != 0;
00324 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00325 <font class="preprocessor"></font>}
00326
00327 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a289">isfile</a> (dirent *de)
00328 {
00329 <a class="code" href="debug_8h.html#a6">nlassert</a> (de != NULL);
00330 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00331 <font class="preprocessor"></font> <font class="keywordflow">return</font> (de->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
00332 <font class="preprocessor">#else</font>
00333 <font class="preprocessor"></font> <font class="keywordflow">return</font> (de->d_type & DT_DIR) == 0;
00334 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00335 <font class="preprocessor"></font>}
00336
00337 string <a class="code" href="namespaceNLMISC.html#a290">getname</a> (dirent *de)
00338 {
00339 <a class="code" href="debug_8h.html#a6">nlassert</a> (de != NULL);
00340 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00341 <font class="preprocessor"></font> <font class="keywordflow">return</font> de->cFileName;
00342 <font class="preprocessor">#else</font>
00343 <font class="preprocessor"></font> <font class="keywordflow">return</font> de->d_name;
00344 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00345 <font class="preprocessor"></font>}
00346
00347 <font class="keywordtype">void</font> CNewPath::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)
00348 {
00349 DIR *dir = opendir (path.c_str());
00350 <font class="keywordflow">if</font> (dir == NULL)
00351 {
00352 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::getPathContent(%s, %d, %d, %d): could not open the directory"</font>, path.c_str(), recurse, wantDir, wantFile);
00353 <font class="keywordflow">return</font>;
00354 }
00355
00356 <font class="comment">// contains path that we have to recurs into</font>
00357 vector<string> recursPath;
00358
00359 <font class="keywordflow">while</font> (true)
00360 {
00361 dirent *de = readdir(dir);
00362 <font class="keywordflow">if</font> (de == NULL)
00363 {
00364 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::getPathContent(%s, %d, %d, %d): end of directory"</font>, path.c_str(), recurse, wantDir, wantFile);
00365 <font class="keywordflow">break</font>;
00366 }
00367
00368 <font class="comment">// skip . and ..</font>
00369 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a290">getname</a> (de) == <font class="stringliteral">"."</font> || <a class="code" href="namespaceNLMISC.html#a290">getname</a> (de) == <font class="stringliteral">".."</font>)
00370 <font class="keywordflow">continue</font>;
00371
00372 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a288">isdirectory</a>(de))
00373 {
00374 string stdName = standardizePath(path + <a class="code" href="namespaceNLMISC.html#a290">getname</a>(de));
00375 <font class="keywordflow">if</font> (recurse)
00376 {
00377 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::getPathContent(%s, %d, %d, %d): need to recurse into '%s'"</font>, path.c_str(), recurse, wantDir, wantFile, stdName.c_str());
00378 recursPath.push_back (stdName);
00379 }
00380
00381 <font class="keywordflow">if</font> (wantDir)
00382 {
00383 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::getPathContent(%s, %d, %d, %d): adding path '%s'"</font>, path.c_str(), recurse, wantDir, wantFile, stdName.c_str());
00384 result.push_back (stdName);
00385 }
00386 }
00387 <font class="keywordflow">if</font> (wantFile && <a class="code" href="namespaceNLMISC.html#a289">isfile</a>(de))
00388 {
00389 string stdName = path + <a class="code" href="namespaceNLMISC.html#a290">getname</a>(de);
00390 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::getPathContent(%s, %d, %d, %d): adding file '%s'"</font>, path.c_str(), recurse, wantDir, wantFile, stdName.c_str());
00391 result.push_back (stdName);
00392 }
00393 }
00394
00395 closedir (dir);
00396
00397 <font class="comment">// let s recurse</font>
00398 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i = 0; i < recursPath.size (); i++)
00399 getPathContent (recursPath[i], recurse, wantDir, wantFile, result);
00400 }
00401
00402 <font class="keywordtype">void</font> CNewPath::addSearchPath (<font class="keyword">const</font> string &path, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> alternative)
00403 {
00404 CNewPath *inst = CNewPath::getInstance();
00405 string newPath = standardizePath(path);
00406
00407 <font class="comment">// check empty directory</font>
00408 <font class="keywordflow">if</font> (newPath.empty())
00409 {
00410 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %d): can't add empty directory, skip it"</font>, path.c_str(), recurse, alternative);
00411 <font class="keywordflow">return</font>;
00412 }
00413
00414 <font class="comment">// check if it s a directory</font>
00415 <font class="keywordflow">if</font> (!CNewFile::isExists (newPath))
00416 {
00417 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %d): '%s' is not found, skip it"</font>, path.c_str(), recurse, alternative, newPath.c_str());
00418 <font class="keywordflow">return</font>;
00419 }
00420
00421 <font class="comment">// check if it s a directory</font>
00422 <font class="keywordflow">if</font> (!CNewFile::isDirectory (newPath))
00423 {
00424 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %d): '%s' is not a directory, skip it"</font>, path.c_str(), recurse, alternative, newPath.c_str());
00425 <font class="keywordflow">return</font>;
00426 }
00427
00428 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %d): try to add '%s'"</font>, path.c_str(), recurse, alternative, newPath.c_str());
00429
00430 <font class="keywordflow">if</font> (alternative)
00431 {
00432 vector<string> pathsToProcess;
00433
00434 <font class="comment">// add the current path</font>
00435 pathsToProcess.push_back (newPath);
00436
00437 <font class="keywordflow">if</font> (recurse)
00438 {
00439 <font class="comment">// find all path and subpath</font>
00440 getPathContent (newPath, recurse, <font class="keyword">true</font>, <font class="keyword">false</font>, pathsToProcess);
00441 }
00442
00443 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> p = 0; p < pathsToProcess.size(); p++)
00444 {
00445 <font class="comment">// check if the path not already in the vector</font>
00446 <a class="code" href="types__nl_8h.html#a14">uint</a> i;
00447 <font class="keywordflow">for</font> (i = 0; i < inst->_AlternativePaths.size(); i++)
00448 {
00449 <font class="keywordflow">if</font> (inst->_AlternativePaths[i] == pathsToProcess[p])
00450 <font class="keywordflow">break</font>;
00451 }
00452 <font class="keywordflow">if</font> (i == inst->_AlternativePaths.size())
00453 {
00454 <font class="comment">// add them in the alternative directory</font>
00455 inst->_AlternativePaths.push_back (pathsToProcess[p]);
00456 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %d): path '%s' added"</font>, newPath.c_str(), recurse, alternative, pathsToProcess[p].c_str());
00457 }
00458 <font class="keywordflow">else</font>
00459 {
00460 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %d): path '%s' already added"</font>, newPath.c_str(), recurse, alternative, pathsToProcess[p].c_str());
00461 }
00462 }
00463 }
00464 <font class="keywordflow">else</font>
00465 {
00466 vector<string> filesToProcess;
00467 <font class="comment">// find all files in the path and subpaths</font>
00468 getPathContent (newPath, recurse, <font class="keyword">false</font>, <font class="keyword">true</font>, filesToProcess);
00469
00470 <font class="comment">// add them in the map</font>
00471 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> f = 0; f < filesToProcess.size(); f++)
00472 {
00473 string filename = CNewFile::getFilename (filesToProcess[f]);
00474 string filepath = CNewFile::getPath (filesToProcess[f]);
00475 <font class="comment">// insertFileInMap (filename, filepath, false, CNewFile::getExtension(filename));</font>
00476 addSearchFile (filesToProcess[f]);
00477 }
00478 }
00479 }
00480
00481 <font class="keywordtype">void</font> CNewPath::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)
00482 {
00483 CNewPath *inst = CNewPath::getInstance();
00484 string newFile = standardizePath(<a class="code" href="cf__lexical_8cpp.html#a95">file</a>, <font class="keyword">false</font>);
00485
00486 <font class="comment">// check empty file</font>
00487 <font class="keywordflow">if</font> (newFile.empty())
00488 {
00489 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::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());
00490 <font class="keywordflow">return</font>;
00491 }
00492
00493 <font class="comment">// check if the file exists</font>
00494 <font class="keywordflow">if</font> (!CNewFile::isExists (newFile))
00495 {
00496 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::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());
00497 <font class="keywordflow">return</font>;
00498 }
00499
00500 <font class="comment">// check if it s a file</font>
00501 <font class="keywordflow">if</font> (CNewFile::isDirectory (newFile))
00502 {
00503 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::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());
00504 <font class="keywordflow">return</font>;
00505 }
00506
00507 string filenamewoext = CNewFile::getFilenameWithoutExtension (newFile);
00508 string filename, ext;
00509
00510 <font class="keywordflow">if</font> (virtual_ext.empty())
00511 {
00512 filename = CNewFile::getFilename (newFile);
00513 ext = CNewFile::getExtension (filename);
00514 }
00515 <font class="keywordflow">else</font>
00516 {
00517 filename = filenamewoext + <font class="stringliteral">"."</font> + virtual_ext;
00518 ext = virtual_ext;
00519 }
00520
00521 map<string, CNewFileEntry>::iterator it = inst->_Files.find (filename);
00522 <font class="keywordflow">if</font> (it == inst->_Files.end ())
00523 {
00524 <font class="comment">// ok, the room is empty, let s add it</font>
00525 insertFileInMap (filename, newFile, remap, ext);
00526 }
00527 <font class="keywordflow">else</font>
00528 {
00529 <font class="keywordflow">if</font> (remap)
00530 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %s): remapped file '%s' already inserted in the map directory"</font>, <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), remap, virtual_ext.c_str(), filename.c_str());
00531 <font class="keywordflow">else</font>
00532 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchPath(%s, %d, %s): file '%s' already inserted in the map directory"</font>, <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.c_str(), remap, virtual_ext.c_str(), filename.c_str());
00533 }
00534
00535 <font class="keywordflow">if</font> (!remap && !ext.empty())
00536 {
00537 <font class="comment">// now, we have to see extension and insert in the map the remapped files</font>
00538 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i = 0; i < inst->_Extensions.size (); i++)
00539 {
00540 <font class="keywordflow">if</font> (inst->_Extensions[i].first == ext)
00541 {
00542 <font class="comment">// need to remap</font>
00543 addSearchFile (newFile, <font class="keyword">true</font>, inst->_Extensions[i].second);
00544 }
00545 }
00546 }
00547 }
00548
00549 <font class="keywordtype">void</font> CNewPath::addSearchListFile (<font class="keyword">const</font> string &filename, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> alternative)
00550 {
00551 CNewPath *inst = CNewPath::getInstance();
00552
00553 <font class="comment">// check empty file</font>
00554 <font class="keywordflow">if</font> (filename.empty())
00555 {
00556 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchListFile(%s, %d, %d): can't add empty file, skip it"</font>, filename.c_str(), recurse, alternative);
00557 <font class="keywordflow">return</font>;
00558 }
00559
00560 <font class="comment">// check if the file exists</font>
00561 <font class="keywordflow">if</font> (!CNewFile::isExists (filename))
00562 {
00563 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchListFile(%s, %d, %d): '%s' is not found, skip it"</font>, filename.c_str(), recurse, alternative, filename.c_str());
00564 <font class="keywordflow">return</font>;
00565 }
00566
00567 <font class="comment">// check if it s a file</font>
00568 <font class="keywordflow">if</font> (CNewFile::isDirectory (filename))
00569 {
00570 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchListFile(%s, %d, %d): '%s' is not a file, skip it"</font>, filename.c_str(), recurse, alternative, filename.c_str());
00571 <font class="keywordflow">return</font>;
00572 }
00573
00574 <font class="comment">// TODO lire le fichier et ajouter les fichiers qui sont dedans</font>
00575
00576 }
00577
00578
00579 <font class="keywordtype">void</font> CNewPath::addSearchBigFile (<font class="keyword">const</font> string &filename, <font class="keywordtype">bool</font> recurse, <font class="keywordtype">bool</font> alternative)
00580 {
00581 <font class="comment">// TODO & CHECK</font>
00582 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::addSearchBigFile(): not impremented"</font>);
00583 }
00584
00585 <font class="keywordtype">void</font> CNewPath::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)
00586 {
00587 CNewPath *inst = CNewPath::getInstance();
00588
00589 <font class="comment">// find if the file already exist</font>
00590 map<string, CNewFileEntry>::iterator it = inst->_Files.find (filename);
00591 <font class="keywordflow">if</font> (it != inst->_Files.end ())
00592 {
00593 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CNewPath::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());
00594 }
00595 <font class="keywordflow">else</font>
00596 {
00597 inst->_Files.insert (make_pair (filename, CNewFileEntry (filepath, remap, extension)));
00598 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<font class="stringliteral">"CNewPath::insertFileInMap(%s, %s, %d, %s): added"</font>, filename.c_str(), filepath.c_str(), remap, extension.c_str());
00599 }
00600 }
00601
00602 <font class="keywordtype">void</font> CNewPath::display ()
00603 {
00604 CNewPath *inst = CNewPath::getInstance ();
00605 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Contents of the map:"</font>);
00606 <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>);
00607 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"----------------------------------------------------"</font>);
00608 <font class="keywordflow">for</font> (map<string, CNewFileEntry>::iterator it = inst->_Files.begin(); it != inst->_Files.end (); it++)
00609 {
00610 <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());
00611 }
00612 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">""</font>);
00613 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Contents of the alternative directory:"</font>);
00614 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i = 0; i < inst->_AlternativePaths.size(); i++)
00615 {
00616 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"'%s'"</font>, inst->_AlternativePaths[i].c_str ());
00617 }
00618 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">""</font>);
00619 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Contents of the remapped entension table:"</font>);
00620 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> j = 0; j < inst->_Extensions.size(); j++)
00621 {
00622 <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 ());
00623 }
00624 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"End of display"</font>);
00625 }
00626
00638
00639 <font class="preprocessor">#if 0</font>
00640 <font class="preprocessor"></font><font class="comment">/*</font>
00641 <font class="comment"> * Adds a search path</font>
00642 <font class="comment"> */</font>
00643 <font class="keywordtype">void</font> CPath::addSearchPath( <font class="keyword">const</font> string& path )
00644 {
00645 <font class="keywordflow">if</font> ( path == <font class="stringliteral">""</font> )
00646 {
00647 <font class="keywordflow">return</font>;
00648 }
00649 string <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> = path;
00650 <font class="keyword">const</font> <font class="keywordtype">char</font> slash = <font class="charliteral">'/'</font>;
00651
00652 <font class="comment">// Add an ending slash if necessary</font>
00653 <font class="keywordflow">if</font> ( path[path.size()-1] != slash )
00654 {
00655 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> += slash;
00656 }
00657
00658 <font class="comment">// Add path to the search paths</font>
00659 _SearchPaths.push_back( <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> );
00660 }
00661
00662
00663 <font class="comment">/* Returns the long name (path and filename) for the specified file, using search paths</font>
00664 <font class="comment"> * stored by addSearchPath.</font>
00665 <font class="comment"> */</font>
00666 string CPath::lookup (<font class="keyword">const</font> string &filename, <font class="keywordtype">bool</font> throwException)
00667 {
00668 <font class="keywordflow">if</font>(!filename.empty())
00669 {
00670 <font class="keywordflow">if</font> ( CNewFile::fileExists(filename) )
00671 {
00672 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(filename);
00673 <font class="keywordflow">return</font> filename;
00674 }
00675 CStringVector::iterator isv;
00676 string <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00677 <font class="keywordflow">for</font> ( isv=CPath::_SearchPaths.begin(); isv!=CPath::_SearchPaths.end(); ++isv )
00678 {
00679 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> = *isv + filename;
00680 <font class="keywordflow">if</font> ( CNewFile::fileExists(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>) )
00681 {
00682 <a class="code" href="path_8cpp.html#a0">NL_DISPLAY_PATH</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>);
00683 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00684 }
00685 }
00686 }
00687
00688 <font class="keywordflow">if</font> (throwException)
00689 <font class="keywordflow">throw</font> EPathNotFound( filename );
00690
00691 <font class="keywordflow">return</font> <font class="stringliteral">""</font>;
00692 }
00693
00694 <font class="preprocessor">#endif</font>
00695 <font class="preprocessor"></font>
00696 <font class="comment">//********************************* CNewFile</font>
00697
00698 <font class="keywordtype">int</font> CNewFile::getLastSeparator (<font class="keyword">const</font> string &filename)
00699 {
00700 <font class="keywordtype">int</font> pos = filename.find_last_of (<font class="charliteral">'/'</font>);
00701 <font class="keywordflow">if</font> (pos == string::npos)
00702 {
00703 pos = filename.find_last_of (<font class="charliteral">'\\'</font>);
00704 }
00705 <font class="keywordflow">return</font> pos;
00706 }
00707
00708 string CNewFile::getFilename (<font class="keyword">const</font> string &filename)
00709 {
00710 <font class="keywordtype">int</font> pos = CNewFile::getLastSeparator(filename);
00711 <font class="keywordflow">if</font> (pos != string::npos)
00712 <font class="keywordflow">return</font> filename.substr (pos + 1);
00713 <font class="keywordflow">else</font>
00714 <font class="keywordflow">return</font> filename;
00715 }
00716
00717 string CNewFile::getFilenameWithoutExtension (<font class="keyword">const</font> string &filename)
00718 {
00719 string filename2 = getFilename (filename);
00720 <font class="keywordtype">int</font> pos = filename2.find_last_of (<font class="charliteral">'.'</font>);
00721 <font class="keywordflow">if</font> (pos == string::npos)
00722 <font class="keywordflow">return</font> filename2;
00723 <font class="keywordflow">else</font>
00724 <font class="keywordflow">return</font> filename2.substr (0, pos);
00725 }
00726
00727 string CNewFile::getExtension (<font class="keyword">const</font> string &filename)
00728 {
00729 <font class="keywordtype">int</font> pos = filename.find_last_of (<font class="charliteral">'.'</font>);
00730 <font class="keywordflow">if</font> (pos == string::npos)
00731 <font class="keywordflow">return</font> <font class="stringliteral">""</font>;
00732 <font class="keywordflow">else</font>
00733 <font class="keywordflow">return</font> filename.substr (pos + 1);
00734 }
00735
00736 string CNewFile::getPath (<font class="keyword">const</font> string &filename)
00737 {
00738 <font class="keywordtype">int</font> pos = CNewFile::getLastSeparator(filename);
00739 <font class="keywordflow">if</font> (pos != string::npos)
00740 <font class="keywordflow">return</font> filename.substr (0, pos + 1);
00741 <font class="keywordflow">else</font>
00742 <font class="keywordflow">return</font> filename;
00743 }
00744
00745 <font class="keywordtype">bool</font> CNewFile::isDirectory (<font class="keyword">const</font> string &filename)
00746 {
00747 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00748 <font class="preprocessor"></font> DWORD <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = GetFileAttributes(filename.c_str());
00749 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> != -1);
00750 <font class="keywordflow">return</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> & FILE_ATTRIBUTE_DIRECTORY) != 0;
00751 <font class="preprocessor">#else // NL_OS_WINDOWS</font>
00752 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf;
00753 <font class="keywordtype">int</font> result = stat (filename.c_str (), &buf);
00754 <a class="code" href="debug_8h.html#a6">nlassert</a> (result == 0);
00755 <font class="keywordflow">return</font> (buf.st_mode & S_IFDIR) != 0;
00756 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00757 <font class="preprocessor"></font>}
00758
00759 <font class="keywordtype">bool</font> CNewFile::isExists (<font class="keyword">const</font> string &filename)
00760 {
00761 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00762 <font class="preprocessor"></font> <font class="keywordflow">return</font> (GetFileAttributes(filename.c_str()) != -1);
00763 <font class="preprocessor">#else // NL_OS_WINDOWS</font>
00764 <font class="preprocessor"></font> <font class="keyword">struct </font>stat buf;
00765 <font class="keywordflow">return</font> stat (filename.c_str (), &buf) == 0;
00766 <font class="preprocessor">#endif NL_OS_WINDOWS</font>
00767 <font class="preprocessor"></font>}
00768
00769 <font class="keywordtype">bool</font> CNewFile::fileExists (<font class="keyword">const</font> string& filename)
00770 {
00771 <font class="keywordflow">return</font> ! ! fstream( filename.c_str(), ios::in );
00772 }
00773
00774
00775 string CNewFile::findNewFile (<font class="keyword">const</font> string &filename)
00776 {
00777 <font class="keywordtype">int</font> pos = filename.find_last_of (<font class="charliteral">'.'</font>);
00778 <font class="keywordflow">if</font> (pos == string::npos)
00779 <font class="keywordflow">return</font> filename;
00780
00781 string start = filename.substr (0, pos);
00782 string end = filename.substr (pos);
00783
00784 <a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a> = 0;
00785 <font class="keywordtype">char</font> numchar[4];
00786 string npath;
00787 <font class="keywordflow">do</font>
00788 {
00789 npath = start;
00790 <a class="code" href="namespaceNLMISC.html#a203">smprintf</a>(numchar,4,<font class="stringliteral">"%03d"</font>,<a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a>++);
00791 npath += numchar;
00792 npath += end;
00793 <font class="keywordflow">if</font> (!CNewFile::fileExists(npath)) <font class="keywordflow">break</font>;
00794 }
00795 <font class="keywordflow">while</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a><999);
00796 <font class="keywordflow">return</font> npath;
00797 }
00798
00799 } <font class="comment">// NLMISC</font>
00800 <font class="preprocessor">#endif</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|