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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifdef _LINUX
#include <ctime> // needed by xercesc
#endif
#include "stdafx.h"
#include "tier0/platform.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <windows.h>
#include <comutil.h> // _variant_t
#include <atlbase.h> // CComPtr
#elif _LINUX
#include <unistd.h>
#include <dirent.h> // scandir()
#define _stat stat
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include "valve_minmax_off.h"
#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif
#include "valve_minmax_on.h"
#define IXMLDOMNode DOMNode
#define IXMLDOMNodeList DOMNodeList
#define _alloca alloca
XERCES_CPP_NAMESPACE_USE
class XStr
{
public :
XStr(const char* const toTranscode)
{
// Call the private transcoding method
fUnicodeForm = XMLString::transcode(toTranscode);
}
~XStr()
{
XMLString::release(&fUnicodeForm);
}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const XMLCh* unicodeForm() const
{
return fUnicodeForm;
}
private :
XMLCh* fUnicodeForm;
};
#define _bstr_t(str) XStr(str).unicodeForm()
#else
#error "Unsupported platform"
#endif
#include "vcprojconvert.h"
#include "utlvector.h"
//-----------------------------------------------------------------------------
// Purpose: constructor
//-----------------------------------------------------------------------------
CVCProjConvert::CVCProjConvert()
{
#ifdef _WIN32
::CoInitialize(NULL);
#elif _LINUX
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
Error( "Error during initialization! : %s\n", message);
XMLString::release(&message);
}
#endif
m_bProjectLoaded = false;
}
//-----------------------------------------------------------------------------
// Purpose: destructor
//-----------------------------------------------------------------------------
CVCProjConvert::~CVCProjConvert()
{
#ifdef _WIN32
::CoUninitialize();
#elif _LINUX
// nothing to shutdown
#endif
}
//-----------------------------------------------------------------------------
// Purpose: load up a project and parse it
//-----------------------------------------------------------------------------
bool CVCProjConvert::LoadProject( const char *project )
{
#ifdef _WIN32
HRESULT hr;
IXMLDOMDocument *pXMLDoc=NULL;
hr = ::CoCreateInstance(CLSID_DOMDocument,
NULL,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument,
(void**)&pXMLDoc);
if (FAILED(hr))
{
Msg ("Cannot instantiate msxml2.dll\n");
Msg ("Please download the MSXML run-time (url below)\n");
Msg ("http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/766/msdncompositedoc.xml\n");
return false;
}
VARIANT_BOOL vtbool;
_variant_t bstrProject(project);
pXMLDoc->put_async( VARIANT_BOOL(FALSE) );
hr = pXMLDoc->load(bstrProject,&vtbool);
if (FAILED(hr) || vtbool==VARIANT_FALSE)
{
Msg ("Could not open %s.\n", bstrProject);
pXMLDoc->Release();
return false;
}
#elif _LINUX
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always); // optional.
parser->setDoNamespaces(true); // optional
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
try {
parser->parse(project);
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
Error( "Exception message is: %s\n", message );
XMLString::release(&message);
return;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.msg);
Error( "Exception message is: %s\n", message );
XMLString::release(&message);
return;
}
catch (...) {
Error( "Unexpected Exception \n" );
return;
}
DOMDocument *pXMLDoc = parser->getDocument();
#endif
ExtractProjectName( pXMLDoc );
if ( !m_Name.IsValid() )
{
Msg( "Failed to extract project name\n" );
return false;
}
char baseDir[ MAX_PATH ];
Q_ExtractFilePath( project, baseDir, sizeof(baseDir) );
Q_StripTrailingSlash( baseDir );
m_BaseDir = baseDir;
ExtractConfigurations( pXMLDoc );
if ( m_Configurations.Count() == 0 )
{
Msg( "Failed to find any configurations to load\n" );
return false;
}
ExtractFiles( pXMLDoc );
#ifdef _WIN32
pXMLDoc->Release();
#elif _LINUX
delete pXMLDoc;
delete errHandler;
#endif
m_bProjectLoaded = true;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: returns the number of different configurations loaded
//-----------------------------------------------------------------------------
int CVCProjConvert::GetNumConfigurations()
{
Assert( m_bProjectLoaded );
return m_Configurations.Count();
}
//-----------------------------------------------------------------------------
// Purpose: returns the index of a config with this name, -1 on err
//-----------------------------------------------------------------------------
int CVCProjConvert::FindConfiguration( CUtlSymbol name )
{
if ( !name.IsValid() )
{
return -1;
}
for ( int i = 0; i < m_Configurations.Count(); i++ )
{
if ( m_Configurations[i].GetName() == name )
{
return i;
}
}
return -1;
}
//-----------------------------------------------------------------------------
// Purpose: extracts the value of the xml attrib "attribName"
//-----------------------------------------------------------------------------
CUtlSymbol CVCProjConvert::GetXMLAttribValue( IXMLDOMElement *p, const char *attribName )
{
if (!p)
{
return CUtlSymbol();
}
#ifdef _WIN32
VARIANT vtValue;
p->getAttribute( _bstr_t(attribName), &vtValue);
if ( vtValue.vt == VT_NULL )
{
return CUtlSymbol(); // element not found
}
Assert( vtValue.vt == VT_BSTR );
CUtlSymbol name( static_cast<char *>( _bstr_t( vtValue.bstrVal ) ) );
::SysFreeString(vtValue.bstrVal);
#elif _LINUX
const XMLCh *xAttrib = XMLString::transcode( attribName );
const XMLCh *value = p->getAttribute( xAttrib );
if ( value == NULL )
{
return CUtlSymbol(); // element not found
}
char *transValue = XMLString::transcode(value);
CUtlSymbol name( transValue );
XMLString::release( &xAttrib );
XMLString::release( &transValue );
#endif
return name;
}
//-----------------------------------------------------------------------------
// Purpose: returns the name of this node
//-----------------------------------------------------------------------------
CUtlSymbol CVCProjConvert::GetXMLNodeName( IXMLDOMElement *p )
{
CUtlSymbol name;
if (!p)
{
return name;
}
#ifdef _WIN32
BSTR bstrName;
p->get_nodeName( &bstrName );
_bstr_t bstr(bstrName);
name = static_cast<char *>(bstr);
return name;
#elif _LINUX
Assert( 0 );
Error( "Function CVCProjConvert::GetXMLNodeName not implemented\n" );
return name;
#endif
}
//-----------------------------------------------------------------------------
// Purpose: returns the config object at this index
//-----------------------------------------------------------------------------
CVCProjConvert::CConfiguration & CVCProjConvert::GetConfiguration( int i )
{
Assert( m_bProjectLoaded );
Assert( m_Configurations.IsValidIndex(i) );
return m_Configurations[i];
}
//-----------------------------------------------------------------------------
// Purpose: extracts the project name from the loaded vcproj
//-----------------------------------------------------------------------------
bool CVCProjConvert::ExtractProjectName( IXMLDOMDocument *pDoc )
{
#ifdef _WIN32
CComPtr<IXMLDOMNodeList> pProj;
pDoc->getElementsByTagName( _bstr_t("VisualStudioProject"), &pProj);
if (pProj)
{
long len = 0;
pProj->get_length(&len);
Assert( len == 1 );
if ( len == 1 )
{
CComPtr<IXMLDOMNode> pNode;
pProj->get_item( 0, &pNode );
if (pNode)
{
CComQIPtr<IXMLDOMElement> pElem( pNode );
m_Name = GetXMLAttribValue( pElem, "Name");
}
}
}
#elif _LINUX
DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("VisualStudioProject") );
if ( nodes )
{
int len = nodes->getLength();
if ( len == 1 )
{
DOMNode *node = nodes->item(0);
if ( node )
{
m_Name = GetXMLAttribValue( node, "Name" );
}
}
}
#endif
return true;
}
//-----------------------------------------------------------------------------
// Purpose: extracts the list of configuration names from the vcproj
//-----------------------------------------------------------------------------
bool CVCProjConvert::ExtractConfigurations( IXMLDOMDocument *pDoc )
{
m_Configurations.RemoveAll();
if (!pDoc)
{
return false;
}
#ifdef _WIN32
CComPtr<IXMLDOMNodeList> pConfigs;
pDoc->getElementsByTagName( _bstr_t("Configuration"), &pConfigs);
if (pConfigs)
{
long len = 0;
pConfigs->get_length(&len);
for ( int i=0; i<len; i++ )
{
CComPtr<IXMLDOMNode> pNode;
pConfigs->get_item( i, &pNode );
if (pNode)
{
CComQIPtr<IXMLDOMElement> pElem( pNode );
CUtlSymbol configName = GetXMLAttribValue( pElem, "Name" );
if ( configName.IsValid() )
{
int newIndex = m_Configurations.AddToTail();
CConfiguration & config = m_Configurations[newIndex];
config.SetName( configName );
ExtractIncludes( pElem, config );
}
}
}
}
#elif _LINUX
DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("Configuration"));
if ( nodes )
{
int len = nodes->getLength();
for ( int i=0; i<len; i++ )
{
DOMNode *node = nodes->item(i);
if (node)
{
CUtlSymbol configName = GetXMLAttribValue( node, "Name" );
if ( configName.IsValid() )
{
int newIndex = m_Configurations.AddToTail();
CConfiguration & config = m_Configurations[newIndex];
config.SetName( configName );
ExtractIncludes( node, config );
}
}
}
}
#endif
return true;
}
//-----------------------------------------------------------------------------
// Purpose: extracts the list of defines and includes used for this config
//-----------------------------------------------------------------------------
bool CVCProjConvert::ExtractIncludes( IXMLDOMElement *pDoc, CConfiguration & config )
{
config.ResetDefines();
config.ResetIncludes();
if (!pDoc)
{
return false;
}
#ifdef _WIN32
CComPtr<IXMLDOMNodeList> pTools;
pDoc->getElementsByTagName( _bstr_t("Tool"), &pTools);
if (pTools)
{
long len = 0;
pTools->get_length(&len);
for ( int i=0; i<len; i++ )
{
CComPtr<IXMLDOMNode> pNode;
pTools->get_item( i, &pNode );
if (pNode)
{
CComQIPtr<IXMLDOMElement> pElem( pNode );
CUtlSymbol toolName = GetXMLAttribValue( pElem, "Name" );
if ( toolName == "VCCLCompilerTool" )
{
CUtlSymbol defines = GetXMLAttribValue( pElem, "PreprocessorDefinitions" );
char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 );
Assert( str );
Q_strcpy( str, defines.String() );
// now tokenize the string on the ";" char
char *delim = strchr( str, ';' );
char *curpos = str;
while ( delim )
{
*delim = 0;
delim++;
if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) &&
Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
{
config.AddDefine( curpos );
}
curpos = delim;
delim = strchr( delim, ';' );
}
if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) &&
Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
{
config.AddDefine( curpos );
}
CUtlSymbol includes = GetXMLAttribValue( pElem, "AdditionalIncludeDirectories" );
char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 );
Assert( str2 );
Q_strcpy( str2, includes.String() );
// now tokenize the string on the ";" char
delim = strchr( str2, ',' );
curpos = str2;
while ( delim )
{
*delim = 0;
delim++;
config.AddInclude( curpos );
curpos = delim;
delim = strchr( delim, ',' );
}
config.AddInclude( curpos );
}
}
}
}
#elif _LINUX
DOMNodeList *nodes= pDoc->getElementsByTagName( _bstr_t("Tool"));
if (nodes)
{
int len = nodes->getLength();
for ( int i=0; i<len; i++ )
{
DOMNode *node = nodes->item(i);
if (node)
{
CUtlSymbol toolName = GetXMLAttribValue( node, "Name" );
if ( toolName == "VCCLCompilerTool" )
{
CUtlSymbol defines = GetXMLAttribValue( node, "PreprocessorDefinitions" );
char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 );
Assert( str );
Q_strcpy( str, defines.String() );
// now tokenize the string on the ";" char
char *delim = strchr( str, ';' );
char *curpos = str;
while ( delim )
{
*delim = 0;
delim++;
if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) &&
Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
{
config.AddDefine( curpos );
}
curpos = delim;
delim = strchr( delim, ';' );
}
if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) &&
Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
{
config.AddDefine( curpos );
}
CUtlSymbol includes = GetXMLAttribValue( node, "AdditionalIncludeDirectories" );
char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 );
Assert( str2 );
Q_strcpy( str2, includes.String() );
// now tokenize the string on the ";" char
char token = ',';
delim = strchr( str2, token );
if ( !delim )
{
token = ';';
delim = strchr( str2, token );
}
curpos = str2;
while ( delim )
{
*delim = 0;
delim++;
Q_FixSlashes( curpos );
char fullPath[ MAX_PATH ];
Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos );
Q_StripTrailingSlash( fullPath );
config.AddInclude( fullPath );
curpos = delim;
delim = strchr( delim, token );
}
Q_FixSlashes( curpos );
Q_strlower( curpos );
char fullPath[ MAX_PATH ];
Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos );
Q_StripTrailingSlash( fullPath );
config.AddInclude( fullPath );
}
}
}
}
#endif
return true;
}
//-----------------------------------------------------------------------------
// Purpose: walks a particular files config entry and removes an files not valid for this config
//-----------------------------------------------------------------------------
bool CVCProjConvert::IterateFileConfigurations( IXMLDOMElement *pFile, CUtlSymbol fileName )
{
#ifdef _WIN32
CComPtr<IXMLDOMNodeList> pConfigs;
pFile->getElementsByTagName( _bstr_t("FileConfiguration"), &pConfigs);
if (pConfigs)
{
long len = 0;
pConfigs->get_length(&len);
for ( int i=0; i<len; i++ )
{
CComPtr<IXMLDOMNode> pNode;
pConfigs->get_item( i, &pNode);
if (pNode)
{
CComQIPtr<IXMLDOMElement> pElem( pNode );
CUtlSymbol configName = GetXMLAttribValue( pElem, "Name");
CUtlSymbol excluded = GetXMLAttribValue( pElem ,"ExcludedFromBuild");
if ( configName.IsValid() && excluded.IsValid() )
{
int index = FindConfiguration( configName );
if ( index > 0 && excluded == "TRUE" )
{
m_Configurations[index].RemoveFile( fileName );
}
}
}
}//for
}//if
#elif _LINUX
DOMNodeList *nodes = pFile->getElementsByTagName( _bstr_t("FileConfiguration"));
if (nodes)
{
int len = nodes->getLength();
for ( int i=0; i<len; i++ )
{
DOMNode *node = nodes->item(i);
if (node)
{
CUtlSymbol configName = GetXMLAttribValue( node, "Name");
CUtlSymbol excluded = GetXMLAttribValue( node ,"ExcludedFromBuild");
if ( configName.IsValid() && excluded.IsValid() )
{
int index = FindConfiguration( configName );
if ( index >= 0 && excluded == "TRUE" )
{
m_Configurations[index].RemoveFile( fileName );
}
}
}
}//for
}//if
#endif
return true;
}
//-----------------------------------------------------------------------------
// Purpose: walks the file elements in the vcproj and inserts them into configs
//-----------------------------------------------------------------------------
bool CVCProjConvert::ExtractFiles( IXMLDOMDocument *pDoc )
{
if (!pDoc)
{
return false;
}
Assert( m_Configurations.Count() ); // some configs must be loaded first
#ifdef _WIN32
CComPtr<IXMLDOMNodeList> pFiles;
pDoc->getElementsByTagName( _bstr_t("File"), &pFiles);
if (pFiles)
{
long len = 0;
pFiles->get_length(&len);
for ( int i=0; i<len; i++ )
{
CComPtr<IXMLDOMNode> pNode;
pFiles->get_item( i, &pNode);
if (pNode)
{
CComQIPtr<IXMLDOMElement> pElem( pNode );
CUtlSymbol fileName = GetXMLAttribValue(pElem,"RelativePath");
if ( fileName.IsValid() )
{
CConfiguration::FileType_e type = GetFileType( fileName.String() );
CConfiguration::CFileEntry fileEntry( fileName.String(), type );
for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs
{
CConfiguration & config = m_Configurations[i];
config.InsertFile( fileEntry );
}
IterateFileConfigurations( pElem, fileName ); // now remove the excluded ones
}
}
}//for
}
#elif _LINUX
DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("File") );
if (nodes)
{
int len = nodes->getLength();
for ( int i=0; i<len; i++ )
{
DOMNode *node = nodes->item(i);
if (node)
{
CUtlSymbol fileName = GetXMLAttribValue(node,"RelativePath");
if ( fileName.IsValid() )
{
char fixedFileName[ MAX_PATH ];
Q_strncpy( fixedFileName, fileName.String(), sizeof(fixedFileName) );
if ( fixedFileName[0] == '.' && fixedFileName[1] == '\\' )
{
Q_memmove( fixedFileName, fixedFileName+2, sizeof(fixedFileName)-2 );
}
Q_FixSlashes( fixedFileName );
FindFileCaseInsensitive( fixedFileName, sizeof(fixedFileName) );
CConfiguration::FileType_e type = GetFileType( fileName.String() );
CConfiguration::CFileEntry fileEntry( fixedFileName, type );
for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs
{
CConfiguration & config = m_Configurations[i];
config.InsertFile( fileEntry );
}
IterateFileConfigurations( node, fixedFileName ); // now remove the excluded ones
}
}
}//for
}
#endif
return true;
}
#ifdef _LINUX
static char fileName[MAX_PATH];
int CheckName(const struct dirent *dir)
{
return !strcasecmp( dir->d_name, fileName );
}
const char *findFileInDirCaseInsensitive(const char *file)
{
const char *dirSep = strrchr(file,'/');
if( !dirSep )
{
dirSep=strrchr(file,'\\');
if( !dirSep )
{
return NULL;
}
}
char *dirName = static_cast<char *>( alloca( ( dirSep - file ) +1 ) );
if( !dirName )
return NULL;
Q_strncpy( dirName, file, dirSep - file );
dirName[ dirSep - file ] = '\0';
struct dirent **namelist;
int n;
Q_strncpy( fileName, dirSep + 1, MAX_PATH );
n = scandir( dirName , &namelist, CheckName, alphasort );
if( n > 0 )
{
while( n > 1 )
{
free( namelist[n] ); // free the malloc'd strings
n--;
}
Q_snprintf( fileName, sizeof( fileName ), "%s/%s", dirName, namelist[0]->d_name );
return fileName;
}
else
{
// last ditch attempt, just return the lower case version!
Q_strncpy( fileName, file, sizeof(fileName) );
Q_strlower( fileName );
return fileName;
}
}
#endif
void CVCProjConvert::FindFileCaseInsensitive( char *fileName, int fileNameSize )
{
char filePath[ MAX_PATH ];
Q_snprintf( filePath, sizeof(filePath), "%s/%s", m_BaseDir.String(), fileName );
struct _stat buf;
if ( _stat( filePath, &buf ) == 0)
{
return; // found the filename directly
}
#ifdef _LINUX
const char *realName = findFileInDirCaseInsensitive( filePath );
if ( realName )
{
Q_strncpy( fileName, realName+strlen(m_BaseDir.String())+1, fileNameSize );
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: extracts the generic type of a file being loaded
//-----------------------------------------------------------------------------
CVCProjConvert::CConfiguration::FileType_e CVCProjConvert::GetFileType( const char *fileName )
{
CConfiguration::FileType_e type = CConfiguration::FILE_TYPE_UNKNOWN_E;
char ext[10];
Q_ExtractFileExtension( fileName, ext, sizeof(ext) );
if ( !Q_stricmp( ext, "lib" ) )
{
type = CConfiguration::FILE_LIBRARY;
}
else if ( !Q_stricmp( ext, "h" ) )
{
type = CConfiguration::FILE_HEADER;
}
else if ( !Q_stricmp( ext, "hh" ) )
{
type = CConfiguration::FILE_HEADER;
}
else if ( !Q_stricmp( ext, "hpp" ) )
{
type = CConfiguration::FILE_HEADER;
}
else if ( !Q_stricmp( ext, "cpp" ) )
{
type = CConfiguration::FILE_SOURCE;
}
else if ( !Q_stricmp( ext, "c" ) )
{
type = CConfiguration::FILE_SOURCE;
}
else if ( !Q_stricmp( ext, "cc" ) )
{
type = CConfiguration::FILE_SOURCE;
}
return type;
}
|