summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2006-07-26 12:35:40 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2006-07-26 12:35:40 (GMT)
commitcc2173478e572faa7f8b3a12143b5092454b30fc (patch)
treebf2d22faf69ca9eaace66325d6bcac4e73487f1c /Source
parentecf914e6975b75166df2a0f36744221fe3b80899 (diff)
downloadCMake-cc2173478e572faa7f8b3a12143b5092454b30fc.zip
CMake-cc2173478e572faa7f8b3a12143b5092454b30fc.tar.gz
CMake-cc2173478e572faa7f8b3a12143b5092454b30fc.tar.bz2
ENH: move changes from main tree
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx1
-rw-r--r--Source/kwsys/SystemTools.cxx53
-rw-r--r--Source/kwsys/SystemTools.hxx.in1
-rw-r--r--Source/kwsys/testSystemTools.cxx147
4 files changed, 196 insertions, 6 deletions
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index 787cc9e..436daea 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -176,6 +176,7 @@ void cmLocalVisualStudio7Generator::AddVCProjBuildRule(cmTarget& tgt)
std::string makefileIn = this->Makefile->GetStartDirectory();
makefileIn += "/";
makefileIn += "CMakeLists.txt";
+ makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
std::string comment = "Building Custom Rule ";
comment += makefileIn;
std::string args;
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index d16d4d3..676e175 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -56,6 +56,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
+#include <signal.h> /* sigprocmask */
#endif
// Windows API. Some parts used even on cygwin.
@@ -886,6 +887,7 @@ kwsys_stl::string SystemTools::UnCapitalizedWords(const kwsys_stl::string& s)
return n;
}
+// only works for words with at least two letters
kwsys_stl::string SystemTools::AddSpaceBetweenCapitalizedWords(
const kwsys_stl::string& s)
{
@@ -1035,7 +1037,7 @@ char* SystemTools::RemoveCharsButUpperHex(const char* str)
char *ptr = clean_str;
while (*str)
{
- if ((*str >= '0' && *str <= '9') || (*str >= 'A' && *str <= 'H'))
+ if ((*str >= '0' && *str <= '9') || (*str >= 'A' && *str <= 'F'))
{
*ptr++ = *str;
}
@@ -1339,13 +1341,17 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
path.replace(0,1,homeEnv);
}
}
-
+ // remove trailing slash if the path is more than
+ // a single /
pathCString = path.c_str();
- if (*(pathCString+(path.size()-1)) == '/')
+ if(path.size() > 1 && *(pathCString+(path.size()-1)) == '/')
+ {
+ // if it is c:/ then do not remove the trailing slash
+ if(!((path.size() == 3 && pathCString[1] == ':')))
{
path = path.substr(0, path.size()-1);
}
-
+ }
}
}
@@ -2503,7 +2509,6 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path,
// Split the input path components.
kwsys_stl::vector<kwsys_stl::string> path_components;
SystemTools::SplitPath(in_path, path_components);
-
// If the input path is relative, start with a base path.
if(path_components[0].length() == 0)
{
@@ -2891,7 +2896,16 @@ kwsys_stl::string SystemTools::GetFilenamePath(const kwsys_stl::string& filename
kwsys_stl::string::size_type slash_pos = fn.rfind("/");
if(slash_pos != kwsys_stl::string::npos)
{
- return fn.substr(0, slash_pos);
+ kwsys_stl::string ret = fn.substr(0, slash_pos);
+ if(ret.size() == 2 && ret[1] == ':')
+ {
+ return ret + '/';
+ }
+ if(ret.size() == 0)
+ {
+ return "/";
+ }
+ return ret;
}
else
{
@@ -3533,7 +3547,34 @@ void SystemTools::Delay(unsigned int msec)
#ifdef _WIN32
Sleep(msec);
#else
+ // Block signals to make sure the entire sleep duration occurs. If
+ // a signal were to arrive the sleep or usleep might return early
+ // and there is no way to accurately know how much time was really
+ // slept without setting up timers.
+ sigset_t newset;
+ sigset_t oldset;
+ sigfillset(&newset);
+ sigprocmask(SIG_BLOCK, &newset, &oldset);
+
+ // The sleep function gives 1 second resolution and the usleep
+ // function gives 1e-6 second resolution but on some platforms has a
+ // maximum sleep time of 1 second. This could be re-implemented to
+ // use select with masked signals or pselect to mask signals
+ // atomically. If select is given empty sets and zero as the max
+ // file descriptor but a non-zero timeout it can be used to block
+ // for a precise amount of time.
+ if(msec >= 1000)
+ {
+ sleep(msec / 1000);
+ usleep((msec % 1000) * 1000);
+ }
+ else
+ {
usleep(msec * 1000);
+ }
+
+ // Restore the signal mask to the previous setting.
+ sigprocmask(SIG_SETMASK, &oldset, 0);
#endif
}
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index 9e3e68d..b18bc5b 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -206,6 +206,7 @@ public:
/**
* Return string with space added between capitalized words
* (i.e. EatMyShorts becomes Eat My Shorts )
+ * (note that IEatShorts becomes IEat Shorts)
*/
static kwsys_stl::string AddSpaceBetweenCapitalizedWords(
const kwsys_stl::string&);
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index 2106f7a..c4da9e1 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -119,6 +119,151 @@ bool CheckDetectFileType()
}
//----------------------------------------------------------------------------
+bool CheckStringOperations()
+{
+ bool res = true;
+
+ kwsys_stl::string test = "mary had a little lamb.";
+ if (kwsys::SystemTools::CapitalizedWords(test) != "Mary Had A Little Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with CapitalizedWords "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ test = "Mary Had A Little Lamb.";
+ if (kwsys::SystemTools::UnCapitalizedWords(test) !=
+ "mary had a little lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with UnCapitalizedWords "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ test = "MaryHadTheLittleLamb.";
+ if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
+ "Mary Had The Little Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with AddSpaceBetweenCapitalizedWords "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ char * cres =
+ kwsys::SystemTools::AppendStrings("Mary Had A"," Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with AppendStrings "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ cres =
+ kwsys::SystemTools::AppendStrings("Mary Had"," A ","Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with AppendStrings "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.",'a') != 3)
+ {
+ kwsys_ios::cerr
+ << "Problem with CountChar "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ cres =
+ kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.","aeiou");
+ if (strcmp(cres,"Mry Hd A Lttl Lmb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with RemoveChars "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ cres =
+ kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
+ if (strcmp(cres,"A"))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with RemoveCharsButUpperHex "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ char *cres2 = new char [strlen("Mary Had A Little Lamb.")+1];
+ strcpy(cres2,"Mary Had A Little Lamb.");
+ kwsys::SystemTools::ReplaceChars(cres2,"aeiou",'X');
+ if (strcmp(cres2,"MXry HXd A LXttlX LXmb."))
+ {
+ delete [] cres2;
+ kwsys_ios::cerr
+ << "Problem with ReplaceChars "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres2;
+
+ if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
+ "Mary "))
+ {
+ kwsys_ios::cerr
+ << "Problem with StringStartsWith "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
+ " Lamb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with StringEndsWith "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with DuplicateString "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ test = "Mary Had A Little Lamb.";
+ if (kwsys::SystemTools::CropString(test,13) !=
+ "Mary ...Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with CropString "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ return res;
+}
+
+//----------------------------------------------------------------------------
int main(/*int argc, char* argv*/)
{
bool res = true;
@@ -145,5 +290,7 @@ int main(/*int argc, char* argv*/)
res &= CheckDetectFileType();
+ res &= CheckStringOperations();
+
return res ? 0 : 1;
}