aboutsummaryrefslogtreecommitdiff
path: root/tools/mhmake/src/fileinfo.cpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-09-18 14:46:17 +0000
committermarha <marha@users.sourceforge.net>2009-09-18 14:46:17 +0000
commit58b69e7eb9be29c60e45d46a880b391e3809e76f (patch)
tree52d02c01fdb64f357275388722df0007f1b2d787 /tools/mhmake/src/fileinfo.cpp
parent6addc90b0516c3cda5cb6c8f9b6918b356db4449 (diff)
downloadvcxsrv-58b69e7eb9be29c60e45d46a880b391e3809e76f.tar.gz
vcxsrv-58b69e7eb9be29c60e45d46a880b391e3809e76f.tar.bz2
vcxsrv-58b69e7eb9be29c60e45d46a880b391e3809e76f.zip
Changes for making it possible to have spaces in the MHMAKECONF environment variable.
Diffstat (limited to 'tools/mhmake/src/fileinfo.cpp')
-rw-r--r--tools/mhmake/src/fileinfo.cpp77
1 files changed, 60 insertions, 17 deletions
diff --git a/tools/mhmake/src/fileinfo.cpp b/tools/mhmake/src/fileinfo.cpp
index 65b7d52a2..b79d51678 100644
--- a/tools/mhmake/src/fileinfo.cpp
+++ b/tools/mhmake/src/fileinfo.cpp
@@ -33,6 +33,51 @@ ZEROTIME g_ZeroTime;
#endif
///////////////////////////////////////////////////////////////////////////////
+string QuoteFileName(const string &Filename)
+{
+ string Ret(Filename);
+#if OSPATHSEP=='\\'
+ /* Put quotes around the string if there are spaces in it */
+ if (Ret.find_first_of(' ')!=string::npos && Ret[0]!='"')
+ {
+ Ret=g_QuoteString+Ret+g_QuoteString;
+ }
+#else
+ int Pos=0;
+ /* Escape the spaces with a backslash */
+ while ((Pos=Ret.find_first_of(' ',Pos))!=string::npos)
+ {
+ Ret=Ret.replace(Pos,1,"\\ ");
+ Pos+=2;
+ }
+#endif
+ return Ret;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+string UnquoteFileName(const string &Filename)
+{
+ int Pos=0;
+ string Name(Filename);
+#if OSPATHSEP=='\\'
+ /* Remove all the quotes from the filename */
+ while ((Pos=Name.find_first_of('"',Pos))!=string::npos)
+ {
+ Name=Name.replace(Pos,1,"");
+ }
+#else
+ /* Remove the escaped spaces */
+ while ((Pos=Name.find_first_of("\\",Pos))!=string::npos)
+ {
+ if (Name[Pos+1]==' ')
+ Name=Name.replace(Pos,2," ");
+ Pos+=1;
+ }
+#endif
+ return Name;
+}
+
+///////////////////////////////////////////////////////////////////////////////
refptr<fileinfo> fileinfo::GetDir() const
{
return GetAbsFileInfo(m_AbsFileName.substr(0,m_AbsFileName.find_last_of(OSPATHSEP)));
@@ -145,7 +190,7 @@ string fileinfo::GetPrerequisits() const
{
Ret+=g_SpaceString;
}
- Ret+=(*DepIt)->GetFullFileName();
+ Ret+=(*DepIt)->GetQuotedFullFileName();
}
Deps.insert(*DepIt);
DepIt++;
@@ -185,8 +230,8 @@ bool fileinfo::IsAutoDepExtention(void) const
///////////////////////////////////////////////////////////////////////////////
void fileinfo::DumpErrorMessageDuplicateRule(const refptr<rule>&pRule)
{
- cerr << m_AbsFileName << ": rule is defined multiple times\n";
- cerr << "First ("<<m_pRule->GetMakefile()->GetMakeDir()->GetFullFileName()<<") :\n";
+ cerr << GetQuotedFullFileName() << ": rule is defined multiple times\n";
+ cerr << "First ("<<m_pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<") :\n";
vector<string>::const_iterator It=m_pRule->GetCommands().begin();
while (It!=m_pRule->GetCommands().end())
@@ -194,7 +239,7 @@ void fileinfo::DumpErrorMessageDuplicateRule(const refptr<rule>&pRule)
cerr << " " << m_pRule->GetMakefile()->ExpandExpression(*It) << endl;
It++;
}
- cerr << "Second ("<<pRule->GetMakefile()->GetMakeDir()->GetFullFileName()<<") :\n";
+ cerr << "Second ("<<pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<") :\n";
It=pRule->GetCommands().begin();
while (It!=pRule->GetCommands().end())
{
@@ -205,7 +250,7 @@ void fileinfo::DumpErrorMessageDuplicateRule(const refptr<rule>&pRule)
#endif
///////////////////////////////////////////////////////////////////////////////
-static inline string &GetFullLowerPathName(string &Name)
+static inline string &NormalizePathName(string &Name)
{
const char *pPtr=Name.c_str();
const char *pBeg=pPtr;
@@ -258,7 +303,11 @@ static inline string &GetFullLowerPathName(string &Name)
}
else
{
+ #ifdef WIN32
*pWr++ = tolower(Char);
+ #else
+ *pWr++ = Char;
+ #endif
}
Char=*pPtr++;
}
@@ -272,8 +321,9 @@ static inline string &GetFullLowerPathName(string &Name)
///////////////////////////////////////////////////////////////////////////////
const refptr<fileinfo> &GetFileInfo(const string &NameIn,const refptr<fileinfo> &RelDir)
{
- string Name=NameIn;
+ string Name=UnquoteFileName(NameIn);
bool DoesExist=true;
+
//Only concatenate if szName is not already a full name
#ifdef WIN32
if (!Name.empty() && Name[1]!=':')
@@ -293,14 +343,7 @@ const refptr<fileinfo> &GetFileInfo(const string &NameIn,const refptr<fileinfo>
}
#endif
}
- const refptr<fileinfo> &Ret=GetAbsFileInfo(GetFullLowerPathName(Name));
- #ifdef _DEBUG
- if (Ret->GetFullFileName().find(' ')!=string::npos)
- {
- cerr << "Spaces are not allowed in filenames: "<< Ret->GetFullFileName() << endl;
- exit(1);
- }
- #endif
+ const refptr<fileinfo> &Ret=GetAbsFileInfo(NormalizePathName(Name));
if (!DoesExist)
Ret->SetNotExist();
return Ret;
@@ -313,14 +356,14 @@ void PrintFileInfos()
set<refptr<fileinfo>,less_refptrfileinfo>::iterator pIt=g_FileInfos.begin();
while (pIt!=g_FileInfos.end())
{
- cout<<(*pIt)->GetFullFileName()<<" :";
+ cout<<(*pIt)->GetQuotedFullFileName()<<" :";
if ((*pIt)->IsPhony())
cout<<" (phony)";
vector< refptr<fileinfo> > &Deps=(*pIt)->GetDeps();
vector< refptr<fileinfo> >::iterator pDepIt=Deps.begin();
while (pDepIt!=Deps.end())
{
- cout<<g_SpaceString<<(*pDepIt)->GetFullFileName();
+ cout<<g_SpaceString<<(*pDepIt)->GetQuotedFullFileName();
pDepIt++;
}
cout<<endl;
@@ -328,7 +371,7 @@ void PrintFileInfos()
refptr<rule> pRule=(*pIt)->GetRule();
if (pRule)
{
- cout<<g_SpaceString<<"Run in: "<<pRule->GetMakefile()->GetMakeDir()->GetFullFileName()<<endl;
+ cout<<g_SpaceString<<"Run in: "<<pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<endl;
pRule->PrintCommands();
}
pIt++;