ENH: Added kwsys library for platform-independent system tools.

This commit is contained in:
Brad King 2003-04-08 13:10:44 -04:00
parent 7f48313225
commit 7dff3a7f69
9 changed files with 3956 additions and 0 deletions

View File

@ -0,0 +1,47 @@
PROJECT(${KWSYS_NAMESPACE})
INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIStreamHeaders.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
CHECK_INCLUDE_FILE_CXX("sstream" CMAKE_HAS_ANSI_STRING_STREAM)
SET(KWSYS_NO_STD_NAMESPACE ${CMAKE_NO_STD_NAMESPACE})
SET(KWSYS_NO_ANSI_STREAM_HEADERS ${CMAKE_NO_ANSI_STREAM_HEADERS})
SET(KWSYS_NO_ANSI_STRING_STREAM ${CMAKE_NO_ANSI_STRING_STREAM})
SET(KWSYS_NO_ANSI_FOR_SCOPE ${CMAKE_NO_ANSI_FOR_SCOPE})
SET(CLASSES Directory RegularExpression SystemTools)
SET(HEADERS Configure StandardIncludes)
SET(SRCS)
SET(KWSYS_INCLUDES)
FOREACH(c ${CLASSES})
SET(SRCS ${SRCS} ${c}.cxx)
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${c}.hxx
@ONLY IMMEDIATE)
SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${c}.hxx)
ENDFOREACH(c)
FOREACH(h ${HEADERS})
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.hxx.in
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${h}.hxx
@ONLY IMMEDIATE)
SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${h}.hxx)
ENDFOREACH(h)
ADD_LIBRARY(${KWSYS_NAMESPACE} ${SRCS})
ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE})
IF(KWSYS_LIBRARY_INSTALL_DIR)
INSTALL_TARGETS(${KWSYS_LIBRARY_INSTALL_DIR} ${KWSYS_NAMESPACE})
ENDIF(KWSYS_LIBRARY_INSTALL_DIR)
IF(KWSYS_INCLUDE_INSTALL_DIR)
INSTALL_FILES(${KWSYS_INCLUDE_INSTALL_DIR}/${KWSYS_NAMESPACE}
FILES ${KWSYS_INCLUDES})
ENDIF(KWSYS_INCLUDE_INSTALL_DIR)

View File

@ -0,0 +1,10 @@
#ifndef @KWSYS_NAMESPACE@_Configure_hxx
#define @KWSYS_NAMESPACE@_Configure_hxx
/* This configuration should match for all instances of kwsys. */
#cmakedefine KWSYS_NO_STD_NAMESPACE
#cmakedefine KWSYS_NO_ANSI_STREAM_HEADERS
#cmakedefine KWSYS_NO_ANSI_STRING_STREAM
#cmakedefine KWSYS_NO_ANSI_FOR_SCOPE
#endif

116
Source/kwsys/Directory.cxx Normal file
View File

@ -0,0 +1,116 @@
/*=========================================================================
Program: KWSys - Kitware System Library
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <Directory.hxx>
// First microsoft compilers
#ifdef _MSC_VER
#include <windows.h>
#include <io.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
namespace KWSYS_NAMESPACE
{
bool Directory::Load(const char* name)
{
char* buf;
size_t n = strlen(name);
if ( name[n - 1] == '/' )
{
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name);
}
else
{
buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name);
}
struct _finddata_t data; // data of current file
// Now put them into the file array
size_t srchHandle = _findfirst(buf, &data);
delete [] buf;
if ( srchHandle == -1 )
{
return 0;
}
// Loop through names
do
{
m_Files.push_back(data.name);
}
while ( _findnext(srchHandle, &data) != -1 );
m_Path = name;
return _findclose(srchHandle) != -1;
}
} // namespace KWSYS_NAMESPACE
#else
// Now the POSIX style directory access
#include <sys/types.h>
#include <dirent.h>
namespace KWSYS_NAMESPACE
{
bool Directory::Load(const char* name)
{
DIR* dir = opendir(name);
if (!dir)
{
return 0;
}
for (dirent* d = readdir(dir); d; d = readdir(dir) )
{
m_Files.push_back(d->d_name);
}
m_Path = name;
closedir(dir);
return 1;
}
} // namespace KWSYS_NAMESPACE
#endif
namespace KWSYS_NAMESPACE
{
const char* Directory::GetFile(size_t dindex)
{
if ( dindex >= m_Files.size() )
{
return 0;
}
return m_Files[dindex].c_str();
}
} // namespace KWSYS_NAMESPACE

View File

@ -0,0 +1,65 @@
/*=========================================================================
Program: KWSys - Kitware System Library
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_Directory_hxx
#define @KWSYS_NAMESPACE@_Directory_hxx
#include <@KWSYS_NAMESPACE@/StandardIncludes.hxx>
#include <string>
#include <vector>
namespace @KWSYS_NAMESPACE@
{
/** \class Directory
* \brief Portable directory/filename traversal.
*
* Directory provides a portable way of finding the names of the files
* in a system directory.
*
* Directory currently works with Windows and Unix operating systems.
*/
class Directory
{
public:
/**
* Load the specified directory and load the names of the files
* in that directory. 0 is returned if the directory can not be
* opened, 1 if it is opened.
*/
bool Load(const char* dir);
/**
* Return the number of files in the current directory.
*/
size_t GetNumberOfFiles() { return m_Files.size();}
/**
* Return the file at the given index, the indexing is 0 based
*/
const char* GetFile(size_t );
private:
kwsys_std::vector<kwsys_std::string> m_Files; // Array of Files
kwsys_std::string m_Path; // Path to Open'ed directory
}; // End Class: Directory
} // namespace @KWSYS_NAMESPACE@
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,385 @@
/*=========================================================================
Program: KWSys - Kitware System Library
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// Original Copyright notice:
// Copyright (C) 1991 Texas Instruments Incorporated.
//
// Permission is granted to any individual or institution to use, copy, modify,
// and distribute this software, provided that this complete copyright and
// permission notice is maintained, intact, in all copies and supporting
// documentation.
//
// Texas Instruments Incorporated provides this software "as is" without
// express or implied warranty.
//
// Created: MNF 06/13/89 Initial Design and Implementation
// Updated: LGO 08/09/89 Inherit from Generic
// Updated: MBN 09/07/89 Added conditional exception handling
// Updated: MBN 12/15/89 Sprinkled "const" qualifiers all over the place!
// Updated: DLS 03/22/91 New lite version
//
#ifndef @KWSYS_NAMESPACE@_RegularExpression_hxx
#define @KWSYS_NAMESPACE@_RegularExpression_hxx
#include <@KWSYS_NAMESPACE@/StandardIncludes.hxx>
#include <string>
namespace @KWSYS_NAMESPACE@
{
const int RegularExpressionNSUBEXP = 10;
/** \class cmRegularExpression
* \brief Implements pattern matching with regular expressions.
*
* This is the header file for the regular expression class. An object of
* this class contains a regular expression, in a special "compiled" format.
* This compiled format consists of several slots all kept as the objects
* private data. The cmRegularExpression class provides a convenient way to
* represent regular expressions. It makes it easy to search for the same
* regular expression in many different strings without having to compile a
* string to regular expression format more than necessary.
*
* This class implements pattern matching via regular expressions.
* A regular expression allows a programmer to specify complex
* patterns that can be searched for and matched against the
* character string of a string object. In its simplest form, a
* regular expression is a sequence of characters used to
* search for exact character matches. However, many times the
* exact sequence to be found is not known, or only a match at
* the beginning or end of a string is desired. The cmRegularExpression regu-
* lar expression class implements regular expression pattern
* matching as is found and implemented in many UNIX commands
* and utilities.
*
* Example: The perl code
*
* $filename =~ m"([a-z]+)\.cc";
* print $1;
*
* Is written as follows in C++
*
* cmRegularExpression re("([a-z]+)\\.cc");
* re.find(filename);
* cerr << re.match(1);
*
*
* The regular expression class provides a convenient mechanism
* for specifying and manipulating regular expressions. The
* regular expression object allows specification of such pat-
* terns by using the following regular expression metacharac-
* ters:
*
* ^ Matches at beginning of a line
*
* $ Matches at end of a line
*
* . Matches any single character
*
* [ ] Matches any character(s) inside the brackets
*
* [^ ] Matches any character(s) not inside the brackets
*
* - Matches any character in range on either side of a dash
*
* * Matches preceding pattern zero or more times
*
* + Matches preceding pattern one or more times
*
* ? Matches preceding pattern zero or once only
*
* () Saves a matched expression and uses it in a later match
*
* Note that more than one of these metacharacters can be used
* in a single regular expression in order to create complex
* search patterns. For example, the pattern [^ab1-9] says to
* match any character sequence that does not begin with the
* characters "ab" followed by numbers in the series one
* through nine.
*
* There are three constructors for cmRegularExpression. One just creates an
* empty cmRegularExpression object. Another creates a cmRegularExpression
* object and initializes it with a regular expression that is given in the
* form of a char*. The third takes a reference to a cmRegularExpression
* object as an argument and creates an object initialized with the
* information from the given cmRegularExpression object.
*
* The find member function finds the first occurence of the regualr
* expression of that object in the string given to find as an argument. Find
* returns a boolean, and if true, mutates the private data appropriately.
* Find sets pointers to the beginning and end of the thing last found, they
* are pointers into the actual string that was searched. The start and end
* member functions return indicies into the searched string that correspond
* to the beginning and end pointers respectively. The compile member
* function takes a char* and puts the compiled version of the char* argument
* into the object's private data fields. The == and != operators only check
* the to see if the compiled regular expression is the same, and the
* deep_equal functions also checks to see if the start and end pointers are
* the same. The is_valid function returns false if program is set to NULL,
* (i.e. there is no valid compiled exression). The set_invalid function sets
* the program to NULL (Warning: this deletes the compiled expression). The
* following examples may help clarify regular expression usage:
*
* * The regular expression "^hello" matches a "hello" only at the
* beginning of a line. It would match "hello there" but not "hi,
* hello there".
*
* * The regular expression "long$" matches a "long" only at the end
* of a line. It would match "so long\0", but not "long ago".
*
* * The regular expression "t..t..g" will match anything that has a
* "t" then any two characters, another "t", any two characters and
* then a "g". It will match "testing", or "test again" but would
* not match "toasting"
*
* * The regular expression "[1-9ab]" matches any number one through
* nine, and the characters "a" and "b". It would match "hello 1"
* or "begin", but would not match "no-match".
*
* * The regular expression "[^1-9ab]" matches any character that is
* not a number one through nine, or an "a" or "b". It would NOT
* match "hello 1" or "begin", but would match "no-match".
*
* * The regular expression "br* " matches something that begins with
* a "b", is followed by zero or more "r"s, and ends in a space. It
* would match "brrrrr ", and "b ", but would not match "brrh ".
*
* * The regular expression "br+ " matches something that begins with
* a "b", is followed by one or more "r"s, and ends in a space. It
* would match "brrrrr ", and "br ", but would not match "b " or
* "brrh ".
*
* * The regular expression "br? " matches something that begins with
* a "b", is followed by zero or one "r"s, and ends in a space. It
* would match "br ", and "b ", but would not match "brrrr " or
* "brrh ".
*
* * The regular expression "(..p)b" matches something ending with pb
* and beginning with whatever the two characters before the first p
* encounterd in the line were. It would find "repb" in "rep drepa
* qrepb". The regular expression "(..p)a" would find "repa qrepb"
* in "rep drepa qrepb"
*
* * The regular expression "d(..p)" matches something ending with p,
* beginning with d, and having two characters in between that are
* the same as the two characters before the first p encounterd in
* the line. It would match "drepa qrepb" in "rep drepa qrepb".
*
*/
class RegularExpression
{
public:
/**
* Instantiate RegularExpression with program=NULL.
*/
inline RegularExpression ();
/**
* Instantiate RegularExpression with compiled char*.
*/
inline RegularExpression (char const*);
/**
* Instantiate RegularExpression as a copy of another regular expression.
*/
RegularExpression (RegularExpression const&);
/**
* Destructor.
*/
inline ~RegularExpression();
/**
* Compile a regular expression into internal code
* for later pattern matching.
*/
bool compile (char const*);
/**
* Matches the regular expression to the given string.
* Returns true if found, and sets start and end indexes accordingly.
*/
bool find (char const*);
/**
* Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly.
*/
bool find (kwsys_std::string const&);
/**
* Index to start of first find.
*/
inline kwsys_std::string::size_type start() const;
/**
* Index to end of first find.
*/
inline kwsys_std::string::size_type end() const;
/**
* Returns true if two regular expressions have the same
* compiled program for pattern matching.
*/
bool operator== (RegularExpression const&) const;
/**
* Returns true if two regular expressions have different
* compiled program for pattern matching.
*/
inline bool operator!= (RegularExpression const&) const;
/**
* Returns true if have the same compiled regular expressions
* and the same start and end pointers.
*/
bool deep_equal (RegularExpression const&) const;
/**
* True if the compiled regexp is valid.
*/
inline bool is_valid() const;
/**
* Marks the regular expression as invalid.
*/
inline void set_invalid();
/**
* Destructor.
*/
// awf added
kwsys_std::string::size_type start(int n) const;
kwsys_std::string::size_type end(int n) const;
kwsys_std::string match(int n) const;
private:
const char* startp[RegularExpressionNSUBEXP];
const char* endp[RegularExpressionNSUBEXP];
char regstart; // Internal use only
char reganch; // Internal use only
const char* regmust; // Internal use only
int regmlen; // Internal use only
char* program;
int progsize;
const char* searchstring;
};
/**
* Create an empty regular expression.
*/
inline RegularExpression::RegularExpression ()
{
this->program = 0;
}
/**
* Creates a regular expression from string s, and
* compiles s.
*/
inline RegularExpression::RegularExpression (const char* s)
{
this->program = 0;
if ( s )
{
this->compile(s);
}
}
/**
* Destroys and frees space allocated for the regular expression.
*/
inline RegularExpression::~RegularExpression ()
{
//#ifndef WIN32
delete [] this->program;
//#endif
}
/**
* Set the start position for the regular expression.
*/
inline kwsys_std::string::size_type RegularExpression::start () const
{
return(this->startp[0] - searchstring);
}
/**
* Returns the start/end index of the last item found.
*/
inline kwsys_std::string::size_type RegularExpression::end () const
{
return(this->endp[0] - searchstring);
}
/**
* Returns true if two regular expressions have different
* compiled program for pattern matching.
*/
inline bool RegularExpression::operator!= (const RegularExpression& r) const
{
return(!(*this == r));
}
/**
* Returns true if a valid regular expression is compiled
* and ready for pattern matching.
*/
inline bool RegularExpression::is_valid () const
{
return (this->program != 0);
}
inline void RegularExpression::set_invalid ()
{
//#ifndef WIN32
delete [] this->program;
//#endif
this->program = 0;
}
/**
* Return start index of nth submatch. start(0) is the start of the full match.
*/
inline kwsys_std::string::size_type RegularExpression::start(int n) const
{
return this->startp[n] - searchstring;
}
/**
* Return end index of nth submatch. end(0) is the end of the full match.
*/
inline kwsys_std::string::size_type RegularExpression::end(int n) const
{
return this->endp[n] - searchstring;
}
/**
* Return nth submatch as a string.
*/
inline kwsys_std::string RegularExpression::match(int n) const
{
return kwsys_std::string(this->startp[n], this->endp[n] - this->startp[n]);
}
} // namespace @KWSYS_NAMESPACE@
#endif

View File

@ -0,0 +1,44 @@
/*=========================================================================
Program: KWSys - Kitware System Library
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_StandardIncludes_hxx
#define @KWSYS_NAMESPACE@_StandardIncludes_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#ifndef KWSYS_NO_ANSI_STREAM_HEADERS
# include <fstream>
# include <iostream>
#else
# include <fstream.h>
# include <iostream.h>
#endif
#if !defined(KWSYS_NO_ANSI_STRING_STREAM)
# include <sstream>
#elif !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
# include <strstream>
#else
# include <strstream.h>
#endif
#if defined(KWSYS_NO_STD_NAMESPACE)
# define kwsys_std
#else
# define kwsys_std std
#endif
#endif

1793
Source/kwsys/SystemTools.cxx Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,285 @@
/*=========================================================================
Program: KWSys - Kitware System Library
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_SystemTools_hxx
#define @KWSYS_NAMESPACE@_SystemTools_hxx
#include <@KWSYS_NAMESPACE@/StandardIncludes.hxx>
#include <string>
#include <vector>
namespace @KWSYS_NAMESPACE@
{
/** \class SystemTools
* \brief A collection of useful platform-independent system functions.
*/
class SystemTools
{
public:
/**
* Replace symbols in str that are not valid in C identifiers as
* defined by the 1999 standard, ie. anything except [A-Za-z0-9_].
* They are replaced with `_' and if the first character is a digit
* then an underscore is prepended. Note that this can produce
* identifiers that the standard reserves (_[A-Z].* and __.*).
*/
static kwsys_std::string MakeCindentifier(const char* s);
/**
* Make a new directory if it is not there. This function
* can make a full path even if none of the directories existed
* prior to calling this function.
*/
static bool MakeDirectory(const char* path);
/**
* Get current time as a double. On certain platforms this will
* return higher resolution than seconds:
* (1) gettimeofday() -- resolution in microseconds
* (2) ftime() -- resolution in milliseconds
* (3) time() -- resolution in seconds
*/
static double GetTime();
/**
* Replace replace all occurances of the string in
* the source string.
*/
static void ReplaceString(kwsys_std::string& source,
const char* replace,
const char* with);
/**
* Read a registry value
*/
static bool ReadRegistryValue(const char *key, kwsys_std::string &value);
/**
* Write a registry value
*/
static bool WriteRegistryValue(const char *key, const char *value);
/**
* Delete a registry value
*/
static bool DeleteRegistryValue(const char *key);
/**
* Look for and replace registry values in a string
*/
static void ExpandRegistryValues(kwsys_std::string& source);
/**
* Return a capitalized string (i.e the first letter is uppercased,
* all other are lowercased).
*/
static kwsys_std::string Capitalized(const kwsys_std::string&);
/**
* Return a lower case string
*/
static kwsys_std::string LowerCase(const kwsys_std::string&);
/**
* Return a lower case string
*/
static kwsys_std::string UpperCase(const kwsys_std::string&);
/**
* Replace Windows file system slashes with Unix-style slashes.
*/
static void ConvertToUnixSlashes(kwsys_std::string& path);
/**
* Platform independent escape spaces, unix uses backslash,
* windows double quotes the string.
*/
static kwsys_std::string EscapeSpaces(const char* str);
/** Escape quotes in a string. */
static kwsys_std::string EscapeQuotes(const char* str);
/**
* For windows this calles ConvertToWindowsOutputPath and for unix
* it calls ConvertToUnixOutputPath
*/
static kwsys_std::string ConvertToOutputPath(const char*);
/** Return true if a file exists in the current directory. */
static bool FileExists(const char* filename);
/**
* Add the paths from the environment variable PATH to the
* string vector passed in.
*/
static void GetPath(kwsys_std::vector<kwsys_std::string>& path);
/**
* Get the file extension (including ".") needed for an executable
* on the current platform ("" for unix, ".exe" for Windows).
*/
static const char* GetExecutableExtension();
/**
* Copy the source file to the destination file only
* if the two files differ.
*/
static bool CopyFileIfDifferent(const char* source,
const char* destination);
///! Compare the contents of two files. Return true if different.
static bool FilesDiffer(const char* source,
const char* destination);
///! return true if the two files are the same file
static bool SameFile(const char* file1, const char* file2);
///! Copy a file.
static bool CopyFileAlways(const char* source, const char* destination);
///! Remove a file.
static bool RemoveFile(const char* source);
///! Find a file in the system PATH, with optional extra paths.
static kwsys_std::string FindFile(const char* name,
const kwsys_std::vector<kwsys_std::string>& path= kwsys_std::vector<kwsys_std::string>());
///! Find an executable in the system PATH, with optional extra paths.
static kwsys_std::string FindProgram(const char* name,
const kwsys_std::vector<kwsys_std::string>& path = kwsys_std::vector<kwsys_std::string>(),
bool no_system_path = false);
///! Find a library in the system PATH, with optional extra paths.
static kwsys_std::string FindLibrary(const char* name,
const kwsys_std::vector<kwsys_std::string>& path);
///! return true if the file is a directory.
static bool FileIsDirectory(const char* name);
static void Glob(const char *directory, const char *regexp,
kwsys_std::vector<kwsys_std::string>& files);
static void GlobDirs(const char *fullPath, kwsys_std::vector<kwsys_std::string>& files);
/**
* Try to find a list of files that match the "simple" globbing
* expression. At this point in time the globbing expressions have
* to be in form: /directory/partial_file_name*. The * character has
* to be at the end of the string and it does not support ?
* []... The optional argument type specifies what kind of files you
* want to find. 0 means all files, -1 means directories, 1 means
* files only. This method returns true if search was succesfull.
*/
static bool SimpleGlob(const kwsys_std::string& glob, kwsys_std::vector<kwsys_std::string>& files,
int type = 0);
static kwsys_std::string GetCurrentWorkingDirectory();
/**
* Given the path to a program executable, get the directory part of
* the path with the file stripped off. If there is no directory
* part, the empty string is returned.
*/
static kwsys_std::string GetProgramPath(const char*);
static bool SplitProgramPath(const char* in_name,
kwsys_std::string& dir,
kwsys_std::string& file,
bool errorReport = true);
/**
* Given a path to a file or directory, convert it to a full path.
* This collapses away relative paths relative to the cwd argument
* (which defaults to the current working directory). The full path
* is returned.
*/
static kwsys_std::string CollapseFullPath(const char* in_relative);
static kwsys_std::string CollapseFullPath(const char* in_relative,
const char* in_base);
///! return path of a full filename (no trailing slashes).
static kwsys_std::string GetFilenamePath(const kwsys_std::string&);
///! return file name of a full filename (i.e. file name without path).
static kwsys_std::string GetFilenameName(const kwsys_std::string&);
///! Split a program from its arguments and handle spaces in the paths.
static void SplitProgramFromArgs(const char* path,
kwsys_std::string& program, kwsys_std::string& args);
///! return file extension of a full filename (dot included).
static kwsys_std::string GetFilenameExtension(const kwsys_std::string&);
///! return file name without extension of a full filename.
static kwsys_std::string GetFilenameWithoutExtension(const kwsys_std::string&);
///! return file name without its last (shortest) extension.
static kwsys_std::string GetFilenameWithoutLastExtension(const kwsys_std::string&);
/** Return whether the path represents a full path (not relative). */
static bool FileIsFullPath(const char*);
static long int ModifiedTime(const char* filename);
///! for windows return the short path for the given path, unix just a pass through
static bool GetShortPath(const char* path, kwsys_std::string& result);
///! change directory the the directory specified
static int ChangeDirectory(const char* dir);
/** Split a string on its newlines into multiple lines. Returns
false only if the last line stored had no newline. */
static bool Split(const char* s, kwsys_std::vector<kwsys_std::string>& l);
static kwsys_std::string GetCurrentDateTime(const char* format);
/** Get the result of strerror(errno). */
static kwsys_std::string GetLastSystemError();
/** When building DEBUG with MSVC, this enables a hook that prevents
* error dialogs from popping up if the program is being run from
* DART.
*/
static void EnableMSVCDebugHook();
/**
* Read line from file. Make sure to get everything. Due to a buggy stream
* library on the HP and another on Mac OSX, we need this very carefully
* written version of getline. Returns true if any data were read before the
* end-of-file was reached.
*/
static bool GetLineFromStream(kwsys_std::istream& istr, kwsys_std::string& line);
protected:
// these two functions can be called from ConvertToOutputPath
/**
* Convert the path to a string that can be used in a unix makefile.
* double slashes are removed, and spaces are escaped.
*/
static kwsys_std::string ConvertToUnixOutputPath(const char*);
/**
* Convert the path to string that can be used in a windows project or
* makefile. Double slashes are removed if they are not at the start of
* the string, the slashes are converted to windows style backslashes, and
* if there are spaces in the string it is double quoted.
*/
static kwsys_std::string ConvertToWindowsOutputPath(const char*);
};
} // namespace @KWSYS_NAMESPACE@
#endif