Add detection of file format from extension

This commit is contained in:
Andy Cedilnik 2002-09-25 09:30:49 -04:00
parent c6384c19b4
commit 6736678ca3
2 changed files with 62 additions and 1 deletions

View File

@ -2148,3 +2148,41 @@ bool cmSystemTools::GetShortPath(const char* path, std::string& shortPath)
return true;
#endif
}
cmSystemTools::e_FileFormat cmSystemTools::GetFileFormat(const char* cext)
{
if ( ! cext || *cext == 0 )
{
return cmSystemTools::NO_FILE_FORMAT;
}
std::string ext = cmSystemTools::LowerCase(cext);
if ( ext == "c" || ext == ".c" ) { return cmSystemTools::C_FILE_FORMAT; }
if ( ext == "cxx" || ext == ".cxx" ||
ext == "cpp" || ext == ".cpp" ||
ext == "c++" || ext == ".c++" ||
ext == "cc" || ext == ".cc" ) { return cmSystemTools::CXX_FILE_FORMAT; }
if ( ext == "java" || ext == ".java" ) { return cmSystemTools::JAVA_FILE_FORMAT; }
if ( ext == "h" || ext == ".h" ||
ext == "hpp" || ext == ".hpp" ||
ext == "h++" || ext == ".h++" ||
ext == "hxx" || ext == ".hxx" ) { return cmSystemTools::HEADER_FILE_FORMAT; }
if ( ext == "rc" || ext == ".rc" ) { return cmSystemTools::RESOURCE_FILE_FORMAT; }
if ( ext == "def" || ext == ".def" ) { return cmSystemTools::DEFINITION_FILE_FORMAT; }
if ( ext == "lib" || ext == ".lib" ||
ext == "a" || ext == ".a") { return cmSystemTools::STATIC_LIBRARY_FILE_FORMAT; }
if ( ext == "o" || ext == ".o" ||
ext == "obj" || ext == ".obj") { return cmSystemTools::OBJECT_FILE_FORMAT; }
#ifdef __APPLE__
if ( ext == "dylib" || ext == ".dylib" )
{ return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT; }
if ( ext == "so" || ext == ".so" ||
ext == "bundle" || ext == ".bundle" )
{ return cmSystemTools::MODULE_FILE_FORMAT; }
#else // __APPLE__
if ( ext == "so" || ext == ".so" ||
ext == "sl" || ext == ".sl" ||
ext == "dll" || ext == ".dll" )
{ return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT; }
#endif // __APPLE__
return cmSystemTools::UNKNOWN_FILE_FORMAT;
}

View File

@ -287,6 +287,30 @@ public:
static void DisableRunCommandOutput() {s_DisableRunCommandOutput = true; }
static void EnableRunCommandOutput() {s_DisableRunCommandOutput = false; }
static bool GetRunCommandOutput() { return s_DisableRunCommandOutput; }
/**
* Come constants for different file formats.
*/
enum e_FileFormat {
NO_FILE_FORMAT = 0,
C_FILE_FORMAT,
CXX_FILE_FORMAT,
JAVA_FILE_FORMAT,
HEADER_FILE_FORMAT,
RESOURCE_FILE_FORMAT,
DEFINITION_FILE_FORMAT,
STATIC_LIBRARY_FILE_FORMAT,
SHARED_LIBRARY_FILE_FORMAT,
MODULE_FILE_FORMAT,
OBJECT_FILE_FORMAT,
UNKNOWN_FILE_FORMAT
};
/**
* Determine the file type based on the extension
*/
static e_FileFormat GetFileFormat(const char* ext);
protected:
// these two functions can be called from ConvertToOutputPath
/**
@ -303,7 +327,6 @@ protected:
*/
static std::string ConvertToWindowsOutputPath(const char*);
private:
static bool s_ErrorOccured;
static bool s_DisableMessages;