Cleanup GetDirectory(), GetFilename() and GetExtension() usage
authorHervé Poussineau <hpoussin@reactos.org>
Wed, 12 Sep 2007 07:04:32 +0000 (07:04 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Wed, 12 Sep 2007 07:04:32 +0000 (07:04 +0000)
svn path=/trunk/; revision=29012

reactos/tools/rbuild/automaticdependency.cpp
reactos/tools/rbuild/backend/codeblocks/codeblocks.cpp
reactos/tools/rbuild/backend/mingw/modulehandler.cpp
reactos/tools/rbuild/backend/msbuild/msbuild.cpp
reactos/tools/rbuild/backend/msvc/msvcmaker.cpp
reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp
reactos/tools/rbuild/compilationunit.cpp
reactos/tools/rbuild/module.cpp
reactos/tools/rbuild/rbuild.h
reactos/tools/rbuild/testsupportcode.cpp
reactos/tools/rbuild/wineresource.cpp

index 98d5f4a..e1b9f86 100644 (file)
@@ -27,6 +27,18 @@ using std::string;
 using std::vector;
 using std::map;
 
+static std::string
+GetExtension ( const std::string& filename )
+{
+       size_t index = filename.find_last_of ( '/' );
+       if (index == string::npos) index = 0;
+       string tmp = filename.substr( index, filename.size() - index );
+       size_t ext_index = tmp.find_last_of( '.' );
+       if (ext_index != string::npos)
+               return filename.substr ( index + ext_index, filename.size() );
+       return "";
+}
+
 SourceFile::SourceFile ( AutomaticDependency* automaticDependency,
                          const Module& module,
                          const string& filename,
@@ -409,17 +421,6 @@ AutomaticDependency::LocateIncludedFile ( const FileLocation& directory,
        return false;
 }
 
-string
-AutomaticDependency::GetFilename ( const string& filename )
-{
-       size_t index = filename.find_last_of ( cSep );
-       if (index == string::npos)
-               return filename;
-       else
-               return filename.substr ( index + 1,
-                                        filename.length () - index - 1);
-}
-
 void
 AutomaticDependency::GetIncludeDirectories ( vector<Include*>& includes,
                                              const Module& module,
index 28610ca..facc236 100644 (file)
@@ -101,6 +101,18 @@ void CBBackend::ProcessModules()
        }
 }
 
+static std::string
+GetExtension ( const std::string& filename )
+{
+       size_t index = filename.find_last_of ( '/' );
+       if (index == string::npos) index = 0;
+       string tmp = filename.substr( index, filename.size() - index );
+       size_t ext_index = tmp.find_last_of( '.' );
+       if (ext_index != string::npos)
+               return filename.substr ( index + ext_index, filename.size() );
+       return "";
+}
+
 static bool FileExists(string &filename)
 {
        ifstream file(filename.c_str());
@@ -342,7 +354,7 @@ CBBackend::_generate_cbproj ( const Module& module )
        string path_basedir = module.GetPathToBaseDir ();
        string intenv = Environment::GetIntermediatePath ();
        string outenv = Environment::GetOutputPath ();
-       string module_type = GetExtension(module.output->name);
+       string module_type = GetExtension(*module.output);
        string cbproj_path = module.output->relative_path;
        string CompilerVar;
        string baseaddr;
index a135c1f..62ac3f5 100644 (file)
@@ -266,7 +266,7 @@ MingwModuleHandler::GetActualSourceFilename (
 {
        string filename = file->name;
 
-       string extension = GetExtension ( filename );
+       string extension = GetExtension ( *file );
        if ( extension == ".spec" || extension == ".SPEC" )
        {
                string basename = GetBasename ( filename );
@@ -305,7 +305,7 @@ string
 MingwModuleHandler::GetExtraDependencies (
        const FileLocation *file ) const
 {
-       string extension = GetExtension ( file->name );
+       string extension = GetExtension ( *file );
        if ( extension == ".idl" || extension == ".IDL" )
        {
                if ( (module.type == RpcServer) || (module.type == RpcClient) )
@@ -349,7 +349,7 @@ MingwModuleHandler::GetModuleArchiveFilename () const
 bool
 MingwModuleHandler::IsGeneratedFile ( const File& file ) const
 {
-       string extension = GetExtension ( file.file.name );
+       string extension = GetExtension ( file.file );
        return ( extension == ".spec" || extension == ".SPEC" );
 }
 
@@ -486,10 +486,9 @@ MingwModuleHandler::GetObjectFilename (
        const FileLocation* sourceFile,
        string_list* pclean_files ) const
 {
-       string sourceFilename = sourceFile->name;
        DirectoryLocation destination_directory;
        string newExtension;
-       string extension = GetExtension ( sourceFilename );
+       string extension = GetExtension ( *sourceFile );
        if ( extension == ".rc" || extension == ".RC" )
                newExtension = ".coff";
        else if ( extension == ".spec" || extension == ".SPEC" )
@@ -1353,8 +1352,7 @@ MingwModuleHandler::GenerateCommands (
        const string& widlflagsMacro )
 {
        const FileLocation* sourceFile = compilationUnit.GetFilename ();
-       string filename = backend->GetFullName ( *sourceFile );
-       string extension = GetExtension ( filename );
+       string extension = GetExtension ( *sourceFile );
        if ( extension == ".c" || extension == ".C" )
        {
                GenerateGccCommand ( sourceFile,
@@ -1419,7 +1417,7 @@ MingwModuleHandler::GenerateCommands (
                                          __LINE__,
                                          "Unsupported filename extension '%s' in file '%s'",
                                          extension.c_str (),
-                                         filename.c_str () );
+                                         backend->GetFullName ( *sourceFile ).c_str () );
 }
 
 void
@@ -1465,10 +1463,9 @@ MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
        fprintf ( fMakefile,
                  "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
 
-       string filename = module.output->name;
        FileLocation nostripFilename ( OutputDirectory,
                                       module.output->relative_path,
-                                      GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ) );
+                                      GetBasename ( module.output->name ) + ".nostrip" + GetExtension ( *module.output ) );
        CLEAN_FILE ( nostripFilename );
 
        OutputCopyCommand ( *module.output, nostripFilename );
@@ -1881,7 +1878,7 @@ MingwModuleHandler::GetRpcHeaderDependencies (
                        {
                                CompilationUnit& compilationUnit = *library.importedModule->non_if_data.compilationUnits[j];
                                const FileLocation* sourceFile = compilationUnit.GetFilename ();
-                               string extension = GetExtension ( sourceFile->name );
+                               string extension = GetExtension ( *sourceFile );
                                if ( extension == ".idl" || extension == ".IDL" )
                                {
                                        string basename = GetBasename ( sourceFile->name );
@@ -1921,7 +1918,7 @@ MingwModuleHandler::GenerateOtherMacros ()
                {
                        CompilationUnit& compilationUnit = *compilationUnits[i];
                        const FileLocation* sourceFile = compilationUnit.GetFilename ();
-                       string extension = GetExtension ( sourceFile->name );
+                       string extension = GetExtension ( *sourceFile );
                        if ( extension == ".spec" || extension == ".SPEC" )
                                GetSpecObjectDependencies ( s, sourceFile );
                }
@@ -2300,7 +2297,7 @@ MingwModuleHandler::GetDefinitionDependencies (
        {
                CompilationUnit& compilationUnit = *compilationUnits[i];
                const FileLocation* sourceFile = compilationUnit.GetFilename ();
-               string extension = GetExtension ( sourceFile->name );
+               string extension = GetExtension ( *sourceFile );
                if ( extension == ".spec" || extension == ".SPEC" )
                        GetSpecObjectDependencies ( dependencies, sourceFile );
                if ( extension == ".idl" || extension == ".IDL" )
index 422e39c..f234e8b 100644 (file)
@@ -83,7 +83,7 @@ MsBuildBackend::_generate_sources ( const Module& module )
 {\r
        size_t i;\r
 \r
-       string module_type = GetExtension(module.output->name);\r
+       string module_type = GetExtension(*module.output);\r
        vector<string> source_files, resource_files, includes, libraries;\r
        vector<string> header_files, common_defines, compiler_flags;\r
        vector<string> vars, values;\r
index 2e51e63..8581163 100644 (file)
@@ -56,7 +56,7 @@ MSVCBackend::_generate_dsp ( const Module& module )
                imports.push_back ( module.non_if_data.libraries[i]->name );
        }
 
-       string module_type = GetExtension(module.output->name);
+       string module_type = GetExtension(*module.output);
        bool lib = (module_type == ".lib") || (module_type == ".a");
        bool dll = (module_type == ".dll") || (module_type == ".cpl");
        bool exe = (module_type == ".exe") || (module_type == ".scr");
index 8c09b25..a3aa58e 100644 (file)
@@ -98,7 +98,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        FILE* OUT = fopen ( vcproj_file.c_str(), "wb" );
 
        vector<string> imports;
-       string module_type = GetExtension(module.output->name);
+       string module_type = GetExtension(*module.output);
        bool lib = (module.type == ObjectLibrary) || (module.type == RpcClient) ||(module.type == RpcServer) || (module_type == ".lib") || (module_type == ".a");
        bool dll = (module_type == ".dll") || (module_type == ".cpl");
        bool exe = (module_type == ".exe") || (module_type == ".scr");
index b827070..27c483b 100644 (file)
@@ -67,7 +67,7 @@ CompilationUnit::IsGeneratedFile () const
        if ( files.size () != 1 )
                return false;
        File* file = files[0];
-       string extension = GetExtension ( file->file.name );
+       string extension = GetExtension ( file->file );
        return ( extension == ".spec" || extension == ".SPEC" );
 }
 
@@ -78,7 +78,7 @@ CompilationUnit::HasFileWithExtension ( const std::string& extension ) const
        for ( i = 0; i < files.size (); i++ )
        {
                File& file = *files[i];
-               string fileExtension = GetExtension ( file.file.name );
+               string fileExtension = GetExtension ( file.file );
                if ( !stricmp ( fileExtension.c_str (), extension.c_str () ) )
                        return true;
        }
index f535a56..f947afd 100644 (file)
@@ -137,7 +137,7 @@ GetSubPath (
        return FixSeparator(path + cSep + att_value);
 }
 
-string
+static string
 GetExtension ( const string& filename )
 {
        size_t index = filename.find_last_of ( '/' );
@@ -150,23 +150,9 @@ GetExtension ( const string& filename )
 }
 
 string
-GetDirectory ( const string& filename )
-{
-       size_t index = filename.find_last_of ( cSep );
-       if ( index == string::npos )
-               return "";
-       else
-               return filename.substr ( 0, index );
-}
-
-string
-GetFilename ( const string& filename )
+GetExtension ( const FileLocation& file )
 {
-       size_t index = filename.find_last_of ( cSep );
-       if ( index == string::npos )
-               return filename;
-       else
-               return filename.substr ( index + 1, filename.length () - index );
+       return GetExtension ( file.name );
 }
 
 string
index 2e2a718..f0ed8f0 100644 (file)
@@ -775,7 +775,6 @@ public:
 
        AutomaticDependency ( const Project& project );
        ~AutomaticDependency ();
-       std::string GetFilename ( const std::string& filename );
        bool LocateIncludedFile ( const FileLocation& directory,
                                  const std::string& includedFilename,
                                  std::string& resolvedFilename );
@@ -1030,13 +1029,7 @@ GetSubPath (
        const std::string& att_value );
 
 extern std::string
-GetExtension ( const std::string& filename );
-
-extern std::string
-GetDirectory ( const std::string& filename );
-
-extern std::string
-GetFilename ( const std::string& filename );
+GetExtension ( const FileLocation& file );
 
 extern std::string
 NormalizeFilename ( const std::string& filename );
index 67752bb..e076c6e 100644 (file)
 using std::string;
 using std::vector;
 
+static std::string
+GetFilename ( const std::string& filename )
+{
+       size_t index = filename.find_last_of ( cSep );
+       if ( index == string::npos )
+               return filename;
+       else
+               return filename.substr ( index + 1, filename.length () - index );
+}
+
 TestSupportCode::TestSupportCode ( const Project& project )
        : project ( project )
 {
index 2127ef4..4e246be 100644 (file)
@@ -37,7 +37,7 @@ WineResource::~WineResource ()
 bool
 WineResource::IsSpecFile ( const File& file )
 {
-       string extension = GetExtension ( file.file.name );
+       string extension = GetExtension ( file.file );
        if ( extension == ".spec" || extension == ".SPEC" )
                return true;
        return false;
@@ -58,7 +58,7 @@ WineResource::IsWineModule ( const Module& module )
 bool
 WineResource::IsResourceFile ( const File& file )
 {
-       string extension = GetExtension ( file.file.name );
+       string extension = GetExtension ( file.file );
        if ( extension == ".rc" || extension == ".RC" )
                return true;
        return false;